ScriptInterpreter.h revision 800332c3988c78ea002b64b698f38b58ed95d3ba
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 ScriptInterpreterObject 24{ 25public: 26 ScriptInterpreterObject() : 27 m_object(NULL) 28 {} 29 30 ScriptInterpreterObject(void* obj) : 31 m_object(obj) 32 {} 33 34 ScriptInterpreterObject(const ScriptInterpreterObject& rhs) 35 : m_object(rhs.m_object) 36 {} 37 38 virtual void* 39 GetObject() 40 { 41 return m_object; 42 } 43 44 ScriptInterpreterObject& 45 operator = (const ScriptInterpreterObject& rhs) 46 { 47 if (this != &rhs) 48 m_object = rhs.m_object; 49 return *this; 50 } 51 52 virtual 53 ~ScriptInterpreterObject() 54 {} 55 56protected: 57 void* m_object; 58}; 59 60class ScriptInterpreter 61{ 62public: 63 64 typedef void (*SWIGInitCallback) (void); 65 66 typedef bool (*SWIGBreakpointCallbackFunction) (const char *python_function_name, 67 const char *session_dictionary_name, 68 const lldb::StackFrameSP& frame_sp, 69 const lldb::BreakpointLocationSP &bp_loc_sp); 70 71 typedef bool (*SWIGWatchpointCallbackFunction) (const char *python_function_name, 72 const char *session_dictionary_name, 73 const lldb::StackFrameSP& frame_sp, 74 const lldb::WatchpointSP &wp_sp); 75 76 typedef bool (*SWIGPythonTypeScriptCallbackFunction) (const char *python_function_name, 77 void *session_dictionary, 78 const lldb::ValueObjectSP& valobj_sp, 79 void** pyfunct_wrapper, 80 std::string& retval); 81 82 typedef void* (*SWIGPythonCreateSyntheticProvider) (const std::string python_class_name, 83 const char *session_dictionary_name, 84 const lldb::ValueObjectSP& valobj_sp); 85 86 typedef void* (*SWIGPythonCreateOSPlugin) (const std::string python_class_name, 87 const char *session_dictionary_name, 88 const lldb::ProcessSP& process_sp); 89 90 typedef uint32_t (*SWIGPythonCalculateNumChildren) (void *implementor); 91 typedef void* (*SWIGPythonGetChildAtIndex) (void *implementor, uint32_t idx); 92 typedef int (*SWIGPythonGetIndexOfChildWithName) (void *implementor, const char* child_name); 93 typedef void* (*SWIGPythonCastPyObjectToSBValue) (void* data); 94 typedef bool (*SWIGPythonUpdateSynthProviderInstance) (void* data); 95 typedef bool (*SWIGPythonMightHaveChildrenSynthProviderInstance) (void* data); 96 97 98 typedef bool (*SWIGPythonCallCommand) (const char *python_function_name, 99 const char *session_dictionary_name, 100 lldb::DebuggerSP& debugger, 101 const char* args, 102 std::string& err_msg, 103 lldb_private::CommandReturnObject& cmd_retobj); 104 105 typedef bool (*SWIGPythonCallModuleInit) (const std::string python_module_name, 106 const char *session_dictionary_name, 107 lldb::DebuggerSP& debugger); 108 109 typedef enum 110 { 111 eScriptReturnTypeCharPtr, 112 eScriptReturnTypeBool, 113 eScriptReturnTypeShortInt, 114 eScriptReturnTypeShortIntUnsigned, 115 eScriptReturnTypeInt, 116 eScriptReturnTypeIntUnsigned, 117 eScriptReturnTypeLongInt, 118 eScriptReturnTypeLongIntUnsigned, 119 eScriptReturnTypeLongLong, 120 eScriptReturnTypeLongLongUnsigned, 121 eScriptReturnTypeFloat, 122 eScriptReturnTypeDouble, 123 eScriptReturnTypeChar, 124 eScriptReturnTypeCharStrOrNone 125 } ScriptReturnType; 126 127 ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang); 128 129 virtual ~ScriptInterpreter (); 130 131 virtual bool 132 ExecuteOneLine (const char *command, 133 CommandReturnObject *result, 134 bool enable_io, 135 bool set_lldb_globals = true) = 0; 136 137 virtual void 138 ExecuteInterpreterLoop () = 0; 139 140 virtual bool 141 ExecuteOneLineWithReturn (const char *in_string, 142 ScriptReturnType return_type, 143 void *ret_value, 144 bool enable_io, 145 bool set_lldb_globals = true) 146 { 147 return true; 148 } 149 150 virtual bool 151 ExecuteMultipleLines (const char *in_string, 152 bool enable_io, 153 bool set_lldb_globals = true) 154 { 155 return true; 156 } 157 158 virtual bool 159 ExportFunctionDefinitionToInterpreter (StringList &function_def) 160 { 161 return false; 162 } 163 164 virtual bool 165 GenerateBreakpointCommandCallbackData (StringList &input, std::string& output) 166 { 167 return false; 168 } 169 170 virtual bool 171 GenerateWatchpointCommandCallbackData (StringList &input, std::string& output) 172 { 173 return false; 174 } 175 176 virtual bool 177 GenerateTypeScriptFunction (const char* oneliner, std::string& output, void* name_token = NULL) 178 { 179 return false; 180 } 181 182 virtual bool 183 GenerateTypeScriptFunction (StringList &input, std::string& output, void* name_token = NULL) 184 { 185 return false; 186 } 187 188 virtual bool 189 GenerateScriptAliasFunction (StringList &input, std::string& output) 190 { 191 return false; 192 } 193 194 virtual bool 195 GenerateTypeSynthClass (StringList &input, std::string& output, void* name_token = NULL) 196 { 197 return false; 198 } 199 200 virtual bool 201 GenerateTypeSynthClass (const char* oneliner, std::string& output, void* name_token = NULL) 202 { 203 return false; 204 } 205 206 virtual lldb::ScriptInterpreterObjectSP 207 CreateSyntheticScriptedProvider (std::string class_name, 208 lldb::ValueObjectSP valobj) 209 { 210 return lldb::ScriptInterpreterObjectSP(); 211 } 212 213 virtual lldb::ScriptInterpreterObjectSP 214 CreateOSPlugin (std::string class_name, 215 lldb::ProcessSP process_sp) 216 { 217 return lldb::ScriptInterpreterObjectSP(); 218 } 219 220 virtual lldb::ScriptInterpreterObjectSP 221 OSPlugin_QueryForRegisterInfo (lldb::ScriptInterpreterObjectSP object) 222 { 223 return lldb::ScriptInterpreterObjectSP(); 224 } 225 226 virtual lldb::ScriptInterpreterObjectSP 227 OSPlugin_QueryForThreadsInfo (lldb::ScriptInterpreterObjectSP object) 228 { 229 return lldb::ScriptInterpreterObjectSP(); 230 } 231 232 virtual lldb::ScriptInterpreterObjectSP 233 OSPlugin_QueryForRegisterContextData (lldb::ScriptInterpreterObjectSP object, 234 lldb::tid_t thread_id) 235 { 236 return lldb::ScriptInterpreterObjectSP(); 237 } 238 239 virtual bool 240 GenerateFunction(const char *signature, const StringList &input) 241 { 242 return false; 243 } 244 245 virtual void 246 CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options, 247 CommandReturnObject &result); 248 249 virtual void 250 CollectDataForWatchpointCommandCallback (WatchpointOptions *wp_options, 251 CommandReturnObject &result); 252 253 /// Set a one-liner as the callback for the breakpoint. 254 virtual void 255 SetBreakpointCommandCallback (BreakpointOptions *bp_options, 256 const char *oneliner) 257 { 258 return; 259 } 260 261 /// Set a one-liner as the callback for the watchpoint. 262 virtual void 263 SetWatchpointCommandCallback (WatchpointOptions *wp_options, 264 const char *oneliner) 265 { 266 return; 267 } 268 269 virtual bool 270 GetScriptedSummary (const char *function_name, 271 lldb::ValueObjectSP valobj, 272 lldb::ScriptInterpreterObjectSP& callee_wrapper_sp, 273 std::string& retval) 274 { 275 return false; 276 } 277 278 virtual uint32_t 279 CalculateNumChildren (const lldb::ScriptInterpreterObjectSP& implementor) 280 { 281 return 0; 282 } 283 284 virtual lldb::ValueObjectSP 285 GetChildAtIndex (const lldb::ScriptInterpreterObjectSP& implementor, uint32_t idx) 286 { 287 return lldb::ValueObjectSP(); 288 } 289 290 virtual int 291 GetIndexOfChildWithName (const lldb::ScriptInterpreterObjectSP& implementor, const char* child_name) 292 { 293 return UINT32_MAX; 294 } 295 296 virtual bool 297 UpdateSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor) 298 { 299 return false; 300 } 301 302 virtual bool 303 MightHaveChildrenSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor) 304 { 305 return true; 306 } 307 308 virtual bool 309 RunScriptBasedCommand (const char* impl_function, 310 const char* args, 311 ScriptedCommandSynchronicity synchronicity, 312 lldb_private::CommandReturnObject& cmd_retobj, 313 Error& error) 314 { 315 return false; 316 } 317 318 virtual bool 319 GetDocumentationForItem (const char* item, std::string& dest) 320 { 321 dest.clear(); 322 return false; 323 } 324 325 virtual bool 326 LoadScriptingModule (const char* filename, 327 bool can_reload, 328 bool init_session, 329 lldb_private::Error& error) 330 { 331 error.SetErrorString("loading unimplemented"); 332 return false; 333 } 334 335 virtual lldb::ScriptInterpreterObjectSP 336 MakeScriptObject (void* object) 337 { 338 return lldb::ScriptInterpreterObjectSP(new ScriptInterpreterObject(object)); 339 } 340 341 const char * 342 GetScriptInterpreterPtyName (); 343 344 int 345 GetMasterFileDescriptor (); 346 347 CommandInterpreter & 348 GetCommandInterpreter (); 349 350 static std::string 351 LanguageToString (lldb::ScriptLanguage language); 352 353 static void 354 InitializeInterpreter (SWIGInitCallback python_swig_init_callback); 355 356 static void 357 TerminateInterpreter (); 358 359 virtual void 360 ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing. 361 362protected: 363 CommandInterpreter &m_interpreter; 364 lldb::ScriptLanguage m_script_lang; 365}; 366 367} // namespace lldb_private 368 369#endif // #ifndef liblldb_ScriptInterpreter_h_ 370