Convert the ScriptInterpreter system to a plugin-based one.

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
This commit is contained in:
Zachary Turner 2015-07-30 20:28:07 +00:00
parent 13ac40ea6e
commit 2c1f46dcc6
33 changed files with 545 additions and 316 deletions

View File

@ -33,7 +33,6 @@ class SystemInitializerFull : public SystemInitializerCommon
private:
void InitializeSWIG();
void TerminateSWIG();
};
}

View File

@ -295,6 +295,23 @@ public:
static const char *
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
//------------------------------------------------------------------

View 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;

View 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:

View File

@ -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_

View File

@ -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_

View 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;

View 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);

View File

@ -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_

View File

@ -426,8 +426,6 @@
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 */; };
@ -644,6 +642,14 @@
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 */; };
@ -772,7 +778,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 */; };
@ -1064,8 +1069,13 @@
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 */,
);
@ -1864,7 +1874,6 @@
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>"; };
@ -1968,7 +1977,6 @@
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>"; };
@ -2141,6 +2149,13 @@
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>"; };
@ -2480,8 +2495,6 @@
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>"; };
@ -2506,8 +2519,6 @@
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>"; };
@ -2937,6 +2948,7 @@
266DFE9013FD64D200D0C574 /* OperatingSystem */,
26C5577E132575B6008FD8FE /* Platform */,
260C898A10F57C5600BB2B04 /* Process */,
3FBA69DA1B6066D20008F44A /* ScriptInterpreter */,
AF11CB34182CA85A00D9B618 /* SystemRuntime */,
260C89B110F57C5600BB2B04 /* SymbolFile */,
260C89E010F57C5600BB2B04 /* SymbolVendor */,
@ -4509,14 +4521,8 @@
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>";
@ -4898,6 +4904,36 @@
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 = (
@ -6157,8 +6193,6 @@
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 */,
@ -6338,6 +6372,7 @@
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 */,
@ -6401,10 +6436,12 @@
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 */,
@ -6466,7 +6503,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 */,

View 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}

View 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"

View 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"
@ -61,10 +73,6 @@
#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()
{
}

View 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

View 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"

View 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"

View 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
}

View File

@ -43,8 +43,5 @@ add_lldb_library(lldbInterpreter
OptionGroupWatchpoint.cpp
Options.cpp
Property.cpp
PythonDataObjects.cpp
ScriptInterpreter.cpp
ScriptInterpreterNone.cpp
ScriptInterpreterPython.cpp
)

View 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 ()
{

View File

@ -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");
}

View 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)

View 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"

View File

@ -0,0 +1,2 @@
add_subdirectory(None)
add_subdirectory(Python)

View File

@ -0,0 +1,3 @@
add_lldb_library(lldbPluginScriptInterpreterNone
ScriptInterpreterNone.cpp
)

View File

@ -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;
}

View File

@ -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_

View File

@ -0,0 +1,4 @@
add_lldb_library(lldbPluginScriptInterpreterPython
PythonDataObjects.cpp
ScriptInterpreterPython.cpp
)

View File

@ -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;

View File

@ -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

View File

@ -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;
@ -222,6 +222,59 @@ ScriptInterpreterPython::~ScriptInterpreterPython ()
PyGILState_Release(gil_state);
}
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)
{

View File

@ -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
@ -17,11 +17,10 @@
#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

View File

@ -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

View 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})