ScriptInterpreter.h revision 102b2c2681c9a830afe25bfea35557421905e42c
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 operator bool () 45 { 46 return m_object != NULL; 47 } 48 49 ScriptInterpreterObject& 50 operator = (const ScriptInterpreterObject& rhs) 51 { 52 if (this != &rhs) 53 m_object = rhs.m_object; 54 return *this; 55 } 56 57 virtual 58 ~ScriptInterpreterObject() 59 {} 60 61protected: 62 void* m_object; 63}; 64 65class ScriptInterpreterLocker 66{ 67public: 68 69 ScriptInterpreterLocker () 70 { 71 } 72 73 virtual ~ScriptInterpreterLocker () 74 { 75 } 76private: 77 DISALLOW_COPY_AND_ASSIGN (ScriptInterpreterLocker); 78}; 79 80 81class ScriptInterpreter 82{ 83public: 84 85 typedef void (*SWIGInitCallback) (void); 86 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); 91 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); 96 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); 102 103 typedef void* (*SWIGPythonCreateSyntheticProvider) (const char *python_class_name, 104 const char *session_dictionary_name, 105 const lldb::ValueObjectSP& valobj_sp); 106 107 typedef void* (*SWIGPythonCreateOSPlugin) (const char *python_class_name, 108 const char *session_dictionary_name, 109 const lldb::ProcessSP& process_sp); 110 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); 117 118 119 typedef bool (*SWIGPythonCallCommand) (const char *python_function_name, 120 const char *session_dictionary_name, 121 lldb::DebuggerSP& debugger, 122 const char* args, 123 std::string& err_msg, 124 lldb_private::CommandReturnObject& cmd_retobj); 125 126 typedef bool (*SWIGPythonCallModuleInit) (const char *python_module_name, 127 const char *session_dictionary_name, 128 lldb::DebuggerSP& debugger); 129 130 typedef enum 131 { 132 eScriptReturnTypeCharPtr, 133 eScriptReturnTypeBool, 134 eScriptReturnTypeShortInt, 135 eScriptReturnTypeShortIntUnsigned, 136 eScriptReturnTypeInt, 137 eScriptReturnTypeIntUnsigned, 138 eScriptReturnTypeLongInt, 139 eScriptReturnTypeLongIntUnsigned, 140 eScriptReturnTypeLongLong, 141 eScriptReturnTypeLongLongUnsigned, 142 eScriptReturnTypeFloat, 143 eScriptReturnTypeDouble, 144 eScriptReturnTypeChar, 145 eScriptReturnTypeCharStrOrNone 146 } ScriptReturnType; 147 148 ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang); 149 150 virtual ~ScriptInterpreter (); 151 152 struct ExecuteScriptOptions 153 { 154 public: 155 ExecuteScriptOptions () : 156 m_enable_io(true), 157 m_set_lldb_globals(true), 158 m_maskout_errors(true) 159 { 160 } 161 162 bool 163 GetEnableIO () const 164 { 165 return m_enable_io; 166 } 167 168 bool 169 GetSetLLDBGlobals () const 170 { 171 return m_set_lldb_globals; 172 } 173 174 bool 175 GetMaskoutErrors () const 176 { 177 return m_maskout_errors; 178 } 179 180 ExecuteScriptOptions& 181 SetEnableIO (bool enable) 182 { 183 m_enable_io = enable; 184 return *this; 185 } 186 187 ExecuteScriptOptions& 188 SetSetLLDBGlobals (bool set) 189 { 190 m_set_lldb_globals = set; 191 return *this; 192 } 193 194 ExecuteScriptOptions& 195 SetMaskoutErrors (bool maskout) 196 { 197 m_maskout_errors = maskout; 198 return *this; 199 } 200 201 private: 202 bool m_enable_io; 203 bool m_set_lldb_globals; 204 bool m_maskout_errors; 205 }; 206 207 virtual bool 208 ExecuteOneLine (const char *command, 209 CommandReturnObject *result, 210 const ExecuteScriptOptions &options = ExecuteScriptOptions()) = 0; 211 212 virtual void 213 ExecuteInterpreterLoop () = 0; 214 215 virtual bool 216 ExecuteOneLineWithReturn (const char *in_string, 217 ScriptReturnType return_type, 218 void *ret_value, 219 const ExecuteScriptOptions &options = ExecuteScriptOptions()) 220 { 221 return true; 222 } 223 224 virtual bool 225 ExecuteMultipleLines (const char *in_string, 226 const ExecuteScriptOptions &options = ExecuteScriptOptions()) 227 { 228 return true; 229 } 230 231 virtual bool 232 ExportFunctionDefinitionToInterpreter (StringList &function_def) 233 { 234 return false; 235 } 236 237 virtual bool 238 GenerateBreakpointCommandCallbackData (StringList &input, std::string& output) 239 { 240 return false; 241 } 242 243 virtual bool 244 GenerateWatchpointCommandCallbackData (StringList &input, std::string& output) 245 { 246 return false; 247 } 248 249 virtual bool 250 GenerateTypeScriptFunction (const char* oneliner, std::string& output, void* name_token = NULL) 251 { 252 return false; 253 } 254 255 virtual bool 256 GenerateTypeScriptFunction (StringList &input, std::string& output, void* name_token = NULL) 257 { 258 return false; 259 } 260 261 virtual bool 262 GenerateScriptAliasFunction (StringList &input, std::string& output) 263 { 264 return false; 265 } 266 267 virtual bool 268 GenerateTypeSynthClass (StringList &input, std::string& output, void* name_token = NULL) 269 { 270 return false; 271 } 272 273 virtual bool 274 GenerateTypeSynthClass (const char* oneliner, std::string& output, void* name_token = NULL) 275 { 276 return false; 277 } 278 279 virtual lldb::ScriptInterpreterObjectSP 280 CreateSyntheticScriptedProvider (const char *class_name, 281 lldb::ValueObjectSP valobj) 282 { 283 return lldb::ScriptInterpreterObjectSP(); 284 } 285 286 virtual lldb::ScriptInterpreterObjectSP 287 OSPlugin_CreatePluginObject (const char *class_name, 288 lldb::ProcessSP process_sp) 289 { 290 return lldb::ScriptInterpreterObjectSP(); 291 } 292 293 virtual lldb::ScriptInterpreterObjectSP 294 OSPlugin_RegisterInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp) 295 { 296 return lldb::ScriptInterpreterObjectSP(); 297 } 298 299 virtual lldb::ScriptInterpreterObjectSP 300 OSPlugin_ThreadsInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp) 301 { 302 return lldb::ScriptInterpreterObjectSP(); 303 } 304 305 virtual lldb::ScriptInterpreterObjectSP 306 OSPlugin_RegisterContextData (lldb::ScriptInterpreterObjectSP os_plugin_object_sp, 307 lldb::tid_t thread_id) 308 { 309 return lldb::ScriptInterpreterObjectSP(); 310 } 311 312 virtual lldb::ScriptInterpreterObjectSP 313 OSPlugin_CreateThread (lldb::ScriptInterpreterObjectSP os_plugin_object_sp, 314 lldb::tid_t tid, 315 lldb::addr_t context) 316 { 317 return lldb::ScriptInterpreterObjectSP(); 318 } 319 320 virtual bool 321 GenerateFunction(const char *signature, const StringList &input) 322 { 323 return false; 324 } 325 326 virtual void 327 CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options, 328 CommandReturnObject &result); 329 330 virtual void 331 CollectDataForWatchpointCommandCallback (WatchpointOptions *wp_options, 332 CommandReturnObject &result); 333 334 /// Set a one-liner as the callback for the breakpoint. 335 virtual void 336 SetBreakpointCommandCallback (BreakpointOptions *bp_options, 337 const char *oneliner) 338 { 339 return; 340 } 341 342 /// Set a one-liner as the callback for the watchpoint. 343 virtual void 344 SetWatchpointCommandCallback (WatchpointOptions *wp_options, 345 const char *oneliner) 346 { 347 return; 348 } 349 350 virtual bool 351 GetScriptedSummary (const char *function_name, 352 lldb::ValueObjectSP valobj, 353 lldb::ScriptInterpreterObjectSP& callee_wrapper_sp, 354 std::string& retval) 355 { 356 return false; 357 } 358 359 virtual size_t 360 CalculateNumChildren (const lldb::ScriptInterpreterObjectSP& implementor) 361 { 362 return 0; 363 } 364 365 virtual lldb::ValueObjectSP 366 GetChildAtIndex (const lldb::ScriptInterpreterObjectSP& implementor, uint32_t idx) 367 { 368 return lldb::ValueObjectSP(); 369 } 370 371 virtual int 372 GetIndexOfChildWithName (const lldb::ScriptInterpreterObjectSP& implementor, const char* child_name) 373 { 374 return UINT32_MAX; 375 } 376 377 virtual bool 378 UpdateSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor) 379 { 380 return false; 381 } 382 383 virtual bool 384 MightHaveChildrenSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor) 385 { 386 return true; 387 } 388 389 virtual bool 390 RunScriptBasedCommand (const char* impl_function, 391 const char* args, 392 ScriptedCommandSynchronicity synchronicity, 393 lldb_private::CommandReturnObject& cmd_retobj, 394 Error& error) 395 { 396 return false; 397 } 398 399 virtual bool 400 GetDocumentationForItem (const char* item, std::string& dest) 401 { 402 dest.clear(); 403 return false; 404 } 405 406 virtual bool 407 CheckObjectExists (const char* name) 408 { 409 return false; 410 } 411 412 virtual bool 413 LoadScriptingModule (const char* filename, 414 bool can_reload, 415 bool init_session, 416 lldb_private::Error& error) 417 { 418 error.SetErrorString("loading unimplemented"); 419 return false; 420 } 421 422 virtual lldb::ScriptInterpreterObjectSP 423 MakeScriptObject (void* object) 424 { 425 return lldb::ScriptInterpreterObjectSP(new ScriptInterpreterObject(object)); 426 } 427 428 virtual std::unique_ptr<ScriptInterpreterLocker> 429 AcquireInterpreterLock (); 430 431 const char * 432 GetScriptInterpreterPtyName (); 433 434 int 435 GetMasterFileDescriptor (); 436 437 CommandInterpreter & 438 GetCommandInterpreter (); 439 440 static std::string 441 LanguageToString (lldb::ScriptLanguage language); 442 443 static void 444 InitializeInterpreter (SWIGInitCallback python_swig_init_callback); 445 446 static void 447 TerminateInterpreter (); 448 449 virtual void 450 ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing. 451 452protected: 453 CommandInterpreter &m_interpreter; 454 lldb::ScriptLanguage m_script_lang; 455}; 456 457} // namespace lldb_private 458 459#endif // #ifndef liblldb_ScriptInterpreter_h_ 460