ScriptInterpreter.h revision 001cd53e9d8d9e481ada536924ea7563b84ee9cf
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 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); 138 139 typedef bool (*SWIGPythonScriptKeyword_Target) (const char* python_function_name, 140 const char* session_dictionary_name, 141 lldb::TargetSP& target, 142 std::string& output); 143 144 typedef bool (*SWIGPythonScriptKeyword_Frame) (const char* python_function_name, 145 const char* session_dictionary_name, 146 lldb::StackFrameSP& frame, 147 std::string& output); 148 149 150 151 typedef enum 152 { 153 eScriptReturnTypeCharPtr, 154 eScriptReturnTypeBool, 155 eScriptReturnTypeShortInt, 156 eScriptReturnTypeShortIntUnsigned, 157 eScriptReturnTypeInt, 158 eScriptReturnTypeIntUnsigned, 159 eScriptReturnTypeLongInt, 160 eScriptReturnTypeLongIntUnsigned, 161 eScriptReturnTypeLongLong, 162 eScriptReturnTypeLongLongUnsigned, 163 eScriptReturnTypeFloat, 164 eScriptReturnTypeDouble, 165 eScriptReturnTypeChar, 166 eScriptReturnTypeCharStrOrNone 167 } ScriptReturnType; 168 169 ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang); 170 171 virtual ~ScriptInterpreter (); 172 173 struct ExecuteScriptOptions 174 { 175 public: 176 ExecuteScriptOptions () : 177 m_enable_io(true), 178 m_set_lldb_globals(true), 179 m_maskout_errors(true) 180 { 181 } 182 183 bool 184 GetEnableIO () const 185 { 186 return m_enable_io; 187 } 188 189 bool 190 GetSetLLDBGlobals () const 191 { 192 return m_set_lldb_globals; 193 } 194 195 bool 196 GetMaskoutErrors () const 197 { 198 return m_maskout_errors; 199 } 200 201 ExecuteScriptOptions& 202 SetEnableIO (bool enable) 203 { 204 m_enable_io = enable; 205 return *this; 206 } 207 208 ExecuteScriptOptions& 209 SetSetLLDBGlobals (bool set) 210 { 211 m_set_lldb_globals = set; 212 return *this; 213 } 214 215 ExecuteScriptOptions& 216 SetMaskoutErrors (bool maskout) 217 { 218 m_maskout_errors = maskout; 219 return *this; 220 } 221 222 private: 223 bool m_enable_io; 224 bool m_set_lldb_globals; 225 bool m_maskout_errors; 226 }; 227 228 virtual bool 229 ExecuteOneLine (const char *command, 230 CommandReturnObject *result, 231 const ExecuteScriptOptions &options = ExecuteScriptOptions()) = 0; 232 233 virtual void 234 ExecuteInterpreterLoop () = 0; 235 236 virtual bool 237 ExecuteOneLineWithReturn (const char *in_string, 238 ScriptReturnType return_type, 239 void *ret_value, 240 const ExecuteScriptOptions &options = ExecuteScriptOptions()) 241 { 242 return true; 243 } 244 245 virtual bool 246 ExecuteMultipleLines (const char *in_string, 247 const ExecuteScriptOptions &options = ExecuteScriptOptions()) 248 { 249 return true; 250 } 251 252 virtual bool 253 ExportFunctionDefinitionToInterpreter (StringList &function_def) 254 { 255 return false; 256 } 257 258 virtual bool 259 GenerateBreakpointCommandCallbackData (StringList &input, std::string& output) 260 { 261 return false; 262 } 263 264 virtual bool 265 GenerateWatchpointCommandCallbackData (StringList &input, std::string& output) 266 { 267 return false; 268 } 269 270 virtual bool 271 GenerateTypeScriptFunction (const char* oneliner, std::string& output, void* name_token = NULL) 272 { 273 return false; 274 } 275 276 virtual bool 277 GenerateTypeScriptFunction (StringList &input, std::string& output, void* name_token = NULL) 278 { 279 return false; 280 } 281 282 virtual bool 283 GenerateScriptAliasFunction (StringList &input, std::string& output) 284 { 285 return false; 286 } 287 288 virtual bool 289 GenerateTypeSynthClass (StringList &input, std::string& output, void* name_token = NULL) 290 { 291 return false; 292 } 293 294 virtual bool 295 GenerateTypeSynthClass (const char* oneliner, std::string& output, void* name_token = NULL) 296 { 297 return false; 298 } 299 300 virtual lldb::ScriptInterpreterObjectSP 301 CreateSyntheticScriptedProvider (const char *class_name, 302 lldb::ValueObjectSP valobj) 303 { 304 return lldb::ScriptInterpreterObjectSP(); 305 } 306 307 virtual lldb::ScriptInterpreterObjectSP 308 OSPlugin_CreatePluginObject (const char *class_name, 309 lldb::ProcessSP process_sp) 310 { 311 return lldb::ScriptInterpreterObjectSP(); 312 } 313 314 virtual lldb::ScriptInterpreterObjectSP 315 OSPlugin_RegisterInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp) 316 { 317 return lldb::ScriptInterpreterObjectSP(); 318 } 319 320 virtual lldb::ScriptInterpreterObjectSP 321 OSPlugin_ThreadsInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp) 322 { 323 return lldb::ScriptInterpreterObjectSP(); 324 } 325 326 virtual lldb::ScriptInterpreterObjectSP 327 OSPlugin_RegisterContextData (lldb::ScriptInterpreterObjectSP os_plugin_object_sp, 328 lldb::tid_t thread_id) 329 { 330 return lldb::ScriptInterpreterObjectSP(); 331 } 332 333 virtual lldb::ScriptInterpreterObjectSP 334 OSPlugin_CreateThread (lldb::ScriptInterpreterObjectSP os_plugin_object_sp, 335 lldb::tid_t tid, 336 lldb::addr_t context) 337 { 338 return lldb::ScriptInterpreterObjectSP(); 339 } 340 341 virtual bool 342 GenerateFunction(const char *signature, const StringList &input) 343 { 344 return false; 345 } 346 347 virtual void 348 CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options, 349 CommandReturnObject &result); 350 351 virtual void 352 CollectDataForWatchpointCommandCallback (WatchpointOptions *wp_options, 353 CommandReturnObject &result); 354 355 /// Set a one-liner as the callback for the breakpoint. 356 virtual void 357 SetBreakpointCommandCallback (BreakpointOptions *bp_options, 358 const char *oneliner) 359 { 360 return; 361 } 362 363 /// Set a one-liner as the callback for the watchpoint. 364 virtual void 365 SetWatchpointCommandCallback (WatchpointOptions *wp_options, 366 const char *oneliner) 367 { 368 return; 369 } 370 371 virtual bool 372 GetScriptedSummary (const char *function_name, 373 lldb::ValueObjectSP valobj, 374 lldb::ScriptInterpreterObjectSP& callee_wrapper_sp, 375 std::string& retval) 376 { 377 return false; 378 } 379 380 virtual size_t 381 CalculateNumChildren (const lldb::ScriptInterpreterObjectSP& implementor) 382 { 383 return 0; 384 } 385 386 virtual lldb::ValueObjectSP 387 GetChildAtIndex (const lldb::ScriptInterpreterObjectSP& implementor, uint32_t idx) 388 { 389 return lldb::ValueObjectSP(); 390 } 391 392 virtual int 393 GetIndexOfChildWithName (const lldb::ScriptInterpreterObjectSP& implementor, const char* child_name) 394 { 395 return UINT32_MAX; 396 } 397 398 virtual bool 399 UpdateSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor) 400 { 401 return false; 402 } 403 404 virtual bool 405 MightHaveChildrenSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor) 406 { 407 return true; 408 } 409 410 virtual bool 411 RunScriptBasedCommand (const char* impl_function, 412 const char* args, 413 ScriptedCommandSynchronicity synchronicity, 414 lldb_private::CommandReturnObject& cmd_retobj, 415 Error& error) 416 { 417 return false; 418 } 419 420 virtual bool 421 RunScriptFormatKeyword (const char* impl_function, 422 Process* process, 423 std::string& output, 424 Error& error) 425 { 426 error.SetErrorString("unimplemented"); 427 return false; 428 } 429 430 virtual bool 431 RunScriptFormatKeyword (const char* impl_function, 432 Thread* thread, 433 std::string& output, 434 Error& error) 435 { 436 error.SetErrorString("unimplemented"); 437 return false; 438 } 439 440 virtual bool 441 RunScriptFormatKeyword (const char* impl_function, 442 Target* target, 443 std::string& output, 444 Error& error) 445 { 446 error.SetErrorString("unimplemented"); 447 return false; 448 } 449 450 virtual bool 451 RunScriptFormatKeyword (const char* impl_function, 452 StackFrame* frame, 453 std::string& output, 454 Error& error) 455 { 456 error.SetErrorString("unimplemented"); 457 return false; 458 } 459 460 virtual bool 461 GetDocumentationForItem (const char* item, std::string& dest) 462 { 463 dest.clear(); 464 return false; 465 } 466 467 virtual bool 468 CheckObjectExists (const char* name) 469 { 470 return false; 471 } 472 473 virtual bool 474 LoadScriptingModule (const char* filename, 475 bool can_reload, 476 bool init_session, 477 lldb_private::Error& error) 478 { 479 error.SetErrorString("loading unimplemented"); 480 return false; 481 } 482 483 virtual lldb::ScriptInterpreterObjectSP 484 MakeScriptObject (void* object) 485 { 486 return lldb::ScriptInterpreterObjectSP(new ScriptInterpreterObject(object)); 487 } 488 489 virtual std::unique_ptr<ScriptInterpreterLocker> 490 AcquireInterpreterLock (); 491 492 const char * 493 GetScriptInterpreterPtyName (); 494 495 int 496 GetMasterFileDescriptor (); 497 498 CommandInterpreter & 499 GetCommandInterpreter (); 500 501 static std::string 502 LanguageToString (lldb::ScriptLanguage language); 503 504 static void 505 InitializeInterpreter (SWIGInitCallback python_swig_init_callback); 506 507 static void 508 TerminateInterpreter (); 509 510 virtual void 511 ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing. 512 513protected: 514 CommandInterpreter &m_interpreter; 515 lldb::ScriptLanguage m_script_lang; 516}; 517 518} // namespace lldb_private 519 520#endif // #ifndef liblldb_ScriptInterpreter_h_ 521