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_
15 // Other libraries and framework includes
17 #include "lldb/lldb-private.h"
19 #include "lldb/Core/Broadcaster.h"
20 #include "lldb/Core/Error.h"
21 #include "lldb/Core/PluginInterface.h"
22 #include "lldb/Core/StructuredData.h"
24 #include "lldb/Utility/PseudoTerminal.h"
26 namespace lldb_private {
28 class ScriptInterpreterLocker
32 ScriptInterpreterLocker() = default;
34 virtual ~ScriptInterpreterLocker() = default;
37 DISALLOW_COPY_AND_ASSIGN (ScriptInterpreterLocker);
40 class ScriptInterpreter : public PluginInterface
45 eScriptReturnTypeCharPtr,
46 eScriptReturnTypeBool,
47 eScriptReturnTypeShortInt,
48 eScriptReturnTypeShortIntUnsigned,
50 eScriptReturnTypeIntUnsigned,
51 eScriptReturnTypeLongInt,
52 eScriptReturnTypeLongIntUnsigned,
53 eScriptReturnTypeLongLong,
54 eScriptReturnTypeLongLongUnsigned,
55 eScriptReturnTypeFloat,
56 eScriptReturnTypeDouble,
57 eScriptReturnTypeChar,
58 eScriptReturnTypeCharStrOrNone,
59 eScriptReturnTypeOpaqueObject
62 ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang);
64 ~ScriptInterpreter() override;
66 struct ExecuteScriptOptions
69 ExecuteScriptOptions () :
71 m_set_lldb_globals(true),
72 m_maskout_errors(true)
83 GetSetLLDBGlobals () const
85 return m_set_lldb_globals;
89 GetMaskoutErrors () const
91 return m_maskout_errors;
95 SetEnableIO (bool enable)
101 ExecuteScriptOptions&
102 SetSetLLDBGlobals (bool set)
104 m_set_lldb_globals = set;
108 ExecuteScriptOptions&
109 SetMaskoutErrors (bool maskout)
111 m_maskout_errors = maskout;
117 bool m_set_lldb_globals;
118 bool m_maskout_errors;
128 ExecuteOneLine (const char *command,
129 CommandReturnObject *result,
130 const ExecuteScriptOptions &options = ExecuteScriptOptions()) = 0;
133 ExecuteInterpreterLoop () = 0;
136 ExecuteOneLineWithReturn (const char *in_string,
137 ScriptReturnType return_type,
139 const ExecuteScriptOptions &options = ExecuteScriptOptions())
145 ExecuteMultipleLines (const char *in_string,
146 const ExecuteScriptOptions &options = ExecuteScriptOptions())
149 error.SetErrorString("not implemented");
154 ExportFunctionDefinitionToInterpreter (StringList &function_def)
157 error.SetErrorString("not implemented");
162 GenerateBreakpointCommandCallbackData (StringList &input, std::string& output)
165 error.SetErrorString("not implemented");
170 GenerateWatchpointCommandCallbackData (StringList &input, std::string& output)
176 GenerateTypeScriptFunction(const char* oneliner, std::string& output, const void* name_token = nullptr)
182 GenerateTypeScriptFunction(StringList &input, std::string& output, const void* name_token = nullptr)
188 GenerateScriptAliasFunction (StringList &input, std::string& output)
194 GenerateTypeSynthClass(StringList &input, std::string& output, const void* name_token = nullptr)
200 GenerateTypeSynthClass(const char* oneliner, std::string& output, const void* name_token = nullptr)
205 virtual StructuredData::ObjectSP
206 CreateSyntheticScriptedProvider(const char *class_name, lldb::ValueObjectSP valobj)
208 return StructuredData::ObjectSP();
211 virtual StructuredData::GenericSP
212 CreateScriptCommandObject (const char *class_name)
214 return StructuredData::GenericSP();
217 virtual StructuredData::GenericSP
218 OSPlugin_CreatePluginObject (const char *class_name,
219 lldb::ProcessSP process_sp)
221 return StructuredData::GenericSP();
224 virtual StructuredData::DictionarySP
225 OSPlugin_RegisterInfo(StructuredData::ObjectSP os_plugin_object_sp)
227 return StructuredData::DictionarySP();
230 virtual StructuredData::ArraySP
231 OSPlugin_ThreadsInfo(StructuredData::ObjectSP os_plugin_object_sp)
233 return StructuredData::ArraySP();
236 virtual StructuredData::StringSP
237 OSPlugin_RegisterContextData(StructuredData::ObjectSP os_plugin_object_sp, lldb::tid_t thread_id)
239 return StructuredData::StringSP();
242 virtual StructuredData::DictionarySP
243 OSPlugin_CreateThread(StructuredData::ObjectSP os_plugin_object_sp, lldb::tid_t tid, lldb::addr_t context)
245 return StructuredData::DictionarySP();
248 virtual StructuredData::ObjectSP
249 CreateScriptedThreadPlan(const char *class_name, lldb::ThreadPlanSP thread_plan_sp)
251 return StructuredData::ObjectSP();
255 ScriptedThreadPlanExplainsStop(StructuredData::ObjectSP implementor_sp, Event *event, bool &script_error)
262 ScriptedThreadPlanShouldStop(StructuredData::ObjectSP implementor_sp, Event *event, bool &script_error)
268 virtual lldb::StateType
269 ScriptedThreadPlanGetRunState(StructuredData::ObjectSP implementor_sp, bool &script_error)
272 return lldb::eStateStepping;
275 virtual StructuredData::ObjectSP
276 LoadPluginModule(const FileSpec &file_spec, lldb_private::Error &error)
278 return StructuredData::ObjectSP();
281 virtual StructuredData::DictionarySP
282 GetDynamicSettings(StructuredData::ObjectSP plugin_module_sp, Target *target, const char *setting_name, lldb_private::Error &error)
284 return StructuredData::DictionarySP();
288 GenerateFunction(const char *signature, const StringList &input)
291 error.SetErrorString("unimplemented");
296 CollectDataForBreakpointCommandCallback (std::vector<BreakpointOptions *> &options,
297 CommandReturnObject &result);
300 CollectDataForWatchpointCommandCallback (WatchpointOptions *wp_options,
301 CommandReturnObject &result);
303 /// Set the specified text as the callback for the breakpoint.
305 SetBreakpointCommandCallback (std::vector<BreakpointOptions *> &bp_options_vec,
306 const char *callback_text);
309 SetBreakpointCommandCallback (BreakpointOptions *bp_options,
310 const char *callback_text)
313 error.SetErrorString("unimplemented");
318 SetBreakpointCommandCallbackFunction (std::vector<BreakpointOptions *> &bp_options_vec,
319 const char *function_name);
321 /// Set a one-liner as the callback for the breakpoint.
323 SetBreakpointCommandCallbackFunction (BreakpointOptions *bp_options,
324 const char *function_name)
328 /// Set a one-liner as the callback for the watchpoint.
330 SetWatchpointCommandCallback (WatchpointOptions *wp_options,
331 const char *oneliner)
336 GetScriptedSummary(const char *function_name, lldb::ValueObjectSP valobj, StructuredData::ObjectSP &callee_wrapper_sp,
337 const TypeSummaryOptions &options, std::string &retval)
345 // Clean up any ref counts to SBObjects that might be in global variables
349 CalculateNumChildren(const StructuredData::ObjectSP &implementor, uint32_t max)
354 virtual lldb::ValueObjectSP
355 GetChildAtIndex(const StructuredData::ObjectSP &implementor, uint32_t idx)
357 return lldb::ValueObjectSP();
361 GetIndexOfChildWithName(const StructuredData::ObjectSP &implementor, const char *child_name)
367 UpdateSynthProviderInstance(const StructuredData::ObjectSP &implementor)
373 MightHaveChildrenSynthProviderInstance(const StructuredData::ObjectSP &implementor)
378 virtual lldb::ValueObjectSP
379 GetSyntheticValue(const StructuredData::ObjectSP &implementor)
385 GetSyntheticTypeName (const StructuredData::ObjectSP &implementor)
387 return ConstString();
391 RunScriptBasedCommand (const char* impl_function,
393 ScriptedCommandSynchronicity synchronicity,
394 lldb_private::CommandReturnObject& cmd_retobj,
396 const lldb_private::ExecutionContext& exe_ctx)
402 RunScriptBasedCommand (StructuredData::GenericSP impl_obj_sp,
404 ScriptedCommandSynchronicity synchronicity,
405 lldb_private::CommandReturnObject& cmd_retobj,
407 const lldb_private::ExecutionContext& exe_ctx)
413 RunScriptFormatKeyword (const char* impl_function,
418 error.SetErrorString("unimplemented");
423 RunScriptFormatKeyword (const char* impl_function,
428 error.SetErrorString("unimplemented");
433 RunScriptFormatKeyword (const char* impl_function,
438 error.SetErrorString("unimplemented");
443 RunScriptFormatKeyword (const char* impl_function,
448 error.SetErrorString("unimplemented");
453 RunScriptFormatKeyword (const char* impl_function,
458 error.SetErrorString("unimplemented");
463 GetDocumentationForItem (const char* item, std::string& dest)
470 GetShortHelpForCommandObject (StructuredData::GenericSP cmd_obj_sp,
478 GetFlagsForCommandObject (StructuredData::GenericSP cmd_obj_sp)
484 GetLongHelpForCommandObject (StructuredData::GenericSP cmd_obj_sp,
492 CheckObjectExists (const char* name)
498 LoadScriptingModule(const char *filename, bool can_reload, bool init_session, lldb_private::Error &error,
499 StructuredData::ObjectSP *module_sp = nullptr)
501 error.SetErrorString("loading unimplemented");
506 IsReservedWord (const char* word)
511 virtual std::unique_ptr<ScriptInterpreterLocker>
512 AcquireInterpreterLock ();
515 GetScriptInterpreterPtyName ();
518 GetMasterFileDescriptor ();
521 GetCommandInterpreter();
524 LanguageToString (lldb::ScriptLanguage language);
527 ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing.
530 CommandInterpreter &m_interpreter;
531 lldb::ScriptLanguage m_script_lang;
534 } // namespace lldb_private
536 #endif // liblldb_ScriptInterpreter_h_