1254721Semaste//===-- ScriptInterpreter.h -------------------------------------*- C++ -*-===// 2254721Semaste// 3254721Semaste// The LLVM Compiler Infrastructure 4254721Semaste// 5254721Semaste// This file is distributed under the University of Illinois Open Source 6254721Semaste// License. See LICENSE.TXT for details. 7254721Semaste// 8254721Semaste//===----------------------------------------------------------------------===// 9254721Semaste 10254721Semaste#ifndef liblldb_ScriptInterpreter_h_ 11254721Semaste#define liblldb_ScriptInterpreter_h_ 12254721Semaste 13254721Semaste#include "lldb/lldb-private.h" 14254721Semaste 15254721Semaste#include "lldb/Core/Broadcaster.h" 16254721Semaste#include "lldb/Core/Error.h" 17254721Semaste 18254721Semaste#include "lldb/Utility/PseudoTerminal.h" 19254721Semaste 20254721Semaste 21254721Semastenamespace lldb_private { 22254721Semaste 23254721Semasteclass ScriptInterpreterObject 24254721Semaste{ 25254721Semastepublic: 26254721Semaste ScriptInterpreterObject() : 27254721Semaste m_object(NULL) 28254721Semaste {} 29254721Semaste 30254721Semaste ScriptInterpreterObject(void* obj) : 31254721Semaste m_object(obj) 32254721Semaste {} 33254721Semaste 34254721Semaste ScriptInterpreterObject(const ScriptInterpreterObject& rhs) 35254721Semaste : m_object(rhs.m_object) 36254721Semaste {} 37254721Semaste 38254721Semaste virtual void* 39254721Semaste GetObject() 40254721Semaste { 41254721Semaste return m_object; 42254721Semaste } 43254721Semaste 44263363Semaste explicit operator bool () 45254721Semaste { 46254721Semaste return m_object != NULL; 47254721Semaste } 48254721Semaste 49254721Semaste ScriptInterpreterObject& 50254721Semaste operator = (const ScriptInterpreterObject& rhs) 51254721Semaste { 52254721Semaste if (this != &rhs) 53254721Semaste m_object = rhs.m_object; 54254721Semaste return *this; 55254721Semaste } 56254721Semaste 57254721Semaste virtual 58254721Semaste ~ScriptInterpreterObject() 59254721Semaste {} 60254721Semaste 61254721Semasteprotected: 62254721Semaste void* m_object; 63254721Semaste}; 64254721Semaste 65254721Semasteclass ScriptInterpreterLocker 66254721Semaste{ 67254721Semastepublic: 68254721Semaste 69254721Semaste ScriptInterpreterLocker () 70254721Semaste { 71254721Semaste } 72254721Semaste 73254721Semaste virtual ~ScriptInterpreterLocker () 74254721Semaste { 75254721Semaste } 76254721Semasteprivate: 77254721Semaste DISALLOW_COPY_AND_ASSIGN (ScriptInterpreterLocker); 78254721Semaste}; 79254721Semaste 80254721Semaste 81254721Semasteclass ScriptInterpreter 82254721Semaste{ 83254721Semastepublic: 84254721Semaste 85254721Semaste typedef void (*SWIGInitCallback) (void); 86254721Semaste 87254721Semaste typedef bool (*SWIGBreakpointCallbackFunction) (const char *python_function_name, 88254721Semaste const char *session_dictionary_name, 89254721Semaste const lldb::StackFrameSP& frame_sp, 90254721Semaste const lldb::BreakpointLocationSP &bp_loc_sp); 91254721Semaste 92254721Semaste typedef bool (*SWIGWatchpointCallbackFunction) (const char *python_function_name, 93254721Semaste const char *session_dictionary_name, 94254721Semaste const lldb::StackFrameSP& frame_sp, 95254721Semaste const lldb::WatchpointSP &wp_sp); 96254721Semaste 97254721Semaste typedef bool (*SWIGPythonTypeScriptCallbackFunction) (const char *python_function_name, 98254721Semaste void *session_dictionary, 99254721Semaste const lldb::ValueObjectSP& valobj_sp, 100254721Semaste void** pyfunct_wrapper, 101254721Semaste std::string& retval); 102254721Semaste 103254721Semaste typedef void* (*SWIGPythonCreateSyntheticProvider) (const char *python_class_name, 104254721Semaste const char *session_dictionary_name, 105254721Semaste const lldb::ValueObjectSP& valobj_sp); 106254721Semaste 107254721Semaste typedef void* (*SWIGPythonCreateOSPlugin) (const char *python_class_name, 108254721Semaste const char *session_dictionary_name, 109254721Semaste const lldb::ProcessSP& process_sp); 110254721Semaste 111263363Semaste typedef uint32_t (*SWIGPythonCalculateNumChildren) (void *implementor); 112263363Semaste typedef void* (*SWIGPythonGetChildAtIndex) (void *implementor, uint32_t idx); 113263363Semaste typedef int (*SWIGPythonGetIndexOfChildWithName) (void *implementor, const char* child_name); 114263363Semaste typedef void* (*SWIGPythonCastPyObjectToSBValue) (void* data); 115263363Semaste typedef lldb::ValueObjectSP (*SWIGPythonGetValueObjectSPFromSBValue) (void* data); 116263363Semaste typedef bool (*SWIGPythonUpdateSynthProviderInstance) (void* data); 117263363Semaste typedef bool (*SWIGPythonMightHaveChildrenSynthProviderInstance) (void* data); 118254721Semaste 119254721Semaste 120263363Semaste typedef bool (*SWIGPythonCallCommand) (const char *python_function_name, 121263363Semaste const char *session_dictionary_name, 122263363Semaste lldb::DebuggerSP& debugger, 123263363Semaste const char* args, 124263363Semaste lldb_private::CommandReturnObject& cmd_retobj); 125254721Semaste 126263363Semaste typedef bool (*SWIGPythonCallModuleInit) (const char *python_module_name, 127263363Semaste const char *session_dictionary_name, 128263363Semaste lldb::DebuggerSP& debugger); 129254721Semaste 130263363Semaste typedef bool (*SWIGPythonScriptKeyword_Process) (const char* python_function_name, 131263363Semaste const char* session_dictionary_name, 132263363Semaste lldb::ProcessSP& process, 133263363Semaste std::string& output); 134263363Semaste typedef bool (*SWIGPythonScriptKeyword_Thread) (const char* python_function_name, 135263363Semaste const char* session_dictionary_name, 136263363Semaste lldb::ThreadSP& thread, 137263363Semaste std::string& output); 138254721Semaste 139263363Semaste typedef bool (*SWIGPythonScriptKeyword_Target) (const char* python_function_name, 140263363Semaste const char* session_dictionary_name, 141263363Semaste lldb::TargetSP& target, 142263363Semaste std::string& output); 143254721Semaste 144263363Semaste typedef bool (*SWIGPythonScriptKeyword_Frame) (const char* python_function_name, 145263363Semaste const char* session_dictionary_name, 146263363Semaste lldb::StackFrameSP& frame, 147263363Semaste std::string& output); 148254721Semaste 149263363Semaste typedef void* (*SWIGPython_GetDynamicSetting) (void* module, 150263363Semaste const char* setting, 151263363Semaste const lldb::TargetSP& target_sp); 152254721Semaste 153254721Semaste typedef enum 154254721Semaste { 155254721Semaste eScriptReturnTypeCharPtr, 156254721Semaste eScriptReturnTypeBool, 157254721Semaste eScriptReturnTypeShortInt, 158254721Semaste eScriptReturnTypeShortIntUnsigned, 159254721Semaste eScriptReturnTypeInt, 160254721Semaste eScriptReturnTypeIntUnsigned, 161254721Semaste eScriptReturnTypeLongInt, 162254721Semaste eScriptReturnTypeLongIntUnsigned, 163254721Semaste eScriptReturnTypeLongLong, 164254721Semaste eScriptReturnTypeLongLongUnsigned, 165254721Semaste eScriptReturnTypeFloat, 166254721Semaste eScriptReturnTypeDouble, 167254721Semaste eScriptReturnTypeChar, 168263363Semaste eScriptReturnTypeCharStrOrNone, 169263363Semaste eScriptReturnTypeOpaqueObject 170254721Semaste } ScriptReturnType; 171254721Semaste 172254721Semaste ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang); 173254721Semaste 174254721Semaste virtual ~ScriptInterpreter (); 175254721Semaste 176254721Semaste struct ExecuteScriptOptions 177254721Semaste { 178254721Semaste public: 179254721Semaste ExecuteScriptOptions () : 180254721Semaste m_enable_io(true), 181254721Semaste m_set_lldb_globals(true), 182254721Semaste m_maskout_errors(true) 183254721Semaste { 184254721Semaste } 185254721Semaste 186254721Semaste bool 187254721Semaste GetEnableIO () const 188254721Semaste { 189254721Semaste return m_enable_io; 190254721Semaste } 191254721Semaste 192254721Semaste bool 193254721Semaste GetSetLLDBGlobals () const 194254721Semaste { 195254721Semaste return m_set_lldb_globals; 196254721Semaste } 197254721Semaste 198254721Semaste bool 199254721Semaste GetMaskoutErrors () const 200254721Semaste { 201254721Semaste return m_maskout_errors; 202254721Semaste } 203254721Semaste 204254721Semaste ExecuteScriptOptions& 205254721Semaste SetEnableIO (bool enable) 206254721Semaste { 207254721Semaste m_enable_io = enable; 208254721Semaste return *this; 209254721Semaste } 210254721Semaste 211254721Semaste ExecuteScriptOptions& 212254721Semaste SetSetLLDBGlobals (bool set) 213254721Semaste { 214254721Semaste m_set_lldb_globals = set; 215254721Semaste return *this; 216254721Semaste } 217254721Semaste 218254721Semaste ExecuteScriptOptions& 219254721Semaste SetMaskoutErrors (bool maskout) 220254721Semaste { 221254721Semaste m_maskout_errors = maskout; 222254721Semaste return *this; 223254721Semaste } 224254721Semaste 225254721Semaste private: 226254721Semaste bool m_enable_io; 227254721Semaste bool m_set_lldb_globals; 228254721Semaste bool m_maskout_errors; 229254721Semaste }; 230254721Semaste 231254721Semaste virtual bool 232254721Semaste ExecuteOneLine (const char *command, 233254721Semaste CommandReturnObject *result, 234254721Semaste const ExecuteScriptOptions &options = ExecuteScriptOptions()) = 0; 235254721Semaste 236254721Semaste virtual void 237254721Semaste ExecuteInterpreterLoop () = 0; 238254721Semaste 239254721Semaste virtual bool 240254721Semaste ExecuteOneLineWithReturn (const char *in_string, 241254721Semaste ScriptReturnType return_type, 242254721Semaste void *ret_value, 243254721Semaste const ExecuteScriptOptions &options = ExecuteScriptOptions()) 244254721Semaste { 245254721Semaste return true; 246254721Semaste } 247254721Semaste 248269024Semaste virtual Error 249254721Semaste ExecuteMultipleLines (const char *in_string, 250254721Semaste const ExecuteScriptOptions &options = ExecuteScriptOptions()) 251254721Semaste { 252269024Semaste Error error; 253269024Semaste error.SetErrorString("not implemented"); 254269024Semaste return error; 255254721Semaste } 256254721Semaste 257254721Semaste virtual bool 258254721Semaste ExportFunctionDefinitionToInterpreter (StringList &function_def) 259254721Semaste { 260254721Semaste return false; 261254721Semaste } 262254721Semaste 263254721Semaste virtual bool 264254721Semaste GenerateBreakpointCommandCallbackData (StringList &input, std::string& output) 265254721Semaste { 266254721Semaste return false; 267254721Semaste } 268254721Semaste 269254721Semaste virtual bool 270254721Semaste GenerateWatchpointCommandCallbackData (StringList &input, std::string& output) 271254721Semaste { 272254721Semaste return false; 273254721Semaste } 274254721Semaste 275254721Semaste virtual bool 276254721Semaste GenerateTypeScriptFunction (const char* oneliner, std::string& output, void* name_token = NULL) 277254721Semaste { 278254721Semaste return false; 279254721Semaste } 280254721Semaste 281254721Semaste virtual bool 282254721Semaste GenerateTypeScriptFunction (StringList &input, std::string& output, void* name_token = NULL) 283254721Semaste { 284254721Semaste return false; 285254721Semaste } 286254721Semaste 287254721Semaste virtual bool 288254721Semaste GenerateScriptAliasFunction (StringList &input, std::string& output) 289254721Semaste { 290254721Semaste return false; 291254721Semaste } 292254721Semaste 293254721Semaste virtual bool 294254721Semaste GenerateTypeSynthClass (StringList &input, std::string& output, void* name_token = NULL) 295254721Semaste { 296254721Semaste return false; 297254721Semaste } 298254721Semaste 299254721Semaste virtual bool 300254721Semaste GenerateTypeSynthClass (const char* oneliner, std::string& output, void* name_token = NULL) 301254721Semaste { 302254721Semaste return false; 303254721Semaste } 304254721Semaste 305254721Semaste virtual lldb::ScriptInterpreterObjectSP 306254721Semaste CreateSyntheticScriptedProvider (const char *class_name, 307254721Semaste lldb::ValueObjectSP valobj) 308254721Semaste { 309254721Semaste return lldb::ScriptInterpreterObjectSP(); 310254721Semaste } 311254721Semaste 312254721Semaste virtual lldb::ScriptInterpreterObjectSP 313254721Semaste OSPlugin_CreatePluginObject (const char *class_name, 314254721Semaste lldb::ProcessSP process_sp) 315254721Semaste { 316254721Semaste return lldb::ScriptInterpreterObjectSP(); 317254721Semaste } 318254721Semaste 319254721Semaste virtual lldb::ScriptInterpreterObjectSP 320254721Semaste OSPlugin_RegisterInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp) 321254721Semaste { 322254721Semaste return lldb::ScriptInterpreterObjectSP(); 323254721Semaste } 324254721Semaste 325254721Semaste virtual lldb::ScriptInterpreterObjectSP 326254721Semaste OSPlugin_ThreadsInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp) 327254721Semaste { 328254721Semaste return lldb::ScriptInterpreterObjectSP(); 329254721Semaste } 330254721Semaste 331254721Semaste virtual lldb::ScriptInterpreterObjectSP 332254721Semaste OSPlugin_RegisterContextData (lldb::ScriptInterpreterObjectSP os_plugin_object_sp, 333254721Semaste lldb::tid_t thread_id) 334254721Semaste { 335254721Semaste return lldb::ScriptInterpreterObjectSP(); 336254721Semaste } 337254721Semaste 338254721Semaste virtual lldb::ScriptInterpreterObjectSP 339254721Semaste OSPlugin_CreateThread (lldb::ScriptInterpreterObjectSP os_plugin_object_sp, 340254721Semaste lldb::tid_t tid, 341254721Semaste lldb::addr_t context) 342254721Semaste { 343254721Semaste return lldb::ScriptInterpreterObjectSP(); 344254721Semaste } 345263363Semaste 346263363Semaste virtual lldb::ScriptInterpreterObjectSP 347263363Semaste LoadPluginModule (const FileSpec& file_spec, 348263363Semaste lldb_private::Error& error) 349263363Semaste { 350263363Semaste return lldb::ScriptInterpreterObjectSP(); 351263363Semaste } 352263363Semaste 353263363Semaste virtual lldb::ScriptInterpreterObjectSP 354263363Semaste GetDynamicSettings (lldb::ScriptInterpreterObjectSP plugin_module_sp, 355263363Semaste Target* target, 356263363Semaste const char* setting_name, 357263363Semaste lldb_private::Error& error) 358263363Semaste { 359263363Semaste return lldb::ScriptInterpreterObjectSP(); 360263363Semaste } 361254721Semaste 362254721Semaste virtual bool 363254721Semaste GenerateFunction(const char *signature, const StringList &input) 364254721Semaste { 365254721Semaste return false; 366254721Semaste } 367254721Semaste 368254721Semaste virtual void 369254721Semaste CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options, 370254721Semaste CommandReturnObject &result); 371254721Semaste 372254721Semaste virtual void 373254721Semaste CollectDataForWatchpointCommandCallback (WatchpointOptions *wp_options, 374254721Semaste CommandReturnObject &result); 375254721Semaste 376254721Semaste /// Set a one-liner as the callback for the breakpoint. 377254721Semaste virtual void 378254721Semaste SetBreakpointCommandCallback (BreakpointOptions *bp_options, 379254721Semaste const char *oneliner) 380254721Semaste { 381254721Semaste return; 382254721Semaste } 383254721Semaste 384254721Semaste /// Set a one-liner as the callback for the watchpoint. 385254721Semaste virtual void 386254721Semaste SetWatchpointCommandCallback (WatchpointOptions *wp_options, 387254721Semaste const char *oneliner) 388254721Semaste { 389254721Semaste return; 390254721Semaste } 391254721Semaste 392254721Semaste virtual bool 393254721Semaste GetScriptedSummary (const char *function_name, 394254721Semaste lldb::ValueObjectSP valobj, 395254721Semaste lldb::ScriptInterpreterObjectSP& callee_wrapper_sp, 396254721Semaste std::string& retval) 397254721Semaste { 398254721Semaste return false; 399254721Semaste } 400254721Semaste 401254721Semaste virtual size_t 402254721Semaste CalculateNumChildren (const lldb::ScriptInterpreterObjectSP& implementor) 403254721Semaste { 404254721Semaste return 0; 405254721Semaste } 406254721Semaste 407254721Semaste virtual lldb::ValueObjectSP 408254721Semaste GetChildAtIndex (const lldb::ScriptInterpreterObjectSP& implementor, uint32_t idx) 409254721Semaste { 410254721Semaste return lldb::ValueObjectSP(); 411254721Semaste } 412254721Semaste 413254721Semaste virtual int 414254721Semaste GetIndexOfChildWithName (const lldb::ScriptInterpreterObjectSP& implementor, const char* child_name) 415254721Semaste { 416254721Semaste return UINT32_MAX; 417254721Semaste } 418254721Semaste 419254721Semaste virtual bool 420254721Semaste UpdateSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor) 421254721Semaste { 422254721Semaste return false; 423254721Semaste } 424254721Semaste 425254721Semaste virtual bool 426254721Semaste MightHaveChildrenSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor) 427254721Semaste { 428254721Semaste return true; 429254721Semaste } 430254721Semaste 431254721Semaste virtual bool 432254721Semaste RunScriptBasedCommand (const char* impl_function, 433254721Semaste const char* args, 434254721Semaste ScriptedCommandSynchronicity synchronicity, 435254721Semaste lldb_private::CommandReturnObject& cmd_retobj, 436254721Semaste Error& error) 437254721Semaste { 438254721Semaste return false; 439254721Semaste } 440254721Semaste 441254721Semaste virtual bool 442254721Semaste RunScriptFormatKeyword (const char* impl_function, 443254721Semaste Process* process, 444254721Semaste std::string& output, 445254721Semaste Error& error) 446254721Semaste { 447254721Semaste error.SetErrorString("unimplemented"); 448254721Semaste return false; 449254721Semaste } 450254721Semaste 451254721Semaste virtual bool 452254721Semaste RunScriptFormatKeyword (const char* impl_function, 453254721Semaste Thread* thread, 454254721Semaste std::string& output, 455254721Semaste Error& error) 456254721Semaste { 457254721Semaste error.SetErrorString("unimplemented"); 458254721Semaste return false; 459254721Semaste } 460254721Semaste 461254721Semaste virtual bool 462254721Semaste RunScriptFormatKeyword (const char* impl_function, 463254721Semaste Target* target, 464254721Semaste std::string& output, 465254721Semaste Error& error) 466254721Semaste { 467254721Semaste error.SetErrorString("unimplemented"); 468254721Semaste return false; 469254721Semaste } 470254721Semaste 471254721Semaste virtual bool 472254721Semaste RunScriptFormatKeyword (const char* impl_function, 473254721Semaste StackFrame* frame, 474254721Semaste std::string& output, 475254721Semaste Error& error) 476254721Semaste { 477254721Semaste error.SetErrorString("unimplemented"); 478254721Semaste return false; 479254721Semaste } 480254721Semaste 481254721Semaste virtual bool 482254721Semaste GetDocumentationForItem (const char* item, std::string& dest) 483254721Semaste { 484254721Semaste dest.clear(); 485254721Semaste return false; 486254721Semaste } 487254721Semaste 488254721Semaste virtual bool 489254721Semaste CheckObjectExists (const char* name) 490254721Semaste { 491254721Semaste return false; 492254721Semaste } 493254721Semaste 494254721Semaste virtual bool 495254721Semaste LoadScriptingModule (const char* filename, 496254721Semaste bool can_reload, 497254721Semaste bool init_session, 498263363Semaste lldb_private::Error& error, 499263363Semaste lldb::ScriptInterpreterObjectSP* module_sp = nullptr) 500254721Semaste { 501254721Semaste error.SetErrorString("loading unimplemented"); 502254721Semaste return false; 503254721Semaste } 504254721Semaste 505254721Semaste virtual lldb::ScriptInterpreterObjectSP 506254721Semaste MakeScriptObject (void* object) 507254721Semaste { 508254721Semaste return lldb::ScriptInterpreterObjectSP(new ScriptInterpreterObject(object)); 509254721Semaste } 510254721Semaste 511254721Semaste virtual std::unique_ptr<ScriptInterpreterLocker> 512254721Semaste AcquireInterpreterLock (); 513254721Semaste 514254721Semaste const char * 515254721Semaste GetScriptInterpreterPtyName (); 516254721Semaste 517254721Semaste int 518254721Semaste GetMasterFileDescriptor (); 519254721Semaste 520254721Semaste CommandInterpreter & 521254721Semaste GetCommandInterpreter (); 522254721Semaste 523254721Semaste static std::string 524254721Semaste LanguageToString (lldb::ScriptLanguage language); 525254721Semaste 526254721Semaste static void 527263363Semaste InitializeInterpreter (SWIGInitCallback python_swig_init_callback, 528263363Semaste SWIGBreakpointCallbackFunction swig_breakpoint_callback, 529263363Semaste SWIGWatchpointCallbackFunction swig_watchpoint_callback, 530263363Semaste SWIGPythonTypeScriptCallbackFunction swig_typescript_callback, 531263363Semaste SWIGPythonCreateSyntheticProvider swig_synthetic_script, 532263363Semaste SWIGPythonCalculateNumChildren swig_calc_children, 533263363Semaste SWIGPythonGetChildAtIndex swig_get_child_index, 534263363Semaste SWIGPythonGetIndexOfChildWithName swig_get_index_child, 535263363Semaste SWIGPythonCastPyObjectToSBValue swig_cast_to_sbvalue , 536263363Semaste SWIGPythonGetValueObjectSPFromSBValue swig_get_valobj_sp_from_sbvalue, 537263363Semaste SWIGPythonUpdateSynthProviderInstance swig_update_provider, 538263363Semaste SWIGPythonMightHaveChildrenSynthProviderInstance swig_mighthavechildren_provider, 539263363Semaste SWIGPythonCallCommand swig_call_command, 540263363Semaste SWIGPythonCallModuleInit swig_call_module_init, 541263363Semaste SWIGPythonCreateOSPlugin swig_create_os_plugin, 542263363Semaste SWIGPythonScriptKeyword_Process swig_run_script_keyword_process, 543263363Semaste SWIGPythonScriptKeyword_Thread swig_run_script_keyword_thread, 544263363Semaste SWIGPythonScriptKeyword_Target swig_run_script_keyword_target, 545263363Semaste SWIGPythonScriptKeyword_Frame swig_run_script_keyword_frame, 546263363Semaste SWIGPython_GetDynamicSetting swig_plugin_get); 547254721Semaste 548254721Semaste static void 549254721Semaste TerminateInterpreter (); 550254721Semaste 551254721Semaste virtual void 552254721Semaste ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing. 553254721Semaste 554254721Semasteprotected: 555254721Semaste CommandInterpreter &m_interpreter; 556254721Semaste lldb::ScriptLanguage m_script_lang; 557254721Semaste}; 558254721Semaste 559254721Semaste} // namespace lldb_private 560254721Semaste 561254721Semaste#endif // #ifndef liblldb_ScriptInterpreter_h_ 562