1 //===-- ScriptInterpreter.h -------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ScriptInterpreter_h_
11 #define liblldb_ScriptInterpreter_h_
13 #include "lldb/lldb-private.h"
15 #include "lldb/Breakpoint/BreakpointOptions.h"
16 #include "lldb/Core/PluginInterface.h"
17 #include "lldb/Core/SearchFilter.h"
18 #include "lldb/Utility/Broadcaster.h"
19 #include "lldb/Utility/Status.h"
20 #include "lldb/Utility/StructuredData.h"
22 #include "lldb/Host/PseudoTerminal.h"
24 namespace lldb_private {
26 class ScriptInterpreterLocker {
28 ScriptInterpreterLocker() = default;
30 virtual ~ScriptInterpreterLocker() = default;
33 DISALLOW_COPY_AND_ASSIGN(ScriptInterpreterLocker);
36 class ScriptInterpreter : public PluginInterface {
39 eScriptReturnTypeCharPtr,
40 eScriptReturnTypeBool,
41 eScriptReturnTypeShortInt,
42 eScriptReturnTypeShortIntUnsigned,
44 eScriptReturnTypeIntUnsigned,
45 eScriptReturnTypeLongInt,
46 eScriptReturnTypeLongIntUnsigned,
47 eScriptReturnTypeLongLong,
48 eScriptReturnTypeLongLongUnsigned,
49 eScriptReturnTypeFloat,
50 eScriptReturnTypeDouble,
51 eScriptReturnTypeChar,
52 eScriptReturnTypeCharStrOrNone,
53 eScriptReturnTypeOpaqueObject
56 ScriptInterpreter(CommandInterpreter &interpreter,
57 lldb::ScriptLanguage script_lang);
59 ~ScriptInterpreter() override;
61 struct ExecuteScriptOptions {
63 ExecuteScriptOptions()
64 : m_enable_io(true), m_set_lldb_globals(true), m_maskout_errors(true) {}
66 bool GetEnableIO() const { return m_enable_io; }
68 bool GetSetLLDBGlobals() const { return m_set_lldb_globals; }
70 bool GetMaskoutErrors() const { return m_maskout_errors; }
72 ExecuteScriptOptions &SetEnableIO(bool enable) {
77 ExecuteScriptOptions &SetSetLLDBGlobals(bool set) {
78 m_set_lldb_globals = set;
82 ExecuteScriptOptions &SetMaskoutErrors(bool maskout) {
83 m_maskout_errors = maskout;
89 bool m_set_lldb_globals;
90 bool m_maskout_errors;
93 virtual bool Interrupt() { return false; }
95 virtual bool ExecuteOneLine(
96 llvm::StringRef command, CommandReturnObject *result,
97 const ExecuteScriptOptions &options = ExecuteScriptOptions()) = 0;
99 virtual void ExecuteInterpreterLoop() = 0;
101 virtual bool ExecuteOneLineWithReturn(
102 llvm::StringRef in_string, ScriptReturnType return_type, void *ret_value,
103 const ExecuteScriptOptions &options = ExecuteScriptOptions()) {
107 virtual Status ExecuteMultipleLines(
108 const char *in_string,
109 const ExecuteScriptOptions &options = ExecuteScriptOptions()) {
111 error.SetErrorString("not implemented");
116 ExportFunctionDefinitionToInterpreter(StringList &function_def) {
118 error.SetErrorString("not implemented");
122 virtual Status GenerateBreakpointCommandCallbackData(StringList &input,
123 std::string &output) {
125 error.SetErrorString("not implemented");
129 virtual bool GenerateWatchpointCommandCallbackData(StringList &input,
130 std::string &output) {
134 virtual bool GenerateTypeScriptFunction(const char *oneliner,
136 const void *name_token = nullptr) {
140 virtual bool GenerateTypeScriptFunction(StringList &input,
142 const void *name_token = nullptr) {
146 virtual bool GenerateScriptAliasFunction(StringList &input,
147 std::string &output) {
151 virtual bool GenerateTypeSynthClass(StringList &input, std::string &output,
152 const void *name_token = nullptr) {
156 virtual bool GenerateTypeSynthClass(const char *oneliner, std::string &output,
157 const void *name_token = nullptr) {
161 virtual StructuredData::ObjectSP
162 CreateSyntheticScriptedProvider(const char *class_name,
163 lldb::ValueObjectSP valobj) {
164 return StructuredData::ObjectSP();
167 virtual StructuredData::GenericSP
168 CreateScriptCommandObject(const char *class_name) {
169 return StructuredData::GenericSP();
172 virtual StructuredData::GenericSP
173 CreateFrameRecognizer(const char *class_name) {
174 return StructuredData::GenericSP();
177 virtual lldb::ValueObjectListSP GetRecognizedArguments(
178 const StructuredData::ObjectSP &implementor,
179 lldb::StackFrameSP frame_sp) {
180 return lldb::ValueObjectListSP();
183 virtual StructuredData::GenericSP
184 OSPlugin_CreatePluginObject(const char *class_name,
185 lldb::ProcessSP process_sp) {
186 return StructuredData::GenericSP();
189 virtual StructuredData::DictionarySP
190 OSPlugin_RegisterInfo(StructuredData::ObjectSP os_plugin_object_sp) {
191 return StructuredData::DictionarySP();
194 virtual StructuredData::ArraySP
195 OSPlugin_ThreadsInfo(StructuredData::ObjectSP os_plugin_object_sp) {
196 return StructuredData::ArraySP();
199 virtual StructuredData::StringSP
200 OSPlugin_RegisterContextData(StructuredData::ObjectSP os_plugin_object_sp,
201 lldb::tid_t thread_id) {
202 return StructuredData::StringSP();
205 virtual StructuredData::DictionarySP
206 OSPlugin_CreateThread(StructuredData::ObjectSP os_plugin_object_sp,
207 lldb::tid_t tid, lldb::addr_t context) {
208 return StructuredData::DictionarySP();
211 virtual StructuredData::ObjectSP
212 CreateScriptedThreadPlan(const char *class_name,
213 lldb::ThreadPlanSP thread_plan_sp) {
214 return StructuredData::ObjectSP();
218 ScriptedThreadPlanExplainsStop(StructuredData::ObjectSP implementor_sp,
219 Event *event, bool &script_error) {
225 ScriptedThreadPlanShouldStop(StructuredData::ObjectSP implementor_sp,
226 Event *event, bool &script_error) {
232 ScriptedThreadPlanIsStale(StructuredData::ObjectSP implementor_sp,
233 bool &script_error) {
238 virtual lldb::StateType
239 ScriptedThreadPlanGetRunState(StructuredData::ObjectSP implementor_sp,
240 bool &script_error) {
242 return lldb::eStateStepping;
245 virtual StructuredData::GenericSP
246 CreateScriptedBreakpointResolver(const char *class_name,
247 StructuredDataImpl *args_data,
248 lldb::BreakpointSP &bkpt_sp) {
249 return StructuredData::GenericSP();
253 ScriptedBreakpointResolverSearchCallback(StructuredData::GenericSP implementor_sp,
254 SymbolContext *sym_ctx)
259 virtual lldb::SearchDepth
260 ScriptedBreakpointResolverSearchDepth(StructuredData::GenericSP implementor_sp)
262 return lldb::eSearchDepthModule;
265 virtual StructuredData::ObjectSP
266 LoadPluginModule(const FileSpec &file_spec, lldb_private::Status &error) {
267 return StructuredData::ObjectSP();
270 virtual StructuredData::DictionarySP
271 GetDynamicSettings(StructuredData::ObjectSP plugin_module_sp, Target *target,
272 const char *setting_name, lldb_private::Status &error) {
273 return StructuredData::DictionarySP();
276 virtual Status GenerateFunction(const char *signature,
277 const StringList &input) {
279 error.SetErrorString("unimplemented");
283 virtual void CollectDataForBreakpointCommandCallback(
284 std::vector<BreakpointOptions *> &options, CommandReturnObject &result);
287 CollectDataForWatchpointCommandCallback(WatchpointOptions *wp_options,
288 CommandReturnObject &result);
290 /// Set the specified text as the callback for the breakpoint.
292 SetBreakpointCommandCallback(std::vector<BreakpointOptions *> &bp_options_vec,
293 const char *callback_text);
295 virtual Status SetBreakpointCommandCallback(BreakpointOptions *bp_options,
296 const char *callback_text) {
298 error.SetErrorString("unimplemented");
302 /// This one is for deserialization:
303 virtual Status SetBreakpointCommandCallback(
304 BreakpointOptions *bp_options,
305 std::unique_ptr<BreakpointOptions::CommandData> &data_up) {
307 error.SetErrorString("unimplemented");
311 void SetBreakpointCommandCallbackFunction(
312 std::vector<BreakpointOptions *> &bp_options_vec,
313 const char *function_name);
315 /// Set a one-liner as the callback for the breakpoint.
317 SetBreakpointCommandCallbackFunction(BreakpointOptions *bp_options,
318 const char *function_name) {}
320 /// Set a one-liner as the callback for the watchpoint.
321 virtual void SetWatchpointCommandCallback(WatchpointOptions *wp_options,
322 const char *oneliner) {}
324 virtual bool GetScriptedSummary(const char *function_name,
325 lldb::ValueObjectSP valobj,
326 StructuredData::ObjectSP &callee_wrapper_sp,
327 const TypeSummaryOptions &options,
328 std::string &retval) {
332 virtual void Clear() {
333 // Clean up any ref counts to SBObjects that might be in global variables
337 CalculateNumChildren(const StructuredData::ObjectSP &implementor,
342 virtual lldb::ValueObjectSP
343 GetChildAtIndex(const StructuredData::ObjectSP &implementor, uint32_t idx) {
344 return lldb::ValueObjectSP();
348 GetIndexOfChildWithName(const StructuredData::ObjectSP &implementor,
349 const char *child_name) {
354 UpdateSynthProviderInstance(const StructuredData::ObjectSP &implementor) {
358 virtual bool MightHaveChildrenSynthProviderInstance(
359 const StructuredData::ObjectSP &implementor) {
363 virtual lldb::ValueObjectSP
364 GetSyntheticValue(const StructuredData::ObjectSP &implementor) {
369 GetSyntheticTypeName(const StructuredData::ObjectSP &implementor) {
370 return ConstString();
374 RunScriptBasedCommand(const char *impl_function, llvm::StringRef args,
375 ScriptedCommandSynchronicity synchronicity,
376 lldb_private::CommandReturnObject &cmd_retobj,
378 const lldb_private::ExecutionContext &exe_ctx) {
382 virtual bool RunScriptBasedCommand(
383 StructuredData::GenericSP impl_obj_sp, llvm::StringRef args,
384 ScriptedCommandSynchronicity synchronicity,
385 lldb_private::CommandReturnObject &cmd_retobj, Status &error,
386 const lldb_private::ExecutionContext &exe_ctx) {
390 virtual bool RunScriptFormatKeyword(const char *impl_function,
391 Process *process, std::string &output,
393 error.SetErrorString("unimplemented");
397 virtual bool RunScriptFormatKeyword(const char *impl_function, Thread *thread,
398 std::string &output, Status &error) {
399 error.SetErrorString("unimplemented");
403 virtual bool RunScriptFormatKeyword(const char *impl_function, Target *target,
404 std::string &output, Status &error) {
405 error.SetErrorString("unimplemented");
409 virtual bool RunScriptFormatKeyword(const char *impl_function,
410 StackFrame *frame, std::string &output,
412 error.SetErrorString("unimplemented");
416 virtual bool RunScriptFormatKeyword(const char *impl_function,
417 ValueObject *value, std::string &output,
419 error.SetErrorString("unimplemented");
423 virtual bool GetDocumentationForItem(const char *item, std::string &dest) {
429 GetShortHelpForCommandObject(StructuredData::GenericSP cmd_obj_sp,
436 GetFlagsForCommandObject(StructuredData::GenericSP cmd_obj_sp) {
440 virtual bool GetLongHelpForCommandObject(StructuredData::GenericSP cmd_obj_sp,
446 virtual bool CheckObjectExists(const char *name) { return false; }
449 LoadScriptingModule(const char *filename, bool can_reload, bool init_session,
450 lldb_private::Status &error,
451 StructuredData::ObjectSP *module_sp = nullptr) {
452 error.SetErrorString("loading unimplemented");
456 virtual bool IsReservedWord(const char *word) { return false; }
458 virtual std::unique_ptr<ScriptInterpreterLocker> AcquireInterpreterLock();
460 const char *GetScriptInterpreterPtyName();
462 int GetMasterFileDescriptor();
464 CommandInterpreter &GetCommandInterpreter();
466 static std::string LanguageToString(lldb::ScriptLanguage language);
468 static lldb::ScriptLanguage StringToLanguage(const llvm::StringRef &string);
470 virtual void ResetOutputFileHandle(FILE *new_fh) {} // By default, do nothing.
472 lldb::ScriptLanguage GetLanguage() { return m_script_lang; }
475 CommandInterpreter &m_interpreter;
476 lldb::ScriptLanguage m_script_lang;
479 } // namespace lldb_private
481 #endif // liblldb_ScriptInterpreter_h_