Rework LLDB system initialization.

In an effort to reduce binary size for components not wishing to
link against all of LLDB, as well as a parallel effort to reduce
link dependencies on Python, this patch splits out the notion of
LLDB initialization into "full" and "common" initialization.

All code related to initializing the full LLDB suite lives directly
in API now.  Previously it was only referenced from API, but because
it was defined in lldbCore, it would get implicitly linked against
by everything including lldb-server, causing a considerable
increase in binary size.

By moving this to the API layer, it also creates a better layering
for the ongoing effort to make the embedded interpreter replacable
with one from a different language (or even be completely removeable).

One semantic change necessary to get this all working was to remove
the notion of a shared debugger refcount.  The debugger is either
initialized or uninitialized now, and calling Initialize() multiple
times will simply have no effect, while the first Terminate() will
now shut it down no matter how many times Initialize() was called.
This behaves nicely with all of our supported usage patterns though,
and allows us to fix a number of nasty hacks from before.

Differential Revision: http://reviews.llvm.org/D8462

llvm-svn: 233758
This commit is contained in:
Zachary Turner 2015-03-31 21:03:22 +00:00
parent 902716728c
commit e6e2bb3842
22 changed files with 998 additions and 951 deletions

View File

@ -0,0 +1,40 @@
//===-- SystemInitializerFull.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_API_SYSTEM_INITIALIZER_FULL_H
#define LLDB_API_SYSTEM_INITIALIZER_FULL_H
#include "lldb/Initialization/SystemInitializerCommon.h"
namespace lldb_private
{
//------------------------------------------------------------------
/// Initializes lldb.
///
/// This class is responsible for initializing all of lldb system
/// services needed to use the full LLDB application. This class is
/// not intended to be used externally, but is instead used
/// internally by SBDebugger to initialize the system.
//------------------------------------------------------------------
class SystemInitializerFull : public SystemInitializerCommon
{
public:
SystemInitializerFull();
virtual ~SystemInitializerFull();
void Initialize() override;
void Terminate() override;
private:
void InitializeSWIG();
void TerminateSWIG();
};
}
#endif

View File

@ -65,10 +65,10 @@ public:
FindTargetWithProcess (Process *process); FindTargetWithProcess (Process *process);
static void static void
Initialize (LoadPluginCallbackType load_plugin_callback); Initialize(LoadPluginCallbackType load_plugin_callback);
static int static void
Terminate (); Terminate();
static void static void
SettingsInitialize (); SettingsInitialize ();
@ -248,9 +248,6 @@ public:
void void
ClearIOHandlers (); ClearIOHandlers ();
static int
TestDebuggerRefCount ();
bool bool
GetCloseInputOnEOF () const; GetCloseInputOnEOF () const;

View File

@ -1,61 +0,0 @@
//===-- InitializeLLDB.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_INITIALIZATION_INITIALIZE_LLDB_H
#define LLDB_INITIALIZATION_INITIALIZE_LLDB_H
#include "lldb/lldb-private-types.h"
namespace lldb_private
{
//------------------------------------------------------------------
/// Initializes lldb.
///
/// This function should be called prior to using any lldb
/// classes to ensure they have a chance to do any static
/// initialization that they need to do.
//------------------------------------------------------------------
void Initialize(LoadPluginCallbackType load_plugin_callback);
//------------------------------------------------------------------
/// Initializes subset of lldb for LLGS.
///
/// This function only initializes the set of components and plugins
/// necessary for lldb-platform and lldb-gdbserver, reducing the
/// impact on the statically linked binary size.
//------------------------------------------------------------------
void InitializeForLLGS(LoadPluginCallbackType load_plugin_callback);
//------------------------------------------------------------------
/// Terminates lldb
///
/// This function optionally can be called when clients are done
/// using lldb functionality to free up any static resources
/// that have been allocated during initialization or during
/// function calls. No lldb functions should be called after
/// calling this function without again calling DCInitialize()
/// again.
//------------------------------------------------------------------
void Terminate();
//------------------------------------------------------------------
/// Terminates subset of lldb initialized by InitializeForLLGS
///
/// This function optionally can be called when clients are done
/// using lldb functionality to free up any static resources
/// that have been allocated during initialization or during
/// function calls. No lldb functions should be called after
/// calling this function without again calling DCInitialize()
/// again.
//------------------------------------------------------------------
void TerminateLLGS();
}
#endif

View File

@ -0,0 +1,26 @@
//===-- SystemInitializer.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_INITIALIZATION_SYSTEM_INITIALIZER_H
#define LLDB_INITIALIZATION_SYSTEM_INITIALIZER_H
namespace lldb_private
{
class SystemInitializer
{
public:
SystemInitializer();
virtual ~SystemInitializer();
virtual void Initialize() = 0;
virtual void Terminate() = 0;
};
}
#endif

View File

@ -0,0 +1,38 @@
//===-- SystemInitializerCommon.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_INITIALIZATION_SYSTEM_INITIALIZER_COMMON_H
#define LLDB_INITIALIZATION_SYSTEM_INITIALIZER_COMMON_H
#include "SystemInitializer.h"
namespace lldb_private
{
//------------------------------------------------------------------
/// Initializes common lldb functionality.
///
/// This class is responsible for initializing a subset of lldb
/// useful to both debug servers and debug clients. Debug servers
/// do not use all of LLDB and desire small binary sizes, so this
/// functionality is separate. This class is used by constructing
/// an instance of SystemLifetimeManager with this class passed to
/// the constructor.
//------------------------------------------------------------------
class SystemInitializerCommon : public SystemInitializer
{
public:
SystemInitializerCommon();
virtual ~SystemInitializerCommon();
void Initialize() override;
void Terminate() override;
};
}
#endif

View File

@ -0,0 +1,42 @@
//===-- SystemLifetimeManager.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_INITIALIZATION_SYSTEM_LIFETIME_MANAGER_H
#define LLDB_INITIALIZATION_SYSTEM_LIFETIME_MANAGER_H
#include "lldb/lldb-private-types.h"
#include "lldb/Host/Mutex.h"
#include <memory>
namespace lldb_private
{
class SystemInitializer;
class SystemLifetimeManager
{
public:
SystemLifetimeManager();
~SystemLifetimeManager();
void Initialize(std::unique_ptr<SystemInitializer> initializer, LoadPluginCallbackType plugin_callback);
void Terminate();
private:
Mutex m_mutex;
std::unique_ptr<SystemInitializer> m_initializer;
bool m_initialized;
// Noncopyable.
SystemLifetimeManager(const SystemLifetimeManager &other) = delete;
SystemLifetimeManager &operator=(const SystemLifetimeManager &other) = delete;
};
}
#endif

View File

@ -41,98 +41,6 @@ class ScriptInterpreter
{ {
public: public:
typedef void (*SWIGInitCallback) (void);
typedef bool (*SWIGBreakpointCallbackFunction) (const char *python_function_name,
const char *session_dictionary_name,
const lldb::StackFrameSP& frame_sp,
const lldb::BreakpointLocationSP &bp_loc_sp);
typedef bool (*SWIGWatchpointCallbackFunction) (const char *python_function_name,
const char *session_dictionary_name,
const lldb::StackFrameSP& frame_sp,
const lldb::WatchpointSP &wp_sp);
typedef bool (*SWIGPythonTypeScriptCallbackFunction) (const char *python_function_name,
void *session_dictionary,
const lldb::ValueObjectSP& valobj_sp,
void** pyfunct_wrapper,
const lldb::TypeSummaryOptionsSP& options,
std::string& retval);
typedef void* (*SWIGPythonCreateSyntheticProvider) (const char *python_class_name,
const char *session_dictionary_name,
const lldb::ValueObjectSP& valobj_sp);
typedef void* (*SWIGPythonCreateCommandObject) (const char *python_class_name,
const char *session_dictionary_name,
const lldb::DebuggerSP debugger_sp);
typedef void* (*SWIGPythonCreateScriptedThreadPlan) (const char *python_class_name,
const char *session_dictionary_name,
const lldb::ThreadPlanSP& thread_plan_sp);
typedef bool (*SWIGPythonCallThreadPlan) (void *implementor, const char *method_name, Event *event_sp, bool &got_error);
typedef void* (*SWIGPythonCreateOSPlugin) (const char *python_class_name,
const char *session_dictionary_name,
const lldb::ProcessSP& process_sp);
typedef size_t (*SWIGPythonCalculateNumChildren) (void *implementor);
typedef void* (*SWIGPythonGetChildAtIndex) (void *implementor, uint32_t idx);
typedef int (*SWIGPythonGetIndexOfChildWithName) (void *implementor, const char* child_name);
typedef void* (*SWIGPythonCastPyObjectToSBValue) (void* data);
typedef lldb::ValueObjectSP (*SWIGPythonGetValueObjectSPFromSBValue) (void* data);
typedef bool (*SWIGPythonUpdateSynthProviderInstance) (void* data);
typedef bool (*SWIGPythonMightHaveChildrenSynthProviderInstance) (void* data);
typedef void* (*SWIGPythonGetValueSynthProviderInstance) (void *implementor);
typedef bool (*SWIGPythonCallCommand) (const char *python_function_name,
const char *session_dictionary_name,
lldb::DebuggerSP& debugger,
const char* args,
lldb_private::CommandReturnObject& cmd_retobj,
lldb::ExecutionContextRefSP exe_ctx_ref_sp);
typedef bool (*SWIGPythonCallCommandObject) (void *implementor,
lldb::DebuggerSP& debugger,
const char* args,
lldb_private::CommandReturnObject& cmd_retobj,
lldb::ExecutionContextRefSP exe_ctx_ref_sp);
typedef bool (*SWIGPythonCallModuleInit) (const char *python_module_name,
const char *session_dictionary_name,
lldb::DebuggerSP& debugger);
typedef bool (*SWIGPythonScriptKeyword_Process) (const char* python_function_name,
const char* session_dictionary_name,
lldb::ProcessSP& process,
std::string& output);
typedef bool (*SWIGPythonScriptKeyword_Thread) (const char* python_function_name,
const char* session_dictionary_name,
lldb::ThreadSP& thread,
std::string& output);
typedef bool (*SWIGPythonScriptKeyword_Target) (const char* python_function_name,
const char* session_dictionary_name,
lldb::TargetSP& target,
std::string& output);
typedef bool (*SWIGPythonScriptKeyword_Frame) (const char* python_function_name,
const char* session_dictionary_name,
lldb::StackFrameSP& frame,
std::string& output);
typedef bool (*SWIGPythonScriptKeyword_Value) (const char* python_function_name,
const char* session_dictionary_name,
lldb::ValueObjectSP& value,
std::string& output);
typedef void* (*SWIGPython_GetDynamicSetting) (void* module,
const char* setting,
const lldb::TargetSP& target_sp);
typedef enum typedef enum
{ {
eScriptReturnTypeCharPtr, eScriptReturnTypeCharPtr,
@ -605,34 +513,6 @@ public:
static std::string static std::string
LanguageToString (lldb::ScriptLanguage language); LanguageToString (lldb::ScriptLanguage language);
static void
InitializeInterpreter (SWIGInitCallback python_swig_init_callback,
SWIGBreakpointCallbackFunction swig_breakpoint_callback,
SWIGWatchpointCallbackFunction swig_watchpoint_callback,
SWIGPythonTypeScriptCallbackFunction swig_typescript_callback,
SWIGPythonCreateSyntheticProvider swig_synthetic_script,
SWIGPythonCreateCommandObject swig_create_cmd,
SWIGPythonCalculateNumChildren swig_calc_children,
SWIGPythonGetChildAtIndex swig_get_child_index,
SWIGPythonGetIndexOfChildWithName swig_get_index_child,
SWIGPythonCastPyObjectToSBValue swig_cast_to_sbvalue ,
SWIGPythonGetValueObjectSPFromSBValue swig_get_valobj_sp_from_sbvalue,
SWIGPythonUpdateSynthProviderInstance swig_update_provider,
SWIGPythonMightHaveChildrenSynthProviderInstance swig_mighthavechildren_provider,
SWIGPythonGetValueSynthProviderInstance swig_getvalue_provider,
SWIGPythonCallCommand swig_call_command,
SWIGPythonCallCommandObject swig_call_command_object,
SWIGPythonCallModuleInit swig_call_module_init,
SWIGPythonCreateOSPlugin swig_create_os_plugin,
SWIGPythonScriptKeyword_Process swig_run_script_keyword_process,
SWIGPythonScriptKeyword_Thread swig_run_script_keyword_thread,
SWIGPythonScriptKeyword_Target swig_run_script_keyword_target,
SWIGPythonScriptKeyword_Frame swig_run_script_keyword_frame,
SWIGPythonScriptKeyword_Value swig_run_script_keyword_value,
SWIGPython_GetDynamicSetting swig_plugin_get,
SWIGPythonCreateScriptedThreadPlan swig_thread_plan_script,
SWIGPythonCallThreadPlan swig_call_thread_plan);
virtual void virtual void
ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing. ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing.

View File

@ -33,6 +33,97 @@ class ScriptInterpreterPython :
public IOHandlerDelegateMultiline public IOHandlerDelegateMultiline
{ {
public: public:
typedef void (*SWIGInitCallback) (void);
typedef bool (*SWIGBreakpointCallbackFunction) (const char *python_function_name,
const char *session_dictionary_name,
const lldb::StackFrameSP& frame_sp,
const lldb::BreakpointLocationSP &bp_loc_sp);
typedef bool (*SWIGWatchpointCallbackFunction) (const char *python_function_name,
const char *session_dictionary_name,
const lldb::StackFrameSP& frame_sp,
const lldb::WatchpointSP &wp_sp);
typedef bool (*SWIGPythonTypeScriptCallbackFunction) (const char *python_function_name,
void *session_dictionary,
const lldb::ValueObjectSP& valobj_sp,
void** pyfunct_wrapper,
const lldb::TypeSummaryOptionsSP& options,
std::string& retval);
typedef void* (*SWIGPythonCreateSyntheticProvider) (const char *python_class_name,
const char *session_dictionary_name,
const lldb::ValueObjectSP& valobj_sp);
typedef void* (*SWIGPythonCreateCommandObject) (const char *python_class_name,
const char *session_dictionary_name,
const lldb::DebuggerSP debugger_sp);
typedef void* (*SWIGPythonCreateScriptedThreadPlan) (const char *python_class_name,
const char *session_dictionary_name,
const lldb::ThreadPlanSP& thread_plan_sp);
typedef bool (*SWIGPythonCallThreadPlan) (void *implementor, const char *method_name, Event *event_sp, bool &got_error);
typedef void* (*SWIGPythonCreateOSPlugin) (const char *python_class_name,
const char *session_dictionary_name,
const lldb::ProcessSP& process_sp);
typedef size_t (*SWIGPythonCalculateNumChildren) (void *implementor);
typedef void* (*SWIGPythonGetChildAtIndex) (void *implementor, uint32_t idx);
typedef int (*SWIGPythonGetIndexOfChildWithName) (void *implementor, const char* child_name);
typedef void* (*SWIGPythonCastPyObjectToSBValue) (void* data);
typedef lldb::ValueObjectSP (*SWIGPythonGetValueObjectSPFromSBValue) (void* data);
typedef bool (*SWIGPythonUpdateSynthProviderInstance) (void* data);
typedef bool (*SWIGPythonMightHaveChildrenSynthProviderInstance) (void* data);
typedef void* (*SWIGPythonGetValueSynthProviderInstance) (void *implementor);
typedef bool (*SWIGPythonCallCommand) (const char *python_function_name,
const char *session_dictionary_name,
lldb::DebuggerSP& debugger,
const char* args,
lldb_private::CommandReturnObject& cmd_retobj,
lldb::ExecutionContextRefSP exe_ctx_ref_sp);
typedef bool (*SWIGPythonCallCommandObject) (void *implementor,
lldb::DebuggerSP& debugger,
const char* args,
lldb_private::CommandReturnObject& cmd_retobj,
lldb::ExecutionContextRefSP exe_ctx_ref_sp);
typedef bool (*SWIGPythonCallModuleInit) (const char *python_module_name,
const char *session_dictionary_name,
lldb::DebuggerSP& debugger);
typedef bool (*SWIGPythonScriptKeyword_Process) (const char* python_function_name,
const char* session_dictionary_name,
lldb::ProcessSP& process,
std::string& output);
typedef bool (*SWIGPythonScriptKeyword_Thread) (const char* python_function_name,
const char* session_dictionary_name,
lldb::ThreadSP& thread,
std::string& output);
typedef bool (*SWIGPythonScriptKeyword_Target) (const char* python_function_name,
const char* session_dictionary_name,
lldb::TargetSP& target,
std::string& output);
typedef bool (*SWIGPythonScriptKeyword_Frame) (const char* python_function_name,
const char* session_dictionary_name,
lldb::StackFrameSP& frame,
std::string& output);
typedef bool (*SWIGPythonScriptKeyword_Value) (const char* python_function_name,
const char* session_dictionary_name,
lldb::ValueObjectSP& value,
std::string& output);
typedef void* (*SWIGPython_GetDynamicSetting) (void* module,
const char* setting,
const lldb::TargetSP& target_sp);
friend class IOHandlerPythonInterpreter; friend class IOHandlerPythonInterpreter;

View File

@ -686,7 +686,10 @@
3F8160A61AB9F7DD001DA9DF /* Logging.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F8160A51AB9F7DD001DA9DF /* Logging.cpp */; }; 3F8160A61AB9F7DD001DA9DF /* Logging.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F8160A51AB9F7DD001DA9DF /* Logging.cpp */; };
3F8169191ABA2419001DA9DF /* ConvertEnum.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F8169171ABA2419001DA9DF /* ConvertEnum.cpp */; }; 3F8169191ABA2419001DA9DF /* ConvertEnum.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F8169171ABA2419001DA9DF /* ConvertEnum.cpp */; };
3F81691A1ABA2419001DA9DF /* NameMatches.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F8169181ABA2419001DA9DF /* NameMatches.cpp */; }; 3F81691A1ABA2419001DA9DF /* NameMatches.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F8169181ABA2419001DA9DF /* NameMatches.cpp */; };
3F8169281ABB73D9001DA9DF /* InitializeLLDB.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F8169271ABB73D9001DA9DF /* InitializeLLDB.cpp */; }; 3F81692C1ABB7A1E001DA9DF /* SystemInitializerFull.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F81692A1ABB7A16001DA9DF /* SystemInitializerFull.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 */; };
3FDFDDBD199C3A06009756A7 /* FileAction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FDFDDBC199C3A06009756A7 /* FileAction.cpp */; }; 3FDFDDBD199C3A06009756A7 /* FileAction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FDFDDBC199C3A06009756A7 /* FileAction.cpp */; };
3FDFDDBF199D345E009756A7 /* FileCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FDFDDBE199D345E009756A7 /* FileCache.cpp */; }; 3FDFDDBF199D345E009756A7 /* FileCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FDFDDBE199D345E009756A7 /* FileCache.cpp */; };
3FDFDDC6199D37ED009756A7 /* FileSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FDFDDC5199D37ED009756A7 /* FileSystem.cpp */; }; 3FDFDDC6199D37ED009756A7 /* FileSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FDFDDC5199D37ED009756A7 /* FileSystem.cpp */; };
@ -2167,8 +2170,14 @@
3F8169181ABA2419001DA9DF /* NameMatches.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NameMatches.cpp; path = source/Utility/NameMatches.cpp; sourceTree = "<group>"; }; 3F8169181ABA2419001DA9DF /* NameMatches.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NameMatches.cpp; path = source/Utility/NameMatches.cpp; sourceTree = "<group>"; };
3F81691B1ABA242B001DA9DF /* ConvertEnum.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ConvertEnum.h; path = include/lldb/Utility/ConvertEnum.h; sourceTree = "<group>"; }; 3F81691B1ABA242B001DA9DF /* ConvertEnum.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ConvertEnum.h; path = include/lldb/Utility/ConvertEnum.h; sourceTree = "<group>"; };
3F81691C1ABA242B001DA9DF /* NameMatches.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = NameMatches.h; path = include/lldb/Utility/NameMatches.h; sourceTree = "<group>"; }; 3F81691C1ABA242B001DA9DF /* NameMatches.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = NameMatches.h; path = include/lldb/Utility/NameMatches.h; sourceTree = "<group>"; };
3F8169271ABB73D9001DA9DF /* InitializeLLDB.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = InitializeLLDB.cpp; path = source/Initialization/InitializeLLDB.cpp; sourceTree = "<group>"; }; 3F81692A1ABB7A16001DA9DF /* SystemInitializerFull.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SystemInitializerFull.cpp; path = source/API/SystemInitializerFull.cpp; sourceTree = "<group>"; };
3F8169291ABB73E6001DA9DF /* InitializeLLDB.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = InitializeLLDB.h; path = include/lldb/Initialization/InitializeLLDB.h; sourceTree = "<group>"; }; 3F81692D1ABB7A40001DA9DF /* SystemInitializerFull.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SystemInitializerFull.h; path = include/lldb/API/SystemInitializerFull.h; sourceTree = "<group>"; };
3F81692E1ABB7A6D001DA9DF /* SystemInitializer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SystemInitializer.cpp; path = source/Initialization/SystemInitializer.cpp; sourceTree = "<group>"; };
3F81692F1ABB7A6D001DA9DF /* SystemInitializerCommon.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SystemInitializerCommon.cpp; path = source/Initialization/SystemInitializerCommon.cpp; sourceTree = "<group>"; };
3F8169301ABB7A6D001DA9DF /* SystemLifetimeManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SystemLifetimeManager.cpp; path = source/Initialization/SystemLifetimeManager.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>"; };
3FDFD6C3199C396E009756A7 /* FileAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileAction.h; path = include/lldb/Target/FileAction.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>"; }; 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>"; }; 3FDFDDBE199D345E009756A7 /* FileCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FileCache.cpp; path = source/Host/common/FileCache.cpp; sourceTree = "<group>"; };
@ -3326,6 +3335,8 @@
94235B9B1A8D5FF300EB2EED /* SBVariablesOptions.cpp */, 94235B9B1A8D5FF300EB2EED /* SBVariablesOptions.cpp */,
B2A58721143119810092BFBA /* SBWatchpoint.h */, B2A58721143119810092BFBA /* SBWatchpoint.h */,
B2A58723143119D50092BFBA /* SBWatchpoint.cpp */, B2A58723143119D50092BFBA /* SBWatchpoint.cpp */,
3F81692D1ABB7A40001DA9DF /* SystemInitializerFull.h */,
3F81692A1ABB7A16001DA9DF /* SystemInitializerFull.cpp */,
); );
name = API; name = API;
sourceTree = "<group>"; sourceTree = "<group>";
@ -4783,8 +4794,12 @@
3F8169261ABB73C1001DA9DF /* Initialization */ = { 3F8169261ABB73C1001DA9DF /* Initialization */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
3F8169291ABB73E6001DA9DF /* InitializeLLDB.h */, 3F8169341ABB7A80001DA9DF /* SystemInitializer.h */,
3F8169271ABB73D9001DA9DF /* InitializeLLDB.cpp */, 3F81692E1ABB7A6D001DA9DF /* SystemInitializer.cpp */,
3F8169351ABB7A80001DA9DF /* SystemInitializerCommon.h */,
3F81692F1ABB7A6D001DA9DF /* SystemInitializerCommon.cpp */,
3F8169361ABB7A80001DA9DF /* SystemLifetimeManager.h */,
3F8169301ABB7A6D001DA9DF /* SystemLifetimeManager.cpp */,
); );
name = Initialization; name = Initialization;
sourceTree = "<group>"; sourceTree = "<group>";
@ -5810,6 +5825,7 @@
26680324116005D9008E1FE4 /* SBThread.cpp in Sources */, 26680324116005D9008E1FE4 /* SBThread.cpp in Sources */,
26680326116005DB008E1FE4 /* SBTarget.cpp in Sources */, 26680326116005DB008E1FE4 /* SBTarget.cpp in Sources */,
26680327116005DC008E1FE4 /* SBSourceManager.cpp in Sources */, 26680327116005DC008E1FE4 /* SBSourceManager.cpp in Sources */,
3F81692C1ABB7A1E001DA9DF /* SystemInitializerFull.cpp in Sources */,
26680328116005DE008E1FE4 /* SBProcess.cpp in Sources */, 26680328116005DE008E1FE4 /* SBProcess.cpp in Sources */,
2668032A116005E0008E1FE4 /* SBListener.cpp in Sources */, 2668032A116005E0008E1FE4 /* SBListener.cpp in Sources */,
2668032C116005E2008E1FE4 /* SBFrame.cpp in Sources */, 2668032C116005E2008E1FE4 /* SBFrame.cpp in Sources */,
@ -5927,6 +5943,7 @@
2689002413353DDE00698AC0 /* CommandObjectSettings.cpp in Sources */, 2689002413353DDE00698AC0 /* CommandObjectSettings.cpp in Sources */,
2689002513353DDE00698AC0 /* CommandObjectSource.cpp in Sources */, 2689002513353DDE00698AC0 /* CommandObjectSource.cpp in Sources */,
2689002613353DDE00698AC0 /* CommandObjectSyntax.cpp in Sources */, 2689002613353DDE00698AC0 /* CommandObjectSyntax.cpp in Sources */,
3F8169331ABB7A6D001DA9DF /* SystemLifetimeManager.cpp in Sources */,
4959511F1A1BC4BC00F6F8FC /* ClangModulesDeclVendor.cpp in Sources */, 4959511F1A1BC4BC00F6F8FC /* ClangModulesDeclVendor.cpp in Sources */,
26BC179918C7F2B300D2196D /* JITLoader.cpp in Sources */, 26BC179918C7F2B300D2196D /* JITLoader.cpp in Sources */,
2689002713353DDE00698AC0 /* CommandObjectTarget.cpp in Sources */, 2689002713353DDE00698AC0 /* CommandObjectTarget.cpp in Sources */,
@ -5995,6 +6012,7 @@
8CCB017E19BA28A80009FD44 /* ThreadCollection.cpp in Sources */, 8CCB017E19BA28A80009FD44 /* ThreadCollection.cpp in Sources */,
2689005613353E0400698AC0 /* Value.cpp in Sources */, 2689005613353E0400698AC0 /* Value.cpp in Sources */,
2689005713353E0400698AC0 /* ValueObject.cpp in Sources */, 2689005713353E0400698AC0 /* ValueObject.cpp in Sources */,
3F8169321ABB7A6D001DA9DF /* SystemInitializerCommon.cpp in Sources */,
2689005813353E0400698AC0 /* ValueObjectChild.cpp in Sources */, 2689005813353E0400698AC0 /* ValueObjectChild.cpp in Sources */,
E7723D441AC4A7FB002BA082 /* RegisterContextPOSIXCore_arm64.cpp in Sources */, E7723D441AC4A7FB002BA082 /* RegisterContextPOSIXCore_arm64.cpp in Sources */,
233B007F1960CB280090E598 /* ProcessLaunchInfo.cpp in Sources */, 233B007F1960CB280090E598 /* ProcessLaunchInfo.cpp in Sources */,
@ -6086,6 +6104,7 @@
268900B013353E5000698AC0 /* RegisterContextLLDB.cpp in Sources */, 268900B013353E5000698AC0 /* RegisterContextLLDB.cpp in Sources */,
3FDFE56C19AF9C44009756A7 /* HostProcessPosix.cpp in Sources */, 3FDFE56C19AF9C44009756A7 /* HostProcessPosix.cpp in Sources */,
268900B413353E5000698AC0 /* RegisterContextMacOSXFrameBackchain.cpp in Sources */, 268900B413353E5000698AC0 /* RegisterContextMacOSXFrameBackchain.cpp in Sources */,
3F8169311ABB7A6D001DA9DF /* SystemInitializer.cpp in Sources */,
3FDFED2D19C257A0009756A7 /* HostProcess.cpp in Sources */, 3FDFED2D19C257A0009756A7 /* HostProcess.cpp in Sources */,
268900B513353E5000698AC0 /* StopInfoMachException.cpp in Sources */, 268900B513353E5000698AC0 /* StopInfoMachException.cpp in Sources */,
268900B613353E5000698AC0 /* UnwindMacOSXFrameBackchain.cpp in Sources */, 268900B613353E5000698AC0 /* UnwindMacOSXFrameBackchain.cpp in Sources */,
@ -6377,7 +6396,6 @@
94CB257216B0A4270059775D /* TypeSynthetic.cpp in Sources */, 94CB257216B0A4270059775D /* TypeSynthetic.cpp in Sources */,
94CB257416B1D3880059775D /* FormatCache.cpp in Sources */, 94CB257416B1D3880059775D /* FormatCache.cpp in Sources */,
A36FF33C17D8E94600244D40 /* OptionParser.cpp in Sources */, A36FF33C17D8E94600244D40 /* OptionParser.cpp in Sources */,
3F8169281ABB73D9001DA9DF /* InitializeLLDB.cpp in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };

View File

@ -66,6 +66,7 @@ add_lldb_library(liblldb SHARED
SBVariablesOptions.cpp SBVariablesOptions.cpp
SBWatchpoint.cpp SBWatchpoint.cpp
SBUnixSignals.cpp SBUnixSignals.cpp
SystemInitializerFull.cpp
${LLDB_WRAP_PYTHON} ${LLDB_WRAP_PYTHON}
${LLDB_VERS_GENERATED_FILE} ${LLDB_VERS_GENERATED_FILE}
) )

View File

@ -588,183 +588,6 @@ SBCommandInterpreter::SetCommandOverrideCallback (const char *command_name,
return false; return false;
} }
#ifndef LLDB_DISABLE_PYTHON
// Defined in the SWIG source file
extern "C" void
init_lldb(void);
// these are the Pythonic implementations of the required callbacks
// these are scripting-language specific, which is why they belong here
// we still need to use function pointers to them instead of relying
// on linkage-time resolution because the SWIG stuff and this file
// get built at different times
extern "C" bool
LLDBSwigPythonBreakpointCallbackFunction (const char *python_function_name,
const char *session_dictionary_name,
const lldb::StackFrameSP& sb_frame,
const lldb::BreakpointLocationSP& sb_bp_loc);
extern "C" bool
LLDBSwigPythonWatchpointCallbackFunction (const char *python_function_name,
const char *session_dictionary_name,
const lldb::StackFrameSP& sb_frame,
const lldb::WatchpointSP& sb_wp);
extern "C" bool
LLDBSwigPythonCallTypeScript (const char *python_function_name,
void *session_dictionary,
const lldb::ValueObjectSP& valobj_sp,
void** pyfunct_wrapper,
const lldb::TypeSummaryOptionsSP& options_sp,
std::string& retval);
extern "C" void*
LLDBSwigPythonCreateSyntheticProvider (const char *python_class_name,
const char *session_dictionary_name,
const lldb::ValueObjectSP& valobj_sp);
extern "C" void*
LLDBSwigPythonCreateCommandObject (const char *python_class_name,
const char *session_dictionary_name,
const lldb::DebuggerSP debugger_sp);
extern "C" void*
LLDBSwigPythonCreateScriptedThreadPlan (const char *python_class_name,
const char *session_dictionary_name,
const lldb::ThreadPlanSP& thread_plan_sp);
extern "C" bool
LLDBSWIGPythonCallThreadPlan (void *implementor,
const char *method_name,
Event *event_sp,
bool &got_error);
extern "C" size_t
LLDBSwigPython_CalculateNumChildren (void *implementor);
extern "C" void *
LLDBSwigPython_GetChildAtIndex (void *implementor, uint32_t idx);
extern "C" int
LLDBSwigPython_GetIndexOfChildWithName (void *implementor, const char* child_name);
extern "C" void *
LLDBSWIGPython_CastPyObjectToSBValue (void* data);
extern lldb::ValueObjectSP
LLDBSWIGPython_GetValueObjectSPFromSBValue (void* data);
extern "C" bool
LLDBSwigPython_UpdateSynthProviderInstance (void* implementor);
extern "C" bool
LLDBSwigPython_MightHaveChildrenSynthProviderInstance (void* implementor);
extern "C" void *
LLDBSwigPython_GetValueSynthProviderInstance (void* implementor);
extern "C" bool
LLDBSwigPythonCallCommand (const char *python_function_name,
const char *session_dictionary_name,
lldb::DebuggerSP& debugger,
const char* args,
lldb_private::CommandReturnObject &cmd_retobj,
lldb::ExecutionContextRefSP exe_ctx_ref_sp);
extern "C" bool
LLDBSwigPythonCallCommandObject (void *implementor,
lldb::DebuggerSP& debugger,
const char* args,
lldb_private::CommandReturnObject& cmd_retobj,
lldb::ExecutionContextRefSP exe_ctx_ref_sp);
extern "C" bool
LLDBSwigPythonCallModuleInit (const char *python_module_name,
const char *session_dictionary_name,
lldb::DebuggerSP& debugger);
extern "C" void*
LLDBSWIGPythonCreateOSPlugin (const char *python_class_name,
const char *session_dictionary_name,
const lldb::ProcessSP& process_sp);
extern "C" bool
LLDBSWIGPythonRunScriptKeywordProcess (const char* python_function_name,
const char* session_dictionary_name,
lldb::ProcessSP& process,
std::string& output);
extern "C" bool
LLDBSWIGPythonRunScriptKeywordThread (const char* python_function_name,
const char* session_dictionary_name,
lldb::ThreadSP& thread,
std::string& output);
extern "C" bool
LLDBSWIGPythonRunScriptKeywordTarget (const char* python_function_name,
const char* session_dictionary_name,
lldb::TargetSP& target,
std::string& output);
extern "C" bool
LLDBSWIGPythonRunScriptKeywordFrame (const char* python_function_name,
const char* session_dictionary_name,
lldb::StackFrameSP& frame,
std::string& output);
extern "C" bool
LLDBSWIGPythonRunScriptKeywordValue (const char* python_function_name,
const char* session_dictionary_name,
lldb::ValueObjectSP& value,
std::string& output);
extern "C" void*
LLDBSWIGPython_GetDynamicSetting (void* module,
const char* setting,
const lldb::TargetSP& target_sp);
#endif
void
SBCommandInterpreter::InitializeSWIG ()
{
static bool g_initialized = false;
if (!g_initialized)
{
g_initialized = true;
#ifndef LLDB_DISABLE_PYTHON
ScriptInterpreter::InitializeInterpreter (init_lldb,
LLDBSwigPythonBreakpointCallbackFunction,
LLDBSwigPythonWatchpointCallbackFunction,
LLDBSwigPythonCallTypeScript,
LLDBSwigPythonCreateSyntheticProvider,
LLDBSwigPythonCreateCommandObject,
LLDBSwigPython_CalculateNumChildren,
LLDBSwigPython_GetChildAtIndex,
LLDBSwigPython_GetIndexOfChildWithName,
LLDBSWIGPython_CastPyObjectToSBValue,
LLDBSWIGPython_GetValueObjectSPFromSBValue,
LLDBSwigPython_UpdateSynthProviderInstance,
LLDBSwigPython_MightHaveChildrenSynthProviderInstance,
LLDBSwigPython_GetValueSynthProviderInstance,
LLDBSwigPythonCallCommand,
LLDBSwigPythonCallCommandObject,
LLDBSwigPythonCallModuleInit,
LLDBSWIGPythonCreateOSPlugin,
LLDBSWIGPythonRunScriptKeywordProcess,
LLDBSWIGPythonRunScriptKeywordThread,
LLDBSWIGPythonRunScriptKeywordTarget,
LLDBSWIGPythonRunScriptKeywordFrame,
LLDBSWIGPythonRunScriptKeywordValue,
LLDBSWIGPython_GetDynamicSetting,
LLDBSwigPythonCreateScriptedThreadPlan,
LLDBSWIGPythonCallThreadPlan);
#endif
}
}
lldb::SBCommand lldb::SBCommand
SBCommandInterpreter::AddMultiwordCommand (const char* name, const char* help) SBCommandInterpreter::AddMultiwordCommand (const char* name, const char* help)
{ {

View File

@ -13,6 +13,7 @@
#include "lldb/lldb-private.h" #include "lldb/lldb-private.h"
#include "lldb/API/SystemInitializerFull.h"
#include "lldb/API/SBListener.h" #include "lldb/API/SBListener.h"
#include "lldb/API/SBBroadcaster.h" #include "lldb/API/SBBroadcaster.h"
#include "lldb/API/SBCommandInterpreter.h" #include "lldb/API/SBCommandInterpreter.h"
@ -37,42 +38,20 @@
#include "lldb/Core/State.h" #include "lldb/Core/State.h"
#include "lldb/Core/StreamFile.h" #include "lldb/Core/StreamFile.h"
#include "lldb/DataFormatters/DataVisualization.h" #include "lldb/DataFormatters/DataVisualization.h"
#include "lldb/Initialization/InitializeLLDB.h" #include "lldb/Initialization/SystemLifetimeManager.h"
#include "lldb/Interpreter/Args.h" #include "lldb/Interpreter/Args.h"
#include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/OptionGroupPlatform.h" #include "lldb/Interpreter/OptionGroupPlatform.h"
#include "lldb/Target/Process.h" #include "lldb/Target/Process.h"
#include "lldb/Target/TargetList.h" #include "lldb/Target/TargetList.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/DynamicLibrary.h" #include "llvm/Support/DynamicLibrary.h"
using namespace lldb; using namespace lldb;
using namespace lldb_private; using namespace lldb_private;
SBInputReader::SBInputReader()
{
}
SBInputReader::~SBInputReader()
{
}
SBError
SBInputReader::Initialize(lldb::SBDebugger& sb_debugger, unsigned long (*)(void*, lldb::SBInputReader*, lldb::InputReaderAction, char const*, unsigned long), void*, lldb::InputReaderGranularity, char const*, char const*, bool)
{
return SBError();
}
void
SBInputReader::SetIsDone(bool)
{
}
bool
SBInputReader::IsActive() const
{
return false;
}
static llvm::sys::DynamicLibrary static llvm::sys::DynamicLibrary
LoadPlugin (const lldb::DebuggerSP &debugger_sp, const FileSpec& spec, Error& error) LoadPlugin (const lldb::DebuggerSP &debugger_sp, const FileSpec& spec, Error& error)
{ {
@ -107,6 +86,34 @@ LoadPlugin (const lldb::DebuggerSP &debugger_sp, const FileSpec& spec, Error& er
return llvm::sys::DynamicLibrary(); return llvm::sys::DynamicLibrary();
} }
static llvm::ManagedStatic<SystemLifetimeManager> g_debugger_lifetime;
SBInputReader::SBInputReader()
{
}
SBInputReader::~SBInputReader()
{
}
SBError
SBInputReader::Initialize(lldb::SBDebugger &sb_debugger,
unsigned long (*)(void *, lldb::SBInputReader *, lldb::InputReaderAction, char const *,
unsigned long),
void *, lldb::InputReaderGranularity, char const *, char const *, bool)
{
return SBError();
}
void
SBInputReader::SetIsDone(bool)
{
}
bool
SBInputReader::IsActive() const
{
return false;
}
void void
SBDebugger::Initialize () SBDebugger::Initialize ()
{ {
@ -115,15 +122,13 @@ SBDebugger::Initialize ()
if (log) if (log)
log->Printf ("SBDebugger::Initialize ()"); log->Printf ("SBDebugger::Initialize ()");
SBCommandInterpreter::InitializeSWIG (); g_debugger_lifetime->Initialize(llvm::make_unique<SystemInitializerFull>(), LoadPlugin);
lldb_private::Initialize(LoadPlugin);
} }
void void
SBDebugger::Terminate () SBDebugger::Terminate ()
{ {
lldb_private::Terminate(); g_debugger_lifetime->Terminate();
} }
void void

View File

@ -0,0 +1,394 @@
//===-- SystemInitializerFull.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/API/SystemInitializerFull.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Timer.h"
#include "lldb/Host/Host.h"
#include "lldb/Initialization/SystemInitializerCommon.h"
#include "Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h"
#include "Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h"
#include "Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h"
#include "Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h"
#include "Plugins/ABI/SysV-ppc/ABISysV_ppc.h"
#include "Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h"
#include "Plugins/Disassembler/llvm/DisassemblerLLVMC.h"
#include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h"
#include "Plugins/Instruction/ARM/EmulateInstructionARM.h"
#include "Plugins/Instruction/ARM64/EmulateInstructionARM64.h"
#include "Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h"
#include "Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.h"
#include "Plugins/JITLoader/GDB/JITLoaderGDB.h"
#include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h"
#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h"
#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h"
#include "Plugins/MemoryHistory/asan/MemoryHistoryASan.h"
#include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h"
#include "Plugins/Process/elf-core/ProcessElfCore.h"
#include "Plugins/Process/gdb-remote/ProcessGDBRemote.h"
#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
#include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h"
#include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h"
#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
#include "Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h"
#include "Plugins/UnwindAssembly/x86/UnwindAssembly-x86.h"
#include "Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h"
#if defined(__APPLE__)
#include "Plugins/Process/mach-core/ProcessMachCore.h"
#include "Plugins/Process/MacOSX-Kernel/ProcessKDP.h"
#include "Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h"
#endif
#if defined(__FreeBSD__)
#include "Plugins/Process/FreeBSD/ProcessFreeBSD.h"
#endif
#if defined(__linux__)
#include "Plugins/Process/Linux/ProcessLinux.h"
#endif
#if defined(_MSC_VER)
#include "lldb/Host/windows/windows.h"
#include "Plugins/Process/Windows/DynamicLoaderWindows.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>
using namespace lldb_private;
#ifndef LLDB_DISABLE_PYTHON
// Defined in the SWIG source file
extern "C" void
init_lldb(void);
// these are the Pythonic implementations of the required callbacks
// these are scripting-language specific, which is why they belong here
// we still need to use function pointers to them instead of relying
// on linkage-time resolution because the SWIG stuff and this file
// get built at different times
extern "C" bool
LLDBSwigPythonBreakpointCallbackFunction (const char *python_function_name,
const char *session_dictionary_name,
const lldb::StackFrameSP& sb_frame,
const lldb::BreakpointLocationSP& sb_bp_loc);
extern "C" bool
LLDBSwigPythonWatchpointCallbackFunction (const char *python_function_name,
const char *session_dictionary_name,
const lldb::StackFrameSP& sb_frame,
const lldb::WatchpointSP& sb_wp);
extern "C" bool
LLDBSwigPythonCallTypeScript (const char *python_function_name,
void *session_dictionary,
const lldb::ValueObjectSP& valobj_sp,
void** pyfunct_wrapper,
const lldb::TypeSummaryOptionsSP& options_sp,
std::string& retval);
extern "C" void*
LLDBSwigPythonCreateSyntheticProvider (const char *python_class_name,
const char *session_dictionary_name,
const lldb::ValueObjectSP& valobj_sp);
extern "C" void*
LLDBSwigPythonCreateCommandObject (const char *python_class_name,
const char *session_dictionary_name,
const lldb::DebuggerSP debugger_sp);
extern "C" void*
LLDBSwigPythonCreateScriptedThreadPlan (const char *python_class_name,
const char *session_dictionary_name,
const lldb::ThreadPlanSP& thread_plan_sp);
extern "C" bool
LLDBSWIGPythonCallThreadPlan (void *implementor,
const char *method_name,
Event *event_sp,
bool &got_error);
extern "C" size_t
LLDBSwigPython_CalculateNumChildren (void *implementor);
extern "C" void *
LLDBSwigPython_GetChildAtIndex (void *implementor, uint32_t idx);
extern "C" int
LLDBSwigPython_GetIndexOfChildWithName (void *implementor, const char* child_name);
extern "C" void *
LLDBSWIGPython_CastPyObjectToSBValue (void* data);
extern lldb::ValueObjectSP
LLDBSWIGPython_GetValueObjectSPFromSBValue (void* data);
extern "C" bool
LLDBSwigPython_UpdateSynthProviderInstance (void* implementor);
extern "C" bool
LLDBSwigPython_MightHaveChildrenSynthProviderInstance (void* implementor);
extern "C" void *
LLDBSwigPython_GetValueSynthProviderInstance (void* implementor);
extern "C" bool
LLDBSwigPythonCallCommand (const char *python_function_name,
const char *session_dictionary_name,
lldb::DebuggerSP& debugger,
const char* args,
lldb_private::CommandReturnObject &cmd_retobj,
lldb::ExecutionContextRefSP exe_ctx_ref_sp);
extern "C" bool
LLDBSwigPythonCallCommandObject (void *implementor,
lldb::DebuggerSP& debugger,
const char* args,
lldb_private::CommandReturnObject& cmd_retobj,
lldb::ExecutionContextRefSP exe_ctx_ref_sp);
extern "C" bool
LLDBSwigPythonCallModuleInit (const char *python_module_name,
const char *session_dictionary_name,
lldb::DebuggerSP& debugger);
extern "C" void*
LLDBSWIGPythonCreateOSPlugin (const char *python_class_name,
const char *session_dictionary_name,
const lldb::ProcessSP& process_sp);
extern "C" bool
LLDBSWIGPythonRunScriptKeywordProcess (const char* python_function_name,
const char* session_dictionary_name,
lldb::ProcessSP& process,
std::string& output);
extern "C" bool
LLDBSWIGPythonRunScriptKeywordThread (const char* python_function_name,
const char* session_dictionary_name,
lldb::ThreadSP& thread,
std::string& output);
extern "C" bool
LLDBSWIGPythonRunScriptKeywordTarget (const char* python_function_name,
const char* session_dictionary_name,
lldb::TargetSP& target,
std::string& output);
extern "C" bool
LLDBSWIGPythonRunScriptKeywordFrame (const char* python_function_name,
const char* session_dictionary_name,
lldb::StackFrameSP& frame,
std::string& output);
extern "C" bool
LLDBSWIGPythonRunScriptKeywordValue (const char* python_function_name,
const char* session_dictionary_name,
lldb::ValueObjectSP& value,
std::string& output);
extern "C" void*
LLDBSWIGPython_GetDynamicSetting (void* module,
const char* setting,
const lldb::TargetSP& target_sp);
#endif
SystemInitializerFull::SystemInitializerFull()
{
}
SystemInitializerFull::~SystemInitializerFull()
{
}
void
SystemInitializerFull::Initialize()
{
InitializeSWIG();
SystemInitializerCommon::Initialize();
// Initialize LLVM and Clang
llvm::InitializeAllTargets();
llvm::InitializeAllAsmPrinters();
llvm::InitializeAllTargetMCs();
llvm::InitializeAllDisassemblers();
ABIMacOSX_i386::Initialize();
ABIMacOSX_arm::Initialize();
ABIMacOSX_arm64::Initialize();
ABISysV_x86_64::Initialize();
ABISysV_ppc::Initialize();
ABISysV_ppc64::Initialize();
DisassemblerLLVMC::Initialize();
JITLoaderGDB::Initialize();
ProcessElfCore::Initialize();
MemoryHistoryASan::Initialize();
AddressSanitizerRuntime::Initialize();
SymbolVendorELF::Initialize();
SymbolFileDWARF::Initialize();
SymbolFileSymtab::Initialize();
UnwindAssemblyInstEmulation::Initialize();
UnwindAssembly_x86::Initialize();
EmulateInstructionARM::Initialize();
EmulateInstructionARM64::Initialize();
EmulateInstructionMIPS64::Initialize();
SymbolFileDWARFDebugMap::Initialize();
ItaniumABILanguageRuntime::Initialize();
AppleObjCRuntimeV2::Initialize();
AppleObjCRuntimeV1::Initialize();
SystemRuntimeMacOSX::Initialize();
#if defined(__linux__)
//----------------------------------------------------------------------
// Linux hosted plugins
//----------------------------------------------------------------------
ProcessLinux::Initialize();
#endif
#if defined(_MSC_VER)
DynamicLoaderWindows::Initialize();
ProcessWindows::Initialize();
#endif
#if defined(__FreeBSD__)
ProcessFreeBSD::Initialize();
#endif
#if defined(__APPLE__)
SymbolVendorMacOSX::Initialize();
ProcessKDP::Initialize();
ProcessMachCore::Initialize();
#endif
//----------------------------------------------------------------------
// Platform agnostic plugins
//----------------------------------------------------------------------
platform_gdb_server::PlatformRemoteGDBServer::Initialize();
process_gdb_remote::ProcessGDBRemote::Initialize();
DynamicLoaderStatic::Initialize();
// Scan for any system or user LLDB plug-ins
PluginManager::Initialize();
// The process settings need to know about installed plug-ins, so the Settings must be initialized
// AFTER PluginManager::Initialize is called.
Debugger::SettingsInitialize();
}
void SystemInitializerFull::InitializeSWIG()
{
#if !defined(LLDB_DISABLE_PYTHON)
ScriptInterpreterPython::InitializeInterpreter(
init_lldb,
LLDBSwigPythonBreakpointCallbackFunction,
LLDBSwigPythonWatchpointCallbackFunction,
LLDBSwigPythonCallTypeScript,
LLDBSwigPythonCreateSyntheticProvider,
LLDBSwigPythonCreateCommandObject,
LLDBSwigPython_CalculateNumChildren,
LLDBSwigPython_GetChildAtIndex,
LLDBSwigPython_GetIndexOfChildWithName,
LLDBSWIGPython_CastPyObjectToSBValue,
LLDBSWIGPython_GetValueObjectSPFromSBValue,
LLDBSwigPython_UpdateSynthProviderInstance,
LLDBSwigPython_MightHaveChildrenSynthProviderInstance,
LLDBSwigPython_GetValueSynthProviderInstance,
LLDBSwigPythonCallCommand,
LLDBSwigPythonCallCommandObject,
LLDBSwigPythonCallModuleInit,
LLDBSWIGPythonCreateOSPlugin,
LLDBSWIGPythonRunScriptKeywordProcess,
LLDBSWIGPythonRunScriptKeywordThread,
LLDBSWIGPythonRunScriptKeywordTarget,
LLDBSWIGPythonRunScriptKeywordFrame,
LLDBSWIGPythonRunScriptKeywordValue,
LLDBSWIGPython_GetDynamicSetting,
LLDBSwigPythonCreateScriptedThreadPlan,
LLDBSWIGPythonCallThreadPlan);
#endif
}
void
SystemInitializerFull::Terminate()
{
Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
Debugger::SettingsTerminate();
// Terminate and unload and loaded system or user LLDB plug-ins
PluginManager::Terminate();
ABIMacOSX_i386::Terminate();
ABIMacOSX_arm::Terminate();
ABIMacOSX_arm64::Terminate();
ABISysV_x86_64::Terminate();
ABISysV_ppc::Terminate();
ABISysV_ppc64::Terminate();
DisassemblerLLVMC::Terminate();
JITLoaderGDB::Terminate();
ProcessElfCore::Terminate();
MemoryHistoryASan::Terminate();
AddressSanitizerRuntime::Terminate();
SymbolVendorELF::Terminate();
SymbolFileDWARF::Terminate();
SymbolFileSymtab::Terminate();
UnwindAssembly_x86::Terminate();
UnwindAssemblyInstEmulation::Terminate();
EmulateInstructionARM::Terminate();
EmulateInstructionARM64::Terminate();
EmulateInstructionMIPS64::Terminate();
SymbolFileDWARFDebugMap::Terminate();
ItaniumABILanguageRuntime::Terminate();
AppleObjCRuntimeV2::Terminate();
AppleObjCRuntimeV1::Terminate();
SystemRuntimeMacOSX::Terminate();
#if defined(__APPLE__)
ProcessMachCore::Terminate();
ProcessKDP::Terminate();
SymbolVendorMacOSX::Terminate();
#endif
#if defined(_MSC_VER)
DynamicLoaderWindows::Terminate();
#endif
#if defined(__linux__)
ProcessLinux::Terminate();
#endif
#if defined(__FreeBSD__)
ProcessFreeBSD::Terminate();
#endif
Debugger::SettingsTerminate();
platform_gdb_server::PlatformRemoteGDBServer::Terminate();
process_gdb_remote::ProcessGDBRemote::Terminate();
DynamicLoaderStatic::Terminate();
// Now shutdown the common parts, in reverse order.
SystemInitializerCommon::Terminate();
}
void SystemInitializerFull::TerminateSWIG()
{
}

View File

@ -38,7 +38,6 @@
#include "lldb/Host/HostInfo.h" #include "lldb/Host/HostInfo.h"
#include "lldb/Host/Terminal.h" #include "lldb/Host/Terminal.h"
#include "lldb/Host/ThreadLauncher.h" #include "lldb/Host/ThreadLauncher.h"
#include "lldb/Initialization/InitializeLLDB.h"
#include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/OptionValueProperties.h" #include "lldb/Interpreter/OptionValueProperties.h"
#include "lldb/Interpreter/OptionValueSInt64.h" #include "lldb/Interpreter/OptionValueSInt64.h"
@ -65,7 +64,6 @@ using namespace lldb;
using namespace lldb_private; using namespace lldb_private;
static uint32_t g_shared_debugger_refcount = 0;
static lldb::user_id_t g_unique_id = 1; static lldb::user_id_t g_unique_id = 1;
static size_t g_debugger_event_thread_stack_bytes = 8 * 1024 * 1024; static size_t g_debugger_event_thread_stack_bytes = 8 * 1024 * 1024;
@ -407,35 +405,24 @@ Debugger::GetEscapeNonPrintables () const
//} //}
// //
int static bool lldb_initialized = false;
Debugger::TestDebuggerRefCount ()
{
return g_shared_debugger_refcount;
}
static bool lldb_initialized = true;
void void
Debugger::Initialize(LoadPluginCallbackType load_plugin_callback) Debugger::Initialize(LoadPluginCallbackType load_plugin_callback)
{ {
assert(!lldb_initialized && "Debugger::Initialize called more than once!");
lldb_initialized = true; lldb_initialized = true;
g_shared_debugger_refcount++;
g_load_plugin_callback = load_plugin_callback; g_load_plugin_callback = load_plugin_callback;
} }
int void
Debugger::Terminate () Debugger::Terminate ()
{ {
if (g_shared_debugger_refcount > 0) assert(lldb_initialized && "Debugger::Terminate called without a matching Debugger::Initialize!");
{
g_shared_debugger_refcount--; // Clear our master list of debugger objects
if (g_shared_debugger_refcount == 0) Mutex::Locker locker (GetDebuggerListMutex ());
{ GetDebuggerList().clear();
// Clear our master list of debugger objects
Mutex::Locker locker (GetDebuggerListMutex ());
GetDebuggerList().clear();
}
}
return g_shared_debugger_refcount;
} }
void void
@ -568,7 +555,7 @@ DebuggerSP
Debugger::CreateInstance (lldb::LogOutputCallback log_callback, void *baton) Debugger::CreateInstance (lldb::LogOutputCallback log_callback, void *baton)
{ {
DebuggerSP debugger_sp (new Debugger(log_callback, baton)); DebuggerSP debugger_sp (new Debugger(log_callback, baton));
if (g_shared_debugger_refcount > 0) if (lldb_initialized)
{ {
Mutex::Locker locker (GetDebuggerListMutex ()); Mutex::Locker locker (GetDebuggerListMutex ());
GetDebuggerList().push_back(debugger_sp); GetDebuggerList().push_back(debugger_sp);
@ -585,7 +572,7 @@ Debugger::Destroy (DebuggerSP &debugger_sp)
debugger_sp->Clear(); debugger_sp->Clear();
if (g_shared_debugger_refcount > 0) if (lldb_initialized)
{ {
Mutex::Locker locker (GetDebuggerListMutex ()); Mutex::Locker locker (GetDebuggerListMutex ());
DebuggerList &debugger_list = GetDebuggerList (); DebuggerList &debugger_list = GetDebuggerList ();
@ -605,7 +592,7 @@ DebuggerSP
Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name) Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
{ {
DebuggerSP debugger_sp; DebuggerSP debugger_sp;
if (g_shared_debugger_refcount > 0) if (lldb_initialized)
{ {
Mutex::Locker locker (GetDebuggerListMutex ()); Mutex::Locker locker (GetDebuggerListMutex ());
DebuggerList &debugger_list = GetDebuggerList(); DebuggerList &debugger_list = GetDebuggerList();
@ -627,7 +614,7 @@ TargetSP
Debugger::FindTargetWithProcessID (lldb::pid_t pid) Debugger::FindTargetWithProcessID (lldb::pid_t pid)
{ {
TargetSP target_sp; TargetSP target_sp;
if (g_shared_debugger_refcount > 0) if (lldb_initialized)
{ {
Mutex::Locker locker (GetDebuggerListMutex ()); Mutex::Locker locker (GetDebuggerListMutex ());
DebuggerList &debugger_list = GetDebuggerList(); DebuggerList &debugger_list = GetDebuggerList();
@ -646,7 +633,7 @@ TargetSP
Debugger::FindTargetWithProcess (Process *process) Debugger::FindTargetWithProcess (Process *process)
{ {
TargetSP target_sp; TargetSP target_sp;
if (g_shared_debugger_refcount > 0) if (lldb_initialized)
{ {
Mutex::Locker locker (GetDebuggerListMutex ()); Mutex::Locker locker (GetDebuggerListMutex ());
DebuggerList &debugger_list = GetDebuggerList(); DebuggerList &debugger_list = GetDebuggerList();
@ -1129,7 +1116,7 @@ Debugger::GetAsyncErrorStream ()
size_t size_t
Debugger::GetNumDebuggers() Debugger::GetNumDebuggers()
{ {
if (g_shared_debugger_refcount > 0) if (lldb_initialized)
{ {
Mutex::Locker locker (GetDebuggerListMutex ()); Mutex::Locker locker (GetDebuggerListMutex ());
return GetDebuggerList().size(); return GetDebuggerList().size();
@ -1142,7 +1129,7 @@ Debugger::GetDebuggerAtIndex (size_t index)
{ {
DebuggerSP debugger_sp; DebuggerSP debugger_sp;
if (g_shared_debugger_refcount > 0) if (lldb_initialized)
{ {
Mutex::Locker locker (GetDebuggerListMutex ()); Mutex::Locker locker (GetDebuggerListMutex ());
DebuggerList &debugger_list = GetDebuggerList(); DebuggerList &debugger_list = GetDebuggerList();
@ -1159,7 +1146,7 @@ Debugger::FindDebuggerWithID (lldb::user_id_t id)
{ {
DebuggerSP debugger_sp; DebuggerSP debugger_sp;
if (g_shared_debugger_refcount > 0) if (lldb_initialized)
{ {
Mutex::Locker locker (GetDebuggerListMutex ()); Mutex::Locker locker (GetDebuggerListMutex ());
DebuggerList &debugger_list = GetDebuggerList(); DebuggerList &debugger_list = GetDebuggerList();

View File

@ -1,3 +1,5 @@
add_lldb_library(lldbInitialization add_lldb_library(lldbInitialization
InitializeLLDB.cpp SystemInitializerCommon.cpp
SystemInitializer.cpp
SystemLifetimeManager.cpp
) )

View File

@ -1,400 +0,0 @@
//===-- InitializeLLDB.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/Core/Debugger.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/Timer.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Host/Mutex.h"
#include "lldb/Initialization/InitializeLLDB.h"
#include "lldb/Interpreter/ScriptInterpreterPython.h"
#include "Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h"
#include "Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h"
#include "Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h"
#include "Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h"
#include "Plugins/ABI/SysV-ppc/ABISysV_ppc.h"
#include "Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h"
#include "Plugins/Disassembler/llvm/DisassemblerLLVMC.h"
#include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h"
#include "Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h"
#include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h"
#include "Plugins/Instruction/ARM/EmulateInstructionARM.h"
#include "Plugins/Instruction/ARM64/EmulateInstructionARM64.h"
#include "Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h"
#include "Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.h"
#include "Plugins/JITLoader/GDB/JITLoaderGDB.h"
#include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h"
#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h"
#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h"
#include "Plugins/MemoryHistory/asan/MemoryHistoryASan.h"
#include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h"
#include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h"
#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
#include "Plugins/OperatingSystem/Python/OperatingSystemPython.h"
#include "Plugins/Platform/Android/PlatformAndroid.h"
#include "Plugins/Platform/FreeBSD/PlatformFreeBSD.h"
#include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h"
#include "Plugins/Platform/Kalimba/PlatformKalimba.h"
#include "Plugins/Platform/Linux/PlatformLinux.h"
#include "Plugins/Platform/MacOSX/PlatformiOSSimulator.h"
#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
#include "Plugins/Platform/MacOSX/PlatformRemoteiOS.h"
#include "Plugins/Platform/Windows/PlatformWindows.h"
#include "Plugins/Process/elf-core/ProcessElfCore.h"
#include "Plugins/Process/gdb-remote/ProcessGDBRemote.h"
#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
#include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h"
#include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h"
#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
#include "Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h"
#include "Plugins/UnwindAssembly/x86/UnwindAssembly-x86.h"
#include "Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h"
#if defined(__APPLE__)
#include "Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h"
#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
#include "Plugins/Platform/MacOSX/PlatformDarwinKernel.h"
#include "Plugins/Process/mach-core/ProcessMachCore.h"
#include "Plugins/Process/MacOSX-Kernel/ProcessKDP.h"
#include "Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h"
#endif
#if defined(__FreeBSD__)
#include "Plugins/Process/FreeBSD/ProcessFreeBSD.h"
#endif
#if defined(__linux__)
#include "Plugins/Process/Linux/ProcessLinux.h"
#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
#endif
#if defined(_MSC_VER)
#include "lldb/Host/windows/windows.h"
#include "Plugins/Process/Windows/DynamicLoaderWindows.h"
#include "Plugins/Process/Windows/ProcessWindows.h"
#endif
#include "llvm/Support/TargetSelect.h"
#include <string>
using namespace lldb_private;
static void
fatal_error_handler(void *user_data, const std::string &reason, bool gen_crash_diag)
{
Host::SetCrashDescription(reason.c_str());
::abort();
}
static bool g_inited_for_llgs = false;
static void
InitializeForLLGSPrivate()
{
if (g_inited_for_llgs)
return;
g_inited_for_llgs = true;
#if defined(_MSC_VER)
const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");
if (disable_crash_dialog_var && llvm::StringRef(disable_crash_dialog_var).equals_lower("true"))
{
// This will prevent Windows from displaying a dialog box requiring user interaction when
// LLDB crashes. This is mostly useful when automating LLDB, for example via the test
// suite, so that a crash in LLDB does not prevent completion of the test suite.
::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
}
#endif
Log::Initialize();
HostInfo::Initialize();
Timer::Initialize();
Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
llvm::install_fatal_error_handler(fatal_error_handler, 0);
process_gdb_remote::ProcessGDBRemoteLog::Initialize();
// Initialize plug-ins
ObjectContainerBSDArchive::Initialize();
ObjectFileELF::Initialize();
ObjectFilePECOFF::Initialize();
DynamicLoaderPOSIXDYLD::Initialize();
PlatformFreeBSD::Initialize();
platform_linux::PlatformLinux::Initialize();
PlatformWindows::Initialize();
PlatformKalimba::Initialize();
platform_android::PlatformAndroid::Initialize();
//----------------------------------------------------------------------
// Apple/Darwin hosted plugins
//----------------------------------------------------------------------
DynamicLoaderMacOSXDYLD::Initialize();
ObjectContainerUniversalMachO::Initialize();
PlatformRemoteiOS::Initialize();
PlatformMacOSX::Initialize();
PlatformiOSSimulator::Initialize();
#if defined(__APPLE__)
DynamicLoaderDarwinKernel::Initialize();
PlatformDarwinKernel::Initialize();
ObjectFileMachO::Initialize();
#endif
#if defined(__linux__)
static ConstString g_linux_log_name("linux");
ProcessPOSIXLog::Initialize(g_linux_log_name);
#endif
#ifndef LLDB_DISABLE_PYTHON
ScriptInterpreterPython::InitializePrivate();
OperatingSystemPython::Initialize();
#endif
}
static bool g_inited = false;
static void
InitializePrivate()
{
if (g_inited)
return;
g_inited = true;
InitializeForLLGSPrivate();
// Initialize LLVM and Clang
llvm::InitializeAllTargets();
llvm::InitializeAllAsmPrinters();
llvm::InitializeAllTargetMCs();
llvm::InitializeAllDisassemblers();
ABIMacOSX_i386::Initialize();
ABIMacOSX_arm::Initialize();
ABIMacOSX_arm64::Initialize();
ABISysV_x86_64::Initialize();
ABISysV_ppc::Initialize();
ABISysV_ppc64::Initialize();
DisassemblerLLVMC::Initialize();
JITLoaderGDB::Initialize();
ProcessElfCore::Initialize();
MemoryHistoryASan::Initialize();
AddressSanitizerRuntime::Initialize();
SymbolVendorELF::Initialize();
SymbolFileDWARF::Initialize();
SymbolFileSymtab::Initialize();
UnwindAssemblyInstEmulation::Initialize();
UnwindAssembly_x86::Initialize();
EmulateInstructionARM::Initialize();
EmulateInstructionARM64::Initialize();
EmulateInstructionMIPS64::Initialize();
SymbolFileDWARFDebugMap::Initialize();
ItaniumABILanguageRuntime::Initialize();
AppleObjCRuntimeV2::Initialize();
AppleObjCRuntimeV1::Initialize();
SystemRuntimeMacOSX::Initialize();
#if defined(__linux__)
//----------------------------------------------------------------------
// Linux hosted plugins
//----------------------------------------------------------------------
process_linux::ProcessLinux::Initialize();
#endif
#if defined(_MSC_VER)
DynamicLoaderWindows::Initialize();
ProcessWindows::Initialize();
#endif
#if defined(__FreeBSD__)
ProcessFreeBSD::Initialize();
#endif
#if defined(__APPLE__)
SymbolVendorMacOSX::Initialize();
ProcessKDP::Initialize();
ProcessMachCore::Initialize();
#endif
//----------------------------------------------------------------------
// Platform agnostic plugins
//----------------------------------------------------------------------
platform_gdb_server::PlatformRemoteGDBServer::Initialize();
process_gdb_remote::ProcessGDBRemote::Initialize();
DynamicLoaderStatic::Initialize();
// Scan for any system or user LLDB plug-ins
PluginManager::Initialize();
// The process settings need to know about installed plug-ins, so the Settings must be initialized
// AFTER PluginManager::Initialize is called.
Debugger::SettingsInitialize();
}
static void
TerminateForLLGSPrivate()
{
if (!g_inited_for_llgs)
return;
g_inited_for_llgs = false;
Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
ObjectContainerBSDArchive::Terminate();
ObjectFileELF::Terminate();
ObjectFilePECOFF::Terminate();
DynamicLoaderPOSIXDYLD::Terminate();
PlatformFreeBSD::Terminate();
platform_linux::PlatformLinux::Terminate();
PlatformWindows::Terminate();
PlatformKalimba::Terminate();
platform_android::PlatformAndroid::Terminate();
DynamicLoaderMacOSXDYLD::Terminate();
ObjectContainerUniversalMachO::Terminate();
PlatformMacOSX::Terminate();
PlatformRemoteiOS::Terminate();
PlatformiOSSimulator::Terminate();
#if defined(__APPLE__)
DynamicLoaderDarwinKernel::Terminate();
ObjectFileMachO::Terminate();
PlatformDarwinKernel::Terminate();
#endif
#ifndef LLDB_DISABLE_PYTHON
OperatingSystemPython::Terminate();
#endif
Log::Terminate();
}
static void
TerminatePrivate()
{
if (!g_inited)
return;
g_inited = false;
Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
// Terminate and unload and loaded system or user LLDB plug-ins
PluginManager::Terminate();
ABIMacOSX_i386::Terminate();
ABIMacOSX_arm::Terminate();
ABIMacOSX_arm64::Terminate();
ABISysV_x86_64::Terminate();
ABISysV_ppc::Terminate();
ABISysV_ppc64::Terminate();
DisassemblerLLVMC::Terminate();
JITLoaderGDB::Terminate();
ProcessElfCore::Terminate();
MemoryHistoryASan::Terminate();
AddressSanitizerRuntime::Terminate();
SymbolVendorELF::Terminate();
SymbolFileDWARF::Terminate();
SymbolFileSymtab::Terminate();
UnwindAssembly_x86::Terminate();
UnwindAssemblyInstEmulation::Terminate();
EmulateInstructionARM::Terminate();
EmulateInstructionARM64::Terminate();
EmulateInstructionMIPS64::Terminate();
SymbolFileDWARFDebugMap::Terminate();
ItaniumABILanguageRuntime::Terminate();
AppleObjCRuntimeV2::Terminate();
AppleObjCRuntimeV1::Terminate();
SystemRuntimeMacOSX::Terminate();
#if defined(__APPLE__)
ProcessMachCore::Terminate();
ProcessKDP::Terminate();
SymbolVendorMacOSX::Terminate();
#endif
#if defined(_MSC_VER)
DynamicLoaderWindows::Terminate();
#endif
#if defined(__linux__)
process_linux::ProcessLinux::Terminate();
#endif
#if defined(__FreeBSD__)
ProcessFreeBSD::Terminate();
#endif
Debugger::SettingsTerminate();
platform_gdb_server::PlatformRemoteGDBServer::Terminate();
process_gdb_remote::ProcessGDBRemote::Terminate();
DynamicLoaderStatic::Terminate();
TerminateForLLGSPrivate();
}
void
lldb_private::InitializeForLLGS(LoadPluginCallbackType load_plugin_callback)
{
// Make sure we initialize only once
static Mutex g_inited_mutex(Mutex::eMutexTypeRecursive);
Mutex::Locker locker(g_inited_mutex);
// Call the actual initializers. If we've already been initialized this
// will do nothing.
InitializeForLLGSPrivate();
// We want to call Debuger::Initialize every time, even if we've already
// been initialized, so that the debugger ref count increases.
Debugger::Initialize(load_plugin_callback);
}
void
lldb_private::Initialize(LoadPluginCallbackType load_plugin_callback)
{
// Make sure we initialize only once
static Mutex g_inited_mutex(Mutex::eMutexTypeRecursive);
Mutex::Locker locker(g_inited_mutex);
// Call the actual initializers. If we've already been initialized this
// will do nothing.
InitializeForLLGSPrivate();
InitializePrivate();
// We want to call Debuger::Initialize every time, even if we've already
// been initialized, so that the debugger ref count increases.
Debugger::Initialize(load_plugin_callback);
}
void
lldb_private::TerminateLLGS()
{
// Terminate the debugger. If the ref count is still greater than 0, we
// shouldn't shutdown yet.
if (Debugger::Terminate() > 0)
return;
TerminateForLLGSPrivate();
}
void
lldb_private::Terminate()
{
// Terminate the debugger. If the ref count is still greater than 0, we
// shouldn't shutdown yet.
if (Debugger::Terminate() > 0)
return;
TerminatePrivate();
}

View File

@ -0,0 +1,20 @@
//===-- SystemInitializer.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/Initialization/SystemInitializer.h"
using namespace lldb_private;
SystemInitializer::SystemInitializer()
{
}
SystemInitializer::~SystemInitializer()
{
}

View File

@ -0,0 +1,167 @@
//===-- SystemInitializerCommon.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/Initialization/SystemInitializerCommon.h"
#include "lldb/Host/Host.h"
#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"
#include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h"
#include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h"
#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
#include "Plugins/OperatingSystem/Python/OperatingSystemPython.h"
#include "Plugins/Platform/Android/PlatformAndroid.h"
#include "Plugins/Platform/FreeBSD/PlatformFreeBSD.h"
#include "Plugins/Platform/Kalimba/PlatformKalimba.h"
#include "Plugins/Platform/Linux/PlatformLinux.h"
#include "Plugins/Platform/MacOSX/PlatformiOSSimulator.h"
#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
#include "Plugins/Platform/MacOSX/PlatformRemoteiOS.h"
#include "Plugins/Platform/Windows/PlatformWindows.h"
#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
#if defined(__APPLE__)
#include "Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h"
#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
#include "Plugins/Platform/MacOSX/PlatformDarwinKernel.h"
#endif
#if defined(__linux__)
#include "Plugins/Process/Linux/ProcessLinux.h"
#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
#endif
#if defined(_MSC_VER)
#include "lldb/Host/windows/windows.h"
#endif
#include "llvm/Support/TargetSelect.h"
#include <string>
using namespace lldb_private;
static void
fatal_error_handler(void *user_data, const std::string &reason, bool gen_crash_diag)
{
Host::SetCrashDescription(reason.c_str());
::abort();
}
SystemInitializerCommon::SystemInitializerCommon()
{
}
SystemInitializerCommon::~SystemInitializerCommon()
{
}
void
SystemInitializerCommon::Initialize()
{
#if defined(_MSC_VER)
const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");
if (disable_crash_dialog_var && llvm::StringRef(disable_crash_dialog_var).equals_lower("true"))
{
// This will prevent Windows from displaying a dialog box requiring user interaction when
// LLDB crashes. This is mostly useful when automating LLDB, for example via the test
// suite, so that a crash in LLDB does not prevent completion of the test suite.
::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
}
#endif
Log::Initialize();
HostInfo::Initialize();
Timer::Initialize();
Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
llvm::install_fatal_error_handler(fatal_error_handler, 0);
process_gdb_remote::ProcessGDBRemoteLog::Initialize();
// Initialize plug-ins
ObjectContainerBSDArchive::Initialize();
ObjectFileELF::Initialize();
ObjectFilePECOFF::Initialize();
DynamicLoaderPOSIXDYLD::Initialize();
PlatformFreeBSD::Initialize();
platform_linux::PlatformLinux::Initialize();
PlatformWindows::Initialize();
PlatformKalimba::Initialize();
platform_android::PlatformAndroid::Initialize();
//----------------------------------------------------------------------
// Apple/Darwin hosted plugins
//----------------------------------------------------------------------
DynamicLoaderMacOSXDYLD::Initialize();
ObjectContainerUniversalMachO::Initialize();
PlatformRemoteiOS::Initialize();
PlatformMacOSX::Initialize();
PlatformiOSSimulator::Initialize();
#if defined(__APPLE__)
DynamicLoaderDarwinKernel::Initialize();
PlatformDarwinKernel::Initialize();
ObjectFileMachO::Initialize();
#endif
#if defined(__linux__)
static ConstString g_linux_log_name("linux");
ProcessPOSIXLog::Initialize(g_linux_log_name);
#endif
#ifndef LLDB_DISABLE_PYTHON
ScriptInterpreterPython::InitializePrivate();
OperatingSystemPython::Initialize();
#endif
}
void
SystemInitializerCommon::Terminate()
{
Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
ObjectContainerBSDArchive::Terminate();
ObjectFileELF::Terminate();
ObjectFilePECOFF::Terminate();
DynamicLoaderPOSIXDYLD::Terminate();
PlatformFreeBSD::Terminate();
platform_linux::PlatformLinux::Terminate();
PlatformWindows::Terminate();
PlatformKalimba::Terminate();
platform_android::PlatformAndroid::Terminate();
DynamicLoaderMacOSXDYLD::Terminate();
ObjectContainerUniversalMachO::Terminate();
PlatformMacOSX::Terminate();
PlatformRemoteiOS::Terminate();
PlatformiOSSimulator::Terminate();
#if defined(__APPLE__)
DynamicLoaderDarwinKernel::Terminate();
ObjectFileMachO::Terminate();
PlatformDarwinKernel::Terminate();
#endif
#ifndef LLDB_DISABLE_PYTHON
OperatingSystemPython::Terminate();
#endif
Log::Terminate();
}

View File

@ -0,0 +1,61 @@
//===-- SystemLifetimeManager.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/Initialization/SystemLifetimeManager.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Host/Mutex.h"
#include "lldb/Initialization/SystemInitializer.h"
#include <utility>
using namespace lldb_private;
SystemLifetimeManager::SystemLifetimeManager()
: m_mutex(Mutex::eMutexTypeRecursive)
, m_initialized(false)
{
}
SystemLifetimeManager::~SystemLifetimeManager()
{
assert(!m_initialized && "SystemLifetimeManager destroyed without calling Terminate!");
}
void
SystemLifetimeManager::Initialize(std::unique_ptr<SystemInitializer> initializer,
LoadPluginCallbackType plugin_callback)
{
Mutex::Locker locker(m_mutex);
if (!m_initialized)
{
assert(!m_initializer &&
"Attempting to call SystemLifetimeManager::Initialize() when it is already initialized");
m_initialized = true;
m_initializer = std::move(initializer);
m_initializer->Initialize();
Debugger::Initialize(plugin_callback);
}
}
void
SystemLifetimeManager::Terminate()
{
Mutex::Locker locker(m_mutex);
if (m_initialized)
{
Debugger::Terminate();
m_initializer->Terminate();
m_initializer.reset();
m_initialized = false;
}
}

View File

@ -110,61 +110,3 @@ ScriptInterpreter::AcquireInterpreterLock ()
{ {
return std::unique_ptr<ScriptInterpreterLocker>(new ScriptInterpreterLocker()); return std::unique_ptr<ScriptInterpreterLocker>(new ScriptInterpreterLocker());
} }
void
ScriptInterpreter::InitializeInterpreter (SWIGInitCallback python_swig_init_callback,
SWIGBreakpointCallbackFunction swig_breakpoint_callback,
SWIGWatchpointCallbackFunction swig_watchpoint_callback,
SWIGPythonTypeScriptCallbackFunction swig_typescript_callback,
SWIGPythonCreateSyntheticProvider swig_synthetic_script,
SWIGPythonCreateCommandObject swig_create_cmd,
SWIGPythonCalculateNumChildren swig_calc_children,
SWIGPythonGetChildAtIndex swig_get_child_index,
SWIGPythonGetIndexOfChildWithName swig_get_index_child,
SWIGPythonCastPyObjectToSBValue swig_cast_to_sbvalue ,
SWIGPythonGetValueObjectSPFromSBValue swig_get_valobj_sp_from_sbvalue,
SWIGPythonUpdateSynthProviderInstance swig_update_provider,
SWIGPythonMightHaveChildrenSynthProviderInstance swig_mighthavechildren_provider,
SWIGPythonGetValueSynthProviderInstance swig_getvalue_provider,
SWIGPythonCallCommand swig_call_command,
SWIGPythonCallCommandObject swig_call_command_object,
SWIGPythonCallModuleInit swig_call_module_init,
SWIGPythonCreateOSPlugin swig_create_os_plugin,
SWIGPythonScriptKeyword_Process swig_run_script_keyword_process,
SWIGPythonScriptKeyword_Thread swig_run_script_keyword_thread,
SWIGPythonScriptKeyword_Target swig_run_script_keyword_target,
SWIGPythonScriptKeyword_Frame swig_run_script_keyword_frame,
SWIGPythonScriptKeyword_Value swig_run_script_keyword_value,
SWIGPython_GetDynamicSetting swig_plugin_get,
SWIGPythonCreateScriptedThreadPlan swig_thread_plan_script,
SWIGPythonCallThreadPlan swig_call_thread_plan)
{
#ifndef LLDB_DISABLE_PYTHON
ScriptInterpreterPython::InitializeInterpreter (python_swig_init_callback,
swig_breakpoint_callback,
swig_watchpoint_callback,
swig_typescript_callback,
swig_synthetic_script,
swig_create_cmd,
swig_calc_children,
swig_get_child_index,
swig_get_index_child,
swig_cast_to_sbvalue ,
swig_get_valobj_sp_from_sbvalue,
swig_update_provider,
swig_mighthavechildren_provider,
swig_getvalue_provider,
swig_call_command,
swig_call_command_object,
swig_call_module_init,
swig_create_os_plugin,
swig_run_script_keyword_process,
swig_run_script_keyword_thread,
swig_run_script_keyword_target,
swig_run_script_keyword_frame,
swig_run_script_keyword_value,
swig_plugin_get,
swig_thread_plan_script,
swig_call_thread_plan);
#endif // #ifndef LLDB_DISABLE_PYTHON
}

View File

@ -48,33 +48,34 @@
using namespace lldb; using namespace lldb;
using namespace lldb_private; using namespace lldb_private;
static ScriptInterpreterPython::SWIGInitCallback g_swig_init_callback = nullptr;
static ScriptInterpreterPython::SWIGBreakpointCallbackFunction g_swig_breakpoint_callback = nullptr;
static ScriptInterpreterPython::SWIGWatchpointCallbackFunction g_swig_watchpoint_callback = nullptr;
static ScriptInterpreterPython::SWIGPythonTypeScriptCallbackFunction g_swig_typescript_callback = nullptr;
static ScriptInterpreterPython::SWIGPythonCreateSyntheticProvider g_swig_synthetic_script = nullptr;
static ScriptInterpreterPython::SWIGPythonCreateCommandObject g_swig_create_cmd = nullptr;
static ScriptInterpreterPython::SWIGPythonCalculateNumChildren g_swig_calc_children = nullptr;
static ScriptInterpreterPython::SWIGPythonGetChildAtIndex g_swig_get_child_index = nullptr;
static ScriptInterpreterPython::SWIGPythonGetIndexOfChildWithName g_swig_get_index_child = nullptr;
static ScriptInterpreterPython::SWIGPythonCastPyObjectToSBValue g_swig_cast_to_sbvalue = nullptr;
static ScriptInterpreterPython::SWIGPythonGetValueObjectSPFromSBValue g_swig_get_valobj_sp_from_sbvalue = nullptr;
static ScriptInterpreterPython::SWIGPythonUpdateSynthProviderInstance g_swig_update_provider = nullptr;
static ScriptInterpreterPython::SWIGPythonMightHaveChildrenSynthProviderInstance g_swig_mighthavechildren_provider = nullptr;
static ScriptInterpreterPython::SWIGPythonGetValueSynthProviderInstance g_swig_getvalue_provider = nullptr;
static ScriptInterpreterPython::SWIGPythonCallCommand g_swig_call_command = nullptr;
static ScriptInterpreterPython::SWIGPythonCallCommandObject g_swig_call_command_object = nullptr;
static ScriptInterpreterPython::SWIGPythonCallModuleInit g_swig_call_module_init = nullptr;
static ScriptInterpreterPython::SWIGPythonCreateOSPlugin g_swig_create_os_plugin = nullptr;
static ScriptInterpreterPython::SWIGPythonScriptKeyword_Process g_swig_run_script_keyword_process = nullptr;
static ScriptInterpreterPython::SWIGPythonScriptKeyword_Thread g_swig_run_script_keyword_thread = nullptr;
static ScriptInterpreterPython::SWIGPythonScriptKeyword_Target g_swig_run_script_keyword_target = nullptr;
static ScriptInterpreterPython::SWIGPythonScriptKeyword_Frame g_swig_run_script_keyword_frame = nullptr;
static ScriptInterpreterPython::SWIGPythonScriptKeyword_Value g_swig_run_script_keyword_value = nullptr;
static ScriptInterpreterPython::SWIGPython_GetDynamicSetting g_swig_plugin_get = nullptr;
static ScriptInterpreterPython::SWIGPythonCreateScriptedThreadPlan g_swig_thread_plan_script = nullptr;
static ScriptInterpreterPython::SWIGPythonCallThreadPlan g_swig_call_thread_plan = nullptr;
static ScriptInterpreter::SWIGInitCallback g_swig_init_callback = nullptr; static bool g_initialized = false;
static ScriptInterpreter::SWIGBreakpointCallbackFunction g_swig_breakpoint_callback = nullptr;
static ScriptInterpreter::SWIGWatchpointCallbackFunction g_swig_watchpoint_callback = nullptr;
static ScriptInterpreter::SWIGPythonTypeScriptCallbackFunction g_swig_typescript_callback = nullptr;
static ScriptInterpreter::SWIGPythonCreateSyntheticProvider g_swig_synthetic_script = nullptr;
static ScriptInterpreter::SWIGPythonCreateCommandObject g_swig_create_cmd = nullptr;
static ScriptInterpreter::SWIGPythonCalculateNumChildren g_swig_calc_children = nullptr;
static ScriptInterpreter::SWIGPythonGetChildAtIndex g_swig_get_child_index = nullptr;
static ScriptInterpreter::SWIGPythonGetIndexOfChildWithName g_swig_get_index_child = nullptr;
static ScriptInterpreter::SWIGPythonCastPyObjectToSBValue g_swig_cast_to_sbvalue = nullptr;
static ScriptInterpreter::SWIGPythonGetValueObjectSPFromSBValue g_swig_get_valobj_sp_from_sbvalue = nullptr;
static ScriptInterpreter::SWIGPythonUpdateSynthProviderInstance g_swig_update_provider = nullptr;
static ScriptInterpreter::SWIGPythonMightHaveChildrenSynthProviderInstance g_swig_mighthavechildren_provider = nullptr;
static ScriptInterpreter::SWIGPythonGetValueSynthProviderInstance g_swig_getvalue_provider = nullptr;
static ScriptInterpreter::SWIGPythonCallCommand g_swig_call_command = nullptr;
static ScriptInterpreter::SWIGPythonCallCommandObject g_swig_call_command_object = nullptr;
static ScriptInterpreter::SWIGPythonCallModuleInit g_swig_call_module_init = nullptr;
static ScriptInterpreter::SWIGPythonCreateOSPlugin g_swig_create_os_plugin = nullptr;
static ScriptInterpreter::SWIGPythonScriptKeyword_Process g_swig_run_script_keyword_process = nullptr;
static ScriptInterpreter::SWIGPythonScriptKeyword_Thread g_swig_run_script_keyword_thread = nullptr;
static ScriptInterpreter::SWIGPythonScriptKeyword_Target g_swig_run_script_keyword_target = nullptr;
static ScriptInterpreter::SWIGPythonScriptKeyword_Frame g_swig_run_script_keyword_frame = nullptr;
static ScriptInterpreter::SWIGPythonScriptKeyword_Value g_swig_run_script_keyword_value = nullptr;
static ScriptInterpreter::SWIGPython_GetDynamicSetting g_swig_plugin_get = nullptr;
static ScriptInterpreter::SWIGPythonCreateScriptedThreadPlan g_swig_thread_plan_script = nullptr;
static ScriptInterpreter::SWIGPythonCallThreadPlan g_swig_call_thread_plan = nullptr;
static std::string static std::string
ReadPythonBacktrace (PyObject* py_backtrace); ReadPythonBacktrace (PyObject* py_backtrace);
@ -175,8 +176,7 @@ ScriptInterpreterPython::ScriptInterpreterPython (CommandInterpreter &interprete
m_lock_count (0), m_lock_count (0),
m_command_thread_state (nullptr) m_command_thread_state (nullptr)
{ {
assert(g_initialized && "ScriptInterpreterPython created but initialize has not been called!");
ScriptInterpreterPython::InitializePrivate ();
m_dictionary_name.append("_dict"); m_dictionary_name.append("_dict");
StreamString run_string; StreamString run_string;
@ -189,16 +189,6 @@ ScriptInterpreterPython::ScriptInterpreterPython (CommandInterpreter &interprete
run_string.Clear(); run_string.Clear();
// Importing 'lldb' module calls SBDebugger::Initialize, which calls Debugger::Initialize, which increments a
// global debugger ref-count; therefore we need to check the ref-count before and after importing lldb, and if the
// ref-count increased we need to call Debugger::Terminate here to decrement the ref-count so that when the final
// call to Debugger::Terminate is made, the ref-count has the correct value.
//
// Bonus question: Why doesn't the ref-count always increase? Because sometimes lldb has already been imported, in
// which case the code inside it, including the call to SBDebugger::Initialize(), does not get executed.
int old_count = Debugger::TestDebuggerRefCount();
run_string.Printf ("run_one_line (%s, 'import copy, keyword, os, re, sys, uuid, lldb')", m_dictionary_name.c_str()); run_string.Printf ("run_one_line (%s, 'import copy, keyword, os, re, sys, uuid, lldb')", m_dictionary_name.c_str());
PyRun_SimpleString (run_string.GetData()); PyRun_SimpleString (run_string.GetData());
@ -209,11 +199,6 @@ ScriptInterpreterPython::ScriptInterpreterPython (CommandInterpreter &interprete
PyRun_SimpleString (run_string.GetData()); PyRun_SimpleString (run_string.GetData());
run_string.Clear(); run_string.Clear();
int new_count = Debugger::TestDebuggerRefCount();
if (new_count > old_count)
Debugger::Terminate();
run_string.Printf ("run_one_line (%s, 'import lldb.embedded_interpreter; from lldb.embedded_interpreter import run_python_interpreter; from lldb.embedded_interpreter import run_one_line')", m_dictionary_name.c_str()); run_string.Printf ("run_one_line (%s, 'import lldb.embedded_interpreter; from lldb.embedded_interpreter import run_python_interpreter; from lldb.embedded_interpreter import run_one_line')", m_dictionary_name.c_str());
PyRun_SimpleString (run_string.GetData()); PyRun_SimpleString (run_string.GetData());
run_string.Clear(); run_string.Clear();
@ -3029,11 +3014,7 @@ ScriptInterpreterPython::InitializeInterpreter (SWIGInitCallback swig_init_callb
void void
ScriptInterpreterPython::InitializePrivate () ScriptInterpreterPython::InitializePrivate ()
{ {
static int g_initialized = false; assert(!g_initialized && "ScriptInterpreterPython::InitializePrivate() called more than once!");
if (g_initialized)
return;
g_initialized = true; g_initialized = true;
Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
@ -3057,7 +3038,6 @@ ScriptInterpreterPython::InitializePrivate ()
} }
Py_InitializeEx (0); Py_InitializeEx (0);
// Initialize SWIG after setting up python
if (g_swig_init_callback) if (g_swig_init_callback)
g_swig_init_callback (); g_swig_init_callback ();
@ -3095,20 +3075,8 @@ ScriptInterpreterPython::InitializePrivate ()
} }
} }
// Importing 'lldb' module calls SBDebugger::Initialize, which calls Debugger::Initialize, which increments a
// global debugger ref-count; therefore we need to check the ref-count before and after importing lldb, and if the
// ref-count increased we need to call Debugger::Terminate here to decrement the ref-count so that when the final
// call to Debugger::Terminate is made, the ref-count has the correct value.
int old_count = Debugger::TestDebuggerRefCount ();
PyRun_SimpleString ("sys.dont_write_bytecode = 1; import lldb.embedded_interpreter; from lldb.embedded_interpreter import run_python_interpreter; from lldb.embedded_interpreter import run_one_line"); PyRun_SimpleString ("sys.dont_write_bytecode = 1; import lldb.embedded_interpreter; from lldb.embedded_interpreter import run_python_interpreter; from lldb.embedded_interpreter import run_one_line");
int new_count = Debugger::TestDebuggerRefCount ();
if (new_count > old_count)
Debugger::Terminate ();
if (threads_already_initialized) { if (threads_already_initialized) {
if (log) if (log)
log->Printf("Releasing PyGILState. Returning to state = %slocked\n", gstate == PyGILState_UNLOCKED ? "un" : ""); log->Printf("Releasing PyGILState. Returning to state = %slocked\n", gstate == PyGILState_UNLOCKED ? "un" : "");

View File

@ -8,11 +8,17 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "lldb/Core/Debugger.h" #include "lldb/Core/Debugger.h"
#include "lldb/Initialization/InitializeLLDB.h" #include "lldb/Initialization/SystemLifetimeManager.h"
#include "lldb/Initialization/SystemInitializerCommon.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/ManagedStatic.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
static llvm::ManagedStatic<lldb_private::SystemLifetimeManager> g_debugger_lifetime;
static void static void
display_usage (const char *progname) display_usage (const char *progname)
{ {
@ -30,13 +36,13 @@ int main_platform (int argc, char *argv[]);
static void static void
initialize () initialize ()
{ {
lldb_private::InitializeForLLGS(nullptr); g_debugger_lifetime->Initialize(llvm::make_unique<lldb_private::SystemInitializerCommon>(), nullptr);
} }
static void static void
terminate () terminate ()
{ {
lldb_private::TerminateLLGS(); g_debugger_lifetime->Terminate();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------