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 #include "lldb/Core/StructuredData.h" 18 19 #include "lldb/Utility/PseudoTerminal.h" 20 21 22 namespace lldb_private { 23 24 class ScriptInterpreterLocker 25 { 26 public: 27 ScriptInterpreterLocker()28 ScriptInterpreterLocker () 29 { 30 } 31 ~ScriptInterpreterLocker()32 virtual ~ScriptInterpreterLocker () 33 { 34 } 35 private: 36 DISALLOW_COPY_AND_ASSIGN (ScriptInterpreterLocker); 37 }; 38 39 40 class ScriptInterpreter 41 { 42 public: 43 44 typedef enum 45 { 46 eScriptReturnTypeCharPtr, 47 eScriptReturnTypeBool, 48 eScriptReturnTypeShortInt, 49 eScriptReturnTypeShortIntUnsigned, 50 eScriptReturnTypeInt, 51 eScriptReturnTypeIntUnsigned, 52 eScriptReturnTypeLongInt, 53 eScriptReturnTypeLongIntUnsigned, 54 eScriptReturnTypeLongLong, 55 eScriptReturnTypeLongLongUnsigned, 56 eScriptReturnTypeFloat, 57 eScriptReturnTypeDouble, 58 eScriptReturnTypeChar, 59 eScriptReturnTypeCharStrOrNone, 60 eScriptReturnTypeOpaqueObject 61 } ScriptReturnType; 62 63 ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang); 64 65 virtual ~ScriptInterpreter (); 66 67 struct ExecuteScriptOptions 68 { 69 public: ExecuteScriptOptionsExecuteScriptOptions70 ExecuteScriptOptions () : 71 m_enable_io(true), 72 m_set_lldb_globals(true), 73 m_maskout_errors(true) 74 { 75 } 76 77 bool GetEnableIOExecuteScriptOptions78 GetEnableIO () const 79 { 80 return m_enable_io; 81 } 82 83 bool GetSetLLDBGlobalsExecuteScriptOptions84 GetSetLLDBGlobals () const 85 { 86 return m_set_lldb_globals; 87 } 88 89 bool GetMaskoutErrorsExecuteScriptOptions90 GetMaskoutErrors () const 91 { 92 return m_maskout_errors; 93 } 94 95 ExecuteScriptOptions& SetEnableIOExecuteScriptOptions96 SetEnableIO (bool enable) 97 { 98 m_enable_io = enable; 99 return *this; 100 } 101 102 ExecuteScriptOptions& SetSetLLDBGlobalsExecuteScriptOptions103 SetSetLLDBGlobals (bool set) 104 { 105 m_set_lldb_globals = set; 106 return *this; 107 } 108 109 ExecuteScriptOptions& SetMaskoutErrorsExecuteScriptOptions110 SetMaskoutErrors (bool maskout) 111 { 112 m_maskout_errors = maskout; 113 return *this; 114 } 115 116 private: 117 bool m_enable_io; 118 bool m_set_lldb_globals; 119 bool m_maskout_errors; 120 }; 121 122 virtual bool Interrupt()123 Interrupt() 124 { 125 return false; 126 } 127 128 virtual bool 129 ExecuteOneLine (const char *command, 130 CommandReturnObject *result, 131 const ExecuteScriptOptions &options = ExecuteScriptOptions()) = 0; 132 133 virtual void 134 ExecuteInterpreterLoop () = 0; 135 136 virtual bool 137 ExecuteOneLineWithReturn (const char *in_string, 138 ScriptReturnType return_type, 139 void *ret_value, 140 const ExecuteScriptOptions &options = ExecuteScriptOptions()) 141 { 142 return true; 143 } 144 145 virtual Error 146 ExecuteMultipleLines (const char *in_string, 147 const ExecuteScriptOptions &options = ExecuteScriptOptions()) 148 { 149 Error error; 150 error.SetErrorString("not implemented"); 151 return error; 152 } 153 154 virtual Error ExportFunctionDefinitionToInterpreter(StringList & function_def)155 ExportFunctionDefinitionToInterpreter (StringList &function_def) 156 { 157 Error error; 158 error.SetErrorString("not implemented"); 159 return error; 160 } 161 162 virtual Error GenerateBreakpointCommandCallbackData(StringList & input,std::string & output)163 GenerateBreakpointCommandCallbackData (StringList &input, std::string& output) 164 { 165 Error error; 166 error.SetErrorString("not implemented"); 167 return error; 168 } 169 170 virtual bool GenerateWatchpointCommandCallbackData(StringList & input,std::string & output)171 GenerateWatchpointCommandCallbackData (StringList &input, std::string& output) 172 { 173 return false; 174 } 175 176 virtual bool 177 GenerateTypeScriptFunction (const char* oneliner, std::string& output, const void* name_token = NULL) 178 { 179 return false; 180 } 181 182 virtual bool 183 GenerateTypeScriptFunction (StringList &input, std::string& output, const void* name_token = NULL) 184 { 185 return false; 186 } 187 188 virtual bool GenerateScriptAliasFunction(StringList & input,std::string & output)189 GenerateScriptAliasFunction (StringList &input, std::string& output) 190 { 191 return false; 192 } 193 194 virtual bool 195 GenerateTypeSynthClass (StringList &input, std::string& output, const void* name_token = NULL) 196 { 197 return false; 198 } 199 200 virtual bool 201 GenerateTypeSynthClass (const char* oneliner, std::string& output, const void* name_token = NULL) 202 { 203 return false; 204 } 205 206 virtual StructuredData::ObjectSP CreateSyntheticScriptedProvider(const char * class_name,lldb::ValueObjectSP valobj)207 CreateSyntheticScriptedProvider(const char *class_name, lldb::ValueObjectSP valobj) 208 { 209 return StructuredData::ObjectSP(); 210 } 211 212 virtual StructuredData::GenericSP CreateScriptCommandObject(const char * class_name)213 CreateScriptCommandObject (const char *class_name) 214 { 215 return StructuredData::GenericSP(); 216 } 217 218 virtual StructuredData::GenericSP OSPlugin_CreatePluginObject(const char * class_name,lldb::ProcessSP process_sp)219 OSPlugin_CreatePluginObject (const char *class_name, 220 lldb::ProcessSP process_sp) 221 { 222 return StructuredData::GenericSP(); 223 } 224 225 virtual StructuredData::DictionarySP OSPlugin_RegisterInfo(StructuredData::ObjectSP os_plugin_object_sp)226 OSPlugin_RegisterInfo(StructuredData::ObjectSP os_plugin_object_sp) 227 { 228 return StructuredData::DictionarySP(); 229 } 230 231 virtual StructuredData::ArraySP OSPlugin_ThreadsInfo(StructuredData::ObjectSP os_plugin_object_sp)232 OSPlugin_ThreadsInfo(StructuredData::ObjectSP os_plugin_object_sp) 233 { 234 return StructuredData::ArraySP(); 235 } 236 237 virtual StructuredData::StringSP OSPlugin_RegisterContextData(StructuredData::ObjectSP os_plugin_object_sp,lldb::tid_t thread_id)238 OSPlugin_RegisterContextData(StructuredData::ObjectSP os_plugin_object_sp, lldb::tid_t thread_id) 239 { 240 return StructuredData::StringSP(); 241 } 242 243 virtual StructuredData::DictionarySP OSPlugin_CreateThread(StructuredData::ObjectSP os_plugin_object_sp,lldb::tid_t tid,lldb::addr_t context)244 OSPlugin_CreateThread(StructuredData::ObjectSP os_plugin_object_sp, lldb::tid_t tid, lldb::addr_t context) 245 { 246 return StructuredData::DictionarySP(); 247 } 248 249 virtual StructuredData::ObjectSP CreateScriptedThreadPlan(const char * class_name,lldb::ThreadPlanSP thread_plan_sp)250 CreateScriptedThreadPlan(const char *class_name, lldb::ThreadPlanSP thread_plan_sp) 251 { 252 return StructuredData::ObjectSP(); 253 } 254 255 virtual bool ScriptedThreadPlanExplainsStop(StructuredData::ObjectSP implementor_sp,Event * event,bool & script_error)256 ScriptedThreadPlanExplainsStop(StructuredData::ObjectSP implementor_sp, Event *event, bool &script_error) 257 { 258 script_error = true; 259 return true; 260 } 261 262 virtual bool ScriptedThreadPlanShouldStop(StructuredData::ObjectSP implementor_sp,Event * event,bool & script_error)263 ScriptedThreadPlanShouldStop(StructuredData::ObjectSP implementor_sp, Event *event, bool &script_error) 264 { 265 script_error = true; 266 return true; 267 } 268 269 virtual lldb::StateType ScriptedThreadPlanGetRunState(StructuredData::ObjectSP implementor_sp,bool & script_error)270 ScriptedThreadPlanGetRunState(StructuredData::ObjectSP implementor_sp, bool &script_error) 271 { 272 script_error = true; 273 return lldb::eStateStepping; 274 } 275 276 virtual StructuredData::ObjectSP LoadPluginModule(const FileSpec & file_spec,lldb_private::Error & error)277 LoadPluginModule(const FileSpec &file_spec, lldb_private::Error &error) 278 { 279 return StructuredData::ObjectSP(); 280 } 281 282 virtual StructuredData::DictionarySP GetDynamicSettings(StructuredData::ObjectSP plugin_module_sp,Target * target,const char * setting_name,lldb_private::Error & error)283 GetDynamicSettings(StructuredData::ObjectSP plugin_module_sp, Target *target, const char *setting_name, lldb_private::Error &error) 284 { 285 return StructuredData::DictionarySP(); 286 } 287 288 virtual Error GenerateFunction(const char * signature,const StringList & input)289 GenerateFunction(const char *signature, const StringList &input) 290 { 291 Error error; 292 error.SetErrorString("unimplemented"); 293 return error; 294 } 295 296 virtual void 297 CollectDataForBreakpointCommandCallback (std::vector<BreakpointOptions *> &options, 298 CommandReturnObject &result); 299 300 virtual void 301 CollectDataForWatchpointCommandCallback (WatchpointOptions *wp_options, 302 CommandReturnObject &result); 303 304 /// Set the specified text as the callback for the breakpoint. 305 Error 306 SetBreakpointCommandCallback (std::vector<BreakpointOptions *> &bp_options_vec, 307 const char *callback_text); 308 309 virtual Error SetBreakpointCommandCallback(BreakpointOptions * bp_options,const char * callback_text)310 SetBreakpointCommandCallback (BreakpointOptions *bp_options, 311 const char *callback_text) 312 { 313 Error error; 314 error.SetErrorString("unimplemented"); 315 return error; 316 } 317 318 void 319 SetBreakpointCommandCallbackFunction (std::vector<BreakpointOptions *> &bp_options_vec, 320 const char *function_name); 321 322 /// Set a one-liner as the callback for the breakpoint. 323 virtual void SetBreakpointCommandCallbackFunction(BreakpointOptions * bp_options,const char * function_name)324 SetBreakpointCommandCallbackFunction (BreakpointOptions *bp_options, 325 const char *function_name) 326 { 327 return; 328 } 329 330 /// Set a one-liner as the callback for the watchpoint. 331 virtual void SetWatchpointCommandCallback(WatchpointOptions * wp_options,const char * oneliner)332 SetWatchpointCommandCallback (WatchpointOptions *wp_options, 333 const char *oneliner) 334 { 335 return; 336 } 337 338 virtual bool GetScriptedSummary(const char * function_name,lldb::ValueObjectSP valobj,StructuredData::ObjectSP & callee_wrapper_sp,const TypeSummaryOptions & options,std::string & retval)339 GetScriptedSummary(const char *function_name, lldb::ValueObjectSP valobj, StructuredData::ObjectSP &callee_wrapper_sp, 340 const TypeSummaryOptions &options, std::string &retval) 341 { 342 return false; 343 } 344 345 virtual void Clear()346 Clear () 347 { 348 // Clean up any ref counts to SBObjects that might be in global variables 349 } 350 351 virtual size_t CalculateNumChildren(const StructuredData::ObjectSP & implementor)352 CalculateNumChildren(const StructuredData::ObjectSP &implementor) 353 { 354 return 0; 355 } 356 357 virtual lldb::ValueObjectSP GetChildAtIndex(const StructuredData::ObjectSP & implementor,uint32_t idx)358 GetChildAtIndex(const StructuredData::ObjectSP &implementor, uint32_t idx) 359 { 360 return lldb::ValueObjectSP(); 361 } 362 363 virtual int GetIndexOfChildWithName(const StructuredData::ObjectSP & implementor,const char * child_name)364 GetIndexOfChildWithName(const StructuredData::ObjectSP &implementor, const char *child_name) 365 { 366 return UINT32_MAX; 367 } 368 369 virtual bool UpdateSynthProviderInstance(const StructuredData::ObjectSP & implementor)370 UpdateSynthProviderInstance(const StructuredData::ObjectSP &implementor) 371 { 372 return false; 373 } 374 375 virtual bool MightHaveChildrenSynthProviderInstance(const StructuredData::ObjectSP & implementor)376 MightHaveChildrenSynthProviderInstance(const StructuredData::ObjectSP &implementor) 377 { 378 return true; 379 } 380 381 virtual lldb::ValueObjectSP GetSyntheticValue(const StructuredData::ObjectSP & implementor)382 GetSyntheticValue(const StructuredData::ObjectSP &implementor) 383 { 384 return nullptr; 385 } 386 387 virtual bool RunScriptBasedCommand(const char * impl_function,const char * args,ScriptedCommandSynchronicity synchronicity,lldb_private::CommandReturnObject & cmd_retobj,Error & error,const lldb_private::ExecutionContext & exe_ctx)388 RunScriptBasedCommand (const char* impl_function, 389 const char* args, 390 ScriptedCommandSynchronicity synchronicity, 391 lldb_private::CommandReturnObject& cmd_retobj, 392 Error& error, 393 const lldb_private::ExecutionContext& exe_ctx) 394 { 395 return false; 396 } 397 398 virtual bool RunScriptBasedCommand(StructuredData::GenericSP impl_obj_sp,const char * args,ScriptedCommandSynchronicity synchronicity,lldb_private::CommandReturnObject & cmd_retobj,Error & error,const lldb_private::ExecutionContext & exe_ctx)399 RunScriptBasedCommand (StructuredData::GenericSP impl_obj_sp, 400 const char* args, 401 ScriptedCommandSynchronicity synchronicity, 402 lldb_private::CommandReturnObject& cmd_retobj, 403 Error& error, 404 const lldb_private::ExecutionContext& exe_ctx) 405 { 406 return false; 407 } 408 409 virtual bool RunScriptFormatKeyword(const char * impl_function,Process * process,std::string & output,Error & error)410 RunScriptFormatKeyword (const char* impl_function, 411 Process* process, 412 std::string& output, 413 Error& error) 414 { 415 error.SetErrorString("unimplemented"); 416 return false; 417 } 418 419 virtual bool RunScriptFormatKeyword(const char * impl_function,Thread * thread,std::string & output,Error & error)420 RunScriptFormatKeyword (const char* impl_function, 421 Thread* thread, 422 std::string& output, 423 Error& error) 424 { 425 error.SetErrorString("unimplemented"); 426 return false; 427 } 428 429 virtual bool RunScriptFormatKeyword(const char * impl_function,Target * target,std::string & output,Error & error)430 RunScriptFormatKeyword (const char* impl_function, 431 Target* target, 432 std::string& output, 433 Error& error) 434 { 435 error.SetErrorString("unimplemented"); 436 return false; 437 } 438 439 virtual bool RunScriptFormatKeyword(const char * impl_function,StackFrame * frame,std::string & output,Error & error)440 RunScriptFormatKeyword (const char* impl_function, 441 StackFrame* frame, 442 std::string& output, 443 Error& error) 444 { 445 error.SetErrorString("unimplemented"); 446 return false; 447 } 448 449 virtual bool RunScriptFormatKeyword(const char * impl_function,ValueObject * value,std::string & output,Error & error)450 RunScriptFormatKeyword (const char* impl_function, 451 ValueObject* value, 452 std::string& output, 453 Error& error) 454 { 455 error.SetErrorString("unimplemented"); 456 return false; 457 } 458 459 virtual bool GetDocumentationForItem(const char * item,std::string & dest)460 GetDocumentationForItem (const char* item, std::string& dest) 461 { 462 dest.clear(); 463 return false; 464 } 465 466 virtual bool GetShortHelpForCommandObject(StructuredData::GenericSP cmd_obj_sp,std::string & dest)467 GetShortHelpForCommandObject (StructuredData::GenericSP cmd_obj_sp, 468 std::string& dest) 469 { 470 dest.clear(); 471 return false; 472 } 473 474 virtual uint32_t GetFlagsForCommandObject(StructuredData::GenericSP cmd_obj_sp)475 GetFlagsForCommandObject (StructuredData::GenericSP cmd_obj_sp) 476 { 477 return 0; 478 } 479 480 virtual bool GetLongHelpForCommandObject(StructuredData::GenericSP cmd_obj_sp,std::string & dest)481 GetLongHelpForCommandObject (StructuredData::GenericSP cmd_obj_sp, 482 std::string& dest) 483 { 484 dest.clear(); 485 return false; 486 } 487 488 virtual bool CheckObjectExists(const char * name)489 CheckObjectExists (const char* name) 490 { 491 return false; 492 } 493 494 virtual bool 495 LoadScriptingModule(const char *filename, bool can_reload, bool init_session, lldb_private::Error &error, 496 StructuredData::ObjectSP *module_sp = nullptr) 497 { 498 error.SetErrorString("loading unimplemented"); 499 return false; 500 } 501 502 virtual bool IsReservedWord(const char * word)503 IsReservedWord (const char* word) 504 { 505 return false; 506 } 507 508 virtual std::unique_ptr<ScriptInterpreterLocker> 509 AcquireInterpreterLock (); 510 511 const char * 512 GetScriptInterpreterPtyName (); 513 514 int 515 GetMasterFileDescriptor (); 516 517 CommandInterpreter & 518 GetCommandInterpreter (); 519 520 static std::string 521 LanguageToString (lldb::ScriptLanguage language); 522 523 virtual void ResetOutputFileHandle(FILE * new_fh)524 ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing. 525 526 protected: 527 CommandInterpreter &m_interpreter; 528 lldb::ScriptLanguage m_script_lang; 529 }; 530 531 } // namespace lldb_private 532 533 #endif // #ifndef liblldb_ScriptInterpreter_h_ 534