Convert the ScriptInterpreter system to a plugin-based one.
authorZachary Turner <zturner@google.com>
Thu, 30 Jul 2015 20:28:07 +0000 (20:28 +0000)
committerZachary Turner <zturner@google.com>
Thu, 30 Jul 2015 20:28:07 +0000 (20:28 +0000)
Previously embedded interpreters were handled as ad-hoc source
files compiled into source/Interpreter.  This made it hard to
disable a specific interpreter, or to add support for other
interpreters and allow the developer to choose which interpreter(s)
were enabled for a particular build.

This patch converts script interpreters over to a plugin-based system.
Script interpreters now live in source/Plugins/ScriptInterpreter, and
the canonical LLDB interpreter, ScriptInterpreterPython, is moved there
as well.

Any new code interfacing with the Python C API must live in this location
from here on out.  Additionally, generic code should never need to
reference or make assumptions about the presence of a specific interpreter
going forward.

Differential Revision: http://reviews.llvm.org/D11431
Reviewed By: Greg Clayton

llvm-svn: 243681

33 files changed:
lldb/include/lldb/API/SystemInitializerFull.h
lldb/include/lldb/Core/PluginManager.h
lldb/include/lldb/Interpreter/CommandInterpreter.h
lldb/include/lldb/Interpreter/ScriptInterpreter.h
lldb/include/lldb/Interpreter/ScriptInterpreterNone.h [deleted file]
lldb/include/lldb/Utility/PythonPointer.h [deleted file]
lldb/include/lldb/lldb-forward.h
lldb/include/lldb/lldb-private-interfaces.h
lldb/include/lldb/lldb-python.h [deleted file]
lldb/lldb.xcodeproj/project.pbxproj
lldb/source/API/CMakeLists.txt
lldb/source/API/SBCommandInterpreter.cpp
lldb/source/API/SystemInitializerFull.cpp
lldb/source/Core/PluginManager.cpp
lldb/source/Host/macosx/HostInfoMacOSX.mm
lldb/source/Host/posix/HostInfoPosix.cpp
lldb/source/Initialization/SystemInitializerCommon.cpp
lldb/source/Interpreter/CMakeLists.txt
lldb/source/Interpreter/CommandInterpreter.cpp
lldb/source/Interpreter/ScriptInterpreterNone.cpp [deleted file]
lldb/source/Plugins/CMakeLists.txt
lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
lldb/source/Plugins/ScriptInterpreter/CMakeLists.txt [new file with mode: 0644]
lldb/source/Plugins/ScriptInterpreter/None/CMakeLists.txt [new file with mode: 0644]
lldb/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp [new file with mode: 0644]
lldb/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h [new file with mode: 0644]
lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt [new file with mode: 0644]
lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp [moved from lldb/source/Interpreter/PythonDataObjects.cpp with 97% similarity]
lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h [moved from lldb/include/lldb/Interpreter/PythonDataObjects.h with 96% similarity]
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp [moved from lldb/source/Interpreter/ScriptInterpreterPython.cpp with 98% similarity]
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h [moved from lldb/include/lldb/Interpreter/ScriptInterpreterPython.h with 95% similarity]
lldb/source/Plugins/ScriptInterpreter/Python/lldb-python.h [new file with mode: 0644]
lldb/unittests/CMakeLists.txt

index 6280fe8..0b4e879 100644 (file)
@@ -33,7 +33,6 @@ class SystemInitializerFull : public SystemInitializerCommon
 
   private:
     void InitializeSWIG();
-    void TerminateSWIG();
 };
 }
 
index 5aa014a..e586417 100644 (file)
@@ -296,6 +296,23 @@ public:
     GetProcessPluginDescriptionAtIndex (uint32_t idx);
 
     //------------------------------------------------------------------
+    // ScriptInterpreter
+    //------------------------------------------------------------------
+    static bool
+    RegisterPlugin(const ConstString &name, const char *description, lldb::ScriptLanguage script_lang,
+                               ScriptInterpreterCreateInstance create_callback);
+
+    static bool
+    UnregisterPlugin(ScriptInterpreterCreateInstance create_callback);
+
+    static ScriptInterpreterCreateInstance
+    GetScriptInterpreterCreateCallbackAtIndex(uint32_t idx);
+
+    static lldb::ScriptInterpreterSP
+    GetScriptInterpreterForLanguage(lldb::ScriptLanguage script_lang,
+                                    CommandInterpreter &interpreter);
+
+    //------------------------------------------------------------------
     // SymbolFile
     //------------------------------------------------------------------
     static bool
index 0b555b5..a5a36a3 100644 (file)
@@ -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"
@@ -520,7 +521,10 @@ public:
     GetOptionArgumentPosition (const char *in_string);
 
     ScriptInterpreter *
-    GetScriptInterpreter (bool can_create = true);
+    GetScriptInterpreter(bool can_create = true);
+
+    void
+    SetScriptInterpreter();
 
     void
     SkipLLDBInitFiles (bool skip_lldbinit_files)
@@ -709,7 +713,7 @@ private:
     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<ScriptInterpreter> m_script_interpreter_ap;
+    lldb::ScriptInterpreterSP m_script_interpreter_sp;
     lldb::IOHandlerSP m_command_io_handler_sp;
     char m_comment_char;
     bool m_batch_command_mode;
index 0f45dd8..8a67807 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "lldb/Core/Broadcaster.h"
 #include "lldb/Core/Error.h"
+#include "lldb/Core/PluginInterface.h"
 #include "lldb/Core/StructuredData.h"
 
 #include "lldb/Utility/PseudoTerminal.h"
@@ -36,8 +37,7 @@ private:
     DISALLOW_COPY_AND_ASSIGN (ScriptInterpreterLocker);
 };
 
-
-class ScriptInterpreter
+class ScriptInterpreter : public PluginInterface
 {
 public:
 
diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreterNone.h b/lldb/include/lldb/Interpreter/ScriptInterpreterNone.h
deleted file mode 100644 (file)
index 6c82b60..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-//===-- ScriptInterpreterNone.h ---------------------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef liblldb_ScriptInterpreterNone_h_
-#define liblldb_ScriptInterpreterNone_h_
-
-#include "lldb/Interpreter/ScriptInterpreter.h"
-
-namespace lldb_private {
-
-class ScriptInterpreterNone : public ScriptInterpreter
-{
-public:
-
-    ScriptInterpreterNone (CommandInterpreter &interpreter);
-
-    ~ScriptInterpreterNone ();
-
-    bool
-    ExecuteOneLine (const char *command, CommandReturnObject *result, const ExecuteScriptOptions &options = ExecuteScriptOptions());
-
-    void
-    ExecuteInterpreterLoop ();
-
-};
-
-} // namespace lldb_private
-
-#endif // #ifndef liblldb_ScriptInterpreterNone_h_
diff --git a/lldb/include/lldb/Utility/PythonPointer.h b/lldb/include/lldb/Utility/PythonPointer.h
deleted file mode 100644 (file)
index fe90670..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-//===---------------------PythonPointer.h ------------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef utility_PythonPointer_h_
-#define utility_PythonPointer_h_
-
-#include <algorithm>
-
-#include "lldb/lldb-python.h"
-
-namespace lldb_private {
-
-template<class T>
-class PythonPointer
-{
-public: 
-    typedef PyObject* element_type; 
-private:
-    element_type*      ptr_;
-    bool my_ref;
-public:
-    
-    PythonPointer(element_type p, bool steal_ref = false) :
-    ptr_(p),
-    my_ref(!steal_ref)
-    {
-        if (my_ref)
-            Py_INCREF(ptr_);
-    }
-    
-    PythonPointer(const PythonPointer& r, bool steal_ref = false) :
-    ptr_(r.ptr_),
-    my_ref(!steal_ref)
-    {
-        if (my_ref)
-            Py_INCREF(ptr_);
-    }
-
-    ~PythonPointer()
-    {
-        if (my_ref)
-            Py_XDECREF(ptr_);
-    }
-    
-    PythonPointer
-    StealReference()
-    {
-        return PythonPointer(ptr_,true);
-    }
-    
-    PythonPointer
-    DuplicateReference()
-    {
-        return PythonPointer(ptr_, false);
-    }
-
-    element_type get() const {return ptr_;}
-    
-    bool IsNull() { return ptr_ == NULL; }
-    bool IsNone() { return ptr_ == Py_None; }
-    
-    operator PyObject* () { return ptr_; }
-};
-
-} // namespace lldb
-
-#endif  // utility_PythonPointer_h_
index da90ac4..d0d6304 100644 (file)
@@ -376,6 +376,8 @@ namespace lldb {
 #ifndef LLDB_DISABLE_PYTHON
     typedef std::shared_ptr<lldb_private::ScriptSummaryFormat> ScriptSummaryFormatSP;
 #endif // #ifndef LLDB_DISABLE_PYTHON
+    typedef std::shared_ptr<lldb_private::ScriptInterpreter> ScriptInterpreterSP;
+    typedef std::unique_ptr<lldb_private::ScriptInterpreter> ScriptInterpreterUP;
     typedef std::shared_ptr<lldb_private::Section> SectionSP;
     typedef std::unique_ptr<lldb_private::SectionList> SectionListUP;
     typedef std::weak_ptr<lldb_private::Section> SectionWP;
index 7b5c1c9..c9a555a 100644 (file)
@@ -33,6 +33,7 @@ namespace lldb_private
     typedef SystemRuntime *(*SystemRuntimeCreateInstance) (Process *process);
     typedef lldb::PlatformSP (*PlatformCreateInstance) (bool force, const ArchSpec *arch);
     typedef lldb::ProcessSP (*ProcessCreateInstance) (Target &target, Listener &listener, const FileSpec *crash_file_path);
+    typedef lldb::ScriptInterpreterSP (*ScriptInterpreterCreateInstance)(CommandInterpreter &interpreter);
     typedef SymbolFile* (*SymbolFileCreateInstance) (ObjectFile* obj_file);
     typedef SymbolVendor* (*SymbolVendorCreateInstance) (const lldb::ModuleSP &module_sp, lldb_private::Stream *feedback_strm);   // Module can be NULL for default system symbol vendor
     typedef bool (*BreakpointHitCallback) (void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
diff --git a/lldb/include/lldb/lldb-python.h b/lldb/include/lldb/lldb-python.h
deleted file mode 100644 (file)
index c8ef054..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-//===-- lldb-python.h --------------------------------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLDB_lldb_python_h_
-#define LLDB_lldb_python_h_
-
-// Python.h needs to be included before any system headers in order to avoid redefinition of macros
-
-#ifdef LLDB_DISABLE_PYTHON
-// Python is disabled in this build
-#else
-       #if defined(__linux__)
-               // features.h will define _POSIX_C_SOURCE if _GNU_SOURCE is defined.  This value
-               // may be different from the value that Python defines it to be which results
-               // in a warning.  Undefine _POSIX_C_SOURCE before including Python.h  The same
-               // holds for _XOPEN_SOURCE.
-               #undef _POSIX_C_SOURCE
-               #undef _XOPEN_SOURCE
-       #endif
-
-       // Include python for non windows machines
-       #include <Python.h>
-#endif // LLDB_DISABLE_PYTHON
-
-#endif  // LLDB_lldb_python_h_
index 1b09945..d892c70 100644 (file)
                2689008513353E2200698AC0 /* CommandReturnObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BC7F0A10F1B8DD00F91463 /* CommandReturnObject.cpp */; };
                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 */; };
                3F8169311ABB7A6D001DA9DF /* SystemInitializer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F81692E1ABB7A6D001DA9DF /* SystemInitializer.cpp */; };
                3F8169321ABB7A6D001DA9DF /* SystemInitializerCommon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F81692F1ABB7A6D001DA9DF /* SystemInitializerCommon.cpp */; };
                3F8169331ABB7A6D001DA9DF /* SystemLifetimeManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F8169301ABB7A6D001DA9DF /* SystemLifetimeManager.cpp */; };
+               3FBA69DF1B6067020008F44A /* ScriptInterpreterNone.cpp in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3FBA69DD1B6067020008F44A /* ScriptInterpreterNone.cpp */; };
+               3FBA69E01B6067020008F44A /* ScriptInterpreterNone.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3FBA69DE1B6067020008F44A /* ScriptInterpreterNone.h */; };
+               3FBA69E11B6067120008F44A /* ScriptInterpreterNone.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FBA69DD1B6067020008F44A /* ScriptInterpreterNone.cpp */; };
+               3FBA69E71B60672A0008F44A /* lldb-python.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3FBA69E21B60672A0008F44A /* lldb-python.h */; };
+               3FBA69E91B60672A0008F44A /* PythonDataObjects.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3FBA69E41B60672A0008F44A /* PythonDataObjects.h */; };
+               3FBA69EB1B60672A0008F44A /* ScriptInterpreterPython.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3FBA69E61B60672A0008F44A /* ScriptInterpreterPython.h */; };
+               3FBA69EC1B6067430008F44A /* PythonDataObjects.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FBA69E31B60672A0008F44A /* PythonDataObjects.cpp */; };
+               3FBA69ED1B60674B0008F44A /* ScriptInterpreterPython.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FBA69E51B60672A0008F44A /* ScriptInterpreterPython.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 */; };
                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 */; };
                        dstPath = "$(DEVELOPER_DIR)/usr/share/man/man1/";
                        dstSubfolderSpec = 0;
                        files = (
+                               3FBA69E91B60672A0008F44A /* PythonDataObjects.h in CopyFiles */,
                                AF90106515AB7D3600FF120D /* lldb.1 in CopyFiles */,
+                               3FBA69E71B60672A0008F44A /* lldb-python.h in CopyFiles */,
+                               3FBA69DF1B6067020008F44A /* ScriptInterpreterNone.cpp in CopyFiles */,
+                               3FBA69E01B6067020008F44A /* ScriptInterpreterNone.h in CopyFiles */,
                                33E5E8461A6736D30024ED68 /* StringConvert.h in CopyFiles */,
+                               3FBA69EB1B60672A0008F44A /* ScriptInterpreterPython.h in CopyFiles */,
                                AFC234081AF85CE000CDE8B6 /* CommandObjectLanguage.cpp in CopyFiles */,
                                33E5E8421A672A240024ED68 /* StringConvert.cpp in CopyFiles */,
                        );
                26BC7DE310F1B7F900F91463 /* CommandObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CommandObject.h; path = include/lldb/Interpreter/CommandObject.h; sourceTree = "<group>"; };
                26BC7DE410F1B7F900F91463 /* CommandReturnObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CommandReturnObject.h; path = include/lldb/Interpreter/CommandReturnObject.h; sourceTree = "<group>"; };
                26BC7DE510F1B7F900F91463 /* ScriptInterpreter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ScriptInterpreter.h; path = include/lldb/Interpreter/ScriptInterpreter.h; sourceTree = "<group>"; };
-               26BC7DE610F1B7F900F91463 /* ScriptInterpreterPython.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ScriptInterpreterPython.h; path = include/lldb/Interpreter/ScriptInterpreterPython.h; sourceTree = "<group>"; };
                26BC7DF110F1B81A00F91463 /* DynamicLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DynamicLoader.h; path = include/lldb/Target/DynamicLoader.h; sourceTree = "<group>"; };
                26BC7DF210F1B81A00F91463 /* ExecutionContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ExecutionContext.h; path = include/lldb/Target/ExecutionContext.h; sourceTree = "<group>"; };
                26BC7DF310F1B81A00F91463 /* Process.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Process.h; path = include/lldb/Target/Process.h; sourceTree = "<group>"; };
                26BC7F0810F1B8DD00F91463 /* CommandInterpreter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommandInterpreter.cpp; path = source/Interpreter/CommandInterpreter.cpp; sourceTree = "<group>"; };
                26BC7F0910F1B8DD00F91463 /* CommandObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommandObject.cpp; path = source/Interpreter/CommandObject.cpp; sourceTree = "<group>"; };
                26BC7F0A10F1B8DD00F91463 /* CommandReturnObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommandReturnObject.cpp; path = source/Interpreter/CommandReturnObject.cpp; sourceTree = "<group>"; };
-               26BC7F0C10F1B8DD00F91463 /* ScriptInterpreterPython.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ScriptInterpreterPython.cpp; path = source/Interpreter/ScriptInterpreterPython.cpp; sourceTree = "<group>"; };
                26BC7F1310F1B8EC00F91463 /* Block.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Block.cpp; path = source/Symbol/Block.cpp; sourceTree = "<group>"; };
                26BC7F1410F1B8EC00F91463 /* ClangASTContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClangASTContext.cpp; path = source/Symbol/ClangASTContext.cpp; sourceTree = "<group>"; };
                26BC7F1510F1B8EC00F91463 /* CompileUnit.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CompileUnit.cpp; path = source/Symbol/CompileUnit.cpp; sourceTree = "<group>"; };
                3F8169341ABB7A80001DA9DF /* SystemInitializer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SystemInitializer.h; path = include/lldb/Initialization/SystemInitializer.h; sourceTree = "<group>"; };
                3F8169351ABB7A80001DA9DF /* SystemInitializerCommon.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SystemInitializerCommon.h; path = include/lldb/Initialization/SystemInitializerCommon.h; sourceTree = "<group>"; };
                3F8169361ABB7A80001DA9DF /* SystemLifetimeManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SystemLifetimeManager.h; path = include/lldb/Initialization/SystemLifetimeManager.h; sourceTree = "<group>"; };
+               3FBA69DD1B6067020008F44A /* ScriptInterpreterNone.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ScriptInterpreterNone.cpp; path = ScriptInterpreter/None/ScriptInterpreterNone.cpp; sourceTree = "<group>"; };
+               3FBA69DE1B6067020008F44A /* ScriptInterpreterNone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ScriptInterpreterNone.h; path = ScriptInterpreter/None/ScriptInterpreterNone.h; sourceTree = "<group>"; };
+               3FBA69E21B60672A0008F44A /* lldb-python.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "lldb-python.h"; path = "ScriptInterpreter/Python/lldb-python.h"; sourceTree = "<group>"; };
+               3FBA69E31B60672A0008F44A /* PythonDataObjects.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PythonDataObjects.cpp; path = ScriptInterpreter/Python/PythonDataObjects.cpp; sourceTree = "<group>"; };
+               3FBA69E41B60672A0008F44A /* PythonDataObjects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PythonDataObjects.h; path = ScriptInterpreter/Python/PythonDataObjects.h; sourceTree = "<group>"; };
+               3FBA69E51B60672A0008F44A /* ScriptInterpreterPython.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ScriptInterpreterPython.cpp; path = ScriptInterpreter/Python/ScriptInterpreterPython.cpp; sourceTree = "<group>"; };
+               3FBA69E61B60672A0008F44A /* ScriptInterpreterPython.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ScriptInterpreterPython.h; path = ScriptInterpreter/Python/ScriptInterpreterPython.h; sourceTree = "<group>"; };
                3FDFD6C3199C396E009756A7 /* FileAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileAction.h; path = include/lldb/Target/FileAction.h; sourceTree = "<group>"; };
                3FDFDDBC199C3A06009756A7 /* FileAction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FileAction.cpp; path = source/Target/FileAction.cpp; sourceTree = "<group>"; };
                3FDFDDBE199D345E009756A7 /* FileCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FileCache.cpp; path = source/Host/common/FileCache.cpp; sourceTree = "<group>"; };
                94D6A0A916CEB55F00833B6E /* NSSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NSSet.cpp; path = source/DataFormatters/NSSet.cpp; sourceTree = "<group>"; };
                94E367CC140C4EC4001C7A5A /* modify-python-lldb.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = "modify-python-lldb.py"; sourceTree = "<group>"; };
                94E367CE140C4EEA001C7A5A /* python-typemaps.swig */ = {isa = PBXFileReference; lastKnownFileType = text; path = "python-typemaps.swig"; sourceTree = "<group>"; };
-               94EA1D5A15E6C99B00D4171A /* PythonDataObjects.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = PythonDataObjects.h; path = include/lldb/Interpreter/PythonDataObjects.h; sourceTree = "<group>"; };
-               94EA1D5B15E6C9B400D4171A /* PythonDataObjects.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PythonDataObjects.cpp; path = source/Interpreter/PythonDataObjects.cpp; sourceTree = "<group>"; };
                94EA27CD17DE91750070F505 /* LibCxxUnorderedMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LibCxxUnorderedMap.cpp; path = source/DataFormatters/LibCxxUnorderedMap.cpp; sourceTree = "<group>"; };
                94EBAC8313D9EE26009BA64E /* PythonPointer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = PythonPointer.h; path = include/lldb/Utility/PythonPointer.h; sourceTree = "<group>"; };
                94ED54A119C8A822007BE2EA /* ThreadSafeDenseMap.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ThreadSafeDenseMap.h; path = include/lldb/Core/ThreadSafeDenseMap.h; sourceTree = "<group>"; };
                9A22A15E135E30370024DDC3 /* EmulateInstructionARM.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EmulateInstructionARM.h; sourceTree = "<group>"; };
                9A22A15F135E30370024DDC3 /* EmulationStateARM.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EmulationStateARM.cpp; sourceTree = "<group>"; };
                9A22A160135E30370024DDC3 /* EmulationStateARM.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EmulationStateARM.h; sourceTree = "<group>"; };
-               9A2771FB1135A35C00E6ADB6 /* ScriptInterpreterNone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ScriptInterpreterNone.h; path = include/lldb/Interpreter/ScriptInterpreterNone.h; sourceTree = "<group>"; };
-               9A2771FC1135A37500E6ADB6 /* ScriptInterpreterNone.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ScriptInterpreterNone.cpp; path = source/Interpreter/ScriptInterpreterNone.cpp; sourceTree = "<group>"; };
                9A357582116CFDEE00E8ED2F /* SBValueList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBValueList.h; path = include/lldb/API/SBValueList.h; sourceTree = "<group>"; };
                9A35758D116CFE0F00E8ED2F /* SBValueList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SBValueList.cpp; path = source/API/SBValueList.cpp; sourceTree = "<group>"; };
                9A35765E116E76A700E8ED2F /* StringList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StringList.h; path = include/lldb/Core/StringList.h; sourceTree = "<group>"; };
                                266DFE9013FD64D200D0C574 /* OperatingSystem */,
                                26C5577E132575B6008FD8FE /* Platform */,
                                260C898A10F57C5600BB2B04 /* Process */,
+                               3FBA69DA1B6066D20008F44A /* ScriptInterpreter */,
                                AF11CB34182CA85A00D9B618 /* SystemRuntime */,
                                260C89B110F57C5600BB2B04 /* SymbolFile */,
                                260C89E010F57C5600BB2B04 /* SymbolVendor */,
                                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 = "<group>";
                        name = Initialization;
                        sourceTree = "<group>";
                };
+               3FBA69DA1B6066D20008F44A /* ScriptInterpreter */ = {
+                       isa = PBXGroup;
+                       children = (
+                               3FBA69DC1B6066E90008F44A /* None */,
+                               3FBA69DB1B6066E40008F44A /* Python */,
+                       );
+                       name = ScriptInterpreter;
+                       sourceTree = "<group>";
+               };
+               3FBA69DB1B6066E40008F44A /* Python */ = {
+                       isa = PBXGroup;
+                       children = (
+                               3FBA69E21B60672A0008F44A /* lldb-python.h */,
+                               3FBA69E31B60672A0008F44A /* PythonDataObjects.cpp */,
+                               3FBA69E41B60672A0008F44A /* PythonDataObjects.h */,
+                               3FBA69E51B60672A0008F44A /* ScriptInterpreterPython.cpp */,
+                               3FBA69E61B60672A0008F44A /* ScriptInterpreterPython.h */,
+                       );
+                       name = Python;
+                       sourceTree = "<group>";
+               };
+               3FBA69DC1B6066E90008F44A /* None */ = {
+                       isa = PBXGroup;
+                       children = (
+                               3FBA69DD1B6067020008F44A /* ScriptInterpreterNone.cpp */,
+                               3FBA69DE1B6067020008F44A /* ScriptInterpreterNone.h */,
+                       );
+                       name = None;
+                       sourceTree = "<group>";
+               };
                3FDFDDC4199D37BE009756A7 /* posix */ = {
                        isa = PBXGroup;
                        children = (
                                26474CBE18D0CB2D0073DEBA /* RegisterContextMach_i386.cpp in Sources */,
                                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 */,
                                26A7A035135E6E4200FB369E /* OptionValue.cpp in Sources */,
                                9A22A161135E30370024DDC3 /* EmulateInstructionARM.cpp in Sources */,
                                AFDFDFD119E34D3400EAE509 /* ConnectionFileDescriptorPosix.cpp in Sources */,
+                               3FBA69ED1B60674B0008F44A /* ScriptInterpreterPython.cpp in Sources */,
                                9A22A163135E30370024DDC3 /* EmulationStateARM.cpp in Sources */,
                                9A4F35101368A51A00823F52 /* StreamAsynchronousIO.cpp in Sources */,
                                AF1D88691B575E8D003CB899 /* ValueObjectConstResultCast.cpp in Sources */,
                                94B6E76213D88365005F417F /* ValueObjectSyntheticFilter.cpp in Sources */,
                                267A47FF1B1411D90021A5BC /* NativeWatchpointList.cpp in Sources */,
                                26F4A21C13FBA31A0064B613 /* ThreadMemory.cpp in Sources */,
+                               3FBA69E11B6067120008F44A /* ScriptInterpreterNone.cpp in Sources */,
                                94EA27CE17DE91750070F505 /* LibCxxUnorderedMap.cpp in Sources */,
                                266DFE9713FD656E00D0C574 /* OperatingSystem.cpp in Sources */,
                                26954EBE1401EE8B00294D09 /* DynamicRegisterInfo.cpp in Sources */,
                                255EFF761AFABA950069F277 /* LockFilePosix.cpp in Sources */,
+                               3FBA69EC1B6067430008F44A /* PythonDataObjects.cpp in Sources */,
                                26274FA714030F79006BA130 /* DynamicLoaderDarwinKernel.cpp in Sources */,
                                94FA3DE01405D50400833217 /* ValueObjectConstResultChild.cpp in Sources */,
                                3FDFED2819BA6D96009756A7 /* HostThread.cpp in Sources */,
                                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 121d742..2fc834d 100644 (file)
@@ -72,6 +72,13 @@ add_lldb_library(liblldb SHARED
   ${LLDB_VERS_GENERATED_FILE}
   )
 
+# This should not be part of LLDBDependencies.cmake, because we don't
+# want every single library taking a dependency on the script interpreters.
+target_link_libraries(liblldb PRIVATE
+  lldbPluginScriptInterpreterNone
+  lldbPluginScriptInterpreterPython
+  )
+
 set_target_properties(liblldb
   PROPERTIES
   VERSION ${LLDB_VERSION}
index d901e72..cd1e28e 100644 (file)
@@ -8,7 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "lldb/lldb-types.h"
-#include "lldb/Core/SourceManager.h"
+
 #include "lldb/Core/Listener.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
 #include "lldb/Interpreter/CommandObjectMultiword.h"
index 01ad815..cccd987 100644 (file)
@@ -7,12 +7,23 @@
 //
 //===----------------------------------------------------------------------===//
 
+#if !defined(LLDB_DISABLE_PYTHON)
+#include "Plugins/ScriptInterpreter/Python/lldb-python.h"
+#endif
+
 #include "lldb/API/SystemInitializerFull.h"
 
+#include "lldb/API/SBCommandInterpreter.h"
+
+#if !defined(LLDB_DISABLE_PYTHON)
+#include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h"
+#endif
+
 #include "lldb/Core/Debugger.h"
 #include "lldb/Core/Timer.h"
 #include "lldb/Host/Host.h"
 #include "lldb/Initialization/SystemInitializerCommon.h"
+#include "lldb/Interpreter/CommandInterpreter.h"
 
 #include "Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h"
 #include "Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h"
@@ -38,6 +49,7 @@
 #include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h"
 #include "Plugins/Process/elf-core/ProcessElfCore.h"
 #include "Plugins/Process/gdb-remote/ProcessGDBRemote.h"
+#include "Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h"
 #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
 #include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h"
 #include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h"
 #include "Plugins/Process/Windows/ProcessWindows.h"
 #endif
 
-#if !defined(LLDB_DISABLE_PYTHON)
-#include "lldb/Interpreter/ScriptInterpreterPython.h"
-#endif
-
 #include "llvm/Support/TargetSelect.h"
 
 #include <string>
@@ -221,9 +229,17 @@ SystemInitializerFull::~SystemInitializerFull()
 void
 SystemInitializerFull::Initialize()
 {
+    SystemInitializerCommon::Initialize();
+
+#if !defined(LLDB_DISABLE_PYTHON)
     InitializeSWIG();
 
-    SystemInitializerCommon::Initialize();
+    // ScriptInterpreterPython::Initialize() depends on things like HostInfo being initialized
+    // so it can compute the python directory etc, so we need to do this after
+    // SystemInitializerCommon::Initialize().
+    ScriptInterpreterNone::Initialize();
+    ScriptInterpreterPython::Initialize();
+#endif
 
     // Initialize LLVM and Clang
     llvm::InitializeAllTargets();
@@ -380,8 +396,3 @@ SystemInitializerFull::Terminate()
     // Now shutdown the common parts, in reverse order.
     SystemInitializerCommon::Terminate();
 }
-
-void SystemInitializerFull::TerminateSWIG()
-{
-
-}
index 7d91653..ac892d2 100644 (file)
@@ -1764,6 +1764,110 @@ PluginManager::GetProcessCreateCallbackForPluginName (const ConstString &name)
     return NULL;
 }
 
+#pragma mark ScriptInterpreter
+
+struct ScriptInterpreterInstance
+{
+    ScriptInterpreterInstance()
+        : name()
+        , language(lldb::eScriptLanguageNone)
+        , description()
+        , create_callback(NULL)
+    {
+    }
+
+    ConstString name;
+    lldb::ScriptLanguage language;
+    std::string description;
+    ScriptInterpreterCreateInstance create_callback;
+};
+
+typedef std::vector<ScriptInterpreterInstance> ScriptInterpreterInstances;
+
+static Mutex &
+GetScriptInterpreterMutex()
+{
+    static Mutex g_instances_mutex(Mutex::eMutexTypeRecursive);
+    return g_instances_mutex;
+}
+
+static ScriptInterpreterInstances &
+GetScriptInterpreterInstances()
+{
+    static ScriptInterpreterInstances g_instances;
+    return g_instances;
+}
+
+bool
+PluginManager::RegisterPlugin(const ConstString &name, const char *description, lldb::ScriptLanguage script_language,
+                              ScriptInterpreterCreateInstance create_callback)
+{
+    if (!create_callback)
+        return false;
+    ScriptInterpreterInstance instance;
+    assert((bool)name);
+    instance.name = name;
+    if (description && description[0])
+        instance.description = description;
+    instance.create_callback = create_callback;
+    instance.language = script_language;
+    Mutex::Locker locker(GetScriptInterpreterMutex());
+    GetScriptInterpreterInstances().push_back(instance);
+    return false;
+}
+
+bool
+PluginManager::UnregisterPlugin(ScriptInterpreterCreateInstance create_callback)
+{
+    if (!create_callback)
+        return false;
+    Mutex::Locker locker(GetScriptInterpreterMutex());
+    ScriptInterpreterInstances &instances = GetScriptInterpreterInstances();
+
+    ScriptInterpreterInstances::iterator pos, end = instances.end();
+    for (pos = instances.begin(); pos != end; ++pos)
+    {
+        if (pos->create_callback != create_callback)
+            continue;
+
+        instances.erase(pos);
+        return true;
+    }
+    return false;
+}
+
+ScriptInterpreterCreateInstance
+PluginManager::GetScriptInterpreterCreateCallbackAtIndex(uint32_t idx)
+{
+    Mutex::Locker locker(GetScriptInterpreterMutex());
+    ScriptInterpreterInstances &instances = GetScriptInterpreterInstances();
+    if (idx < instances.size())
+        return instances[idx].create_callback;
+    return nullptr;
+}
+
+lldb::ScriptInterpreterSP
+PluginManager::GetScriptInterpreterForLanguage(lldb::ScriptLanguage script_lang, CommandInterpreter &interpreter)
+{
+    Mutex::Locker locker(GetScriptInterpreterMutex());
+    ScriptInterpreterInstances &instances = GetScriptInterpreterInstances();
+
+    ScriptInterpreterInstances::iterator pos, end = instances.end();
+    ScriptInterpreterCreateInstance none_instance = nullptr;
+    for (pos = instances.begin(); pos != end; ++pos)
+    {
+        if (pos->language == lldb::eScriptLanguageNone)
+            none_instance = pos->create_callback;
+
+        if (script_lang == pos->language)
+            return pos->create_callback(interpreter);
+    }
+
+    // If we didn't find one, return the ScriptInterpreter for the null language.
+    assert(none_instance != nullptr);
+    return none_instance(interpreter);
+}
+
 #pragma mark SymbolFile
 
 struct SymbolFileInstance
index edaff08..9738849 100644 (file)
@@ -7,7 +7,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "lldb/lldb-python.h"
+#if !defined(LLDB_DISABLE_PYTHON)
+#include "Plugins/ScriptInterpreter/Python/lldb-python.h"
+#endif
 
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Host/macosx/HostInfoMacOSX.h"
index c04db71..632f422 100644 (file)
@@ -7,7 +7,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "lldb/lldb-python.h"
+#if !defined(LLDB_DISABLE_PYTHON)
+#include "Plugins/ScriptInterpreter/Python/lldb-python.h"
+#endif
+
 #include "lldb/Core/Log.h"
 #include "lldb/Host/posix/HostInfoPosix.h"
 
index 51f32a2..dcf823e 100644 (file)
@@ -13,7 +13,6 @@
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Core/Log.h"
 #include "lldb/Core/Timer.h"
-#include "lldb/Interpreter/ScriptInterpreterPython.h"
 
 #include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h"
 #include "Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h"
@@ -141,7 +140,6 @@ SystemInitializerCommon::Initialize()
     ProcessWindowsLog::Initialize();
 #endif
 #ifndef LLDB_DISABLE_PYTHON
-    ScriptInterpreterPython::InitializePrivate();
     OperatingSystemPython::Initialize();
 #endif
 }
index 413067f..220e6a0 100644 (file)
@@ -43,8 +43,5 @@ add_lldb_library(lldbInterpreter
   OptionGroupWatchpoint.cpp
   Options.cpp
   Property.cpp
-  PythonDataObjects.cpp
   ScriptInterpreter.cpp
-  ScriptInterpreterNone.cpp
-  ScriptInterpreterPython.cpp
   )
index 965ba5b..1147d13 100644 (file)
@@ -41,9 +41,9 @@
 #include "../Commands/CommandObjectWatchpoint.h"
 #include "../Commands/CommandObjectLanguage.h"
 
-
 #include "lldb/Core/Debugger.h"
 #include "lldb/Core/Log.h"
+#include "lldb/Core/PluginManager.h"
 #include "lldb/Core/State.h"
 #include "lldb/Core/Stream.h"
 #include "lldb/Core/StreamFile.h"
@@ -62,8 +62,6 @@
 #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/Target/Process.h"
@@ -104,29 +102,23 @@ CommandInterpreter::GetStaticBroadcasterClass ()
     return class_name;
 }
 
-CommandInterpreter::CommandInterpreter
-(
-    Debugger &debugger,
-    ScriptLanguage script_language,
-    bool synchronous_execution
-) :
-    Broadcaster (&debugger, CommandInterpreter::GetStaticBroadcasterClass().AsCString()),
-    Properties(OptionValuePropertiesSP(new OptionValueProperties(ConstString("interpreter")))),
-    IOHandlerDelegate (IOHandlerDelegate::Completion::LLDBCommand),
-    m_debugger (debugger),
-    m_synchronous_execution (synchronous_execution),
-    m_skip_lldbinit_files (false),
-    m_skip_app_init_files (false),
-    m_script_interpreter_ap (),
-    m_command_io_handler_sp (),
-    m_comment_char ('#'),
-    m_batch_command_mode (false),
-    m_truncation_warning(eNoTruncation),
-    m_command_source_depth (0),
-    m_num_errors(0),
-    m_quit_requested(false),
-    m_stopped_for_crash(false)
-
+CommandInterpreter::CommandInterpreter(Debugger &debugger, ScriptLanguage script_language, bool synchronous_execution)
+    : Broadcaster(&debugger, CommandInterpreter::GetStaticBroadcasterClass().AsCString()),
+      Properties(OptionValuePropertiesSP(new OptionValueProperties(ConstString("interpreter")))),
+      IOHandlerDelegate(IOHandlerDelegate::Completion::LLDBCommand),
+      m_debugger(debugger),
+      m_synchronous_execution(synchronous_execution),
+      m_skip_lldbinit_files(false),
+      m_skip_app_init_files(false),
+      m_script_interpreter_sp(),
+      m_command_io_handler_sp(),
+      m_comment_char('#'),
+      m_batch_command_mode(false),
+      m_truncation_warning(eNoTruncation),
+      m_command_source_depth(0),
+      m_num_errors(0),
+      m_quit_requested(false),
+      m_stopped_for_crash(false)
 {
     debugger.SetScriptLanguage (script_language);
     SetEventName (eBroadcastBitThreadShouldExit, "thread-should-exit");
@@ -392,9 +384,9 @@ void
 CommandInterpreter::Clear()
 {
     m_command_io_handler_sp.reset();
-    
-    if (m_script_interpreter_ap)
-        m_script_interpreter_ap->Clear();
+
+    if (m_script_interpreter_sp)
+        m_script_interpreter_sp->Clear();
 }
 
 const char *
@@ -2708,48 +2700,19 @@ CommandInterpreter::HandleCommandsFromFile (FileSpec &cmd_file,
 }
 
 ScriptInterpreter *
-CommandInterpreter::GetScriptInterpreter (bool can_create)
+CommandInterpreter::GetScriptInterpreter(bool can_create)
 {
-    if (m_script_interpreter_ap.get() != nullptr)
-        return m_script_interpreter_ap.get();
-    
+    if (m_script_interpreter_sp)
+        return m_script_interpreter_sp.get();
+
     if (!can_create)
         return nullptr;
-    // <rdar://problem/11751427>
-    // 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();
+    m_script_interpreter_sp = PluginManager::GetScriptInterpreterForLanguage(script_lang, *this);
+    return m_script_interpreter_sp.get();
 }
 
-
-
 bool
 CommandInterpreter::GetSynchronous ()
 {
diff --git a/lldb/source/Interpreter/ScriptInterpreterNone.cpp b/lldb/source/Interpreter/ScriptInterpreterNone.cpp
deleted file mode 100644 (file)
index 909a116..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-//===-- ScriptInterpreterNone.cpp -------------------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "lldb/Interpreter/ScriptInterpreterNone.h"
-#include "lldb/Core/Stream.h"
-#include "lldb/Core/StreamFile.h"
-#include "lldb/Core/StringList.h"
-#include "lldb/Core/Debugger.h"
-#include "lldb/Interpreter/CommandInterpreter.h"
-
-using namespace lldb;
-using namespace lldb_private;
-
-ScriptInterpreterNone::ScriptInterpreterNone (CommandInterpreter &interpreter) :
-    ScriptInterpreter (interpreter, eScriptLanguageNone)
-{
-}
-
-ScriptInterpreterNone::~ScriptInterpreterNone ()
-{
-}
-
-bool
-ScriptInterpreterNone::ExecuteOneLine (const char *command, CommandReturnObject *, const ExecuteScriptOptions&)
-{
-    m_interpreter.GetDebugger().GetErrorFile()->PutCString ("error: there is no embedded script interpreter in this mode.\n");
-    return false;
-}
-
-void
-ScriptInterpreterNone::ExecuteInterpreterLoop ()
-{
-    m_interpreter.GetDebugger().GetErrorFile()->PutCString ("error: there is no embedded script interpreter in this mode.\n");
-}
-
-
index 9219560..67ae85d 100644 (file)
@@ -11,6 +11,7 @@ add_subdirectory(ObjectFile)
 add_subdirectory(OperatingSystem)
 add_subdirectory(Platform)
 add_subdirectory(Process)
+add_subdirectory(ScriptInterpreter)
 add_subdirectory(SymbolFile)
 add_subdirectory(SystemRuntime)
 add_subdirectory(SymbolVendor)
index f5f134e..e3d5bea 100644 (file)
@@ -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"
diff --git a/lldb/source/Plugins/ScriptInterpreter/CMakeLists.txt b/lldb/source/Plugins/ScriptInterpreter/CMakeLists.txt
new file mode 100644 (file)
index 0000000..dc2a27d
--- /dev/null
@@ -0,0 +1,2 @@
+add_subdirectory(None)
+add_subdirectory(Python)
diff --git a/lldb/source/Plugins/ScriptInterpreter/None/CMakeLists.txt b/lldb/source/Plugins/ScriptInterpreter/None/CMakeLists.txt
new file mode 100644 (file)
index 0000000..5692d2f
--- /dev/null
@@ -0,0 +1,3 @@
+add_lldb_library(lldbPluginScriptInterpreterNone
+  ScriptInterpreterNone.cpp
+  )
\ No newline at end of file
diff --git a/lldb/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp b/lldb/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp
new file mode 100644 (file)
index 0000000..1a352fa
--- /dev/null
@@ -0,0 +1,93 @@
+//===-- ScriptInterpreterNone.cpp -------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ScriptInterpreterNone.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Core/Stream.h"
+#include "lldb/Core/StreamFile.h"
+#include "lldb/Core/StringList.h"
+#include "lldb/Interpreter/CommandInterpreter.h"
+
+#include <mutex>
+
+using namespace lldb;
+using namespace lldb_private;
+
+ScriptInterpreterNone::ScriptInterpreterNone(CommandInterpreter &interpreter)
+    : ScriptInterpreter(interpreter, eScriptLanguageNone)
+{
+}
+
+ScriptInterpreterNone::~ScriptInterpreterNone()
+{
+}
+
+bool
+ScriptInterpreterNone::ExecuteOneLine(const char *command, CommandReturnObject *, const ExecuteScriptOptions &)
+{
+    m_interpreter.GetDebugger().GetErrorFile()->PutCString(
+        "error: there is no embedded script interpreter in this mode.\n");
+    return false;
+}
+
+void
+ScriptInterpreterNone::ExecuteInterpreterLoop()
+{
+    m_interpreter.GetDebugger().GetErrorFile()->PutCString(
+        "error: there is no embedded script interpreter in this mode.\n");
+}
+
+void
+ScriptInterpreterNone::Initialize()
+{
+    static std::once_flag g_once_flag;
+
+    std::call_once(g_once_flag, []()
+                   {
+                       PluginManager::RegisterPlugin(GetPluginNameStatic(), GetPluginDescriptionStatic(),
+                                                     lldb::eScriptLanguageNone, CreateInstance);
+                   });
+}
+
+void
+ScriptInterpreterNone::Terminate()
+{
+}
+
+lldb::ScriptInterpreterSP
+ScriptInterpreterNone::CreateInstance(CommandInterpreter &interpreter)
+{
+    return std::make_shared<ScriptInterpreterNone>(interpreter);
+}
+
+lldb_private::ConstString
+ScriptInterpreterNone::GetPluginNameStatic()
+{
+    static ConstString g_name("script-none");
+    return g_name;
+}
+
+const char *
+ScriptInterpreterNone::GetPluginDescriptionStatic()
+{
+    return "Null script interpreter";
+}
+
+lldb_private::ConstString
+ScriptInterpreterNone::GetPluginName()
+{
+    return GetPluginNameStatic();
+}
+
+uint32_t
+ScriptInterpreterNone::GetPluginVersion()
+{
+    return 1;
+}
diff --git a/lldb/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h b/lldb/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h
new file mode 100644 (file)
index 0000000..d29600a
--- /dev/null
@@ -0,0 +1,62 @@
+//===-- ScriptInterpreterNone.h ---------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_ScriptInterpreterNone_h_
+#define liblldb_ScriptInterpreterNone_h_
+
+#include "lldb/Interpreter/ScriptInterpreter.h"
+
+namespace lldb_private
+{
+
+class ScriptInterpreterNone : public ScriptInterpreter
+{
+  public:
+    ScriptInterpreterNone(CommandInterpreter &interpreter);
+
+    ~ScriptInterpreterNone();
+
+    bool
+    ExecuteOneLine(const char *command, CommandReturnObject *result,
+                   const ExecuteScriptOptions &options = ExecuteScriptOptions());
+
+    void
+    ExecuteInterpreterLoop();
+
+    //------------------------------------------------------------------
+    // Static Functions
+    //------------------------------------------------------------------
+    static void
+    Initialize();
+
+    static void
+    Terminate();
+
+    static lldb::ScriptInterpreterSP
+    CreateInstance(CommandInterpreter &interpreter);
+
+    static lldb_private::ConstString
+    GetPluginNameStatic();
+
+    static const char *
+    GetPluginDescriptionStatic();
+
+    //------------------------------------------------------------------
+    // PluginInterface protocol
+    //------------------------------------------------------------------
+    virtual lldb_private::ConstString
+    GetPluginName();
+
+    virtual uint32_t
+    GetPluginVersion();
+};
+
+} // namespace lldb_private
+
+#endif // #ifndef liblldb_ScriptInterpreterNone_h_
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt b/lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
new file mode 100644 (file)
index 0000000..16efb4e
--- /dev/null
@@ -0,0 +1,4 @@
+add_lldb_library(lldbPluginScriptInterpreterPython
+  PythonDataObjects.cpp
+  ScriptInterpreterPython.cpp
+  )
@@ -7,23 +7,21 @@
 //
 //===----------------------------------------------------------------------===//
 
-// In order to guarantee correct working with Python, Python.h *MUST* be
-// the *FIRST* header file included here.
 #ifdef LLDB_DISABLE_PYTHON
 
 // Python is disabled in this build
 
 #else
 
-#include "lldb/lldb-python.h"
-
-#include <stdio.h>
+#include "lldb-python.h"
+#include "PythonDataObjects.h"
+#include "ScriptInterpreterPython.h"
 
 #include "lldb/Core/Stream.h"
 #include "lldb/Host/File.h"
-#include "lldb/Interpreter/PythonDataObjects.h"
 #include "lldb/Interpreter/ScriptInterpreter.h"
-#include "lldb/Interpreter/ScriptInterpreterPython.h"
+
+#include <stdio.h>
 
 using namespace lldb_private;
 using namespace lldb;
@@ -7,8 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef liblldb_PythonDataObjects_h_
-#define liblldb_PythonDataObjects_h_
+#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_PYTHONDATAOBJECTS_H
+#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_PYTHONDATAOBJECTS_H
 
 // C Includes
 // C++ Includes
@@ -20,7 +20,6 @@
 #include "lldb/Core/StructuredData.h"
 #include "lldb/Core/Flags.h"
 #include "lldb/Interpreter/OptionValue.h"
-#include "lldb/lldb-python.h"
 
 namespace lldb_private {
 class PythonString;
@@ -277,4 +276,4 @@ enum class PyObjectType
     
 } // namespace lldb_private
 
-#endif  // liblldb_PythonDataObjects_h_
+#endif  // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_PYTHONDATAOBJECTS_H
@@ -7,20 +7,20 @@
 //
 //===----------------------------------------------------------------------===//
 
-// In order to guarantee correct working with Python, Python.h *MUST* be
-// the *FIRST* header file included here.
 #ifdef LLDB_DISABLE_PYTHON
 
 // Python is disabled in this build
 
 #else
 
-#include "lldb/lldb-python.h"
-#include "lldb/Interpreter/ScriptInterpreterPython.h"
+#include "lldb-python.h"
+#include "ScriptInterpreterPython.h"
+#include "PythonDataObjects.h"
 
 #include <stdlib.h>
 #include <stdio.h>
 
+#include <mutex>
 #include <string>
 
 #include "lldb/API/SBValue.h"
@@ -29,6 +29,7 @@
 #include "lldb/Breakpoint/WatchpointOptions.h"
 #include "lldb/Core/Communication.h"
 #include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
 #include "lldb/Core/Timer.h"
 #include "lldb/Core/ValueObject.h"
 #include "lldb/DataFormatters/TypeSummary.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"
 
@@ -178,7 +178,7 @@ ScriptInterpreterPython::ScriptInterpreterPython (CommandInterpreter &interprete
     m_lock_count (0),
     m_command_thread_state (nullptr)
 {
-    assert(g_initialized && "ScriptInterpreterPython created but initialize has not been called!");
+    assert(g_initialized && "ScriptInterpreterPython created but InitializePrivate has not been called!");
 
     m_dictionary_name.append("_dict");
     StreamString run_string;
@@ -223,6 +223,59 @@ ScriptInterpreterPython::~ScriptInterpreterPython ()
 }
 
 void
+ScriptInterpreterPython::Initialize()
+{
+    static std::once_flag g_once_flag;
+
+    std::call_once(g_once_flag, []()
+    {
+        InitializePrivate();
+
+        PluginManager::RegisterPlugin(GetPluginNameStatic(),
+                                      GetPluginDescriptionStatic(),
+                                      lldb::eScriptLanguagePython,
+                                      CreateInstance);
+    });
+}
+    
+void
+ScriptInterpreterPython::Terminate()
+{
+
+}
+    
+lldb::ScriptInterpreterSP
+ScriptInterpreterPython::CreateInstance(CommandInterpreter &interpreter)
+{
+    return std::make_shared<ScriptInterpreterPython>(interpreter);
+}
+    
+lldb_private::ConstString
+ScriptInterpreterPython::GetPluginNameStatic()
+{
+    static ConstString g_name("script-python");
+    return g_name;
+}
+
+const char *
+ScriptInterpreterPython::GetPluginDescriptionStatic()
+{
+    return "Embedded Python interpreter";
+}
+    
+lldb_private::ConstString
+ScriptInterpreterPython::GetPluginName()
+{
+    return GetPluginNameStatic();
+}
+    
+uint32_t
+ScriptInterpreterPython::GetPluginVersion()
+{
+    return 1;
+}
+
+void
 ScriptInterpreterPython::IOHandlerActivated (IOHandler &io_handler)
 {
     const char *instructions = nullptr;
@@ -8,8 +8,8 @@
 //===----------------------------------------------------------------------===//
 
 
-#ifndef liblldb_ScriptInterpreterPython_h_
-#define liblldb_ScriptInterpreterPython_h_
+#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTINTERPRETERPYTHON_H
+#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTINTERPRETERPYTHON_H
 
 #ifdef LLDB_DISABLE_PYTHON
 
 
 #else
 
-#include "lldb/lldb-python.h"
 #include "lldb/lldb-private.h"
+#include "PythonDataObjects.h"
 #include "lldb/Core/IOHandler.h"
 #include "lldb/Interpreter/ScriptInterpreter.h"
-#include "lldb/Interpreter/PythonDataObjects.h"
 #include "lldb/Host/Terminal.h"
 
 class IOHandlerPythonInterpreter;
@@ -412,6 +411,34 @@ public:
     void
     IOHandlerInputComplete (IOHandler &io_handler, std::string &data) override;
 
+
+    //------------------------------------------------------------------
+    // Static Functions
+    //------------------------------------------------------------------
+    static void
+    Initialize();
+    
+    static void
+    Terminate();
+    
+    static lldb::ScriptInterpreterSP
+    CreateInstance(CommandInterpreter &interpreter);
+    
+    static lldb_private::ConstString
+    GetPluginNameStatic();
+    
+    static const char *
+    GetPluginDescriptionStatic();
+    
+    //------------------------------------------------------------------
+    // PluginInterface protocol
+    //------------------------------------------------------------------
+    virtual lldb_private::ConstString
+    GetPluginName();
+    
+    virtual uint32_t
+    GetPluginVersion();
+
 protected:
 
     bool
@@ -560,4 +587,4 @@ protected:
 
 #endif // #ifdef LLDB_DISABLE_PYTHON
 
-#endif // #ifndef liblldb_ScriptInterpreterPython_h_
+#endif // #ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTINTERPRETERPYTHON_H
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/lldb-python.h b/lldb/source/Plugins/ScriptInterpreter/Python/lldb-python.h
new file mode 100644 (file)
index 0000000..013492c
--- /dev/null
@@ -0,0 +1,31 @@
+//===-- lldb-python.h --------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_LLDB_PYTHON_H
+#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_LLDB_PYTHON_H
+
+// Python.h needs to be included before any system headers in order to avoid redefinition of macros
+
+#ifdef LLDB_DISABLE_PYTHON
+// Python is disabled in this build
+#else
+#if defined(__linux__)
+// features.h will define _POSIX_C_SOURCE if _GNU_SOURCE is defined.  This value
+// may be different from the value that Python defines it to be which results
+// in a warning.  Undefine _POSIX_C_SOURCE before including Python.h  The same
+// holds for _XOPEN_SOURCE.
+#undef _POSIX_C_SOURCE
+#undef _XOPEN_SOURCE
+#endif
+
+// Include python for non windows machines
+#include <Python.h>
+#endif // LLDB_DISABLE_PYTHON
+
+#endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_LLDB_PYTHON_H
index a641b33..874a057 100644 (file)
@@ -18,10 +18,6 @@ function(add_lldb_unittest test_name)
     ${ARGN}
     )
 
-  if (MSVC)
-    target_link_libraries(${test_name} ${PYTHON_LIBRARY})
-  endif()
-
   lldb_link_common_libs(${test_name} EXE)
   target_link_libraries(${test_name} ${CLANG_USED_LIBS} ${LLDB_SYSTEM_LIBS})
   llvm_config(${test_name} ${LLVM_LINK_COMPONENTS})