ScriptInterpreter.h revision 16376ed044df3ee70fcf69e19f06af01e71a8e9a
1//===-- ScriptInterpreter.h -------------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef liblldb_ScriptInterpreter_h_ 11#define liblldb_ScriptInterpreter_h_ 12 13#include "lldb/lldb-private.h" 14 15#include "lldb/Core/Broadcaster.h" 16#include "lldb/Core/Error.h" 17 18#include "lldb/Utility/PseudoTerminal.h" 19 20 21namespace lldb_private { 22 23class ScriptInterpreter 24{ 25public: 26 27 typedef void (*SWIGInitCallback) (void); 28 29 typedef bool (*SWIGBreakpointCallbackFunction) (const char *python_function_name, 30 const char *session_dictionary_name, 31 const lldb::StackFrameSP& frame_sp, 32 const lldb::BreakpointLocationSP &bp_loc_sp); 33 34 typedef std::string (*SWIGPythonTypeScriptCallbackFunction) (const char *python_function_name, 35 const char *session_dictionary_name, 36 const lldb::ValueObjectSP& valobj_sp); 37 38 typedef void* (*SWIGPythonCreateSyntheticProvider) (const std::string python_class_name, 39 const char *session_dictionary_name, 40 const lldb::ValueObjectSP& valobj_sp); 41 42 typedef uint32_t (*SWIGPythonCalculateNumChildren) (void *implementor); 43 typedef void* (*SWIGPythonGetChildAtIndex) (void *implementor, uint32_t idx); 44 typedef int (*SWIGPythonGetIndexOfChildWithName) (void *implementor, const char* child_name); 45 typedef void* (*SWIGPythonCastPyObjectToSBValue) (void* data); 46 typedef void (*SWIGPythonUpdateSynthProviderInstance) (void* data); 47 48 typedef bool (*SWIGPythonCallCommand) (const char *python_function_name, 49 const char *session_dictionary_name, 50 lldb::DebuggerSP& debugger, 51 const char* args, 52 std::string& err_msg, 53 lldb_private::CommandReturnObject& cmd_retobj); 54 55 typedef bool (*SWIGPythonCallModuleInit) (const std::string python_module_name, 56 const char *session_dictionary_name, 57 lldb::DebuggerSP& debugger); 58 59 typedef enum 60 { 61 eScriptReturnTypeCharPtr, 62 eScriptReturnTypeBool, 63 eScriptReturnTypeShortInt, 64 eScriptReturnTypeShortIntUnsigned, 65 eScriptReturnTypeInt, 66 eScriptReturnTypeIntUnsigned, 67 eScriptReturnTypeLongInt, 68 eScriptReturnTypeLongIntUnsigned, 69 eScriptReturnTypeLongLong, 70 eScriptReturnTypeLongLongUnsigned, 71 eScriptReturnTypeFloat, 72 eScriptReturnTypeDouble, 73 eScriptReturnTypeChar, 74 eScriptReturnTypeCharStrOrNone 75 } ScriptReturnType; 76 77 ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang); 78 79 virtual ~ScriptInterpreter (); 80 81 virtual bool 82 ExecuteOneLine (const char *command, CommandReturnObject *result) = 0; 83 84 virtual void 85 ExecuteInterpreterLoop () = 0; 86 87 virtual bool 88 ExecuteOneLineWithReturn (const char *in_string, ScriptReturnType return_type, void *ret_value) 89 { 90 return true; 91 } 92 93 virtual bool 94 ExecuteMultipleLines (const char *in_string) 95 { 96 return true; 97 } 98 99 virtual bool 100 ExportFunctionDefinitionToInterpreter (StringList &function_def) 101 { 102 return false; 103 } 104 105 virtual bool 106 GenerateBreakpointCommandCallbackData (StringList &input, StringList &output) 107 { 108 return false; 109 } 110 111 virtual bool 112 GenerateTypeScriptFunction (const char* oneliner, StringList &output, void* name_token = NULL) 113 { 114 return false; 115 } 116 117 virtual bool 118 GenerateTypeScriptFunction (StringList &input, StringList &output, void* name_token = NULL) 119 { 120 return false; 121 } 122 123 virtual bool 124 GenerateScriptAliasFunction (StringList &input, StringList &output) 125 { 126 return false; 127 } 128 129 virtual bool 130 GenerateTypeSynthClass (StringList &input, StringList &output, void* name_token = NULL) 131 { 132 return false; 133 } 134 135 virtual bool 136 GenerateTypeSynthClass (const char* oneliner, StringList &output, void* name_token = NULL) 137 { 138 return false; 139 } 140 141 virtual void* 142 CreateSyntheticScriptedProvider (std::string class_name, 143 lldb::ValueObjectSP valobj) 144 { 145 return NULL; 146 } 147 148 virtual bool 149 GenerateFunction(std::string& signature, StringList &input, StringList &output) 150 { 151 return false; 152 } 153 154 virtual void 155 CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options, 156 CommandReturnObject &result); 157 158 /// Set a one-liner as the callback for the breakpoint. 159 virtual void 160 SetBreakpointCommandCallback (BreakpointOptions *bp_options, 161 const char *oneliner) 162 { 163 return; 164 } 165 166 virtual uint32_t 167 CalculateNumChildren (void *implementor) 168 { 169 return 0; 170 } 171 172 virtual lldb::ValueObjectSP 173 GetChildAtIndex (void *implementor, uint32_t idx) 174 { 175 return lldb::ValueObjectSP(); 176 } 177 178 virtual int 179 GetIndexOfChildWithName (void *implementor, const char* child_name) 180 { 181 return UINT32_MAX; 182 } 183 184 virtual void 185 UpdateSynthProviderInstance (void* implementor) 186 { 187 } 188 189 virtual bool 190 RunScriptBasedCommand (const char* impl_function, 191 const char* args, 192 ScriptedCommandSynchronicity synchronicity, 193 lldb_private::CommandReturnObject& cmd_retobj, 194 Error& error) 195 { 196 return false; 197 } 198 199 virtual std::string 200 GetDocumentationForItem (const char* item) 201 { 202 return std::string(""); 203 } 204 205 virtual bool 206 LoadScriptingModule (const char* filename, 207 bool can_reload, 208 lldb_private::Error& error) 209 { 210 error.SetErrorString("loading unimplemented"); 211 return false; 212 } 213 214 const char * 215 GetScriptInterpreterPtyName (); 216 217 int 218 GetMasterFileDescriptor (); 219 220 CommandInterpreter & 221 GetCommandInterpreter (); 222 223 static std::string 224 LanguageToString (lldb::ScriptLanguage language); 225 226 static void 227 InitializeInterpreter (SWIGInitCallback python_swig_init_callback, 228 SWIGBreakpointCallbackFunction python_swig_breakpoint_callback, 229 SWIGPythonTypeScriptCallbackFunction python_swig_typescript_callback, 230 SWIGPythonCreateSyntheticProvider python_swig_synthetic_script, 231 SWIGPythonCalculateNumChildren python_swig_calc_children, 232 SWIGPythonGetChildAtIndex python_swig_get_child_index, 233 SWIGPythonGetIndexOfChildWithName python_swig_get_index_child, 234 SWIGPythonCastPyObjectToSBValue python_swig_cast_to_sbvalue, 235 SWIGPythonUpdateSynthProviderInstance python_swig_update_provider, 236 SWIGPythonCallCommand python_swig_call_command, 237 SWIGPythonCallModuleInit python_swig_call_mod_init); 238 239 static void 240 TerminateInterpreter (); 241 242 virtual void 243 ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing. 244 245protected: 246 CommandInterpreter &m_interpreter; 247 lldb::ScriptLanguage m_script_lang; 248}; 249 250} // namespace lldb_private 251 252#endif // #ifndef liblldb_ScriptInterpreter_h_ 253