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 std::string& retval);
103 typedef void* (*SWIGPythonCreateSyntheticProvider) (const char *python_class_name,
104 const char *session_dictionary_name,
105 const lldb::ValueObjectSP& valobj_sp);
107 typedef void* (*SWIGPythonCreateOSPlugin) (const char *python_class_name,
108 const char *session_dictionary_name,
109 const lldb::ProcessSP& process_sp);
111 typedef uint32_t (*SWIGPythonCalculateNumChildren) (void *implementor);
112 typedef void* (*SWIGPythonGetChildAtIndex) (void *implementor, uint32_t idx);
113 typedef int (*SWIGPythonGetIndexOfChildWithName) (void *implementor, const char* child_name);
114 typedef void* (*SWIGPythonCastPyObjectToSBValue) (void* data);
115 typedef lldb::ValueObjectSP (*SWIGPythonGetValueObjectSPFromSBValue) (void* data);
116 typedef bool (*SWIGPythonUpdateSynthProviderInstance) (void* data);
117 typedef bool (*SWIGPythonMightHaveChildrenSynthProviderInstance) (void* data);
120 typedef bool (*SWIGPythonCallCommand) (const char *python_function_name,
121 const char *session_dictionary_name,
122 lldb::DebuggerSP& debugger,
124 lldb_private::CommandReturnObject& cmd_retobj);
126 typedef bool (*SWIGPythonCallModuleInit) (const char *python_module_name,
127 const char *session_dictionary_name,
128 lldb::DebuggerSP& debugger);
130 typedef bool (*SWIGPythonScriptKeyword_Process) (const char* python_function_name,
131 const char* session_dictionary_name,
132 lldb::ProcessSP& process,
133 std::string& output);
134 typedef bool (*SWIGPythonScriptKeyword_Thread) (const char* python_function_name,
135 const char* session_dictionary_name,
136 lldb::ThreadSP& thread,
137 std::string& output);
139 typedef bool (*SWIGPythonScriptKeyword_Target) (const char* python_function_name,
140 const char* session_dictionary_name,
141 lldb::TargetSP& target,
142 std::string& output);
144 typedef bool (*SWIGPythonScriptKeyword_Frame) (const char* python_function_name,
145 const char* session_dictionary_name,
146 lldb::StackFrameSP& frame,
147 std::string& output);
149 typedef void* (*SWIGPython_GetDynamicSetting) (void* module,
151 const lldb::TargetSP& target_sp);
155 eScriptReturnTypeCharPtr,
156 eScriptReturnTypeBool,
157 eScriptReturnTypeShortInt,
158 eScriptReturnTypeShortIntUnsigned,
159 eScriptReturnTypeInt,
160 eScriptReturnTypeIntUnsigned,
161 eScriptReturnTypeLongInt,
162 eScriptReturnTypeLongIntUnsigned,
163 eScriptReturnTypeLongLong,
164 eScriptReturnTypeLongLongUnsigned,
165 eScriptReturnTypeFloat,
166 eScriptReturnTypeDouble,
167 eScriptReturnTypeChar,
168 eScriptReturnTypeCharStrOrNone,
169 eScriptReturnTypeOpaqueObject
172 ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang);
174 virtual ~ScriptInterpreter ();
176 struct ExecuteScriptOptions
179 ExecuteScriptOptions () :
181 m_set_lldb_globals(true),
182 m_maskout_errors(true)
193 GetSetLLDBGlobals () const
195 return m_set_lldb_globals;
199 GetMaskoutErrors () const
201 return m_maskout_errors;
204 ExecuteScriptOptions&
205 SetEnableIO (bool enable)
207 m_enable_io = enable;
211 ExecuteScriptOptions&
212 SetSetLLDBGlobals (bool set)
214 m_set_lldb_globals = set;
218 ExecuteScriptOptions&
219 SetMaskoutErrors (bool maskout)
221 m_maskout_errors = maskout;
227 bool m_set_lldb_globals;
228 bool m_maskout_errors;
232 ExecuteOneLine (const char *command,
233 CommandReturnObject *result,
234 const ExecuteScriptOptions &options = ExecuteScriptOptions()) = 0;
237 ExecuteInterpreterLoop () = 0;
240 ExecuteOneLineWithReturn (const char *in_string,
241 ScriptReturnType return_type,
243 const ExecuteScriptOptions &options = ExecuteScriptOptions())
249 ExecuteMultipleLines (const char *in_string,
250 const ExecuteScriptOptions &options = ExecuteScriptOptions())
253 error.SetErrorString("not implemented");
258 ExportFunctionDefinitionToInterpreter (StringList &function_def)
264 GenerateBreakpointCommandCallbackData (StringList &input, std::string& output)
270 GenerateWatchpointCommandCallbackData (StringList &input, std::string& output)
276 GenerateTypeScriptFunction (const char* oneliner, std::string& output, void* name_token = NULL)
282 GenerateTypeScriptFunction (StringList &input, std::string& output, void* name_token = NULL)
288 GenerateScriptAliasFunction (StringList &input, std::string& output)
294 GenerateTypeSynthClass (StringList &input, std::string& output, void* name_token = NULL)
300 GenerateTypeSynthClass (const char* oneliner, std::string& output, void* name_token = NULL)
305 virtual lldb::ScriptInterpreterObjectSP
306 CreateSyntheticScriptedProvider (const char *class_name,
307 lldb::ValueObjectSP valobj)
309 return lldb::ScriptInterpreterObjectSP();
312 virtual lldb::ScriptInterpreterObjectSP
313 OSPlugin_CreatePluginObject (const char *class_name,
314 lldb::ProcessSP process_sp)
316 return lldb::ScriptInterpreterObjectSP();
319 virtual lldb::ScriptInterpreterObjectSP
320 OSPlugin_RegisterInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp)
322 return lldb::ScriptInterpreterObjectSP();
325 virtual lldb::ScriptInterpreterObjectSP
326 OSPlugin_ThreadsInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp)
328 return lldb::ScriptInterpreterObjectSP();
331 virtual lldb::ScriptInterpreterObjectSP
332 OSPlugin_RegisterContextData (lldb::ScriptInterpreterObjectSP os_plugin_object_sp,
333 lldb::tid_t thread_id)
335 return lldb::ScriptInterpreterObjectSP();
338 virtual lldb::ScriptInterpreterObjectSP
339 OSPlugin_CreateThread (lldb::ScriptInterpreterObjectSP os_plugin_object_sp,
341 lldb::addr_t context)
343 return lldb::ScriptInterpreterObjectSP();
346 virtual lldb::ScriptInterpreterObjectSP
347 LoadPluginModule (const FileSpec& file_spec,
348 lldb_private::Error& error)
350 return lldb::ScriptInterpreterObjectSP();
353 virtual lldb::ScriptInterpreterObjectSP
354 GetDynamicSettings (lldb::ScriptInterpreterObjectSP plugin_module_sp,
356 const char* setting_name,
357 lldb_private::Error& error)
359 return lldb::ScriptInterpreterObjectSP();
363 GenerateFunction(const char *signature, const StringList &input)
369 CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options,
370 CommandReturnObject &result);
373 CollectDataForWatchpointCommandCallback (WatchpointOptions *wp_options,
374 CommandReturnObject &result);
376 /// Set a one-liner as the callback for the breakpoint.
378 SetBreakpointCommandCallback (BreakpointOptions *bp_options,
379 const char *oneliner)
384 /// Set a one-liner as the callback for the watchpoint.
386 SetWatchpointCommandCallback (WatchpointOptions *wp_options,
387 const char *oneliner)
393 GetScriptedSummary (const char *function_name,
394 lldb::ValueObjectSP valobj,
395 lldb::ScriptInterpreterObjectSP& callee_wrapper_sp,
402 CalculateNumChildren (const lldb::ScriptInterpreterObjectSP& implementor)
407 virtual lldb::ValueObjectSP
408 GetChildAtIndex (const lldb::ScriptInterpreterObjectSP& implementor, uint32_t idx)
410 return lldb::ValueObjectSP();
414 GetIndexOfChildWithName (const lldb::ScriptInterpreterObjectSP& implementor, const char* child_name)
420 UpdateSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor)
426 MightHaveChildrenSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor)
432 RunScriptBasedCommand (const char* impl_function,
434 ScriptedCommandSynchronicity synchronicity,
435 lldb_private::CommandReturnObject& cmd_retobj,
442 RunScriptFormatKeyword (const char* impl_function,
447 error.SetErrorString("unimplemented");
452 RunScriptFormatKeyword (const char* impl_function,
457 error.SetErrorString("unimplemented");
462 RunScriptFormatKeyword (const char* impl_function,
467 error.SetErrorString("unimplemented");
472 RunScriptFormatKeyword (const char* impl_function,
477 error.SetErrorString("unimplemented");
482 GetDocumentationForItem (const char* item, std::string& dest)
489 CheckObjectExists (const char* name)
495 LoadScriptingModule (const char* filename,
498 lldb_private::Error& error,
499 lldb::ScriptInterpreterObjectSP* module_sp = nullptr)
501 error.SetErrorString("loading unimplemented");
505 virtual lldb::ScriptInterpreterObjectSP
506 MakeScriptObject (void* object)
508 return lldb::ScriptInterpreterObjectSP(new ScriptInterpreterObject(object));
511 virtual std::unique_ptr<ScriptInterpreterLocker>
512 AcquireInterpreterLock ();
515 GetScriptInterpreterPtyName ();
518 GetMasterFileDescriptor ();
521 GetCommandInterpreter ();
524 LanguageToString (lldb::ScriptLanguage language);
527 InitializeInterpreter (SWIGInitCallback python_swig_init_callback,
528 SWIGBreakpointCallbackFunction swig_breakpoint_callback,
529 SWIGWatchpointCallbackFunction swig_watchpoint_callback,
530 SWIGPythonTypeScriptCallbackFunction swig_typescript_callback,
531 SWIGPythonCreateSyntheticProvider swig_synthetic_script,
532 SWIGPythonCalculateNumChildren swig_calc_children,
533 SWIGPythonGetChildAtIndex swig_get_child_index,
534 SWIGPythonGetIndexOfChildWithName swig_get_index_child,
535 SWIGPythonCastPyObjectToSBValue swig_cast_to_sbvalue ,
536 SWIGPythonGetValueObjectSPFromSBValue swig_get_valobj_sp_from_sbvalue,
537 SWIGPythonUpdateSynthProviderInstance swig_update_provider,
538 SWIGPythonMightHaveChildrenSynthProviderInstance swig_mighthavechildren_provider,
539 SWIGPythonCallCommand swig_call_command,
540 SWIGPythonCallModuleInit swig_call_module_init,
541 SWIGPythonCreateOSPlugin swig_create_os_plugin,
542 SWIGPythonScriptKeyword_Process swig_run_script_keyword_process,
543 SWIGPythonScriptKeyword_Thread swig_run_script_keyword_thread,
544 SWIGPythonScriptKeyword_Target swig_run_script_keyword_target,
545 SWIGPythonScriptKeyword_Frame swig_run_script_keyword_frame,
546 SWIGPython_GetDynamicSetting swig_plugin_get);
549 TerminateInterpreter ();
552 ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing.
555 CommandInterpreter &m_interpreter;
556 lldb::ScriptLanguage m_script_lang;
559 } // namespace lldb_private
561 #endif // #ifndef liblldb_ScriptInterpreter_h_