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/Core/Broadcaster.h"
16 #include "lldb/Core/Error.h"
18 #include "lldb/Utility/PseudoTerminal.h"
21 namespace lldb_private {
23 class ScriptInterpreterObject
26 ScriptInterpreterObject() :
30 ScriptInterpreterObject(void* obj) :
34 ScriptInterpreterObject(const ScriptInterpreterObject& rhs)
35 : m_object(rhs.m_object)
44 explicit operator bool ()
46 return m_object != NULL;
49 ScriptInterpreterObject&
50 operator = (const ScriptInterpreterObject& rhs)
53 m_object = rhs.m_object;
58 ~ScriptInterpreterObject()
65 class ScriptInterpreterLocker
69 ScriptInterpreterLocker ()
73 virtual ~ScriptInterpreterLocker ()
77 DISALLOW_COPY_AND_ASSIGN (ScriptInterpreterLocker);
81 class ScriptInterpreter
85 typedef void (*SWIGInitCallback) (void);
87 typedef bool (*SWIGBreakpointCallbackFunction) (const char *python_function_name,
88 const char *session_dictionary_name,
89 const lldb::StackFrameSP& frame_sp,
90 const lldb::BreakpointLocationSP &bp_loc_sp);
92 typedef bool (*SWIGWatchpointCallbackFunction) (const char *python_function_name,
93 const char *session_dictionary_name,
94 const lldb::StackFrameSP& frame_sp,
95 const lldb::WatchpointSP &wp_sp);
97 typedef bool (*SWIGPythonTypeScriptCallbackFunction) (const char *python_function_name,
98 void *session_dictionary,
99 const lldb::ValueObjectSP& valobj_sp,
100 void** pyfunct_wrapper,
101 const lldb::TypeSummaryOptionsSP& options,
102 std::string& retval);
104 typedef void* (*SWIGPythonCreateSyntheticProvider) (const char *python_class_name,
105 const char *session_dictionary_name,
106 const lldb::ValueObjectSP& valobj_sp);
108 typedef void* (*SWIGPythonCreateScriptedThreadPlan) (const char *python_class_name,
109 const char *session_dictionary_name,
110 const lldb::ThreadPlanSP& thread_plan_sp);
112 typedef bool (*SWIGPythonCallThreadPlan) (void *implementor, const char *method_name, Event *event_sp, bool &got_error);
114 typedef void* (*SWIGPythonCreateOSPlugin) (const char *python_class_name,
115 const char *session_dictionary_name,
116 const lldb::ProcessSP& process_sp);
118 typedef uint32_t (*SWIGPythonCalculateNumChildren) (void *implementor);
119 typedef void* (*SWIGPythonGetChildAtIndex) (void *implementor, uint32_t idx);
120 typedef int (*SWIGPythonGetIndexOfChildWithName) (void *implementor, const char* child_name);
121 typedef void* (*SWIGPythonCastPyObjectToSBValue) (void* data);
122 typedef lldb::ValueObjectSP (*SWIGPythonGetValueObjectSPFromSBValue) (void* data);
123 typedef bool (*SWIGPythonUpdateSynthProviderInstance) (void* data);
124 typedef bool (*SWIGPythonMightHaveChildrenSynthProviderInstance) (void* data);
125 typedef void* (*SWIGPythonGetValueSynthProviderInstance) (void *implementor);
127 typedef bool (*SWIGPythonCallCommand) (const char *python_function_name,
128 const char *session_dictionary_name,
129 lldb::DebuggerSP& debugger,
131 lldb_private::CommandReturnObject& cmd_retobj,
132 lldb::ExecutionContextRefSP exe_ctx_ref_sp);
134 typedef bool (*SWIGPythonCallModuleInit) (const char *python_module_name,
135 const char *session_dictionary_name,
136 lldb::DebuggerSP& debugger);
138 typedef bool (*SWIGPythonScriptKeyword_Process) (const char* python_function_name,
139 const char* session_dictionary_name,
140 lldb::ProcessSP& process,
141 std::string& output);
142 typedef bool (*SWIGPythonScriptKeyword_Thread) (const char* python_function_name,
143 const char* session_dictionary_name,
144 lldb::ThreadSP& thread,
145 std::string& output);
147 typedef bool (*SWIGPythonScriptKeyword_Target) (const char* python_function_name,
148 const char* session_dictionary_name,
149 lldb::TargetSP& target,
150 std::string& output);
152 typedef bool (*SWIGPythonScriptKeyword_Frame) (const char* python_function_name,
153 const char* session_dictionary_name,
154 lldb::StackFrameSP& frame,
155 std::string& output);
157 typedef bool (*SWIGPythonScriptKeyword_Value) (const char* python_function_name,
158 const char* session_dictionary_name,
159 lldb::ValueObjectSP& value,
160 std::string& output);
162 typedef void* (*SWIGPython_GetDynamicSetting) (void* module,
164 const lldb::TargetSP& target_sp);
168 eScriptReturnTypeCharPtr,
169 eScriptReturnTypeBool,
170 eScriptReturnTypeShortInt,
171 eScriptReturnTypeShortIntUnsigned,
172 eScriptReturnTypeInt,
173 eScriptReturnTypeIntUnsigned,
174 eScriptReturnTypeLongInt,
175 eScriptReturnTypeLongIntUnsigned,
176 eScriptReturnTypeLongLong,
177 eScriptReturnTypeLongLongUnsigned,
178 eScriptReturnTypeFloat,
179 eScriptReturnTypeDouble,
180 eScriptReturnTypeChar,
181 eScriptReturnTypeCharStrOrNone,
182 eScriptReturnTypeOpaqueObject
185 ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang);
187 virtual ~ScriptInterpreter ();
189 struct ExecuteScriptOptions
192 ExecuteScriptOptions () :
194 m_set_lldb_globals(true),
195 m_maskout_errors(true)
206 GetSetLLDBGlobals () const
208 return m_set_lldb_globals;
212 GetMaskoutErrors () const
214 return m_maskout_errors;
217 ExecuteScriptOptions&
218 SetEnableIO (bool enable)
220 m_enable_io = enable;
224 ExecuteScriptOptions&
225 SetSetLLDBGlobals (bool set)
227 m_set_lldb_globals = set;
231 ExecuteScriptOptions&
232 SetMaskoutErrors (bool maskout)
234 m_maskout_errors = maskout;
240 bool m_set_lldb_globals;
241 bool m_maskout_errors;
251 ExecuteOneLine (const char *command,
252 CommandReturnObject *result,
253 const ExecuteScriptOptions &options = ExecuteScriptOptions()) = 0;
256 ExecuteInterpreterLoop () = 0;
259 ExecuteOneLineWithReturn (const char *in_string,
260 ScriptReturnType return_type,
262 const ExecuteScriptOptions &options = ExecuteScriptOptions())
268 ExecuteMultipleLines (const char *in_string,
269 const ExecuteScriptOptions &options = ExecuteScriptOptions())
272 error.SetErrorString("not implemented");
277 ExportFunctionDefinitionToInterpreter (StringList &function_def)
280 error.SetErrorString("not implemented");
285 GenerateBreakpointCommandCallbackData (StringList &input, std::string& output)
288 error.SetErrorString("not implemented");
293 GenerateWatchpointCommandCallbackData (StringList &input, std::string& output)
299 GenerateTypeScriptFunction (const char* oneliner, std::string& output, const void* name_token = NULL)
305 GenerateTypeScriptFunction (StringList &input, std::string& output, const void* name_token = NULL)
311 GenerateScriptAliasFunction (StringList &input, std::string& output)
317 GenerateTypeSynthClass (StringList &input, std::string& output, const void* name_token = NULL)
323 GenerateTypeSynthClass (const char* oneliner, std::string& output, const void* name_token = NULL)
328 virtual lldb::ScriptInterpreterObjectSP
329 CreateSyntheticScriptedProvider (const char *class_name,
330 lldb::ValueObjectSP valobj)
332 return lldb::ScriptInterpreterObjectSP();
335 virtual lldb::ScriptInterpreterObjectSP
336 OSPlugin_CreatePluginObject (const char *class_name,
337 lldb::ProcessSP process_sp)
339 return lldb::ScriptInterpreterObjectSP();
342 virtual lldb::ScriptInterpreterObjectSP
343 OSPlugin_RegisterInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp)
345 return lldb::ScriptInterpreterObjectSP();
348 virtual lldb::ScriptInterpreterObjectSP
349 OSPlugin_ThreadsInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp)
351 return lldb::ScriptInterpreterObjectSP();
354 virtual lldb::ScriptInterpreterObjectSP
355 OSPlugin_RegisterContextData (lldb::ScriptInterpreterObjectSP os_plugin_object_sp,
356 lldb::tid_t thread_id)
358 return lldb::ScriptInterpreterObjectSP();
361 virtual lldb::ScriptInterpreterObjectSP
362 OSPlugin_CreateThread (lldb::ScriptInterpreterObjectSP os_plugin_object_sp,
364 lldb::addr_t context)
366 return lldb::ScriptInterpreterObjectSP();
369 virtual lldb::ScriptInterpreterObjectSP
370 CreateScriptedThreadPlan (const char *class_name,
371 lldb::ThreadPlanSP thread_plan_sp)
373 return lldb::ScriptInterpreterObjectSP();
377 ScriptedThreadPlanExplainsStop (lldb::ScriptInterpreterObjectSP implementor_sp,
386 ScriptedThreadPlanShouldStop (lldb::ScriptInterpreterObjectSP implementor_sp,
394 virtual lldb::StateType
395 ScriptedThreadPlanGetRunState (lldb::ScriptInterpreterObjectSP implementor_sp,
399 return lldb::eStateStepping;
402 virtual lldb::ScriptInterpreterObjectSP
403 LoadPluginModule (const FileSpec& file_spec,
404 lldb_private::Error& error)
406 return lldb::ScriptInterpreterObjectSP();
409 virtual lldb::ScriptInterpreterObjectSP
410 GetDynamicSettings (lldb::ScriptInterpreterObjectSP plugin_module_sp,
412 const char* setting_name,
413 lldb_private::Error& error)
415 return lldb::ScriptInterpreterObjectSP();
419 GenerateFunction(const char *signature, const StringList &input)
422 error.SetErrorString("unimplemented");
427 CollectDataForBreakpointCommandCallback (std::vector<BreakpointOptions *> &options,
428 CommandReturnObject &result);
431 CollectDataForWatchpointCommandCallback (WatchpointOptions *wp_options,
432 CommandReturnObject &result);
434 /// Set the specified text as the callback for the breakpoint.
436 SetBreakpointCommandCallback (std::vector<BreakpointOptions *> &bp_options_vec,
437 const char *callback_text);
440 SetBreakpointCommandCallback (BreakpointOptions *bp_options,
441 const char *callback_text)
444 error.SetErrorString("unimplemented");
449 SetBreakpointCommandCallbackFunction (std::vector<BreakpointOptions *> &bp_options_vec,
450 const char *function_name);
452 /// Set a one-liner as the callback for the breakpoint.
454 SetBreakpointCommandCallbackFunction (BreakpointOptions *bp_options,
455 const char *function_name)
460 /// Set a one-liner as the callback for the watchpoint.
462 SetWatchpointCommandCallback (WatchpointOptions *wp_options,
463 const char *oneliner)
469 GetScriptedSummary (const char *function_name,
470 lldb::ValueObjectSP valobj,
471 lldb::ScriptInterpreterObjectSP& callee_wrapper_sp,
472 const TypeSummaryOptions& options,
481 // Clean up any ref counts to SBObjects that might be in global variables
485 CalculateNumChildren (const lldb::ScriptInterpreterObjectSP& implementor)
490 virtual lldb::ValueObjectSP
491 GetChildAtIndex (const lldb::ScriptInterpreterObjectSP& implementor, uint32_t idx)
493 return lldb::ValueObjectSP();
497 GetIndexOfChildWithName (const lldb::ScriptInterpreterObjectSP& implementor, const char* child_name)
503 UpdateSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor)
509 MightHaveChildrenSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor)
514 virtual lldb::ValueObjectSP
515 GetSyntheticValue (const lldb::ScriptInterpreterObjectSP& implementor)
521 RunScriptBasedCommand (const char* impl_function,
523 ScriptedCommandSynchronicity synchronicity,
524 lldb_private::CommandReturnObject& cmd_retobj,
526 const lldb_private::ExecutionContext& exe_ctx)
532 RunScriptFormatKeyword (const char* impl_function,
537 error.SetErrorString("unimplemented");
542 RunScriptFormatKeyword (const char* impl_function,
547 error.SetErrorString("unimplemented");
552 RunScriptFormatKeyword (const char* impl_function,
557 error.SetErrorString("unimplemented");
562 RunScriptFormatKeyword (const char* impl_function,
567 error.SetErrorString("unimplemented");
572 RunScriptFormatKeyword (const char* impl_function,
577 error.SetErrorString("unimplemented");
582 GetDocumentationForItem (const char* item, std::string& dest)
589 CheckObjectExists (const char* name)
595 LoadScriptingModule (const char* filename,
598 lldb_private::Error& error,
599 lldb::ScriptInterpreterObjectSP* module_sp = nullptr)
601 error.SetErrorString("loading unimplemented");
605 virtual lldb::ScriptInterpreterObjectSP
606 MakeScriptObject (void* object)
608 return lldb::ScriptInterpreterObjectSP(new ScriptInterpreterObject(object));
611 virtual std::unique_ptr<ScriptInterpreterLocker>
612 AcquireInterpreterLock ();
615 GetScriptInterpreterPtyName ();
618 GetMasterFileDescriptor ();
621 GetCommandInterpreter ();
624 LanguageToString (lldb::ScriptLanguage language);
627 InitializeInterpreter (SWIGInitCallback python_swig_init_callback,
628 SWIGBreakpointCallbackFunction swig_breakpoint_callback,
629 SWIGWatchpointCallbackFunction swig_watchpoint_callback,
630 SWIGPythonTypeScriptCallbackFunction swig_typescript_callback,
631 SWIGPythonCreateSyntheticProvider swig_synthetic_script,
632 SWIGPythonCalculateNumChildren swig_calc_children,
633 SWIGPythonGetChildAtIndex swig_get_child_index,
634 SWIGPythonGetIndexOfChildWithName swig_get_index_child,
635 SWIGPythonCastPyObjectToSBValue swig_cast_to_sbvalue ,
636 SWIGPythonGetValueObjectSPFromSBValue swig_get_valobj_sp_from_sbvalue,
637 SWIGPythonUpdateSynthProviderInstance swig_update_provider,
638 SWIGPythonMightHaveChildrenSynthProviderInstance swig_mighthavechildren_provider,
639 SWIGPythonGetValueSynthProviderInstance swig_getvalue_provider,
640 SWIGPythonCallCommand swig_call_command,
641 SWIGPythonCallModuleInit swig_call_module_init,
642 SWIGPythonCreateOSPlugin swig_create_os_plugin,
643 SWIGPythonScriptKeyword_Process swig_run_script_keyword_process,
644 SWIGPythonScriptKeyword_Thread swig_run_script_keyword_thread,
645 SWIGPythonScriptKeyword_Target swig_run_script_keyword_target,
646 SWIGPythonScriptKeyword_Frame swig_run_script_keyword_frame,
647 SWIGPythonScriptKeyword_Value swig_run_script_keyword_value,
648 SWIGPython_GetDynamicSetting swig_plugin_get,
649 SWIGPythonCreateScriptedThreadPlan swig_thread_plan_script,
650 SWIGPythonCallThreadPlan swig_call_thread_plan);
653 ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing.
656 CommandInterpreter &m_interpreter;
657 lldb::ScriptLanguage m_script_lang;
660 } // namespace lldb_private
662 #endif // #ifndef liblldb_ScriptInterpreter_h_