19f2f44ceSEd Maste //===-- ScriptInterpreterPython.h -------------------------------*- C++ -*-===// 29f2f44ceSEd Maste // 39f2f44ceSEd Maste // The LLVM Compiler Infrastructure 49f2f44ceSEd Maste // 59f2f44ceSEd Maste // This file is distributed under the University of Illinois Open Source 69f2f44ceSEd Maste // License. See LICENSE.TXT for details. 79f2f44ceSEd Maste // 89f2f44ceSEd Maste //===----------------------------------------------------------------------===// 99f2f44ceSEd Maste 109f2f44ceSEd Maste #ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTINTERPRETERPYTHON_H 119f2f44ceSEd Maste #define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTINTERPRETERPYTHON_H 129f2f44ceSEd Maste 139f2f44ceSEd Maste #ifdef LLDB_DISABLE_PYTHON 149f2f44ceSEd Maste 159f2f44ceSEd Maste // Python is disabled in this build 169f2f44ceSEd Maste 179f2f44ceSEd Maste #else 189f2f44ceSEd Maste 199f2f44ceSEd Maste #include <memory> 209f2f44ceSEd Maste #include <string> 219f2f44ceSEd Maste #include <vector> 229f2f44ceSEd Maste 239f2f44ceSEd Maste #include "PythonDataObjects.h" 24435933ddSDimitry Andric #include "lldb/Breakpoint/BreakpointOptions.h" 259f2f44ceSEd Maste #include "lldb/Core/IOHandler.h" 269f2f44ceSEd Maste #include "lldb/Host/Terminal.h" 27435933ddSDimitry Andric #include "lldb/Interpreter/ScriptInterpreter.h" 28435933ddSDimitry Andric #include "lldb/lldb-private.h" 299f2f44ceSEd Maste 309f2f44ceSEd Maste class IOHandlerPythonInterpreter; 319f2f44ceSEd Maste 329f2f44ceSEd Maste namespace lldb_private { 339f2f44ceSEd Maste 34435933ddSDimitry Andric class ScriptInterpreterPython : public ScriptInterpreter, 35435933ddSDimitry Andric public IOHandlerDelegateMultiline { 369f2f44ceSEd Maste public: 37435933ddSDimitry Andric class CommandDataPython : public BreakpointOptions::CommandData { 38435933ddSDimitry Andric public: CommandDataPython()39435933ddSDimitry Andric CommandDataPython() : BreakpointOptions::CommandData() { 40435933ddSDimitry Andric interpreter = lldb::eScriptLanguagePython; 41435933ddSDimitry Andric } 42435933ddSDimitry Andric }; 43435933ddSDimitry Andric 449f2f44ceSEd Maste #if PY_MAJOR_VERSION >= 3 459f2f44ceSEd Maste typedef PyObject *(*SWIGInitCallback)(void); 469f2f44ceSEd Maste #else 479f2f44ceSEd Maste typedef void (*SWIGInitCallback)(void); 489f2f44ceSEd Maste #endif 499f2f44ceSEd Maste 50435933ddSDimitry Andric typedef bool (*SWIGBreakpointCallbackFunction)( 51435933ddSDimitry Andric const char *python_function_name, const char *session_dictionary_name, 529f2f44ceSEd Maste const lldb::StackFrameSP &frame_sp, 539f2f44ceSEd Maste const lldb::BreakpointLocationSP &bp_loc_sp); 549f2f44ceSEd Maste 55435933ddSDimitry Andric typedef bool (*SWIGWatchpointCallbackFunction)( 56435933ddSDimitry Andric const char *python_function_name, const char *session_dictionary_name, 57435933ddSDimitry Andric const lldb::StackFrameSP &frame_sp, const lldb::WatchpointSP &wp_sp); 589f2f44ceSEd Maste 59435933ddSDimitry Andric typedef bool (*SWIGPythonTypeScriptCallbackFunction)( 60435933ddSDimitry Andric const char *python_function_name, void *session_dictionary, 61435933ddSDimitry Andric const lldb::ValueObjectSP &valobj_sp, void **pyfunct_wrapper, 62435933ddSDimitry Andric const lldb::TypeSummaryOptionsSP &options, std::string &retval); 639f2f44ceSEd Maste 64435933ddSDimitry Andric typedef void *(*SWIGPythonCreateSyntheticProvider)( 65435933ddSDimitry Andric const char *python_class_name, const char *session_dictionary_name, 669f2f44ceSEd Maste const lldb::ValueObjectSP &valobj_sp); 679f2f44ceSEd Maste 68435933ddSDimitry Andric typedef void *(*SWIGPythonCreateCommandObject)( 69435933ddSDimitry Andric const char *python_class_name, const char *session_dictionary_name, 709f2f44ceSEd Maste const lldb::DebuggerSP debugger_sp); 719f2f44ceSEd Maste 72435933ddSDimitry Andric typedef void *(*SWIGPythonCreateScriptedThreadPlan)( 73435933ddSDimitry Andric const char *python_class_name, const char *session_dictionary_name, 749f2f44ceSEd Maste const lldb::ThreadPlanSP &thread_plan_sp); 759f2f44ceSEd Maste 76435933ddSDimitry Andric typedef bool (*SWIGPythonCallThreadPlan)(void *implementor, 77435933ddSDimitry Andric const char *method_name, 78435933ddSDimitry Andric Event *event_sp, bool &got_error); 799f2f44ceSEd Maste 80*b5893f02SDimitry Andric typedef void *(*SWIGPythonCreateScriptedBreakpointResolver)( 81*b5893f02SDimitry Andric const char *python_class_name, const char *session_dictionary_name, 82*b5893f02SDimitry Andric lldb_private::StructuredDataImpl *args_impl, 83*b5893f02SDimitry Andric lldb::BreakpointSP &bkpt_sp); 84*b5893f02SDimitry Andric 85*b5893f02SDimitry Andric typedef unsigned int (*SWIGPythonCallBreakpointResolver)(void *implementor, 86*b5893f02SDimitry Andric const char *method_name, 87*b5893f02SDimitry Andric lldb_private::SymbolContext *sym_ctx); 88*b5893f02SDimitry Andric 899f2f44ceSEd Maste typedef void *(*SWIGPythonCreateOSPlugin)(const char *python_class_name, 909f2f44ceSEd Maste const char *session_dictionary_name, 919f2f44ceSEd Maste const lldb::ProcessSP &process_sp); 929f2f44ceSEd Maste 93*b5893f02SDimitry Andric typedef void *(*SWIGPythonCreateFrameRecognizer)( 94*b5893f02SDimitry Andric const char *python_class_name, const char *session_dictionary_name); 95*b5893f02SDimitry Andric 96*b5893f02SDimitry Andric typedef void *(*SWIGPythonGetRecognizedArguments)( 97*b5893f02SDimitry Andric void *implementor, const lldb::StackFrameSP &frame_sp); 98*b5893f02SDimitry Andric 99435933ddSDimitry Andric typedef size_t (*SWIGPythonCalculateNumChildren)(void *implementor, 100435933ddSDimitry Andric uint32_t max); 1019f2f44ceSEd Maste 1029f2f44ceSEd Maste typedef void *(*SWIGPythonGetChildAtIndex)(void *implementor, uint32_t idx); 1039f2f44ceSEd Maste 104435933ddSDimitry Andric typedef int (*SWIGPythonGetIndexOfChildWithName)(void *implementor, 105435933ddSDimitry Andric const char *child_name); 1069f2f44ceSEd Maste 1079f2f44ceSEd Maste typedef void *(*SWIGPythonCastPyObjectToSBValue)(void *data); 1089f2f44ceSEd Maste 109435933ddSDimitry Andric typedef lldb::ValueObjectSP (*SWIGPythonGetValueObjectSPFromSBValue)( 110435933ddSDimitry Andric void *data); 1119f2f44ceSEd Maste 1129f2f44ceSEd Maste typedef bool (*SWIGPythonUpdateSynthProviderInstance)(void *data); 1139f2f44ceSEd Maste 1149f2f44ceSEd Maste typedef bool (*SWIGPythonMightHaveChildrenSynthProviderInstance)(void *data); 1159f2f44ceSEd Maste 1169f2f44ceSEd Maste typedef void *(*SWIGPythonGetValueSynthProviderInstance)(void *implementor); 1179f2f44ceSEd Maste 118435933ddSDimitry Andric typedef bool (*SWIGPythonCallCommand)( 119435933ddSDimitry Andric const char *python_function_name, const char *session_dictionary_name, 120435933ddSDimitry Andric lldb::DebuggerSP &debugger, const char *args, 1219f2f44ceSEd Maste lldb_private::CommandReturnObject &cmd_retobj, 1229f2f44ceSEd Maste lldb::ExecutionContextRefSP exe_ctx_ref_sp); 1239f2f44ceSEd Maste 124435933ddSDimitry Andric typedef bool (*SWIGPythonCallCommandObject)( 125435933ddSDimitry Andric void *implementor, lldb::DebuggerSP &debugger, const char *args, 1269f2f44ceSEd Maste lldb_private::CommandReturnObject &cmd_retobj, 1279f2f44ceSEd Maste lldb::ExecutionContextRefSP exe_ctx_ref_sp); 1289f2f44ceSEd Maste 1299f2f44ceSEd Maste typedef bool (*SWIGPythonCallModuleInit)(const char *python_module_name, 1309f2f44ceSEd Maste const char *session_dictionary_name, 1319f2f44ceSEd Maste lldb::DebuggerSP &debugger); 1329f2f44ceSEd Maste 133435933ddSDimitry Andric typedef bool (*SWIGPythonScriptKeyword_Process)( 134435933ddSDimitry Andric const char *python_function_name, const char *session_dictionary_name, 135435933ddSDimitry Andric lldb::ProcessSP &process, std::string &output); 1369f2f44ceSEd Maste 137435933ddSDimitry Andric typedef bool (*SWIGPythonScriptKeyword_Thread)( 138435933ddSDimitry Andric const char *python_function_name, const char *session_dictionary_name, 139435933ddSDimitry Andric lldb::ThreadSP &thread, std::string &output); 1409f2f44ceSEd Maste 141435933ddSDimitry Andric typedef bool (*SWIGPythonScriptKeyword_Target)( 142435933ddSDimitry Andric const char *python_function_name, const char *session_dictionary_name, 143435933ddSDimitry Andric lldb::TargetSP &target, std::string &output); 1449f2f44ceSEd Maste 145435933ddSDimitry Andric typedef bool (*SWIGPythonScriptKeyword_Frame)( 146435933ddSDimitry Andric const char *python_function_name, const char *session_dictionary_name, 147435933ddSDimitry Andric lldb::StackFrameSP &frame, std::string &output); 1489f2f44ceSEd Maste 149435933ddSDimitry Andric typedef bool (*SWIGPythonScriptKeyword_Value)( 150435933ddSDimitry Andric const char *python_function_name, const char *session_dictionary_name, 151435933ddSDimitry Andric lldb::ValueObjectSP &value, std::string &output); 1529f2f44ceSEd Maste 153435933ddSDimitry Andric typedef void *(*SWIGPython_GetDynamicSetting)( 154435933ddSDimitry Andric void *module, const char *setting, const lldb::TargetSP &target_sp); 1559f2f44ceSEd Maste 1569f2f44ceSEd Maste friend class ::IOHandlerPythonInterpreter; 1579f2f44ceSEd Maste 1589f2f44ceSEd Maste ScriptInterpreterPython(CommandInterpreter &interpreter); 1599f2f44ceSEd Maste 1609f2f44ceSEd Maste ~ScriptInterpreterPython() override; 1619f2f44ceSEd Maste 162435933ddSDimitry Andric bool Interrupt() override; 1639f2f44ceSEd Maste 164435933ddSDimitry Andric bool ExecuteOneLine( 1654ba319b5SDimitry Andric llvm::StringRef command, CommandReturnObject *result, 1669f2f44ceSEd Maste const ExecuteScriptOptions &options = ExecuteScriptOptions()) override; 1679f2f44ceSEd Maste 168435933ddSDimitry Andric void ExecuteInterpreterLoop() override; 1699f2f44ceSEd Maste 170435933ddSDimitry Andric bool ExecuteOneLineWithReturn( 1714ba319b5SDimitry Andric llvm::StringRef in_string, 1724ba319b5SDimitry Andric ScriptInterpreter::ScriptReturnType return_type, void *ret_value, 1739f2f44ceSEd Maste const ExecuteScriptOptions &options = ExecuteScriptOptions()) override; 1749f2f44ceSEd Maste 1755517e702SDimitry Andric lldb_private::Status ExecuteMultipleLines( 176435933ddSDimitry Andric const char *in_string, 1779f2f44ceSEd Maste const ExecuteScriptOptions &options = ExecuteScriptOptions()) override; 1789f2f44ceSEd Maste 1795517e702SDimitry Andric Status 1809f2f44ceSEd Maste ExportFunctionDefinitionToInterpreter(StringList &function_def) override; 1819f2f44ceSEd Maste 182435933ddSDimitry Andric bool GenerateTypeScriptFunction(StringList &input, std::string &output, 183435933ddSDimitry Andric const void *name_token = nullptr) override; 1849f2f44ceSEd Maste 185435933ddSDimitry Andric bool GenerateTypeSynthClass(StringList &input, std::string &output, 186435933ddSDimitry Andric const void *name_token = nullptr) override; 1879f2f44ceSEd Maste 188435933ddSDimitry Andric bool GenerateTypeSynthClass(const char *oneliner, std::string &output, 189435933ddSDimitry Andric const void *name_token = nullptr) override; 1909f2f44ceSEd Maste 1919f2f44ceSEd Maste // use this if the function code is just a one-liner script 192435933ddSDimitry Andric bool GenerateTypeScriptFunction(const char *oneliner, std::string &output, 193435933ddSDimitry Andric const void *name_token = nullptr) override; 1949f2f44ceSEd Maste 195435933ddSDimitry Andric bool GenerateScriptAliasFunction(StringList &input, 196435933ddSDimitry Andric std::string &output) override; 1979f2f44ceSEd Maste 198435933ddSDimitry Andric StructuredData::ObjectSP 199435933ddSDimitry Andric CreateSyntheticScriptedProvider(const char *class_name, 200435933ddSDimitry Andric lldb::ValueObjectSP valobj) override; 2019f2f44ceSEd Maste 202435933ddSDimitry Andric StructuredData::GenericSP 203435933ddSDimitry Andric CreateScriptCommandObject(const char *class_name) override; 2049f2f44ceSEd Maste 205435933ddSDimitry Andric StructuredData::ObjectSP 206435933ddSDimitry Andric CreateScriptedThreadPlan(const char *class_name, 207435933ddSDimitry Andric lldb::ThreadPlanSP thread_plan) override; 2089f2f44ceSEd Maste 209435933ddSDimitry Andric bool ScriptedThreadPlanExplainsStop(StructuredData::ObjectSP implementor_sp, 210435933ddSDimitry Andric Event *event, 211435933ddSDimitry Andric bool &script_error) override; 2129f2f44ceSEd Maste 213435933ddSDimitry Andric bool ScriptedThreadPlanShouldStop(StructuredData::ObjectSP implementor_sp, 214435933ddSDimitry Andric Event *event, bool &script_error) override; 2159f2f44ceSEd Maste 216435933ddSDimitry Andric bool ScriptedThreadPlanIsStale(StructuredData::ObjectSP implementor_sp, 217435933ddSDimitry Andric bool &script_error) override; 2189f2f44ceSEd Maste 219435933ddSDimitry Andric lldb::StateType 220435933ddSDimitry Andric ScriptedThreadPlanGetRunState(StructuredData::ObjectSP implementor_sp, 221435933ddSDimitry Andric bool &script_error) override; 2229f2f44ceSEd Maste 223435933ddSDimitry Andric StructuredData::GenericSP 224*b5893f02SDimitry Andric CreateScriptedBreakpointResolver(const char *class_name, 225*b5893f02SDimitry Andric StructuredDataImpl *args_data, 226*b5893f02SDimitry Andric lldb::BreakpointSP &bkpt_sp) override; 227*b5893f02SDimitry Andric bool 228*b5893f02SDimitry Andric ScriptedBreakpointResolverSearchCallback(StructuredData::GenericSP 229*b5893f02SDimitry Andric implementor_sp, 230*b5893f02SDimitry Andric SymbolContext *sym_ctx) override; 231*b5893f02SDimitry Andric 232*b5893f02SDimitry Andric lldb::SearchDepth 233*b5893f02SDimitry Andric ScriptedBreakpointResolverSearchDepth(StructuredData::GenericSP 234*b5893f02SDimitry Andric implementor_sp) override; 235*b5893f02SDimitry Andric 236*b5893f02SDimitry Andric StructuredData::GenericSP 237*b5893f02SDimitry Andric CreateFrameRecognizer(const char *class_name) override; 238*b5893f02SDimitry Andric 239*b5893f02SDimitry Andric lldb::ValueObjectListSP 240*b5893f02SDimitry Andric GetRecognizedArguments(const StructuredData::ObjectSP &implementor, 241*b5893f02SDimitry Andric lldb::StackFrameSP frame_sp) override; 242*b5893f02SDimitry Andric 243*b5893f02SDimitry Andric StructuredData::GenericSP 244435933ddSDimitry Andric OSPlugin_CreatePluginObject(const char *class_name, 245435933ddSDimitry Andric lldb::ProcessSP process_sp) override; 2469f2f44ceSEd Maste 247435933ddSDimitry Andric StructuredData::DictionarySP 248435933ddSDimitry Andric OSPlugin_RegisterInfo(StructuredData::ObjectSP os_plugin_object_sp) override; 2499f2f44ceSEd Maste 250435933ddSDimitry Andric StructuredData::ArraySP 251435933ddSDimitry Andric OSPlugin_ThreadsInfo(StructuredData::ObjectSP os_plugin_object_sp) override; 2529f2f44ceSEd Maste 253435933ddSDimitry Andric StructuredData::StringSP 254435933ddSDimitry Andric OSPlugin_RegisterContextData(StructuredData::ObjectSP os_plugin_object_sp, 255435933ddSDimitry Andric lldb::tid_t thread_id) override; 2569f2f44ceSEd Maste 257435933ddSDimitry Andric StructuredData::DictionarySP 258435933ddSDimitry Andric OSPlugin_CreateThread(StructuredData::ObjectSP os_plugin_object_sp, 259435933ddSDimitry Andric lldb::tid_t tid, lldb::addr_t context) override; 2609f2f44ceSEd Maste 261435933ddSDimitry Andric StructuredData::ObjectSP 262435933ddSDimitry Andric LoadPluginModule(const FileSpec &file_spec, 2635517e702SDimitry Andric lldb_private::Status &error) override; 2649f2f44ceSEd Maste 265435933ddSDimitry Andric StructuredData::DictionarySP 266435933ddSDimitry Andric GetDynamicSettings(StructuredData::ObjectSP plugin_module_sp, Target *target, 267435933ddSDimitry Andric const char *setting_name, 2685517e702SDimitry Andric lldb_private::Status &error) override; 2699f2f44ceSEd Maste 270435933ddSDimitry Andric size_t CalculateNumChildren(const StructuredData::ObjectSP &implementor, 271435933ddSDimitry Andric uint32_t max) override; 2729f2f44ceSEd Maste 273435933ddSDimitry Andric lldb::ValueObjectSP 274435933ddSDimitry Andric GetChildAtIndex(const StructuredData::ObjectSP &implementor, 275435933ddSDimitry Andric uint32_t idx) override; 2769f2f44ceSEd Maste 277435933ddSDimitry Andric int GetIndexOfChildWithName(const StructuredData::ObjectSP &implementor, 278435933ddSDimitry Andric const char *child_name) override; 2799f2f44ceSEd Maste 280435933ddSDimitry Andric bool UpdateSynthProviderInstance( 281435933ddSDimitry Andric const StructuredData::ObjectSP &implementor) override; 2829f2f44ceSEd Maste 283435933ddSDimitry Andric bool MightHaveChildrenSynthProviderInstance( 284435933ddSDimitry Andric const StructuredData::ObjectSP &implementor) override; 2859f2f44ceSEd Maste 286435933ddSDimitry Andric lldb::ValueObjectSP 287435933ddSDimitry Andric GetSyntheticValue(const StructuredData::ObjectSP &implementor) override; 288435933ddSDimitry Andric 289435933ddSDimitry Andric ConstString 290435933ddSDimitry Andric GetSyntheticTypeName(const StructuredData::ObjectSP &implementor) override; 2914bb0738eSEd Maste 2929f2f44ceSEd Maste bool 2934ba319b5SDimitry Andric RunScriptBasedCommand(const char *impl_function, llvm::StringRef args, 2949f2f44ceSEd Maste ScriptedCommandSynchronicity synchronicity, 2959f2f44ceSEd Maste lldb_private::CommandReturnObject &cmd_retobj, 2965517e702SDimitry Andric Status &error, 2979f2f44ceSEd Maste const lldb_private::ExecutionContext &exe_ctx) override; 2989f2f44ceSEd Maste 2994ba319b5SDimitry Andric bool RunScriptBasedCommand( 3004ba319b5SDimitry Andric StructuredData::GenericSP impl_obj_sp, llvm::StringRef args, 3019f2f44ceSEd Maste ScriptedCommandSynchronicity synchronicity, 3024ba319b5SDimitry Andric lldb_private::CommandReturnObject &cmd_retobj, Status &error, 3039f2f44ceSEd Maste const lldb_private::ExecutionContext &exe_ctx) override; 3049f2f44ceSEd Maste 3055517e702SDimitry Andric Status GenerateFunction(const char *signature, 306435933ddSDimitry Andric const StringList &input) override; 3079f2f44ceSEd Maste 3085517e702SDimitry Andric Status GenerateBreakpointCommandCallbackData(StringList &input, 309435933ddSDimitry Andric std::string &output) override; 3109f2f44ceSEd Maste 311435933ddSDimitry Andric bool GenerateWatchpointCommandCallbackData(StringList &input, 312435933ddSDimitry Andric std::string &output) override; 3139f2f44ceSEd Maste 3149f2f44ceSEd Maste // static size_t 3159f2f44ceSEd Maste // GenerateBreakpointOptionsCommandCallback (void *baton, 3169f2f44ceSEd Maste // InputReader &reader, 317435933ddSDimitry Andric // lldb::InputReaderAction 318435933ddSDimitry Andric // notification, 3199f2f44ceSEd Maste // const char *bytes, 3209f2f44ceSEd Maste // size_t bytes_len); 3219f2f44ceSEd Maste // 3229f2f44ceSEd Maste // static size_t 3239f2f44ceSEd Maste // GenerateWatchpointOptionsCommandCallback (void *baton, 3249f2f44ceSEd Maste // InputReader &reader, 325435933ddSDimitry Andric // lldb::InputReaderAction 326435933ddSDimitry Andric // notification, 3279f2f44ceSEd Maste // const char *bytes, 3289f2f44ceSEd Maste // size_t bytes_len); 3299f2f44ceSEd Maste 330435933ddSDimitry Andric static bool BreakpointCallbackFunction(void *baton, 3319f2f44ceSEd Maste StoppointCallbackContext *context, 3329f2f44ceSEd Maste lldb::user_id_t break_id, 3339f2f44ceSEd Maste lldb::user_id_t break_loc_id); 3349f2f44ceSEd Maste 335435933ddSDimitry Andric static bool WatchpointCallbackFunction(void *baton, 3369f2f44ceSEd Maste StoppointCallbackContext *context, 3379f2f44ceSEd Maste lldb::user_id_t watch_id); 3389f2f44ceSEd Maste 339435933ddSDimitry Andric bool GetScriptedSummary(const char *function_name, lldb::ValueObjectSP valobj, 340435933ddSDimitry Andric StructuredData::ObjectSP &callee_wrapper_sp, 341435933ddSDimitry Andric const TypeSummaryOptions &options, 342435933ddSDimitry Andric std::string &retval) override; 3439f2f44ceSEd Maste 344435933ddSDimitry Andric void Clear() override; 3459f2f44ceSEd Maste 346435933ddSDimitry Andric bool GetDocumentationForItem(const char *item, std::string &dest) override; 3479f2f44ceSEd Maste 348435933ddSDimitry Andric bool GetShortHelpForCommandObject(StructuredData::GenericSP cmd_obj_sp, 349435933ddSDimitry Andric std::string &dest) override; 3509f2f44ceSEd Maste 3519f2f44ceSEd Maste uint32_t 3529f2f44ceSEd Maste GetFlagsForCommandObject(StructuredData::GenericSP cmd_obj_sp) override; 3539f2f44ceSEd Maste 354435933ddSDimitry Andric bool GetLongHelpForCommandObject(StructuredData::GenericSP cmd_obj_sp, 355435933ddSDimitry Andric std::string &dest) override; 3569f2f44ceSEd Maste CheckObjectExists(const char * name)357435933ddSDimitry Andric bool CheckObjectExists(const char *name) override { 3589f2f44ceSEd Maste if (!name || !name[0]) 3599f2f44ceSEd Maste return false; 3609f2f44ceSEd Maste std::string temp; 3619f2f44ceSEd Maste return GetDocumentationForItem(name, temp); 3629f2f44ceSEd Maste } 3639f2f44ceSEd Maste 364435933ddSDimitry Andric bool RunScriptFormatKeyword(const char *impl_function, Process *process, 3655517e702SDimitry Andric std::string &output, Status &error) override; 366435933ddSDimitry Andric 367435933ddSDimitry Andric bool RunScriptFormatKeyword(const char *impl_function, Thread *thread, 3685517e702SDimitry Andric std::string &output, Status &error) override; 369435933ddSDimitry Andric 370435933ddSDimitry Andric bool RunScriptFormatKeyword(const char *impl_function, Target *target, 3715517e702SDimitry Andric std::string &output, Status &error) override; 372435933ddSDimitry Andric 373435933ddSDimitry Andric bool RunScriptFormatKeyword(const char *impl_function, StackFrame *frame, 3745517e702SDimitry Andric std::string &output, Status &error) override; 375435933ddSDimitry Andric 376435933ddSDimitry Andric bool RunScriptFormatKeyword(const char *impl_function, ValueObject *value, 3775517e702SDimitry Andric std::string &output, Status &error) override; 3789f2f44ceSEd Maste 3799f2f44ceSEd Maste bool 380435933ddSDimitry Andric LoadScriptingModule(const char *filename, bool can_reload, bool init_session, 3815517e702SDimitry Andric lldb_private::Status &error, 3829f2f44ceSEd Maste StructuredData::ObjectSP *module_sp = nullptr) override; 3839f2f44ceSEd Maste 384435933ddSDimitry Andric bool IsReservedWord(const char *word) override; 3859f2f44ceSEd Maste 386435933ddSDimitry Andric std::unique_ptr<ScriptInterpreterLocker> AcquireInterpreterLock() override; 3879f2f44ceSEd Maste 388435933ddSDimitry Andric void CollectDataForBreakpointCommandCallback( 389435933ddSDimitry Andric std::vector<BreakpointOptions *> &bp_options_vec, 3909f2f44ceSEd Maste CommandReturnObject &result) override; 3919f2f44ceSEd Maste 3929f2f44ceSEd Maste void 3939f2f44ceSEd Maste CollectDataForWatchpointCommandCallback(WatchpointOptions *wp_options, 3949f2f44ceSEd Maste CommandReturnObject &result) override; 3959f2f44ceSEd Maste 3969f2f44ceSEd Maste /// Set the callback body text into the callback for the breakpoint. 3975517e702SDimitry Andric Status SetBreakpointCommandCallback(BreakpointOptions *bp_options, 3989f2f44ceSEd Maste const char *callback_body) override; 3999f2f44ceSEd Maste 400435933ddSDimitry Andric void SetBreakpointCommandCallbackFunction(BreakpointOptions *bp_options, 4019f2f44ceSEd Maste const char *function_name) override; 4029f2f44ceSEd Maste 403435933ddSDimitry Andric /// This one is for deserialization: 4045517e702SDimitry Andric Status SetBreakpointCommandCallback( 405435933ddSDimitry Andric BreakpointOptions *bp_options, 406435933ddSDimitry Andric std::unique_ptr<BreakpointOptions::CommandData> &data_up) override; 407435933ddSDimitry Andric 4089f2f44ceSEd Maste /// Set a one-liner as the callback for the watchpoint. 409435933ddSDimitry Andric void SetWatchpointCommandCallback(WatchpointOptions *wp_options, 4109f2f44ceSEd Maste const char *oneliner) override; 4119f2f44ceSEd Maste 412435933ddSDimitry Andric StringList ReadCommandInputFromUser(FILE *in_file); 4139f2f44ceSEd Maste 4149f2f44ceSEd Maste void ResetOutputFileHandle(FILE *new_fh) override; 4159f2f44ceSEd Maste 416435933ddSDimitry Andric static void InitializePrivate(); 4179f2f44ceSEd Maste 418435933ddSDimitry Andric static void InitializeInterpreter( 419435933ddSDimitry Andric SWIGInitCallback python_swig_init_callback, 4209f2f44ceSEd Maste SWIGBreakpointCallbackFunction swig_breakpoint_callback, 4219f2f44ceSEd Maste SWIGWatchpointCallbackFunction swig_watchpoint_callback, 4229f2f44ceSEd Maste SWIGPythonTypeScriptCallbackFunction swig_typescript_callback, 4239f2f44ceSEd Maste SWIGPythonCreateSyntheticProvider swig_synthetic_script, 4249f2f44ceSEd Maste SWIGPythonCreateCommandObject swig_create_cmd, 4259f2f44ceSEd Maste SWIGPythonCalculateNumChildren swig_calc_children, 4269f2f44ceSEd Maste SWIGPythonGetChildAtIndex swig_get_child_index, 4279f2f44ceSEd Maste SWIGPythonGetIndexOfChildWithName swig_get_index_child, 4289f2f44ceSEd Maste SWIGPythonCastPyObjectToSBValue swig_cast_to_sbvalue, 4299f2f44ceSEd Maste SWIGPythonGetValueObjectSPFromSBValue swig_get_valobj_sp_from_sbvalue, 4309f2f44ceSEd Maste SWIGPythonUpdateSynthProviderInstance swig_update_provider, 431435933ddSDimitry Andric SWIGPythonMightHaveChildrenSynthProviderInstance 432435933ddSDimitry Andric swig_mighthavechildren_provider, 4339f2f44ceSEd Maste SWIGPythonGetValueSynthProviderInstance swig_getvalue_provider, 4349f2f44ceSEd Maste SWIGPythonCallCommand swig_call_command, 4359f2f44ceSEd Maste SWIGPythonCallCommandObject swig_call_command_object, 4369f2f44ceSEd Maste SWIGPythonCallModuleInit swig_call_module_init, 4379f2f44ceSEd Maste SWIGPythonCreateOSPlugin swig_create_os_plugin, 438*b5893f02SDimitry Andric SWIGPythonCreateFrameRecognizer swig_create_frame_recognizer, 439*b5893f02SDimitry Andric SWIGPythonGetRecognizedArguments swig_get_recognized_arguments, 4409f2f44ceSEd Maste SWIGPythonScriptKeyword_Process swig_run_script_keyword_process, 4419f2f44ceSEd Maste SWIGPythonScriptKeyword_Thread swig_run_script_keyword_thread, 4429f2f44ceSEd Maste SWIGPythonScriptKeyword_Target swig_run_script_keyword_target, 4439f2f44ceSEd Maste SWIGPythonScriptKeyword_Frame swig_run_script_keyword_frame, 4449f2f44ceSEd Maste SWIGPythonScriptKeyword_Value swig_run_script_keyword_value, 4459f2f44ceSEd Maste SWIGPython_GetDynamicSetting swig_plugin_get, 4469f2f44ceSEd Maste SWIGPythonCreateScriptedThreadPlan swig_thread_plan_script, 447*b5893f02SDimitry Andric SWIGPythonCallThreadPlan swig_call_thread_plan, 448*b5893f02SDimitry Andric SWIGPythonCreateScriptedBreakpointResolver swig_bkpt_resolver_script, 449*b5893f02SDimitry Andric SWIGPythonCallBreakpointResolver swig_call_breakpoint_resolver); 4509f2f44ceSEd Maste GetDictionaryName()451435933ddSDimitry Andric const char *GetDictionaryName() { return m_dictionary_name.c_str(); } 4529f2f44ceSEd Maste GetThreadState()453435933ddSDimitry Andric PyThreadState *GetThreadState() { return m_command_thread_state; } 4549f2f44ceSEd Maste SetThreadState(PyThreadState * s)455435933ddSDimitry Andric void SetThreadState(PyThreadState *s) { 4569f2f44ceSEd Maste if (s) 4579f2f44ceSEd Maste m_command_thread_state = s; 4589f2f44ceSEd Maste } 4599f2f44ceSEd Maste 4609f2f44ceSEd Maste //---------------------------------------------------------------------- 4619f2f44ceSEd Maste // IOHandlerDelegate 4629f2f44ceSEd Maste //---------------------------------------------------------------------- 463435933ddSDimitry Andric void IOHandlerActivated(IOHandler &io_handler) override; 4649f2f44ceSEd Maste 465435933ddSDimitry Andric void IOHandlerInputComplete(IOHandler &io_handler, 466435933ddSDimitry Andric std::string &data) override; 4679f2f44ceSEd Maste 4689f2f44ceSEd Maste //------------------------------------------------------------------ 4699f2f44ceSEd Maste // Static Functions 4709f2f44ceSEd Maste //------------------------------------------------------------------ 471435933ddSDimitry Andric static void Initialize(); 4729f2f44ceSEd Maste 473435933ddSDimitry Andric static void Terminate(); 4749f2f44ceSEd Maste 4759f2f44ceSEd Maste static lldb::ScriptInterpreterSP 4769f2f44ceSEd Maste CreateInstance(CommandInterpreter &interpreter); 4779f2f44ceSEd Maste 478435933ddSDimitry Andric static lldb_private::ConstString GetPluginNameStatic(); 4799f2f44ceSEd Maste 480435933ddSDimitry Andric static const char *GetPluginDescriptionStatic(); 4819f2f44ceSEd Maste 4824ba319b5SDimitry Andric static FileSpec GetPythonDir(); 4834ba319b5SDimitry Andric 4849f2f44ceSEd Maste //------------------------------------------------------------------ 4859f2f44ceSEd Maste // PluginInterface protocol 4869f2f44ceSEd Maste //------------------------------------------------------------------ 487435933ddSDimitry Andric lldb_private::ConstString GetPluginName() override; 4889f2f44ceSEd Maste 489435933ddSDimitry Andric uint32_t GetPluginVersion() override; 4909f2f44ceSEd Maste 491435933ddSDimitry Andric class Locker : public ScriptInterpreterLocker { 4929f2f44ceSEd Maste public: 493435933ddSDimitry Andric enum OnEntry { 4949f2f44ceSEd Maste AcquireLock = 0x0001, 4959f2f44ceSEd Maste InitSession = 0x0002, 4969f2f44ceSEd Maste InitGlobals = 0x0004, 4979f2f44ceSEd Maste NoSTDIN = 0x0008 4989f2f44ceSEd Maste }; 4999f2f44ceSEd Maste 500435933ddSDimitry Andric enum OnLeave { 5019f2f44ceSEd Maste FreeLock = 0x0001, 502435933ddSDimitry Andric FreeAcquiredLock = 0x0002, // do not free the lock if we already held it 503435933ddSDimitry Andric // when calling constructor 5049f2f44ceSEd Maste TearDownSession = 0x0004 5059f2f44ceSEd Maste }; 5069f2f44ceSEd Maste 5079f2f44ceSEd Maste Locker(ScriptInterpreterPython *py_interpreter = nullptr, 5089f2f44ceSEd Maste uint16_t on_entry = AcquireLock | InitSession, 509435933ddSDimitry Andric uint16_t on_leave = FreeLock | TearDownSession, FILE *in = nullptr, 510435933ddSDimitry Andric FILE *out = nullptr, FILE *err = nullptr); 5119f2f44ceSEd Maste 5129f2f44ceSEd Maste ~Locker() override; 5139f2f44ceSEd Maste 5149f2f44ceSEd Maste private: 515435933ddSDimitry Andric bool DoAcquireLock(); 5169f2f44ceSEd Maste 517435933ddSDimitry Andric bool DoInitSession(uint16_t on_entry_flags, FILE *in, FILE *out, FILE *err); 5189f2f44ceSEd Maste 519435933ddSDimitry Andric bool DoFreeLock(); 5209f2f44ceSEd Maste 521435933ddSDimitry Andric bool DoTearDownSession(); 5229f2f44ceSEd Maste 523435933ddSDimitry Andric static void ReleasePythonLock(); 5249f2f44ceSEd Maste 5259f2f44ceSEd Maste bool m_teardown_session; 5269f2f44ceSEd Maste ScriptInterpreterPython *m_python_interpreter; 5279f2f44ceSEd Maste // FILE* m_tmp_fh; 5289f2f44ceSEd Maste PyGILState_STATE m_GILState; 5299f2f44ceSEd Maste }; 5309f2f44ceSEd Maste 5319f2f44ceSEd Maste protected: 532435933ddSDimitry Andric class SynchronicityHandler { 5339f2f44ceSEd Maste private: 5349f2f44ceSEd Maste lldb::DebuggerSP m_debugger_sp; 5359f2f44ceSEd Maste ScriptedCommandSynchronicity m_synch_wanted; 5369f2f44ceSEd Maste bool m_old_asynch; 5379f2f44ceSEd Maste 5389f2f44ceSEd Maste public: 539435933ddSDimitry Andric SynchronicityHandler(lldb::DebuggerSP, ScriptedCommandSynchronicity); 5409f2f44ceSEd Maste 5419f2f44ceSEd Maste ~SynchronicityHandler(); 5429f2f44ceSEd Maste }; 5439f2f44ceSEd Maste 544435933ddSDimitry Andric enum class AddLocation { Beginning, End }; 5459f2f44ceSEd Maste 5469f2f44ceSEd Maste static void AddToSysPath(AddLocation location, std::string path); 5479f2f44ceSEd Maste 5484ba319b5SDimitry Andric static void ComputePythonDirForApple(llvm::SmallVectorImpl<char> &path); 5494ba319b5SDimitry Andric static void ComputePythonDirForPosix(llvm::SmallVectorImpl<char> &path); 5504ba319b5SDimitry Andric static void ComputePythonDirForWindows(llvm::SmallVectorImpl<char> &path); 5514ba319b5SDimitry Andric 552435933ddSDimitry Andric bool EnterSession(uint16_t on_entry_flags, FILE *in, FILE *out, FILE *err); 5539f2f44ceSEd Maste 554435933ddSDimitry Andric void LeaveSession(); 5559f2f44ceSEd Maste 556435933ddSDimitry Andric void SaveTerminalState(int fd); 5579f2f44ceSEd Maste 558435933ddSDimitry Andric void RestoreTerminalState(); 5599f2f44ceSEd Maste IsExecutingPython()560435933ddSDimitry Andric uint32_t IsExecutingPython() const { return m_lock_count > 0; } 5619f2f44ceSEd Maste IncrementLockCount()562435933ddSDimitry Andric uint32_t IncrementLockCount() { return ++m_lock_count; } 5639f2f44ceSEd Maste DecrementLockCount()564435933ddSDimitry Andric uint32_t DecrementLockCount() { 5659f2f44ceSEd Maste if (m_lock_count > 0) 5669f2f44ceSEd Maste --m_lock_count; 5679f2f44ceSEd Maste return m_lock_count; 5689f2f44ceSEd Maste } 5699f2f44ceSEd Maste 5709f2f44ceSEd Maste enum ActiveIOHandler { 5719f2f44ceSEd Maste eIOHandlerNone, 5729f2f44ceSEd Maste eIOHandlerBreakpoint, 5739f2f44ceSEd Maste eIOHandlerWatchpoint 5749f2f44ceSEd Maste }; 5759f2f44ceSEd Maste 5769f2f44ceSEd Maste PythonObject &GetMainModule(); 5779f2f44ceSEd Maste 578435933ddSDimitry Andric PythonDictionary &GetSessionDictionary(); 5799f2f44ceSEd Maste 580435933ddSDimitry Andric PythonDictionary &GetSysModuleDictionary(); 5819f2f44ceSEd Maste 582435933ddSDimitry Andric bool GetEmbeddedInterpreterModuleObjects(); 5839f2f44ceSEd Maste 584435933ddSDimitry Andric bool SetStdHandle(File &file, const char *py_name, PythonFile &save_file, 585435933ddSDimitry Andric const char *mode); 5864bb0738eSEd Maste 5879f2f44ceSEd Maste PythonFile m_saved_stdin; 5889f2f44ceSEd Maste PythonFile m_saved_stdout; 5899f2f44ceSEd Maste PythonFile m_saved_stderr; 5909f2f44ceSEd Maste PythonObject m_main_module; 5919f2f44ceSEd Maste PythonObject m_lldb_module; 5929f2f44ceSEd Maste PythonDictionary m_session_dict; 5939f2f44ceSEd Maste PythonDictionary m_sys_module_dict; 5949f2f44ceSEd Maste PythonObject m_run_one_line_function; 5959f2f44ceSEd Maste PythonObject m_run_one_line_str_global; 5969f2f44ceSEd Maste std::string m_dictionary_name; 5979f2f44ceSEd Maste TerminalState m_terminal_state; 5989f2f44ceSEd Maste ActiveIOHandler m_active_io_handler; 5999f2f44ceSEd Maste bool m_session_is_active; 6009f2f44ceSEd Maste bool m_pty_slave_is_open; 6019f2f44ceSEd Maste bool m_valid_session; 6029f2f44ceSEd Maste uint32_t m_lock_count; 6039f2f44ceSEd Maste PyThreadState *m_command_thread_state; 6049f2f44ceSEd Maste }; 6059f2f44ceSEd Maste 6069f2f44ceSEd Maste } // namespace lldb_private 6079f2f44ceSEd Maste 6089f2f44ceSEd Maste #endif // LLDB_DISABLE_PYTHON 6099f2f44ceSEd Maste 6109f2f44ceSEd Maste #endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTINTERPRETERPYTHON_H 611