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)
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 bool (*SWIGPythonUpdateSynthProviderInstance) (void* data);
116 typedef bool (*SWIGPythonMightHaveChildrenSynthProviderInstance) (void* data);
119 typedef bool (*SWIGPythonCallCommand) (const char *python_function_name,
120 const char *session_dictionary_name,
121 lldb::DebuggerSP& debugger,
123 lldb_private::CommandReturnObject& cmd_retobj);
125 typedef bool (*SWIGPythonCallModuleInit) (const char *python_module_name,
126 const char *session_dictionary_name,
127 lldb::DebuggerSP& debugger);
129 typedef bool (*SWIGPythonScriptKeyword_Process) (const char* python_function_name,
130 const char* session_dictionary_name,
131 lldb::ProcessSP& process,
132 std::string& output);
133 typedef bool (*SWIGPythonScriptKeyword_Thread) (const char* python_function_name,
134 const char* session_dictionary_name,
135 lldb::ThreadSP& thread,
136 std::string& output);
138 typedef bool (*SWIGPythonScriptKeyword_Target) (const char* python_function_name,
139 const char* session_dictionary_name,
140 lldb::TargetSP& target,
141 std::string& output);
143 typedef bool (*SWIGPythonScriptKeyword_Frame) (const char* python_function_name,
144 const char* session_dictionary_name,
145 lldb::StackFrameSP& frame,
146 std::string& output);
152 eScriptReturnTypeCharPtr,
153 eScriptReturnTypeBool,
154 eScriptReturnTypeShortInt,
155 eScriptReturnTypeShortIntUnsigned,
156 eScriptReturnTypeInt,
157 eScriptReturnTypeIntUnsigned,
158 eScriptReturnTypeLongInt,
159 eScriptReturnTypeLongIntUnsigned,
160 eScriptReturnTypeLongLong,
161 eScriptReturnTypeLongLongUnsigned,
162 eScriptReturnTypeFloat,
163 eScriptReturnTypeDouble,
164 eScriptReturnTypeChar,
165 eScriptReturnTypeCharStrOrNone
168 ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang);
170 virtual ~ScriptInterpreter ();
172 struct ExecuteScriptOptions
175 ExecuteScriptOptions () :
177 m_set_lldb_globals(true),
178 m_maskout_errors(true)
189 GetSetLLDBGlobals () const
191 return m_set_lldb_globals;
195 GetMaskoutErrors () const
197 return m_maskout_errors;
200 ExecuteScriptOptions&
201 SetEnableIO (bool enable)
203 m_enable_io = enable;
207 ExecuteScriptOptions&
208 SetSetLLDBGlobals (bool set)
210 m_set_lldb_globals = set;
214 ExecuteScriptOptions&
215 SetMaskoutErrors (bool maskout)
217 m_maskout_errors = maskout;
223 bool m_set_lldb_globals;
224 bool m_maskout_errors;
228 ExecuteOneLine (const char *command,
229 CommandReturnObject *result,
230 const ExecuteScriptOptions &options = ExecuteScriptOptions()) = 0;
233 ExecuteInterpreterLoop () = 0;
236 ExecuteOneLineWithReturn (const char *in_string,
237 ScriptReturnType return_type,
239 const ExecuteScriptOptions &options = ExecuteScriptOptions())
245 ExecuteMultipleLines (const char *in_string,
246 const ExecuteScriptOptions &options = ExecuteScriptOptions())
252 ExportFunctionDefinitionToInterpreter (StringList &function_def)
258 GenerateBreakpointCommandCallbackData (StringList &input, std::string& output)
264 GenerateWatchpointCommandCallbackData (StringList &input, std::string& output)
270 GenerateTypeScriptFunction (const char* oneliner, std::string& output, void* name_token = NULL)
276 GenerateTypeScriptFunction (StringList &input, std::string& output, void* name_token = NULL)
282 GenerateScriptAliasFunction (StringList &input, std::string& output)
288 GenerateTypeSynthClass (StringList &input, std::string& output, void* name_token = NULL)
294 GenerateTypeSynthClass (const char* oneliner, std::string& output, void* name_token = NULL)
299 virtual lldb::ScriptInterpreterObjectSP
300 CreateSyntheticScriptedProvider (const char *class_name,
301 lldb::ValueObjectSP valobj)
303 return lldb::ScriptInterpreterObjectSP();
306 virtual lldb::ScriptInterpreterObjectSP
307 OSPlugin_CreatePluginObject (const char *class_name,
308 lldb::ProcessSP process_sp)
310 return lldb::ScriptInterpreterObjectSP();
313 virtual lldb::ScriptInterpreterObjectSP
314 OSPlugin_RegisterInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp)
316 return lldb::ScriptInterpreterObjectSP();
319 virtual lldb::ScriptInterpreterObjectSP
320 OSPlugin_ThreadsInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp)
322 return lldb::ScriptInterpreterObjectSP();
325 virtual lldb::ScriptInterpreterObjectSP
326 OSPlugin_RegisterContextData (lldb::ScriptInterpreterObjectSP os_plugin_object_sp,
327 lldb::tid_t thread_id)
329 return lldb::ScriptInterpreterObjectSP();
332 virtual lldb::ScriptInterpreterObjectSP
333 OSPlugin_CreateThread (lldb::ScriptInterpreterObjectSP os_plugin_object_sp,
335 lldb::addr_t context)
337 return lldb::ScriptInterpreterObjectSP();
341 GenerateFunction(const char *signature, const StringList &input)
347 CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options,
348 CommandReturnObject &result);
351 CollectDataForWatchpointCommandCallback (WatchpointOptions *wp_options,
352 CommandReturnObject &result);
354 /// Set a one-liner as the callback for the breakpoint.
356 SetBreakpointCommandCallback (BreakpointOptions *bp_options,
357 const char *oneliner)
362 /// Set a one-liner as the callback for the watchpoint.
364 SetWatchpointCommandCallback (WatchpointOptions *wp_options,
365 const char *oneliner)
371 GetScriptedSummary (const char *function_name,
372 lldb::ValueObjectSP valobj,
373 lldb::ScriptInterpreterObjectSP& callee_wrapper_sp,
380 CalculateNumChildren (const lldb::ScriptInterpreterObjectSP& implementor)
385 virtual lldb::ValueObjectSP
386 GetChildAtIndex (const lldb::ScriptInterpreterObjectSP& implementor, uint32_t idx)
388 return lldb::ValueObjectSP();
392 GetIndexOfChildWithName (const lldb::ScriptInterpreterObjectSP& implementor, const char* child_name)
398 UpdateSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor)
404 MightHaveChildrenSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor)
410 RunScriptBasedCommand (const char* impl_function,
412 ScriptedCommandSynchronicity synchronicity,
413 lldb_private::CommandReturnObject& cmd_retobj,
420 RunScriptFormatKeyword (const char* impl_function,
425 error.SetErrorString("unimplemented");
430 RunScriptFormatKeyword (const char* impl_function,
435 error.SetErrorString("unimplemented");
440 RunScriptFormatKeyword (const char* impl_function,
445 error.SetErrorString("unimplemented");
450 RunScriptFormatKeyword (const char* impl_function,
455 error.SetErrorString("unimplemented");
460 GetDocumentationForItem (const char* item, std::string& dest)
467 CheckObjectExists (const char* name)
473 LoadScriptingModule (const char* filename,
476 lldb_private::Error& error)
478 error.SetErrorString("loading unimplemented");
482 virtual lldb::ScriptInterpreterObjectSP
483 MakeScriptObject (void* object)
485 return lldb::ScriptInterpreterObjectSP(new ScriptInterpreterObject(object));
488 virtual std::unique_ptr<ScriptInterpreterLocker>
489 AcquireInterpreterLock ();
492 GetScriptInterpreterPtyName ();
495 GetMasterFileDescriptor ();
498 GetCommandInterpreter ();
501 LanguageToString (lldb::ScriptLanguage language);
504 InitializeInterpreter (SWIGInitCallback python_swig_init_callback);
507 TerminateInterpreter ();
510 ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing.
513 CommandInterpreter &m_interpreter;
514 lldb::ScriptLanguage m_script_lang;
517 } // namespace lldb_private
519 #endif // #ifndef liblldb_ScriptInterpreter_h_