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;
245 ExecuteOneLine (const char *command,
246 CommandReturnObject *result,
247 const ExecuteScriptOptions &options = ExecuteScriptOptions()) = 0;
250 ExecuteInterpreterLoop () = 0;
253 ExecuteOneLineWithReturn (const char *in_string,
254 ScriptReturnType return_type,
256 const ExecuteScriptOptions &options = ExecuteScriptOptions())
262 ExecuteMultipleLines (const char *in_string,
263 const ExecuteScriptOptions &options = ExecuteScriptOptions())
266 error.SetErrorString("not implemented");
271 ExportFunctionDefinitionToInterpreter (StringList &function_def)
274 error.SetErrorString("not implemented");
279 GenerateBreakpointCommandCallbackData (StringList &input, std::string& output)
282 error.SetErrorString("not implemented");
287 GenerateWatchpointCommandCallbackData (StringList &input, std::string& output)
293 GenerateTypeScriptFunction (const char* oneliner, std::string& output, void* name_token = NULL)
299 GenerateTypeScriptFunction (StringList &input, std::string& output, void* name_token = NULL)
305 GenerateScriptAliasFunction (StringList &input, std::string& output)
311 GenerateTypeSynthClass (StringList &input, std::string& output, void* name_token = NULL)
317 GenerateTypeSynthClass (const char* oneliner, std::string& output, void* name_token = NULL)
322 virtual lldb::ScriptInterpreterObjectSP
323 CreateSyntheticScriptedProvider (const char *class_name,
324 lldb::ValueObjectSP valobj)
326 return lldb::ScriptInterpreterObjectSP();
329 virtual lldb::ScriptInterpreterObjectSP
330 OSPlugin_CreatePluginObject (const char *class_name,
331 lldb::ProcessSP process_sp)
333 return lldb::ScriptInterpreterObjectSP();
336 virtual lldb::ScriptInterpreterObjectSP
337 OSPlugin_RegisterInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp)
339 return lldb::ScriptInterpreterObjectSP();
342 virtual lldb::ScriptInterpreterObjectSP
343 OSPlugin_ThreadsInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp)
345 return lldb::ScriptInterpreterObjectSP();
348 virtual lldb::ScriptInterpreterObjectSP
349 OSPlugin_RegisterContextData (lldb::ScriptInterpreterObjectSP os_plugin_object_sp,
350 lldb::tid_t thread_id)
352 return lldb::ScriptInterpreterObjectSP();
355 virtual lldb::ScriptInterpreterObjectSP
356 OSPlugin_CreateThread (lldb::ScriptInterpreterObjectSP os_plugin_object_sp,
358 lldb::addr_t context)
360 return lldb::ScriptInterpreterObjectSP();
363 virtual lldb::ScriptInterpreterObjectSP
364 CreateScriptedThreadPlan (const char *class_name,
365 lldb::ThreadPlanSP thread_plan_sp)
367 return lldb::ScriptInterpreterObjectSP();
371 ScriptedThreadPlanExplainsStop (lldb::ScriptInterpreterObjectSP implementor_sp,
380 ScriptedThreadPlanShouldStop (lldb::ScriptInterpreterObjectSP implementor_sp,
388 virtual lldb::StateType
389 ScriptedThreadPlanGetRunState (lldb::ScriptInterpreterObjectSP implementor_sp,
393 return lldb::eStateStepping;
396 virtual lldb::ScriptInterpreterObjectSP
397 LoadPluginModule (const FileSpec& file_spec,
398 lldb_private::Error& error)
400 return lldb::ScriptInterpreterObjectSP();
403 virtual lldb::ScriptInterpreterObjectSP
404 GetDynamicSettings (lldb::ScriptInterpreterObjectSP plugin_module_sp,
406 const char* setting_name,
407 lldb_private::Error& error)
409 return lldb::ScriptInterpreterObjectSP();
413 GenerateFunction(const char *signature, const StringList &input)
416 error.SetErrorString("unimplemented");
421 CollectDataForBreakpointCommandCallback (std::vector<BreakpointOptions *> &options,
422 CommandReturnObject &result);
425 CollectDataForWatchpointCommandCallback (WatchpointOptions *wp_options,
426 CommandReturnObject &result);
428 /// Set the specified text as the callback for the breakpoint.
430 SetBreakpointCommandCallback (std::vector<BreakpointOptions *> &bp_options_vec,
431 const char *callback_text);
434 SetBreakpointCommandCallback (BreakpointOptions *bp_options,
435 const char *callback_text)
438 error.SetErrorString("unimplemented");
443 SetBreakpointCommandCallbackFunction (std::vector<BreakpointOptions *> &bp_options_vec,
444 const char *function_name);
446 /// Set a one-liner as the callback for the breakpoint.
448 SetBreakpointCommandCallbackFunction (BreakpointOptions *bp_options,
449 const char *function_name)
454 /// Set a one-liner as the callback for the watchpoint.
456 SetWatchpointCommandCallback (WatchpointOptions *wp_options,
457 const char *oneliner)
463 GetScriptedSummary (const char *function_name,
464 lldb::ValueObjectSP valobj,
465 lldb::ScriptInterpreterObjectSP& callee_wrapper_sp,
466 const TypeSummaryOptions& options,
475 // Clean up any ref counts to SBObjects that might be in global variables
479 CalculateNumChildren (const lldb::ScriptInterpreterObjectSP& implementor)
484 virtual lldb::ValueObjectSP
485 GetChildAtIndex (const lldb::ScriptInterpreterObjectSP& implementor, uint32_t idx)
487 return lldb::ValueObjectSP();
491 GetIndexOfChildWithName (const lldb::ScriptInterpreterObjectSP& implementor, const char* child_name)
497 UpdateSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor)
503 MightHaveChildrenSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor)
508 virtual lldb::ValueObjectSP
509 GetSyntheticValue (const lldb::ScriptInterpreterObjectSP& implementor)
515 RunScriptBasedCommand (const char* impl_function,
517 ScriptedCommandSynchronicity synchronicity,
518 lldb_private::CommandReturnObject& cmd_retobj,
520 const lldb_private::ExecutionContext& exe_ctx)
526 RunScriptFormatKeyword (const char* impl_function,
531 error.SetErrorString("unimplemented");
536 RunScriptFormatKeyword (const char* impl_function,
541 error.SetErrorString("unimplemented");
546 RunScriptFormatKeyword (const char* impl_function,
551 error.SetErrorString("unimplemented");
556 RunScriptFormatKeyword (const char* impl_function,
561 error.SetErrorString("unimplemented");
566 RunScriptFormatKeyword (const char* impl_function,
571 error.SetErrorString("unimplemented");
576 GetDocumentationForItem (const char* item, std::string& dest)
583 CheckObjectExists (const char* name)
589 LoadScriptingModule (const char* filename,
592 lldb_private::Error& error,
593 lldb::ScriptInterpreterObjectSP* module_sp = nullptr)
595 error.SetErrorString("loading unimplemented");
599 virtual lldb::ScriptInterpreterObjectSP
600 MakeScriptObject (void* object)
602 return lldb::ScriptInterpreterObjectSP(new ScriptInterpreterObject(object));
605 virtual std::unique_ptr<ScriptInterpreterLocker>
606 AcquireInterpreterLock ();
609 GetScriptInterpreterPtyName ();
612 GetMasterFileDescriptor ();
615 GetCommandInterpreter ();
618 LanguageToString (lldb::ScriptLanguage language);
621 InitializeInterpreter (SWIGInitCallback python_swig_init_callback,
622 SWIGBreakpointCallbackFunction swig_breakpoint_callback,
623 SWIGWatchpointCallbackFunction swig_watchpoint_callback,
624 SWIGPythonTypeScriptCallbackFunction swig_typescript_callback,
625 SWIGPythonCreateSyntheticProvider swig_synthetic_script,
626 SWIGPythonCalculateNumChildren swig_calc_children,
627 SWIGPythonGetChildAtIndex swig_get_child_index,
628 SWIGPythonGetIndexOfChildWithName swig_get_index_child,
629 SWIGPythonCastPyObjectToSBValue swig_cast_to_sbvalue ,
630 SWIGPythonGetValueObjectSPFromSBValue swig_get_valobj_sp_from_sbvalue,
631 SWIGPythonUpdateSynthProviderInstance swig_update_provider,
632 SWIGPythonMightHaveChildrenSynthProviderInstance swig_mighthavechildren_provider,
633 SWIGPythonGetValueSynthProviderInstance swig_getvalue_provider,
634 SWIGPythonCallCommand swig_call_command,
635 SWIGPythonCallModuleInit swig_call_module_init,
636 SWIGPythonCreateOSPlugin swig_create_os_plugin,
637 SWIGPythonScriptKeyword_Process swig_run_script_keyword_process,
638 SWIGPythonScriptKeyword_Thread swig_run_script_keyword_thread,
639 SWIGPythonScriptKeyword_Target swig_run_script_keyword_target,
640 SWIGPythonScriptKeyword_Frame swig_run_script_keyword_frame,
641 SWIGPythonScriptKeyword_Value swig_run_script_keyword_value,
642 SWIGPython_GetDynamicSetting swig_plugin_get,
643 SWIGPythonCreateScriptedThreadPlan swig_thread_plan_script,
644 SWIGPythonCallThreadPlan swig_call_thread_plan);
647 ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing.
650 CommandInterpreter &m_interpreter;
651 lldb::ScriptLanguage m_script_lang;
654 } // namespace lldb_private
656 #endif // #ifndef liblldb_ScriptInterpreter_h_