Index: cmake/LLDBDependencies.cmake =================================================================== --- cmake/LLDBDependencies.cmake +++ cmake/LLDBDependencies.cmake @@ -107,6 +107,10 @@ ) endif() +if (NOT LLDB_DISABLE_PYTHON) + list(APPEND LLDB_USED_LIBS lldbPythonInterpreter) +endif() + set( CLANG_USED_LIBS clangAnalysis clangAST Index: cmake/modules/LLDBConfig.cmake =================================================================== --- cmake/modules/LLDBConfig.cmake +++ cmake/modules/LLDBConfig.cmake @@ -22,10 +22,10 @@ endif () set(LLDB_ENABLE_PYTHON_SCRIPTS_SWIG_API_GENERATION ${LLDB_DEFAULT_ENABLE_PYTHON_SCRIPTS_SWIG_API_GENERATION} CACHE BOOL - "Enables using new Python scripts for SWIG API generation .") + "Enables using new Python scripts for SWIG API generation .") set(LLDB_SOURCE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/source") -set(LLDB_INCLUDE_ROOT "${LLDB_INCLUDE_ROOT}/include") +set(LLDB_INCLUDE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/include") set(LLDB_DISABLE_PYTHON 0 CACHE BOOL "Disables the Python scripting integration.") Index: include/lldb/API/SBBreakpointLocation.h =================================================================== --- include/lldb/API/SBBreakpointLocation.h +++ include/lldb/API/SBBreakpointLocation.h @@ -101,9 +101,6 @@ private: friend class SBBreakpoint; -#ifndef LLDB_DISABLE_PYTHON - friend class lldb_private::ScriptInterpreterPython; -#endif void SetLocation (const lldb::BreakpointLocationSP &break_loc_sp); Index: include/lldb/API/SBCommandInterpreter.h =================================================================== --- include/lldb/API/SBCommandInterpreter.h +++ include/lldb/API/SBCommandInterpreter.h @@ -229,9 +229,6 @@ private: friend class SBDebugger; - static void - InitializeSWIG (); - lldb_private::CommandInterpreter *m_opaque_ptr; }; Index: include/lldb/API/SBFrame.h =================================================================== --- include/lldb/API/SBFrame.h +++ include/lldb/API/SBFrame.h @@ -213,9 +213,6 @@ friend class SBInstruction; friend class SBThread; friend class SBValue; -#ifndef LLDB_DISABLE_PYTHON - friend class lldb_private::ScriptInterpreterPython; -#endif lldb::StackFrameSP GetFrameSP() const; Index: include/lldb/API/bindings/Python/ScriptInterpreterPython.h =================================================================== --- include/lldb/API/bindings/Python/ScriptInterpreterPython.h +++ include/lldb/API/bindings/Python/ScriptInterpreterPython.h @@ -21,7 +21,7 @@ #include "lldb/lldb-private.h" #include "lldb/Core/IOHandler.h" #include "lldb/Interpreter/ScriptInterpreter.h" -#include "lldb/Interpreter/PythonDataObjects.h" +#include "lldb/API/Bindings/Python/PythonDataObjects.h" #include "lldb/Host/Terminal.h" class IOHandlerPythonInterpreter; @@ -288,32 +288,6 @@ static void InitializePrivate (); - static void - InitializeInterpreter (SWIGInitCallback python_swig_init_callback, - SWIGBreakpointCallbackFunction swig_breakpoint_callback, - SWIGWatchpointCallbackFunction swig_watchpoint_callback, - SWIGPythonTypeScriptCallbackFunction swig_typescript_callback, - SWIGPythonCreateSyntheticProvider swig_synthetic_script, - SWIGPythonCalculateNumChildren swig_calc_children, - SWIGPythonGetChildAtIndex swig_get_child_index, - SWIGPythonGetIndexOfChildWithName swig_get_index_child, - SWIGPythonCastPyObjectToSBValue swig_cast_to_sbvalue , - SWIGPythonGetValueObjectSPFromSBValue swig_get_valobj_sp_from_sbvalue, - SWIGPythonUpdateSynthProviderInstance swig_update_provider, - SWIGPythonMightHaveChildrenSynthProviderInstance swig_mighthavechildren_provider, - SWIGPythonGetValueSynthProviderInstance swig_getvalue_provider, - SWIGPythonCallCommand swig_call_command, - SWIGPythonCallModuleInit swig_call_module_init, - SWIGPythonCreateOSPlugin swig_create_os_plugin, - SWIGPythonScriptKeyword_Process swig_run_script_keyword_process, - SWIGPythonScriptKeyword_Thread swig_run_script_keyword_thread, - SWIGPythonScriptKeyword_Target swig_run_script_keyword_target, - SWIGPythonScriptKeyword_Frame swig_run_script_keyword_frame, - SWIGPythonScriptKeyword_Value swig_run_script_keyword_value, - SWIGPython_GetDynamicSetting swig_plugin_get, - SWIGPythonCreateScriptedThreadPlan swig_thread_plan_script, - SWIGPythonCallThreadPlan swig_call_thread_plan); - const char * GetDictionaryName () { Index: include/lldb/DataFormatters/TypeSummary.h =================================================================== --- include/lldb/DataFormatters/TypeSummary.h +++ include/lldb/DataFormatters/TypeSummary.h @@ -26,7 +26,7 @@ #include "lldb/Core/Error.h" #include "lldb/Core/FormatEntity.h" #include "lldb/Core/ValueObject.h" -#include "lldb/Interpreter/ScriptInterpreterPython.h" +#include "lldb/Interpreter/ScriptInterpreter.h" #include "lldb/Symbol/Type.h" namespace lldb_private { Index: include/lldb/Interpreter/CommandInterpreter.h =================================================================== --- include/lldb/Interpreter/CommandInterpreter.h +++ include/lldb/Interpreter/CommandInterpreter.h @@ -14,6 +14,7 @@ // C++ Includes // Other libraries and framework includes // Project includes +#include "lldb/lldb-forward.h" #include "lldb/lldb-private.h" #include "lldb/Core/Broadcaster.h" #include "lldb/Core/Debugger.h" @@ -21,7 +22,6 @@ #include "lldb/Core/Log.h" #include "lldb/Interpreter/CommandHistory.h" #include "lldb/Interpreter/CommandObject.h" -#include "lldb/Interpreter/ScriptInterpreter.h" #include "lldb/Core/Event.h" #include "lldb/Interpreter/Args.h" #include "lldb/Core/StringList.h" @@ -696,7 +696,7 @@ OptionArgMap m_alias_options; // Stores any options (with or without arguments) that go with any alias. CommandHistory m_command_history; std::string m_repeat_command; // Stores the command that will be executed for an empty command string. - std::unique_ptr m_script_interpreter_ap; + lldb::ScriptInterpreterUP m_script_interpreter_ap; lldb::IOHandlerSP m_command_io_handler_sp; char m_comment_char; bool m_batch_command_mode; Index: include/lldb/Interpreter/ScriptInterpreter.h =================================================================== --- include/lldb/Interpreter/ScriptInterpreter.h +++ include/lldb/Interpreter/ScriptInterpreter.h @@ -20,6 +20,8 @@ namespace lldb_private { +class CommandInterpreter; + class ScriptInterpreterObject { public: @@ -40,7 +42,7 @@ { return m_object; } - + explicit operator bool () { return m_object != NULL; @@ -81,88 +83,6 @@ class ScriptInterpreter { public: - - typedef void (*SWIGInitCallback) (void); - - typedef bool (*SWIGBreakpointCallbackFunction) (const char *python_function_name, - const char *session_dictionary_name, - const lldb::StackFrameSP& frame_sp, - const lldb::BreakpointLocationSP &bp_loc_sp); - - typedef bool (*SWIGWatchpointCallbackFunction) (const char *python_function_name, - const char *session_dictionary_name, - const lldb::StackFrameSP& frame_sp, - const lldb::WatchpointSP &wp_sp); - - typedef bool (*SWIGPythonTypeScriptCallbackFunction) (const char *python_function_name, - void *session_dictionary, - const lldb::ValueObjectSP& valobj_sp, - void** pyfunct_wrapper, - const lldb::TypeSummaryOptionsSP& options, - std::string& retval); - - typedef void* (*SWIGPythonCreateSyntheticProvider) (const char *python_class_name, - const char *session_dictionary_name, - const lldb::ValueObjectSP& valobj_sp); - - typedef void* (*SWIGPythonCreateScriptedThreadPlan) (const char *python_class_name, - const char *session_dictionary_name, - const lldb::ThreadPlanSP& thread_plan_sp); - - typedef bool (*SWIGPythonCallThreadPlan) (void *implementor, const char *method_name, Event *event_sp, bool &got_error); - - typedef void* (*SWIGPythonCreateOSPlugin) (const char *python_class_name, - const char *session_dictionary_name, - const lldb::ProcessSP& process_sp); - - typedef uint32_t (*SWIGPythonCalculateNumChildren) (void *implementor); - typedef void* (*SWIGPythonGetChildAtIndex) (void *implementor, uint32_t idx); - typedef int (*SWIGPythonGetIndexOfChildWithName) (void *implementor, const char* child_name); - typedef void* (*SWIGPythonCastPyObjectToSBValue) (void* data); - typedef lldb::ValueObjectSP (*SWIGPythonGetValueObjectSPFromSBValue) (void* data); - typedef bool (*SWIGPythonUpdateSynthProviderInstance) (void* data); - typedef bool (*SWIGPythonMightHaveChildrenSynthProviderInstance) (void* data); - typedef void* (*SWIGPythonGetValueSynthProviderInstance) (void *implementor); - - typedef bool (*SWIGPythonCallCommand) (const char *python_function_name, - const char *session_dictionary_name, - lldb::DebuggerSP& debugger, - const char* args, - lldb_private::CommandReturnObject& cmd_retobj, - lldb::ExecutionContextRefSP exe_ctx_ref_sp); - - typedef bool (*SWIGPythonCallModuleInit) (const char *python_module_name, - const char *session_dictionary_name, - lldb::DebuggerSP& debugger); - - typedef bool (*SWIGPythonScriptKeyword_Process) (const char* python_function_name, - const char* session_dictionary_name, - lldb::ProcessSP& process, - std::string& output); - typedef bool (*SWIGPythonScriptKeyword_Thread) (const char* python_function_name, - const char* session_dictionary_name, - lldb::ThreadSP& thread, - std::string& output); - - typedef bool (*SWIGPythonScriptKeyword_Target) (const char* python_function_name, - const char* session_dictionary_name, - lldb::TargetSP& target, - std::string& output); - - typedef bool (*SWIGPythonScriptKeyword_Frame) (const char* python_function_name, - const char* session_dictionary_name, - lldb::StackFrameSP& frame, - std::string& output); - - typedef bool (*SWIGPythonScriptKeyword_Value) (const char* python_function_name, - const char* session_dictionary_name, - lldb::ValueObjectSP& value, - std::string& output); - - typedef void* (*SWIGPython_GetDynamicSetting) (void* module, - const char* setting, - const lldb::TargetSP& target_sp); - typedef enum { eScriptReturnTypeCharPtr, @@ -623,41 +543,18 @@ int GetMasterFileDescriptor (); - CommandInterpreter & - GetCommandInterpreter (); + CommandInterpreter &GetCommandInterpreter(); static std::string LanguageToString (lldb::ScriptLanguage language); - - static void - InitializeInterpreter (SWIGInitCallback python_swig_init_callback, - SWIGBreakpointCallbackFunction swig_breakpoint_callback, - SWIGWatchpointCallbackFunction swig_watchpoint_callback, - SWIGPythonTypeScriptCallbackFunction swig_typescript_callback, - SWIGPythonCreateSyntheticProvider swig_synthetic_script, - SWIGPythonCalculateNumChildren swig_calc_children, - SWIGPythonGetChildAtIndex swig_get_child_index, - SWIGPythonGetIndexOfChildWithName swig_get_index_child, - SWIGPythonCastPyObjectToSBValue swig_cast_to_sbvalue , - SWIGPythonGetValueObjectSPFromSBValue swig_get_valobj_sp_from_sbvalue, - SWIGPythonUpdateSynthProviderInstance swig_update_provider, - SWIGPythonMightHaveChildrenSynthProviderInstance swig_mighthavechildren_provider, - SWIGPythonGetValueSynthProviderInstance swig_getvalue_provider, - SWIGPythonCallCommand swig_call_command, - SWIGPythonCallModuleInit swig_call_module_init, - SWIGPythonCreateOSPlugin swig_create_os_plugin, - SWIGPythonScriptKeyword_Process swig_run_script_keyword_process, - SWIGPythonScriptKeyword_Thread swig_run_script_keyword_thread, - SWIGPythonScriptKeyword_Target swig_run_script_keyword_target, - SWIGPythonScriptKeyword_Frame swig_run_script_keyword_frame, - SWIGPythonScriptKeyword_Value swig_run_script_keyword_value, - SWIGPython_GetDynamicSetting swig_plugin_get, - SWIGPythonCreateScriptedThreadPlan swig_thread_plan_script, - SWIGPythonCallThreadPlan swig_call_thread_plan); virtual void ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing. + static ScriptInterpreter *GetScriptInterpreter(lldb::ScriptLanguage script_lang, CommandInterpreter &interpreter, bool can_create); + + static void InitializePrivate(); + protected: CommandInterpreter &m_interpreter; lldb::ScriptLanguage m_script_lang; Index: include/lldb/lldb-forward.h =================================================================== --- include/lldb/lldb-forward.h +++ include/lldb/lldb-forward.h @@ -187,7 +187,6 @@ class ScriptInterpreterLocker; class ScriptInterpreterObject; #ifndef LLDB_DISABLE_PYTHON -class ScriptInterpreterPython; struct ScriptSummaryFormat; #endif class SearchFilter; @@ -380,6 +379,7 @@ typedef std::shared_ptr QueueSP; typedef std::weak_ptr QueueWP; typedef std::shared_ptr QueueItemSP; + typedef std::shared_ptr ScriptInterpreterUP; typedef std::shared_ptr ScriptInterpreterObjectSP; #ifndef LLDB_DISABLE_PYTHON typedef std::shared_ptr ScriptSummaryFormatSP; Index: lldb.xcodeproj/project.pbxproj =================================================================== --- lldb.xcodeproj/project.pbxproj +++ lldb.xcodeproj/project.pbxproj @@ -448,7 +448,6 @@ 2689008613353E2200698AC0 /* Options.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BC7E8610F1B85900F91463 /* Options.cpp */; }; 2689008713353E2200698AC0 /* ScriptInterpreter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A82010B10FFB49800182560 /* ScriptInterpreter.cpp */; }; 2689008813353E2200698AC0 /* ScriptInterpreterNone.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A2771FC1135A37500E6ADB6 /* ScriptInterpreterNone.cpp */; }; - 2689008913353E2200698AC0 /* ScriptInterpreterPython.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BC7F0C10F1B8DD00F91463 /* ScriptInterpreterPython.cpp */; }; 2689008D13353E4200698AC0 /* DynamicLoaderMacOSXDYLD.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 260C897A10F57C5600BB2B04 /* DynamicLoaderMacOSXDYLD.cpp */; }; 2689008E13353E4200698AC0 /* DynamicLoaderStatic.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 268A683D1321B53B000E3FB8 /* DynamicLoaderStatic.cpp */; }; 2689009613353E4200698AC0 /* ObjectContainerBSDArchive.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26A3B4AC1181454800381BC2 /* ObjectContainerBSDArchive.cpp */; }; @@ -682,6 +681,8 @@ 33E5E8421A672A240024ED68 /* StringConvert.cpp in CopyFiles */ = {isa = PBXBuildFile; fileRef = 33E5E8411A672A240024ED68 /* StringConvert.cpp */; }; 33E5E8461A6736D30024ED68 /* StringConvert.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 33E5E8451A6736D30024ED68 /* StringConvert.h */; }; 33E5E8471A674FB60024ED68 /* StringConvert.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33E5E8411A672A240024ED68 /* StringConvert.cpp */; }; + 3FDBEC021AA7AD2C0042A8A7 /* ScriptInterpreterPython.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FDBEBFE1AA7ACE30042A8A7 /* ScriptInterpreterPython.cpp */; }; + 3FDBEC031AA7AD300042A8A7 /* PythonDataObjects.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FDBEBFD1AA7ACE30042A8A7 /* PythonDataObjects.cpp */; }; 3FDFDDBD199C3A06009756A7 /* FileAction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FDFDDBC199C3A06009756A7 /* FileAction.cpp */; }; 3FDFDDBF199D345E009756A7 /* FileCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FDFDDBE199D345E009756A7 /* FileCache.cpp */; }; 3FDFDDC6199D37ED009756A7 /* FileSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FDFDDC5199D37ED009756A7 /* FileSystem.cpp */; }; @@ -820,7 +821,6 @@ 94D6A0AB16CEB55F00833B6E /* NSDictionary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94D6A0A816CEB55F00833B6E /* NSDictionary.cpp */; }; 94D6A0AC16CEB55F00833B6E /* NSSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94D6A0A916CEB55F00833B6E /* NSSet.cpp */; }; 94E829CA152D33C1006F96A3 /* lldb-server in Resources */ = {isa = PBXBuildFile; fileRef = 26DC6A101337FE6900FF7998 /* lldb-server */; }; - 94EA1D5C15E6C9B400D4171A /* PythonDataObjects.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94EA1D5B15E6C9B400D4171A /* PythonDataObjects.cpp */; }; 94EA27CE17DE91750070F505 /* LibCxxUnorderedMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94EA27CD17DE91750070F505 /* LibCxxUnorderedMap.cpp */; }; 94F48F251A01C687005C0EC6 /* StringPrinter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94F48F241A01C687005C0EC6 /* StringPrinter.cpp */; }; 94FA3DE01405D50400833217 /* ValueObjectConstResultChild.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94FA3DDF1405D50300833217 /* ValueObjectConstResultChild.cpp */; }; @@ -1898,7 +1898,6 @@ 26BC7DE310F1B7F900F91463 /* CommandObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CommandObject.h; path = include/lldb/Interpreter/CommandObject.h; sourceTree = ""; }; 26BC7DE410F1B7F900F91463 /* CommandReturnObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CommandReturnObject.h; path = include/lldb/Interpreter/CommandReturnObject.h; sourceTree = ""; }; 26BC7DE510F1B7F900F91463 /* ScriptInterpreter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ScriptInterpreter.h; path = include/lldb/Interpreter/ScriptInterpreter.h; sourceTree = ""; }; - 26BC7DE610F1B7F900F91463 /* ScriptInterpreterPython.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ScriptInterpreterPython.h; path = include/lldb/Interpreter/ScriptInterpreterPython.h; sourceTree = ""; }; 26BC7DF110F1B81A00F91463 /* DynamicLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DynamicLoader.h; path = include/lldb/Target/DynamicLoader.h; sourceTree = ""; }; 26BC7DF210F1B81A00F91463 /* ExecutionContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ExecutionContext.h; path = include/lldb/Target/ExecutionContext.h; sourceTree = ""; }; 26BC7DF310F1B81A00F91463 /* Process.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Process.h; path = include/lldb/Target/Process.h; sourceTree = ""; }; @@ -2003,7 +2002,6 @@ 26BC7F0810F1B8DD00F91463 /* CommandInterpreter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommandInterpreter.cpp; path = source/Interpreter/CommandInterpreter.cpp; sourceTree = ""; }; 26BC7F0910F1B8DD00F91463 /* CommandObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommandObject.cpp; path = source/Interpreter/CommandObject.cpp; sourceTree = ""; }; 26BC7F0A10F1B8DD00F91463 /* CommandReturnObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommandReturnObject.cpp; path = source/Interpreter/CommandReturnObject.cpp; sourceTree = ""; }; - 26BC7F0C10F1B8DD00F91463 /* ScriptInterpreterPython.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ScriptInterpreterPython.cpp; path = source/Interpreter/ScriptInterpreterPython.cpp; sourceTree = ""; }; 26BC7F1310F1B8EC00F91463 /* Block.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Block.cpp; path = source/Symbol/Block.cpp; sourceTree = ""; }; 26BC7F1410F1B8EC00F91463 /* ClangASTContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClangASTContext.cpp; path = source/Symbol/ClangASTContext.cpp; sourceTree = ""; }; 26BC7F1510F1B8EC00F91463 /* CompileUnit.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CompileUnit.cpp; path = source/Symbol/CompileUnit.cpp; sourceTree = ""; }; @@ -2153,6 +2151,12 @@ 33E5E8411A672A240024ED68 /* StringConvert.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringConvert.cpp; sourceTree = ""; }; 33E5E8451A6736D30024ED68 /* StringConvert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StringConvert.h; path = include/lldb/Host/StringConvert.h; sourceTree = SOURCE_ROOT; }; 3F5E8AF31A40D4A500A73232 /* PipeBase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = PipeBase.h; path = include/lldb/Host/PipeBase.h; sourceTree = ""; }; + 3FDBEBFC1AA7ACE30042A8A7 /* embedded_interpreter.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; name = embedded_interpreter.py; path = source/API/Bindings/Python/embedded_interpreter.py; sourceTree = ""; }; + 3FDBEBFD1AA7ACE30042A8A7 /* PythonDataObjects.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PythonDataObjects.cpp; path = source/API/Bindings/Python/PythonDataObjects.cpp; sourceTree = ""; }; + 3FDBEBFE1AA7ACE30042A8A7 /* ScriptInterpreterPython.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ScriptInterpreterPython.cpp; path = source/API/Bindings/Python/ScriptInterpreterPython.cpp; sourceTree = ""; }; + 3FDBEC041AA7AD7A0042A8A7 /* PythonDataObjects.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = PythonDataObjects.h; path = include/lldb/API/bindings/Python/PythonDataObjects.h; sourceTree = ""; }; + 3FDBEC051AA7AD7A0042A8A7 /* PythonPointer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = PythonPointer.h; path = include/lldb/API/bindings/Python/PythonPointer.h; sourceTree = ""; }; + 3FDBEC061AA7AD7A0042A8A7 /* ScriptInterpreterPython.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ScriptInterpreterPython.h; path = include/lldb/API/bindings/Python/ScriptInterpreterPython.h; sourceTree = ""; }; 3FDFD6C3199C396E009756A7 /* FileAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileAction.h; path = include/lldb/Target/FileAction.h; sourceTree = ""; }; 3FDFDDBC199C3A06009756A7 /* FileAction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FileAction.cpp; path = source/Target/FileAction.cpp; sourceTree = ""; }; 3FDFDDBE199D345E009756A7 /* FileCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FileCache.cpp; path = source/Host/common/FileCache.cpp; sourceTree = ""; }; @@ -2374,7 +2378,6 @@ 8CF02AED19DD15CF00B14BE0 /* InstrumentationRuntimeStopInfo.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = InstrumentationRuntimeStopInfo.cpp; path = source/Target/InstrumentationRuntimeStopInfo.cpp; sourceTree = ""; }; 8CF02AEE19DD15CF00B14BE0 /* InstrumentationRuntimeStopInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = InstrumentationRuntimeStopInfo.h; path = include/lldb/Target/InstrumentationRuntimeStopInfo.h; sourceTree = ""; }; 94005E0313F438DF001EF42D /* python-wrapper.swig */ = {isa = PBXFileReference; lastKnownFileType = text; path = "python-wrapper.swig"; sourceTree = ""; }; - 94005E0513F45A1B001EF42D /* embedded_interpreter.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; name = embedded_interpreter.py; path = source/Interpreter/embedded_interpreter.py; sourceTree = ""; }; 94031A9F13CF5B3D00DCFF3C /* PriorityPointerPair.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = PriorityPointerPair.h; path = include/lldb/Utility/PriorityPointerPair.h; sourceTree = ""; }; 94094C68163B6CCC0083A547 /* ValueObjectCast.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ValueObjectCast.h; path = include/lldb/Core/ValueObjectCast.h; sourceTree = ""; }; 94094C69163B6CD90083A547 /* ValueObjectCast.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ValueObjectCast.cpp; path = source/Core/ValueObjectCast.cpp; sourceTree = ""; }; @@ -2484,10 +2487,7 @@ 94D6A0A916CEB55F00833B6E /* NSSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NSSet.cpp; path = source/DataFormatters/NSSet.cpp; sourceTree = ""; }; 94E367CC140C4EC4001C7A5A /* modify-python-lldb.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = "modify-python-lldb.py"; sourceTree = ""; }; 94E367CE140C4EEA001C7A5A /* python-typemaps.swig */ = {isa = PBXFileReference; lastKnownFileType = text; path = "python-typemaps.swig"; sourceTree = ""; }; - 94EA1D5A15E6C99B00D4171A /* PythonDataObjects.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = PythonDataObjects.h; path = include/lldb/Interpreter/PythonDataObjects.h; sourceTree = ""; }; - 94EA1D5B15E6C9B400D4171A /* PythonDataObjects.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PythonDataObjects.cpp; path = source/Interpreter/PythonDataObjects.cpp; sourceTree = ""; }; 94EA27CD17DE91750070F505 /* LibCxxUnorderedMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LibCxxUnorderedMap.cpp; path = source/DataFormatters/LibCxxUnorderedMap.cpp; sourceTree = ""; }; - 94EBAC8313D9EE26009BA64E /* PythonPointer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = PythonPointer.h; path = include/lldb/Utility/PythonPointer.h; sourceTree = ""; }; 94ED54A119C8A822007BE2EA /* ThreadSafeDenseMap.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ThreadSafeDenseMap.h; path = include/lldb/Core/ThreadSafeDenseMap.h; sourceTree = ""; }; 94EE33F218643C6900CD703B /* FormattersContainer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = FormattersContainer.h; path = include/lldb/DataFormatters/FormattersContainer.h; sourceTree = ""; }; 94F48F231A01C679005C0EC6 /* StringPrinter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = StringPrinter.h; path = include/lldb/DataFormatters/StringPrinter.h; sourceTree = ""; }; @@ -3177,6 +3177,7 @@ 262D3190111B4341004E6F88 /* API */ = { isa = PBXGroup; children = ( + 3FDBEBFA1AA7ACBE0042A8A7 /* Bindings */, 254FBBA41A91670E00BD6378 /* SBAttachInfo.cpp */, 254FBBA21A9166F100BD6378 /* SBAttachInfo.h */, 2611FEEE142D83060017FEA3 /* interface */, @@ -3478,7 +3479,6 @@ 94380B8119940B0A00BFE4A8 /* StringLexer.cpp */, 26D1804616CEE12C00EDFB5B /* TimeSpecTimeout.h */, 26D1804016CEDF0700EDFB5B /* TimeSpecTimeout.cpp */, - 94EBAC8313D9EE26009BA64E /* PythonPointer.h */, 94BA8B6E176F8CA0005A91B5 /* Range.h */, 94BA8B6C176F8C9B005A91B5 /* Range.cpp */, AF1FA8891A60A69500272AFC /* RegisterNumber.cpp */, @@ -4319,7 +4319,6 @@ 25420ECC1A6490B8009ADBCB /* OptionValueChar.cpp */, 26BC7D5310F1B77400F91463 /* Args.h */, 26BC7E6C10F1B85900F91463 /* Args.cpp */, - 26A4EEB511682AAC007A372A /* LLDBWrapPython.cpp */, 4C09CB73116BD98B00C7A725 /* CommandCompletions.h */, 4C09CB74116BD98B00C7A725 /* CommandCompletions.cpp */, 94BA8B71176F97D4005A91B5 /* CommandHistory.h */, @@ -4335,7 +4334,6 @@ 23DDF224196C3EE600BB8417 /* CommandOptionValidators.cpp */, 26BC7DE410F1B7F900F91463 /* CommandReturnObject.h */, 26BC7F0A10F1B8DD00F91463 /* CommandReturnObject.cpp */, - 94005E0513F45A1B001EF42D /* embedded_interpreter.py */, 26A7A036135E6E5300FB369E /* OptionValue.h */, 26A7A034135E6E4200FB369E /* OptionValue.cpp */, 260A248D15D06C4F009981B0 /* OptionValues.h */, @@ -4403,14 +4401,10 @@ B2462246141AD37D00F3D409 /* OptionGroupWatchpoint.cpp */, 26ACEC2715E077AE00E94760 /* Property.h */, 2640E19E15DC78FD00F23B50 /* Property.cpp */, - 94EA1D5A15E6C99B00D4171A /* PythonDataObjects.h */, - 94EA1D5B15E6C9B400D4171A /* PythonDataObjects.cpp */, 26BC7DE510F1B7F900F91463 /* ScriptInterpreter.h */, 9A82010B10FFB49800182560 /* ScriptInterpreter.cpp */, 9A2771FB1135A35C00E6ADB6 /* ScriptInterpreterNone.h */, 9A2771FC1135A37500E6ADB6 /* ScriptInterpreterNone.cpp */, - 26BC7DE610F1B7F900F91463 /* ScriptInterpreterPython.h */, - 26BC7F0C10F1B8DD00F91463 /* ScriptInterpreterPython.cpp */, ); name = Interpreter; sourceTree = ""; @@ -4741,6 +4735,28 @@ path = "POSIX-DYLD"; sourceTree = ""; }; + 3FDBEBFA1AA7ACBE0042A8A7 /* Bindings */ = { + isa = PBXGroup; + children = ( + 3FDBEBFB1AA7ACC80042A8A7 /* Python */, + ); + name = Bindings; + sourceTree = ""; + }; + 3FDBEBFB1AA7ACC80042A8A7 /* Python */ = { + isa = PBXGroup; + children = ( + 3FDBEC041AA7AD7A0042A8A7 /* PythonDataObjects.h */, + 3FDBEC051AA7AD7A0042A8A7 /* PythonPointer.h */, + 3FDBEC061AA7AD7A0042A8A7 /* ScriptInterpreterPython.h */, + 3FDBEBFC1AA7ACE30042A8A7 /* embedded_interpreter.py */, + 26A4EEB511682AAC007A372A /* LLDBWrapPython.cpp */, + 3FDBEBFD1AA7ACE30042A8A7 /* PythonDataObjects.cpp */, + 3FDBEBFE1AA7ACE30042A8A7 /* ScriptInterpreterPython.cpp */, + ); + name = Python; + sourceTree = ""; + }; 3FDFDDC4199D37BE009756A7 /* posix */ = { isa = PBXGroup; children = ( @@ -5763,9 +5779,11 @@ 26DE204711618AED00A093E2 /* SBSymbolContext.cpp in Sources */, 26DE204D11618E7A00A093E2 /* SBModule.cpp in Sources */, 26DE205D1161901400A093E2 /* SBFunction.cpp in Sources */, + 3FDBEC021AA7AD2C0042A8A7 /* ScriptInterpreterPython.cpp in Sources */, 26DE205F1161901B00A093E2 /* SBCompileUnit.cpp in Sources */, AF0EBBE9185940FB0059E52F /* SBQueueItem.cpp in Sources */, AF0EBBE8185940FB0059E52F /* SBQueue.cpp in Sources */, + 3FDBEC031AA7AD300042A8A7 /* PythonDataObjects.cpp in Sources */, 26DE20611161902700A093E2 /* SBBlock.cpp in Sources */, 26DE20631161904200A093E2 /* SBLineEntry.cpp in Sources */, 26DE20651161904E00A093E2 /* SBSymbol.cpp in Sources */, @@ -5996,7 +6014,6 @@ 2689008613353E2200698AC0 /* Options.cpp in Sources */, 2689008713353E2200698AC0 /* ScriptInterpreter.cpp in Sources */, 2689008813353E2200698AC0 /* ScriptInterpreterNone.cpp in Sources */, - 2689008913353E2200698AC0 /* ScriptInterpreterPython.cpp in Sources */, 260A63191861009E00FECF8E /* IOHandler.cpp in Sources */, 2689008D13353E4200698AC0 /* DynamicLoaderMacOSXDYLD.cpp in Sources */, 2689008E13353E4200698AC0 /* DynamicLoaderStatic.cpp in Sources */, @@ -6282,7 +6299,6 @@ 26491E3E15E1DB9F00CBFFC2 /* OptionValueRegex.cpp in Sources */, 2697A39315E404B1003E682C /* OptionValueArch.cpp in Sources */, 6D55B2921A8A806200A70529 /* GDBRemoteCommunicationServerPlatform.cpp in Sources */, - 94EA1D5C15E6C9B400D4171A /* PythonDataObjects.cpp in Sources */, 94D6A0AC16CEB55F00833B6E /* NSSet.cpp in Sources */, 94CD704E16F8DDEA00CF1E42 /* Cocoa.cpp in Sources */, 2698699B15E6CBD0002415FF /* OperatingSystemPython.cpp in Sources */, Index: source/API/Bindings/Python/PythonDataObjects.cpp =================================================================== --- source/API/Bindings/Python/PythonDataObjects.cpp +++ source/API/Bindings/Python/PythonDataObjects.cpp @@ -19,9 +19,9 @@ #include +#include "lldb/API/Bindings/Python/PythonDataObjects.h" #include "lldb/Core/Stream.h" #include "lldb/Host/File.h" -#include "lldb/Interpreter/PythonDataObjects.h" #include "lldb/Interpreter/ScriptInterpreter.h" using namespace lldb_private; Index: source/API/Bindings/Python/ScriptInterpreterPython.cpp =================================================================== --- source/API/Bindings/Python/ScriptInterpreterPython.cpp +++ source/API/Bindings/Python/ScriptInterpreterPython.cpp @@ -16,13 +16,14 @@ #else #include "lldb/lldb-python.h" -#include "lldb/Interpreter/ScriptInterpreterPython.h" +#include "lldb/API/Bindings/Python/ScriptInterpreterPython.h" #include #include #include +#include "lldb/API/Bindings/Python/PythonDataObjects.h" #include "lldb/API/SBValue.h" #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Breakpoint/StoppointCallbackContext.h" @@ -37,7 +38,6 @@ #include "lldb/Host/Pipe.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" -#include "lldb/Interpreter/PythonDataObjects.h" #include "lldb/Target/Thread.h" #include "lldb/Target/ThreadPlan.h" @@ -48,31 +48,74 @@ using namespace lldb; using namespace lldb_private; +// these are the Pythonic implementations of the required callbacks +// these are scripting-language specific, which is why they belong here +// we still need to use function pointers to them instead of relying +// on linkage-time resolution because the SWIG stuff and this file +// get built at different times +// Defined in the SWIG source file +extern "C" void init_lldb(void); -static ScriptInterpreter::SWIGInitCallback g_swig_init_callback = nullptr; -static ScriptInterpreter::SWIGBreakpointCallbackFunction g_swig_breakpoint_callback = nullptr; -static ScriptInterpreter::SWIGWatchpointCallbackFunction g_swig_watchpoint_callback = nullptr; -static ScriptInterpreter::SWIGPythonTypeScriptCallbackFunction g_swig_typescript_callback = nullptr; -static ScriptInterpreter::SWIGPythonCreateSyntheticProvider g_swig_synthetic_script = nullptr; -static ScriptInterpreter::SWIGPythonCalculateNumChildren g_swig_calc_children = nullptr; -static ScriptInterpreter::SWIGPythonGetChildAtIndex g_swig_get_child_index = nullptr; -static ScriptInterpreter::SWIGPythonGetIndexOfChildWithName g_swig_get_index_child = nullptr; -static ScriptInterpreter::SWIGPythonCastPyObjectToSBValue g_swig_cast_to_sbvalue = nullptr; -static ScriptInterpreter::SWIGPythonGetValueObjectSPFromSBValue g_swig_get_valobj_sp_from_sbvalue = nullptr; -static ScriptInterpreter::SWIGPythonUpdateSynthProviderInstance g_swig_update_provider = nullptr; -static ScriptInterpreter::SWIGPythonMightHaveChildrenSynthProviderInstance g_swig_mighthavechildren_provider = nullptr; -static ScriptInterpreter::SWIGPythonGetValueSynthProviderInstance g_swig_getvalue_provider = nullptr; -static ScriptInterpreter::SWIGPythonCallCommand g_swig_call_command = nullptr; -static ScriptInterpreter::SWIGPythonCallModuleInit g_swig_call_module_init = nullptr; -static ScriptInterpreter::SWIGPythonCreateOSPlugin g_swig_create_os_plugin = nullptr; -static ScriptInterpreter::SWIGPythonScriptKeyword_Process g_swig_run_script_keyword_process = nullptr; -static ScriptInterpreter::SWIGPythonScriptKeyword_Thread g_swig_run_script_keyword_thread = nullptr; -static ScriptInterpreter::SWIGPythonScriptKeyword_Target g_swig_run_script_keyword_target = nullptr; -static ScriptInterpreter::SWIGPythonScriptKeyword_Frame g_swig_run_script_keyword_frame = nullptr; -static ScriptInterpreter::SWIGPythonScriptKeyword_Value g_swig_run_script_keyword_value = nullptr; -static ScriptInterpreter::SWIGPython_GetDynamicSetting g_swig_plugin_get = nullptr; -static ScriptInterpreter::SWIGPythonCreateScriptedThreadPlan g_swig_thread_plan_script = nullptr; -static ScriptInterpreter::SWIGPythonCallThreadPlan g_swig_call_thread_plan = nullptr; +extern "C" bool LLDBSwigPythonBreakpointCallbackFunction(const char *python_function_name, const char *session_dictionary_name, + const lldb::StackFrameSP &sb_frame, const lldb::BreakpointLocationSP &sb_bp_loc); + +extern "C" bool LLDBSwigPythonWatchpointCallbackFunction(const char *python_function_name, const char *session_dictionary_name, + const lldb::StackFrameSP &sb_frame, const lldb::WatchpointSP &sb_wp); + +extern "C" bool LLDBSwigPythonCallTypeScript(const char *python_function_name, void *session_dictionary, + const lldb::ValueObjectSP &valobj_sp, void **pyfunct_wrapper, + const lldb::TypeSummaryOptionsSP &options_sp, std::string &retval); + +extern "C" void *LLDBSwigPythonCreateSyntheticProvider(const char *python_class_name, const char *session_dictionary_name, + const lldb::ValueObjectSP &valobj_sp); + +extern "C" void *LLDBSwigPythonCreateScriptedThreadPlan(const char *python_class_name, const char *session_dictionary_name, + const lldb::ThreadPlanSP &thread_plan_sp); + +extern "C" bool LLDBSWIGPythonCallThreadPlan(void *implementor, const char *method_name, Event *event_sp, bool &got_error); + +extern "C" uint32_t LLDBSwigPython_CalculateNumChildren(void *implementor); + +extern "C" void *LLDBSwigPython_GetChildAtIndex(void *implementor, uint32_t idx); + +extern "C" int LLDBSwigPython_GetIndexOfChildWithName(void *implementor, const char *child_name); + +extern "C" void *LLDBSWIGPython_CastPyObjectToSBValue(void *data); + +extern lldb::ValueObjectSP LLDBSWIGPython_GetValueObjectSPFromSBValue(void *data); + +extern "C" bool LLDBSwigPython_UpdateSynthProviderInstance(void *implementor); + +extern "C" bool LLDBSwigPython_MightHaveChildrenSynthProviderInstance(void *implementor); + +extern "C" void *LLDBSwigPython_GetValueSynthProviderInstance(void *implementor); + +extern "C" bool LLDBSwigPythonCallCommand(const char *python_function_name, const char *session_dictionary_name, lldb::DebuggerSP &debugger, + const char *args, lldb_private::CommandReturnObject &cmd_retobj, + lldb::ExecutionContextRefSP exe_ctx_ref_sp); + +extern "C" bool LLDBSwigPythonCallModuleInit(const char *python_module_name, const char *session_dictionary_name, + lldb::DebuggerSP &debugger); + +extern "C" void *LLDBSWIGPythonCreateOSPlugin(const char *python_class_name, const char *session_dictionary_name, + const lldb::ProcessSP &process_sp); + +extern "C" bool LLDBSWIGPythonRunScriptKeywordProcess(const char *python_function_name, const char *session_dictionary_name, + lldb::ProcessSP &process, std::string &output); + +extern "C" bool LLDBSWIGPythonRunScriptKeywordThread(const char *python_function_name, const char *session_dictionary_name, + lldb::ThreadSP &thread, std::string &output); + +extern "C" bool LLDBSWIGPythonRunScriptKeywordTarget(const char *python_function_name, const char *session_dictionary_name, + lldb::TargetSP &target, std::string &output); + +extern "C" bool LLDBSWIGPythonRunScriptKeywordFrame(const char *python_function_name, const char *session_dictionary_name, + lldb::StackFrameSP &frame, std::string &output); + +extern "C" bool LLDBSWIGPythonRunScriptKeywordValue(const char *python_function_name, const char *session_dictionary_name, + lldb::ValueObjectSP &value, std::string &output); + +extern "C" void *LLDBSWIGPython_GetDynamicSetting(void *module, const char *setting, const lldb::TargetSP &target_sp); static std::string ReadPythonBacktrace (PyObject* py_backtrace); @@ -1365,9 +1408,7 @@ Locker py_lock (this, Locker::AcquireLock | Locker::NoSTDIN, Locker::FreeLock); - ret_val = g_swig_create_os_plugin (class_name, - m_dictionary_name.c_str(), - process_sp); + ret_val = LLDBSWIGPythonCreateOSPlugin(class_name, m_dictionary_name.c_str(), process_sp); } return MakeScriptObject(ret_val); @@ -1671,10 +1712,8 @@ { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - - ret_val = g_swig_thread_plan_script (class_name, - python_interpreter->m_dictionary_name.c_str(), - thread_plan_sp); + + ret_val = LLDBSwigPythonCreateScriptedThreadPlan(class_name, python_interpreter->m_dictionary_name.c_str(), thread_plan_sp); } return MakeScriptObject(ret_val); @@ -1689,7 +1728,7 @@ if (implementor_sp) { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - explains_stop = g_swig_call_thread_plan (implementor_sp->GetObject(), "explains_stop", event, script_error); + explains_stop = LLDBSWIGPythonCallThreadPlan(implementor_sp->GetObject(), "explains_stop", event, script_error); if (script_error) return true; } @@ -1705,7 +1744,7 @@ if (implementor_sp) { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - should_stop = g_swig_call_thread_plan (implementor_sp->GetObject(), "should_stop", event, script_error); + should_stop = LLDBSWIGPythonCallThreadPlan(implementor_sp->GetObject(), "should_stop", event, script_error); if (script_error) return true; } @@ -1720,7 +1759,7 @@ if (implementor_sp) { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - should_step = g_swig_call_thread_plan (implementor_sp->GetObject(), "should_step", NULL, script_error); + should_step = LLDBSWIGPythonCallThreadPlan(implementor_sp->GetObject(), "should_step", NULL, script_error); if (script_error) should_step = true; } @@ -1758,15 +1797,12 @@ if (!plugin_module_sp || !target || !setting_name || !setting_name[0]) return lldb::ScriptInterpreterObjectSP(); - if (!g_swig_plugin_get) - return lldb::ScriptInterpreterObjectSP(); - PyObject *reply_pyobj = nullptr; { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); TargetSP target_sp(target->shared_from_this()); - reply_pyobj = (PyObject*)g_swig_plugin_get(plugin_module_sp->GetObject(),setting_name,target_sp); + reply_pyobj = (PyObject *)LLDBSWIGPython_GetDynamicSetting(plugin_module_sp->GetObject(), setting_name, target_sp); } return MakeScriptObject(reply_pyobj); @@ -1799,9 +1835,7 @@ { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - ret_val = g_swig_synthetic_script (class_name, - python_interpreter->m_dictionary_name.c_str(), - valobj); + ret_val = LLDBSwigPythonCreateSyntheticProvider(class_name, python_interpreter->m_dictionary_name.c_str(), valobj); } return MakeScriptObject(ret_val); @@ -1897,14 +1931,10 @@ Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); { TypeSummaryOptionsSP options_sp(new TypeSummaryOptions(options)); - - Timer scoped_timer ("g_swig_typescript_callback","g_swig_typescript_callback"); - ret_val = g_swig_typescript_callback (python_function_name, - GetSessionDictionary().get(), - valobj, - &new_callee, - options_sp, - retval); + + Timer scoped_timer("LLDBSwigPythonCallTypeScript", "LLDBSwigPythonCallTypeScript"); + ret_val = LLDBSwigPythonCallTypeScript(python_function_name, GetSessionDictionary().get(), valobj, &new_callee, options_sp, + retval); } } } @@ -1977,10 +2007,8 @@ bool ret_val = true; { Locker py_lock(python_interpreter, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - ret_val = g_swig_breakpoint_callback (python_function_name, - python_interpreter->m_dictionary_name.c_str(), - stop_frame_sp, - bp_loc_sp); + ret_val = LLDBSwigPythonBreakpointCallbackFunction(python_function_name, python_interpreter->m_dictionary_name.c_str(), + stop_frame_sp, bp_loc_sp); } return ret_val; } @@ -2029,10 +2057,8 @@ bool ret_val = true; { Locker py_lock(python_interpreter, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - ret_val = g_swig_watchpoint_callback (python_function_name, - python_interpreter->m_dictionary_name.c_str(), - stop_frame_sp, - wp_sp); + ret_val = LLDBSwigPythonWatchpointCallbackFunction(python_function_name, python_interpreter->m_dictionary_name.c_str(), + stop_frame_sp, wp_sp); } return ret_val; } @@ -2054,14 +2080,11 @@ if (!implementor) return 0; - if (!g_swig_calc_children) - return 0; - uint32_t ret_val = 0; { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - ret_val = g_swig_calc_children (implementor); + ret_val = LLDBSwigPython_CalculateNumChildren(implementor); } return ret_val; @@ -2078,21 +2101,18 @@ if (!implementor) return lldb::ValueObjectSP(); - if (!g_swig_get_child_index || !g_swig_cast_to_sbvalue) - return lldb::ValueObjectSP(); - lldb::ValueObjectSP ret_val; { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - void* child_ptr = g_swig_get_child_index (implementor,idx); + void *child_ptr = LLDBSwigPython_GetChildAtIndex(implementor, idx); if (child_ptr != nullptr && child_ptr != Py_None) { - lldb::SBValue* sb_value_ptr = (lldb::SBValue*)g_swig_cast_to_sbvalue(child_ptr); + lldb::SBValue *sb_value_ptr = (lldb::SBValue *)LLDBSWIGPython_CastPyObjectToSBValue(child_ptr); if (sb_value_ptr == nullptr) Py_XDECREF(child_ptr); else - ret_val = g_swig_get_valobj_sp_from_sbvalue (sb_value_ptr); + ret_val = LLDBSWIGPython_GetValueObjectSPFromSBValue(sb_value_ptr); } else { @@ -2114,14 +2134,11 @@ if (!implementor) return UINT32_MAX; - if (!g_swig_get_index_child) - return UINT32_MAX; - int ret_val = UINT32_MAX; { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - ret_val = g_swig_get_index_child (implementor, child_name); + ret_val = LLDBSwigPython_GetIndexOfChildWithName(implementor, child_name); } return ret_val; @@ -2140,12 +2157,9 @@ if (!implementor) return ret_val; - if (!g_swig_update_provider) - return ret_val; - { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - ret_val = g_swig_update_provider (implementor); + ret_val = LLDBSwigPython_UpdateSynthProviderInstance(implementor); } return ret_val; @@ -2164,12 +2178,9 @@ if (!implementor) return ret_val; - if (!g_swig_mighthavechildren_provider) - return ret_val; - { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - ret_val = g_swig_mighthavechildren_provider (implementor); + ret_val = LLDBSwigPython_MightHaveChildrenSynthProviderInstance(implementor); } return ret_val; @@ -2188,19 +2199,16 @@ if (!implementor) return ret_val; - if (!g_swig_getvalue_provider || !g_swig_cast_to_sbvalue || !g_swig_get_valobj_sp_from_sbvalue) - return ret_val; - { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - void* child_ptr = g_swig_getvalue_provider (implementor); + void *child_ptr = LLDBSwigPython_GetValueSynthProviderInstance(implementor); if (child_ptr != nullptr && child_ptr != Py_None) { - lldb::SBValue* sb_value_ptr = (lldb::SBValue*)g_swig_cast_to_sbvalue(child_ptr); + lldb::SBValue *sb_value_ptr = (lldb::SBValue *)LLDBSWIGPython_CastPyObjectToSBValue(child_ptr); if (sb_value_ptr == nullptr) Py_XDECREF(child_ptr); else - ret_val = g_swig_get_valobj_sp_from_sbvalue (sb_value_ptr); + ret_val = LLDBSWIGPython_GetValueObjectSPFromSBValue(sb_value_ptr); } else { @@ -2285,15 +2293,10 @@ error.SetErrorString("no function to execute"); return false; } - if (!g_swig_run_script_keyword_process) - { - error.SetErrorString("internal helper function missing"); - return false; - } { ProcessSP process_sp(process->shared_from_this()); Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - ret_val = g_swig_run_script_keyword_process (impl_function, m_dictionary_name.c_str(), process_sp, output); + ret_val = LLDBSWIGPythonRunScriptKeywordProcess(impl_function, m_dictionary_name.c_str(), process_sp, output); if (!ret_val) error.SetErrorString("python script evaluation failed"); } @@ -2317,15 +2320,10 @@ error.SetErrorString("no function to execute"); return false; } - if (!g_swig_run_script_keyword_thread) - { - error.SetErrorString("internal helper function missing"); - return false; - } { ThreadSP thread_sp(thread->shared_from_this()); Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - ret_val = g_swig_run_script_keyword_thread (impl_function, m_dictionary_name.c_str(), thread_sp, output); + ret_val = LLDBSWIGPythonRunScriptKeywordThread(impl_function, m_dictionary_name.c_str(), thread_sp, output); if (!ret_val) error.SetErrorString("python script evaluation failed"); } @@ -2349,15 +2347,10 @@ error.SetErrorString("no function to execute"); return false; } - if (!g_swig_run_script_keyword_target) - { - error.SetErrorString("internal helper function missing"); - return false; - } { TargetSP target_sp(target->shared_from_this()); Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - ret_val = g_swig_run_script_keyword_target (impl_function, m_dictionary_name.c_str(), target_sp, output); + ret_val = LLDBSWIGPythonRunScriptKeywordTarget(impl_function, m_dictionary_name.c_str(), target_sp, output); if (!ret_val) error.SetErrorString("python script evaluation failed"); } @@ -2365,10 +2358,7 @@ } bool -ScriptInterpreterPython::RunScriptFormatKeyword (const char* impl_function, - StackFrame* frame, - std::string& output, - Error& error) +ScriptInterpreterPython::RunScriptFormatKeyword(const char *impl_function, StackFrame *frame, std::string &output, Error &error) { bool ret_val; if (!frame) @@ -2381,26 +2371,18 @@ error.SetErrorString("no function to execute"); return false; } - if (!g_swig_run_script_keyword_frame) - { - error.SetErrorString("internal helper function missing"); - return false; - } { StackFrameSP frame_sp(frame->shared_from_this()); Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - ret_val = g_swig_run_script_keyword_frame (impl_function, m_dictionary_name.c_str(), frame_sp, output); + ret_val = LLDBSWIGPythonRunScriptKeywordFrame(impl_function, m_dictionary_name.c_str(), frame_sp, output); if (!ret_val) error.SetErrorString("python script evaluation failed"); } return ret_val; } - + bool -ScriptInterpreterPython::RunScriptFormatKeyword (const char* impl_function, - ValueObject *value, - std::string& output, - Error& error) +ScriptInterpreterPython::RunScriptFormatKeyword(const char *impl_function, ValueObject *value, std::string &output, Error &error) { bool ret_val; if (!value) @@ -2413,15 +2395,10 @@ error.SetErrorString("no function to execute"); return false; } - if (!g_swig_run_script_keyword_value) - { - error.SetErrorString("internal helper function missing"); - return false; - } { ValueObjectSP value_sp(value->GetSP()); Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - ret_val = g_swig_run_script_keyword_value (impl_function, m_dictionary_name.c_str(), value_sp, output); + ret_val = LLDBSWIGPythonRunScriptKeywordValue(impl_function, m_dictionary_name.c_str(), value_sp, output); if (!ret_val) error.SetErrorString("python script evaluation failed"); } @@ -2454,12 +2431,6 @@ return false; } - if (!g_swig_call_module_init) - { - error.SetErrorString("internal helper function missing"); - return false; - } - lldb::DebuggerSP debugger_sp = m_interpreter.GetDebugger().shared_from_this(); { @@ -2562,9 +2533,7 @@ // if we are here, everything worked // call __lldb_init_module(debugger,dict) - if (!g_swig_call_module_init (basename.c_str(), - m_dictionary_name.c_str(), - debugger_sp)) + if (!LLDBSwigPythonCallModuleInit(basename.c_str(), m_dictionary_name.c_str(), debugger_sp)) { error.SetErrorString("calling __lldb_init_module failed"); return false; @@ -2637,12 +2606,6 @@ return false; } - if (!g_swig_call_command) - { - error.SetErrorString("no helper function to run scripted commands"); - return false; - } - lldb::DebuggerSP debugger_sp = m_interpreter.GetDebugger().shared_from_this(); lldb::ExecutionContextRefSP exe_ctx_ref_sp(new ExecutionContextRef(exe_ctx)); @@ -2663,13 +2626,8 @@ SynchronicityHandler synch_handler(debugger_sp, synchronicity); - - ret_val = g_swig_call_command (impl_function, - m_dictionary_name.c_str(), - debugger_sp, - args, - cmd_retobj, - exe_ctx_ref_sp); + + ret_val = LLDBSwigPythonCallCommand(impl_function, m_dictionary_name.c_str(), debugger_sp, args, cmd_retobj, exe_ctx_ref_sp); } if (!ret_val) @@ -2722,58 +2680,6 @@ } void -ScriptInterpreterPython::InitializeInterpreter (SWIGInitCallback swig_init_callback, - SWIGBreakpointCallbackFunction swig_breakpoint_callback, - SWIGWatchpointCallbackFunction swig_watchpoint_callback, - SWIGPythonTypeScriptCallbackFunction swig_typescript_callback, - SWIGPythonCreateSyntheticProvider swig_synthetic_script, - SWIGPythonCalculateNumChildren swig_calc_children, - SWIGPythonGetChildAtIndex swig_get_child_index, - SWIGPythonGetIndexOfChildWithName swig_get_index_child, - SWIGPythonCastPyObjectToSBValue swig_cast_to_sbvalue , - SWIGPythonGetValueObjectSPFromSBValue swig_get_valobj_sp_from_sbvalue, - SWIGPythonUpdateSynthProviderInstance swig_update_provider, - SWIGPythonMightHaveChildrenSynthProviderInstance swig_mighthavechildren_provider, - SWIGPythonGetValueSynthProviderInstance swig_getvalue_provider, - SWIGPythonCallCommand swig_call_command, - SWIGPythonCallModuleInit swig_call_module_init, - SWIGPythonCreateOSPlugin swig_create_os_plugin, - SWIGPythonScriptKeyword_Process swig_run_script_keyword_process, - SWIGPythonScriptKeyword_Thread swig_run_script_keyword_thread, - SWIGPythonScriptKeyword_Target swig_run_script_keyword_target, - SWIGPythonScriptKeyword_Frame swig_run_script_keyword_frame, - SWIGPythonScriptKeyword_Value swig_run_script_keyword_value, - SWIGPython_GetDynamicSetting swig_plugin_get, - SWIGPythonCreateScriptedThreadPlan swig_thread_plan_script, - SWIGPythonCallThreadPlan swig_call_thread_plan) -{ - g_swig_init_callback = swig_init_callback; - g_swig_breakpoint_callback = swig_breakpoint_callback; - g_swig_watchpoint_callback = swig_watchpoint_callback; - g_swig_typescript_callback = swig_typescript_callback; - g_swig_synthetic_script = swig_synthetic_script; - g_swig_calc_children = swig_calc_children; - g_swig_get_child_index = swig_get_child_index; - g_swig_get_index_child = swig_get_index_child; - g_swig_cast_to_sbvalue = swig_cast_to_sbvalue; - g_swig_get_valobj_sp_from_sbvalue = swig_get_valobj_sp_from_sbvalue; - g_swig_update_provider = swig_update_provider; - g_swig_mighthavechildren_provider = swig_mighthavechildren_provider; - g_swig_getvalue_provider = swig_getvalue_provider; - g_swig_call_command = swig_call_command; - g_swig_call_module_init = swig_call_module_init; - g_swig_create_os_plugin = swig_create_os_plugin; - g_swig_run_script_keyword_process = swig_run_script_keyword_process; - g_swig_run_script_keyword_thread = swig_run_script_keyword_thread; - g_swig_run_script_keyword_target = swig_run_script_keyword_target; - g_swig_run_script_keyword_frame = swig_run_script_keyword_frame; - g_swig_run_script_keyword_value = swig_run_script_keyword_value; - g_swig_plugin_get = swig_plugin_get; - g_swig_thread_plan_script = swig_thread_plan_script; - g_swig_call_thread_plan = swig_call_thread_plan; -} - -void ScriptInterpreterPython::InitializePrivate () { static int g_initialized = false; @@ -2805,8 +2711,7 @@ Py_InitializeEx (0); // Initialize SWIG after setting up python - if (g_swig_init_callback) - g_swig_init_callback (); + init_lldb(); // Update the path python uses to search for modules to include the current directory. Index: source/API/CMakeLists.txt =================================================================== --- source/API/CMakeLists.txt +++ source/API/CMakeLists.txt @@ -78,3 +78,5 @@ SBWatchpoint.cpp SBUnixSignals.cpp ) + +add_subdirectory(Bindings) \ No newline at end of file Index: source/API/SBCommandInterpreter.cpp =================================================================== --- source/API/SBCommandInterpreter.cpp +++ source/API/SBCommandInterpreter.cpp @@ -567,170 +567,6 @@ return false; } -#ifndef LLDB_DISABLE_PYTHON - -// Defined in the SWIG source file -extern "C" void -init_lldb(void); - -// these are the Pythonic implementations of the required callbacks -// these are scripting-language specific, which is why they belong here -// we still need to use function pointers to them instead of relying -// on linkage-time resolution because the SWIG stuff and this file -// get built at different times -extern "C" bool -LLDBSwigPythonBreakpointCallbackFunction (const char *python_function_name, - const char *session_dictionary_name, - const lldb::StackFrameSP& sb_frame, - const lldb::BreakpointLocationSP& sb_bp_loc); - -extern "C" bool -LLDBSwigPythonWatchpointCallbackFunction (const char *python_function_name, - const char *session_dictionary_name, - const lldb::StackFrameSP& sb_frame, - const lldb::WatchpointSP& sb_wp); - -extern "C" bool -LLDBSwigPythonCallTypeScript (const char *python_function_name, - void *session_dictionary, - const lldb::ValueObjectSP& valobj_sp, - void** pyfunct_wrapper, - const lldb::TypeSummaryOptionsSP& options_sp, - std::string& retval); - -extern "C" void* -LLDBSwigPythonCreateSyntheticProvider (const char *python_class_name, - const char *session_dictionary_name, - const lldb::ValueObjectSP& valobj_sp); - - -extern "C" void* -LLDBSwigPythonCreateScriptedThreadPlan (const char *python_class_name, - const char *session_dictionary_name, - const lldb::ThreadPlanSP& thread_plan_sp); - -extern "C" bool -LLDBSWIGPythonCallThreadPlan (void *implementor, - const char *method_name, - Event *event_sp, - bool &got_error); - -extern "C" uint32_t -LLDBSwigPython_CalculateNumChildren (void *implementor); - -extern "C" void * -LLDBSwigPython_GetChildAtIndex (void *implementor, uint32_t idx); - -extern "C" int -LLDBSwigPython_GetIndexOfChildWithName (void *implementor, const char* child_name); - -extern "C" void * -LLDBSWIGPython_CastPyObjectToSBValue (void* data); - -extern lldb::ValueObjectSP -LLDBSWIGPython_GetValueObjectSPFromSBValue (void* data); - -extern "C" bool -LLDBSwigPython_UpdateSynthProviderInstance (void* implementor); - -extern "C" bool -LLDBSwigPython_MightHaveChildrenSynthProviderInstance (void* implementor); - -extern "C" void * -LLDBSwigPython_GetValueSynthProviderInstance (void* implementor); - -extern "C" bool -LLDBSwigPythonCallCommand (const char *python_function_name, - const char *session_dictionary_name, - lldb::DebuggerSP& debugger, - const char* args, - lldb_private::CommandReturnObject &cmd_retobj, - lldb::ExecutionContextRefSP exe_ctx_ref_sp); - -extern "C" bool -LLDBSwigPythonCallModuleInit (const char *python_module_name, - const char *session_dictionary_name, - lldb::DebuggerSP& debugger); - -extern "C" void* -LLDBSWIGPythonCreateOSPlugin (const char *python_class_name, - const char *session_dictionary_name, - const lldb::ProcessSP& process_sp); - -extern "C" bool -LLDBSWIGPythonRunScriptKeywordProcess (const char* python_function_name, - const char* session_dictionary_name, - lldb::ProcessSP& process, - std::string& output); - -extern "C" bool -LLDBSWIGPythonRunScriptKeywordThread (const char* python_function_name, - const char* session_dictionary_name, - lldb::ThreadSP& thread, - std::string& output); - -extern "C" bool -LLDBSWIGPythonRunScriptKeywordTarget (const char* python_function_name, - const char* session_dictionary_name, - lldb::TargetSP& target, - std::string& output); - -extern "C" bool -LLDBSWIGPythonRunScriptKeywordFrame (const char* python_function_name, - const char* session_dictionary_name, - lldb::StackFrameSP& frame, - std::string& output); - -extern "C" bool -LLDBSWIGPythonRunScriptKeywordValue (const char* python_function_name, - const char* session_dictionary_name, - lldb::ValueObjectSP& value, - std::string& output); - -extern "C" void* -LLDBSWIGPython_GetDynamicSetting (void* module, - const char* setting, - const lldb::TargetSP& target_sp); - - -#endif - -void -SBCommandInterpreter::InitializeSWIG () -{ - static bool g_initialized = false; - if (!g_initialized) - { - g_initialized = true; -#ifndef LLDB_DISABLE_PYTHON - ScriptInterpreter::InitializeInterpreter (init_lldb, - LLDBSwigPythonBreakpointCallbackFunction, - LLDBSwigPythonWatchpointCallbackFunction, - LLDBSwigPythonCallTypeScript, - LLDBSwigPythonCreateSyntheticProvider, - LLDBSwigPython_CalculateNumChildren, - LLDBSwigPython_GetChildAtIndex, - LLDBSwigPython_GetIndexOfChildWithName, - LLDBSWIGPython_CastPyObjectToSBValue, - LLDBSWIGPython_GetValueObjectSPFromSBValue, - LLDBSwigPython_UpdateSynthProviderInstance, - LLDBSwigPython_MightHaveChildrenSynthProviderInstance, - LLDBSwigPython_GetValueSynthProviderInstance, - LLDBSwigPythonCallCommand, - LLDBSwigPythonCallModuleInit, - LLDBSWIGPythonCreateOSPlugin, - LLDBSWIGPythonRunScriptKeywordProcess, - LLDBSWIGPythonRunScriptKeywordThread, - LLDBSWIGPythonRunScriptKeywordTarget, - LLDBSWIGPythonRunScriptKeywordFrame, - LLDBSWIGPythonRunScriptKeywordValue, - LLDBSWIGPython_GetDynamicSetting, - LLDBSwigPythonCreateScriptedThreadPlan, - LLDBSWIGPythonCallThreadPlan); -#endif - } -} - lldb::SBCommand SBCommandInterpreter::AddMultiwordCommand (const char* name, const char* help) { Index: source/API/SBDebugger.cpp =================================================================== --- source/API/SBDebugger.cpp +++ source/API/SBDebugger.cpp @@ -115,8 +115,6 @@ if (log) log->Printf ("SBDebugger::Initialize ()"); - SBCommandInterpreter::InitializeSWIG (); - Debugger::Initialize(LoadPlugin); } Index: source/Commands/CommandObjectBreakpointCommand.cpp =================================================================== --- source/Commands/CommandObjectBreakpointCommand.cpp +++ source/Commands/CommandObjectBreakpointCommand.cpp @@ -26,6 +26,7 @@ #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Breakpoint/StoppointCallbackContext.h" #include "lldb/Core/State.h" +#include "lldb/Interpreter/ScriptInterpreter.h" using namespace lldb; using namespace lldb_private; Index: source/Commands/CommandObjectCommands.cpp =================================================================== --- source/Commands/CommandObjectCommands.cpp +++ source/Commands/CommandObjectCommands.cpp @@ -29,7 +29,6 @@ #include "lldb/Interpreter/OptionValueUInt64.h" #include "lldb/Interpreter/Options.h" #include "lldb/Interpreter/ScriptInterpreter.h" -#include "lldb/Interpreter/ScriptInterpreterPython.h" using namespace lldb; using namespace lldb_private; Index: source/Commands/CommandObjectThread.cpp =================================================================== --- source/Commands/CommandObjectThread.cpp +++ source/Commands/CommandObjectThread.cpp @@ -24,6 +24,7 @@ #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Interpreter/Options.h" +#include "lldb/Interpreter/ScriptInterpreter.h" #include "lldb/Symbol/CompileUnit.h" #include "lldb/Symbol/Function.h" #include "lldb/Symbol/LineTable.h" Index: source/Commands/CommandObjectWatchpointCommand.cpp =================================================================== --- source/Commands/CommandObjectWatchpointCommand.cpp +++ source/Commands/CommandObjectWatchpointCommand.cpp @@ -24,6 +24,7 @@ #include "lldb/Breakpoint/Watchpoint.h" #include "lldb/Breakpoint/StoppointCallbackContext.h" #include "lldb/Core/State.h" +#include "lldb/Interpreter/ScriptInterpreter.h" #include Index: source/Core/ValueObject.cpp =================================================================== --- source/Core/ValueObject.cpp +++ source/Core/ValueObject.cpp @@ -43,7 +43,6 @@ #include "lldb/Host/Endian.h" #include "lldb/Interpreter/CommandInterpreter.h" -#include "lldb/Interpreter/ScriptInterpreterPython.h" #include "lldb/Symbol/ClangASTType.h" #include "lldb/Symbol/ClangASTContext.h" Index: source/DataFormatters/FormatManager.cpp =================================================================== --- source/DataFormatters/FormatManager.cpp +++ source/DataFormatters/FormatManager.cpp @@ -18,7 +18,6 @@ #include "lldb/Core/Debugger.h" #include "lldb/DataFormatters/CXXFormatterFunctions.h" -#include "lldb/Interpreter/ScriptInterpreterPython.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/Platform.h" #include "llvm/ADT/STLExtras.h" Index: source/DataFormatters/TypeSynthetic.cpp =================================================================== --- source/DataFormatters/TypeSynthetic.cpp +++ source/DataFormatters/TypeSynthetic.cpp @@ -23,7 +23,9 @@ #include "lldb/Core/StreamString.h" #include "lldb/DataFormatters/TypeSynthetic.h" #include "lldb/Interpreter/CommandInterpreter.h" -#include "lldb/Interpreter/ScriptInterpreterPython.h" +#ifndef LLDB_DISABLE_PYTHON +#include "lldb/API/Bindings/Python/ScriptInterpreterPython.h" +#endif #include "lldb/Symbol/ClangASTType.h" #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" Index: source/Interpreter/CMakeLists.txt =================================================================== --- source/Interpreter/CMakeLists.txt +++ source/Interpreter/CMakeLists.txt @@ -43,8 +43,6 @@ OptionGroupWatchpoint.cpp Options.cpp Property.cpp - PythonDataObjects.cpp ScriptInterpreter.cpp ScriptInterpreterNone.cpp - ScriptInterpreterPython.cpp ) Index: source/Interpreter/CommandInterpreter.cpp =================================================================== --- source/Interpreter/CommandInterpreter.cpp +++ source/Interpreter/CommandInterpreter.cpp @@ -62,9 +62,7 @@ #include "lldb/Interpreter/Options.h" #include "lldb/Interpreter/OptionValueProperties.h" #include "lldb/Interpreter/Property.h" -#include "lldb/Interpreter/ScriptInterpreterNone.h" -#include "lldb/Interpreter/ScriptInterpreterPython.h" - +#include "lldb/Interpreter/ScriptInterpreter.h" #include "lldb/Target/Process.h" #include "lldb/Target/Thread.h" @@ -2852,42 +2850,8 @@ ScriptInterpreter * CommandInterpreter::GetScriptInterpreter (bool can_create) { - if (m_script_interpreter_ap.get() != nullptr) - return m_script_interpreter_ap.get(); - - if (!can_create) - return nullptr; - - // - // we need to protect the initialization of the script interpreter - // otherwise we could end up with two threads both trying to create - // their instance of it, and for some languages (e.g. Python) - // this is a bulletproof recipe for disaster! - // this needs to be a function-level static because multiple Debugger instances living in the same process - // still need to be isolated and not try to initialize Python concurrently - static Mutex g_interpreter_mutex(Mutex::eMutexTypeRecursive); - Mutex::Locker interpreter_lock(g_interpreter_mutex); - - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); - if (log) - log->Printf("Initializing the ScriptInterpreter now\n"); - lldb::ScriptLanguage script_lang = GetDebugger().GetScriptLanguage(); - switch (script_lang) - { - case eScriptLanguagePython: -#ifndef LLDB_DISABLE_PYTHON - m_script_interpreter_ap.reset (new ScriptInterpreterPython (*this)); - break; -#else - // Fall through to the None case when python is disabled -#endif - case eScriptLanguageNone: - m_script_interpreter_ap.reset (new ScriptInterpreterNone (*this)); - break; - }; - - return m_script_interpreter_ap.get(); + return ScriptInterpreter::GetScriptInterpreter(script_lang, *this, can_create); } Index: source/Interpreter/CommandObject.cpp =================================================================== --- source/Interpreter/CommandObject.cpp +++ source/Interpreter/CommandObject.cpp @@ -31,8 +31,6 @@ #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" -#include "lldb/Interpreter/ScriptInterpreter.h" -#include "lldb/Interpreter/ScriptInterpreterPython.h" using namespace lldb; using namespace lldb_private; Index: source/Interpreter/ScriptInterpreter.cpp =================================================================== --- source/Interpreter/ScriptInterpreter.cpp +++ source/Interpreter/ScriptInterpreter.cpp @@ -16,15 +16,28 @@ #include #include "lldb/Core/Error.h" +#include "lldb/Core/Log.h" #include "lldb/Core/Stream.h" #include "lldb/Core/StringList.h" +#include "lldb/Host/Mutex.h" #include "lldb/Interpreter/CommandReturnObject.h" -#include "lldb/Interpreter/ScriptInterpreterPython.h" +#include "lldb/Interpreter/ScriptInterpreterNone.h" +#ifndef LLDB_DISABLE_PYTHON +#include "lldb/API/Bindings/Python/ScriptInterpreterPython.h" +#endif #include "lldb/Utility/PseudoTerminal.h" using namespace lldb; using namespace lldb_private; +namespace +{ +ScriptInterpreterNone *g_none_interpreter = nullptr; +#ifndef LLDB_DISABLE_PYTHON +ScriptInterpreterPython *g_python_interpreter = nullptr; +#endif +} + ScriptInterpreter::ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang) : m_interpreter (interpreter), m_script_lang (script_lang) @@ -111,56 +124,47 @@ return std::unique_ptr(new ScriptInterpreterLocker()); } +ScriptInterpreter * +ScriptInterpreter::GetScriptInterpreter(lldb::ScriptLanguage script_lang, CommandInterpreter &command_interpreter, bool can_create) +{ + // + // we need to protect the initialization of the script interpreter + // otherwise we could end up with two threads both trying to create + // their instance of it, and for some languages (e.g. Python) + // this is a bulletproof recipe for disaster! + // this needs to be a function-level static because multiple Debugger + // instances living in the same process still need to be isolated and + // not try to initialize the script interpreter concurrently. + static Mutex g_interpreter_mutex(Mutex::eMutexTypeRecursive); + Mutex::Locker interpreter_lock(g_interpreter_mutex); + + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT)); + if (log) + log->Printf("Initializing the ScriptInterpreter now\n"); + + switch (script_lang) + { + case eScriptLanguagePython: +#ifndef LLDB_DISABLE_PYTHON + if (!g_python_interpreter && can_create) + g_python_interpreter = new ScriptInterpreterPython(command_interpreter); + return g_python_interpreter; +#else +// Fall through to the None case when python is disabled +#endif + case eScriptLanguageNone: + if (!g_none_interpreter && can_create) + g_none_interpreter = new ScriptInterpreterNone(command_interpreter); + return g_none_interpreter; + }; + + return nullptr; +} + void -ScriptInterpreter::InitializeInterpreter (SWIGInitCallback python_swig_init_callback, - SWIGBreakpointCallbackFunction swig_breakpoint_callback, - SWIGWatchpointCallbackFunction swig_watchpoint_callback, - SWIGPythonTypeScriptCallbackFunction swig_typescript_callback, - SWIGPythonCreateSyntheticProvider swig_synthetic_script, - SWIGPythonCalculateNumChildren swig_calc_children, - SWIGPythonGetChildAtIndex swig_get_child_index, - SWIGPythonGetIndexOfChildWithName swig_get_index_child, - SWIGPythonCastPyObjectToSBValue swig_cast_to_sbvalue , - SWIGPythonGetValueObjectSPFromSBValue swig_get_valobj_sp_from_sbvalue, - SWIGPythonUpdateSynthProviderInstance swig_update_provider, - SWIGPythonMightHaveChildrenSynthProviderInstance swig_mighthavechildren_provider, - SWIGPythonGetValueSynthProviderInstance swig_getvalue_provider, - SWIGPythonCallCommand swig_call_command, - SWIGPythonCallModuleInit swig_call_module_init, - SWIGPythonCreateOSPlugin swig_create_os_plugin, - SWIGPythonScriptKeyword_Process swig_run_script_keyword_process, - SWIGPythonScriptKeyword_Thread swig_run_script_keyword_thread, - SWIGPythonScriptKeyword_Target swig_run_script_keyword_target, - SWIGPythonScriptKeyword_Frame swig_run_script_keyword_frame, - SWIGPythonScriptKeyword_Value swig_run_script_keyword_value, - SWIGPython_GetDynamicSetting swig_plugin_get, - SWIGPythonCreateScriptedThreadPlan swig_thread_plan_script, - SWIGPythonCallThreadPlan swig_call_thread_plan) +ScriptInterpreter::InitializePrivate() { #ifndef LLDB_DISABLE_PYTHON - ScriptInterpreterPython::InitializeInterpreter (python_swig_init_callback, - swig_breakpoint_callback, - swig_watchpoint_callback, - swig_typescript_callback, - swig_synthetic_script, - swig_calc_children, - swig_get_child_index, - swig_get_index_child, - swig_cast_to_sbvalue , - swig_get_valobj_sp_from_sbvalue, - swig_update_provider, - swig_mighthavechildren_provider, - swig_getvalue_provider, - swig_call_command, - swig_call_module_init, - swig_create_os_plugin, - swig_run_script_keyword_process, - swig_run_script_keyword_thread, - swig_run_script_keyword_target, - swig_run_script_keyword_frame, - swig_run_script_keyword_value, - swig_plugin_get, - swig_thread_plan_script, - swig_call_thread_plan); -#endif // #ifndef LLDB_DISABLE_PYTHON + ScriptInterpreterPython::InitializePrivate(); +#endif } Index: source/Interpreter/ScriptInterpreterNone.cpp =================================================================== --- source/Interpreter/ScriptInterpreterNone.cpp +++ source/Interpreter/ScriptInterpreterNone.cpp @@ -7,8 +7,6 @@ // //===----------------------------------------------------------------------===// -#include "lldb/lldb-python.h" - #include "lldb/Interpreter/ScriptInterpreterNone.h" #include "lldb/Core/Stream.h" #include "lldb/Core/StreamFile.h" Index: source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp =================================================================== --- source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp +++ source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp @@ -15,6 +15,7 @@ // C Includes // C++ Includes // Other libraries and framework includes +#include "lldb/API/Bindings/Python/PythonDataObjects.h" #include "lldb/Core/ArchSpec.h" #include "lldb/Core/DataBufferHeap.h" #include "lldb/Core/Debugger.h" @@ -24,7 +25,6 @@ #include "lldb/Core/StreamString.h" #include "lldb/Core/ValueObjectVariable.h" #include "lldb/Interpreter/CommandInterpreter.h" -#include "lldb/Interpreter/PythonDataObjects.h" #include "lldb/Symbol/ClangNamespaceDecl.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Symbol/VariableList.h" Index: source/Plugins/Platform/MacOSX/PlatformDarwin.cpp =================================================================== --- source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -29,6 +29,7 @@ #include "lldb/Host/FileSystem.h" #include "lldb/Host/Symbols.h" #include "lldb/Interpreter/CommandInterpreter.h" +#include "lldb/Interpreter/ScriptInterpreter.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Symbol/SymbolFile.h" #include "lldb/Symbol/SymbolVendor.h" Index: source/Plugins/Process/Utility/DynamicRegisterInfo.cpp =================================================================== --- source/Plugins/Process/Utility/DynamicRegisterInfo.cpp +++ source/Plugins/Process/Utility/DynamicRegisterInfo.cpp @@ -15,15 +15,14 @@ // C++ Includes // Other libraries and framework includes // Project includes +#ifndef LLDB_DISABLE_PYTHON +#include "lldb/API/Bindings/Python/PythonDataObjects.h" +#endif #include "lldb/Host/StringConvert.h" #include "lldb/Core/RegularExpression.h" #include "lldb/Core/StreamFile.h" #include "lldb/DataFormatters/FormatManager.h" -#ifndef LLDB_DISABLE_PYTHON -#include "lldb/Interpreter/PythonDataObjects.h" -#endif - using namespace lldb; using namespace lldb_private; Index: source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp =================================================================== --- source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp +++ source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp @@ -17,9 +17,6 @@ #include "lldb/Core/RegisterValue.h" #include "lldb/Core/Scalar.h" #include "lldb/Core/StreamString.h" -#ifndef LLDB_DISABLE_PYTHON -#include "lldb/Interpreter/PythonDataObjects.h" -#endif #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/Target.h" #include "lldb/Utility/Utils.h" Index: source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp =================================================================== --- source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -27,6 +27,9 @@ // Other libraries and framework includes +#ifndef LLDB_DISABLE_PYTHON +#include "lldb/API/Bindings/Python/PythonDataObjects.h" +#endif #include "lldb/Breakpoint/Watchpoint.h" #include "lldb/Interpreter/Args.h" #include "lldb/Core/ArchSpec.h" @@ -52,9 +55,7 @@ #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Interpreter/OptionValueProperties.h" #include "lldb/Interpreter/Property.h" -#ifndef LLDB_DISABLE_PYTHON -#include "lldb/Interpreter/PythonDataObjects.h" -#endif +#include "lldb/Interpreter/ScriptInterpreter.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Target/DynamicLoader.h" #include "lldb/Target/Target.h" Index: source/Target/ThreadPlanPython.cpp =================================================================== --- source/Target/ThreadPlanPython.cpp +++ source/Target/ThreadPlanPython.cpp @@ -20,7 +20,6 @@ #include "lldb/Core/State.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/ScriptInterpreter.h" -#include "lldb/Interpreter/ScriptInterpreterPython.h" #include "lldb/Target/RegisterContext.h" #include "lldb/Target/Thread.h" #include "lldb/Target/ThreadPlan.h" Index: source/lldb.cpp =================================================================== --- source/lldb.cpp +++ source/lldb.cpp @@ -20,7 +20,7 @@ #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" #include "lldb/Host/Mutex.h" -#include "lldb/Interpreter/ScriptInterpreterPython.h" +#include "lldb/Interpreter/ScriptInterpreter.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" @@ -187,8 +187,8 @@ ObjectFileMachO::Initialize(); #endif + ScriptInterpreter::InitializePrivate(); #ifndef LLDB_DISABLE_PYTHON - ScriptInterpreterPython::InitializePrivate(); OperatingSystemPython::Initialize(); #endif } Index: tools/driver/CMakeLists.txt =================================================================== --- tools/driver/CMakeLists.txt +++ tools/driver/CMakeLists.txt @@ -2,6 +2,8 @@ add_lldb_executable(lldb Driver.cpp Platform.cpp + ADDITIONAL_HEADER_DIRS + ${LLDB_INCLUDE_ROOT}/lldb ) if ( CMAKE_SYSTEM_NAME MATCHES "Windows" ) Index: tools/lldb-server/CMakeLists.txt =================================================================== --- tools/lldb-server/CMakeLists.txt +++ tools/lldb-server/CMakeLists.txt @@ -2,19 +2,19 @@ if ( CMAKE_SYSTEM_NAME MATCHES "Linux" ) include_directories( - ../../source/Plugins/Process/Linux - ../../source/Plugins/Process/POSIX + ${LLDB_SOURCE_ROOT}/Plugins/Process/Linux + ${LLDB_SOURCE_ROOT}/Plugins/Process/POSIX ) endif () if ( CMAKE_SYSTEM_NAME MATCHES "FreeBSD" ) include_directories( - ../../source/Plugins/Process/FreeBSD - ../../source/Plugins/Process/POSIX + ${LLDB_SOURCE_ROOT}/Plugins/Process/FreeBSD + ${LLDB_SOURCE_ROOT}/Plugins/Process/POSIX ) endif () -include_directories(../../source) +include_directories(${LLDB_SOURCE_ROOT}) include(../../cmake/LLDBDependencies.cmake) @@ -31,8 +31,10 @@ lldb-server.cpp lldb-gdbserver.cpp lldb-platform.cpp - ../../source/lldb-log.cpp - ../../source/lldb.cpp + ${LLDB_SOURCE_ROOT}/lldb-log.cpp + ${LLDB_SOURCE_ROOT}/lldb.cpp + $ + ${LLDB_WRAP_PYTHON} ) # The Darwin linker doesn't understand --start-group/--end-group.