Index: cmake/LLDBDependencies.cmake =================================================================== --- cmake/LLDBDependencies.cmake +++ cmake/LLDBDependencies.cmake @@ -1,4 +1,5 @@ set( LLDB_USED_LIBS + lldbApplication lldbBase lldbBreakpoint lldbCommands Index: include/lldb/Application/InitializeLLDB.h =================================================================== --- /dev/null +++ include/lldb/Application/InitializeLLDB.h @@ -0,0 +1,61 @@ +//===-- 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_APPLICATION_INITIALIZE_LLDB_H +#define LLDB_APPLICATION_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 \ No newline at end of file Index: include/lldb/Core/Debugger.h =================================================================== --- include/lldb/Core/Debugger.h +++ include/lldb/Core/Debugger.h @@ -55,10 +55,6 @@ public: - typedef llvm::sys::DynamicLibrary (*LoadPluginCallbackType) (const lldb::DebuggerSP &debugger_sp, - const FileSpec& spec, - Error& error); - static lldb::DebuggerSP CreateInstance (lldb::LogOutputCallback log_callback = NULL, void *baton = NULL); Index: include/lldb/Host/Host.h =================================================================== --- include/lldb/Host/Host.h +++ include/lldb/Host/Host.h @@ -133,9 +133,6 @@ static const char * GetSignalAsCString (int signo); - static void - WillTerminate (); - typedef void (*ThreadLocalStorageCleanupCallback) (void *p); static lldb::thread_key_t Index: include/lldb/lldb-forward.h =================================================================== --- include/lldb/lldb-forward.h +++ include/lldb/lldb-forward.h @@ -433,7 +433,7 @@ typedef std::shared_ptr VariableListSP; typedef std::shared_ptr ValueObjectListSP; typedef std::shared_ptr WatchpointSP; - + } // namespace lldb Index: include/lldb/lldb-private-types.h =================================================================== --- include/lldb/lldb-private-types.h +++ include/lldb/lldb-private-types.h @@ -14,11 +14,22 @@ #include "lldb/lldb-private.h" +namespace llvm +{ +namespace sys +{ +class DynamicLibrary; +} +} + namespace lldb_private { class Platform; class ExecutionContext; + typedef llvm::sys::DynamicLibrary (*LoadPluginCallbackType)(const lldb::DebuggerSP &debugger_sp, + const FileSpec &spec, Error &error); + //---------------------------------------------------------------------- // Every register is described in detail including its name, alternate // name (optional), encoding, size in bytes and the default display Index: include/lldb/lldb-private.h =================================================================== --- include/lldb/lldb-private.h +++ include/lldb/lldb-private.h @@ -27,70 +27,6 @@ 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(); - -//------------------------------------------------------------------ -/// 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(); - -//------------------------------------------------------------------ -/// Notifies any classes that lldb will be terminating soon. -/// -/// This function will be called when the Debugger shared instance -/// is being destructed and will give classes the ability to clean -/// up any threads or other resources they have that they might not -/// be able to clean up in their own destructors. -/// -/// Internal classes that need this ability will need to add their -/// void T::WillTerminate() method in the body of this function in -/// lldb.cpp to ensure it will get called. -/// -/// TODO: when we start having external plug-ins, we will need a way -/// for plug-ins to register a WillTerminate callback. -//------------------------------------------------------------------ -void -WillTerminate(); - -//------------------------------------------------------------------ -/// 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(); - const char * GetVersion (); Index: lldb.xcodeproj/project.pbxproj =================================================================== --- lldb.xcodeproj/project.pbxproj +++ lldb.xcodeproj/project.pbxproj @@ -686,6 +686,7 @@ 3F8160A61AB9F7DD001DA9DF /* Logging.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F8160A51AB9F7DD001DA9DF /* Logging.cpp */; }; 3F8169191ABA2419001DA9DF /* ConvertEnum.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F8169171ABA2419001DA9DF /* ConvertEnum.cpp */; }; 3F81691A1ABA2419001DA9DF /* NameMatches.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F8169181ABA2419001DA9DF /* NameMatches.cpp */; }; + 3F8169211ABA259F001DA9DF /* InitializeLLDB.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F8169201ABA259F001DA9DF /* InitializeLLDB.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 */; }; @@ -2165,6 +2166,8 @@ 3F8169181ABA2419001DA9DF /* NameMatches.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NameMatches.cpp; path = source/Utility/NameMatches.cpp; sourceTree = ""; }; 3F81691B1ABA242B001DA9DF /* ConvertEnum.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ConvertEnum.h; path = include/lldb/Utility/ConvertEnum.h; sourceTree = ""; }; 3F81691C1ABA242B001DA9DF /* NameMatches.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = NameMatches.h; path = include/lldb/Utility/NameMatches.h; sourceTree = ""; }; + 3F8169201ABA259F001DA9DF /* InitializeLLDB.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = InitializeLLDB.cpp; path = source/Application/InitializeLLDB.cpp; sourceTree = ""; }; + 3F8169221ABA25AD001DA9DF /* InitializeLLDB.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = InitializeLLDB.h; path = include/lldb/Application/InitializeLLDB.h; sourceTree = ""; }; 3FDFD6C3199C396E009756A7 /* FileAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileAction.h; path = include/lldb/Target/FileAction.h; sourceTree = ""; }; 3FDFDDBC199C3A06009756A7 /* FileAction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FileAction.cpp; path = source/Target/FileAction.cpp; sourceTree = ""; }; 3FDFDDBE199D345E009756A7 /* FileCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FileCache.cpp; path = source/Host/common/FileCache.cpp; sourceTree = ""; }; @@ -2803,6 +2806,7 @@ 26BC7C2810F1B3BC00F91463 /* lldb-private-interfaces.h */, 26217930133BC8640083B112 /* lldb-private-types.h */, 262D3190111B4341004E6F88 /* API */, + 3F81691F1ABA256D001DA9DF /* Application */, 26BC7CEB10F1B70800F91463 /* Breakpoint */, 26BC7D0D10F1B71D00F91463 /* Commands */, 26BC7C1010F1B34800F91463 /* Core */, @@ -4765,6 +4769,15 @@ path = "POSIX-DYLD"; sourceTree = ""; }; + 3F81691F1ABA256D001DA9DF /* Application */ = { + isa = PBXGroup; + children = ( + 3F8169221ABA25AD001DA9DF /* InitializeLLDB.h */, + 3F8169201ABA259F001DA9DF /* InitializeLLDB.cpp */, + ); + name = Application; + sourceTree = ""; + }; 3FDFDDC4199D37BE009756A7 /* posix */ = { isa = PBXGroup; children = ( @@ -6345,6 +6358,7 @@ 94CB257216B0A4270059775D /* TypeSynthetic.cpp in Sources */, 94CB257416B1D3880059775D /* FormatCache.cpp in Sources */, A36FF33C17D8E94600244D40 /* OptionParser.cpp in Sources */, + 3F8169211ABA259F001DA9DF /* InitializeLLDB.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; Index: source/Application/CMakeLists.txt =================================================================== --- /dev/null +++ source/Application/CMakeLists.txt @@ -0,0 +1,3 @@ +add_lldb_library(lldbApplication + InitializeLLDB.cpp + ) Index: source/Application/InitializeLLDB.cpp =================================================================== --- /dev/null +++ source/Application/InitializeLLDB.cpp @@ -0,0 +1,375 @@ +//===-- 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/Application/InitializeLLDB.h" +#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/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 + +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); + + ProcessGDBRemoteLog::Initialize(); + + // Initialize plug-ins + ObjectContainerBSDArchive::Initialize(); + ObjectFileELF::Initialize(); + ObjectFilePECOFF::Initialize(); + DynamicLoaderPOSIXDYLD::Initialize(); + PlatformFreeBSD::Initialize(); + PlatformLinux::Initialize(); + PlatformWindows::Initialize(); + PlatformKalimba::Initialize(); + 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 +lldb_private::InitializeForLLGS(LoadPluginCallbackType load_plugin_callback) +{ + // We want to do this every time, even if we've already been initted, so + // that the debugger ref count increases. + Debugger::InitializeForLLGS(load_plugin_callback); + + // Make sure we initialize only once + static Mutex g_inited_mutex(Mutex::eMutexTypeRecursive); + Mutex::Locker locker(g_inited_mutex); + + InitializeForLLGSPrivate(); +} + +static bool g_inited = false; +static void +InitializePrivate() +{ + if (g_inited) + return; + + g_inited = true; + + // 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 + //---------------------------------------------------------------------- + PlatformRemoteGDBServer::Initialize(); + + 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 +lldb_private::Initialize(LoadPluginCallbackType load_plugin_callback) +{ + // We want to do this every time, even if we've already been initted, so + // that the debugger ref count increases. + Debugger::Initialize(load_plugin_callback); + + // Make sure we initialize only once + static Mutex g_inited_mutex(Mutex::eMutexTypeRecursive); + Mutex::Locker locker(g_inited_mutex); + + InitializeForLLGSPrivate(); + InitializePrivate(); +} + +void +lldb_private::TerminateLLGS() +{ + if (g_inited_for_llgs) + { + g_inited_for_llgs = false; + + Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); + ObjectContainerBSDArchive::Terminate(); + ObjectFileELF::Terminate(); + ObjectFilePECOFF::Terminate(); + DynamicLoaderPOSIXDYLD::Terminate(); + PlatformFreeBSD::Terminate(); + PlatformLinux::Terminate(); + PlatformWindows::Terminate(); + PlatformKalimba::Terminate(); + 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(); + } +} + +void +lldb_private::Terminate() +{ + if (g_inited) + { + 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__) + ProcessLinux::Terminate(); +#endif + +#if defined(__FreeBSD__) + ProcessFreeBSD::Terminate(); +#endif + Debugger::SettingsTerminate(); + + PlatformRemoteGDBServer::Terminate(); + ProcessGDBRemote::Terminate(); + DynamicLoaderStatic::Terminate(); + + TerminateLLGS(); + } +} Index: source/Application/Makefile =================================================================== --- /dev/null +++ source/Application/Makefile @@ -0,0 +1,14 @@ +##===- source/Application/Makefile -------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LLDB_LEVEL := ../.. +LIBRARYNAME := lldbApplication +BUILD_ARCHIVE = 1 + +include $(LLDB_LEVEL)/Makefile Index: source/CMakeLists.txt =================================================================== --- source/CMakeLists.txt +++ source/CMakeLists.txt @@ -29,6 +29,7 @@ lldb.cpp ) +add_subdirectory(Application) add_subdirectory(Breakpoint) add_subdirectory(Commands) add_subdirectory(Core) @@ -41,7 +42,8 @@ add_subdirectory(Target) add_subdirectory(Utility) -# Build API last, since liblldb needs to link against every other target +# Build API last. Since liblldb needs to link against every other target, it needs +# those targets to have already been created. add_subdirectory(API) # Determine LLDB revision and repository. GetSourceVersion and GetRepositoryPath are shell-scripts, and as Index: source/Core/Debugger.cpp =================================================================== --- source/Core/Debugger.cpp +++ source/Core/Debugger.cpp @@ -18,6 +18,7 @@ #include "llvm/ADT/StringRef.h" #include "lldb/lldb-private.h" +#include "lldb/Application/InitializeLLDB.h" #include "lldb/Core/FormatEntity.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" @@ -185,7 +186,7 @@ ePropertyEscapeNonPrintables }; -Debugger::LoadPluginCallbackType Debugger::g_load_plugin_callback = NULL; +LoadPluginCallbackType Debugger::g_load_plugin_callback = NULL; Error Debugger::SetPropertyValue (const ExecutionContext *exe_ctx, @@ -414,22 +415,20 @@ static bool lldb_initialized_for_llgs = false; void -Debugger::InitializeForLLGS (LoadPluginCallbackType load_plugin_callback) +Debugger::InitializeForLLGS(LoadPluginCallbackType load_plugin_callback) { lldb_initialized_for_llgs = true; g_shared_debugger_refcount++; g_load_plugin_callback = load_plugin_callback; - lldb_private::InitializeForLLGS(); } static bool lldb_initialized = true; void -Debugger::Initialize (LoadPluginCallbackType load_plugin_callback) +Debugger::Initialize(LoadPluginCallbackType load_plugin_callback) { lldb_initialized = true; g_shared_debugger_refcount++; g_load_plugin_callback = load_plugin_callback; - lldb_private::Initialize(); } void @@ -440,7 +439,6 @@ g_shared_debugger_refcount--; if (g_shared_debugger_refcount == 0) { - lldb_private::WillTerminate(); if (lldb_initialized_for_llgs) { lldb_initialized_for_llgs = false; lldb_private::TerminateLLGS(); Index: source/Host/common/Host.cpp =================================================================== --- source/Host/common/Host.cpp +++ source/Host/common/Host.cpp @@ -423,11 +423,6 @@ #endif -void -Host::WillTerminate () -{ -} - #if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined (__FreeBSD_kernel__) && !defined (__linux__) // see macosx/Host.mm size_t Index: source/Makefile =================================================================== --- source/Makefile +++ source/Makefile @@ -8,7 +8,7 @@ ##===----------------------------------------------------------------------===## LLDB_LEVEL := .. -PARALLEL_DIRS := API Breakpoint Commands Core DataFormatters Expression Host Interpreter Plugins Symbol Target Utility +PARALLEL_DIRS := API Application Breakpoint Commands Core DataFormatters Expression Host Interpreter Plugins Symbol Target Utility LIBRARYNAME := lldbInitAndLog BUILD_ARCHIVE = 1 Index: source/lldb.cpp =================================================================== --- source/lldb.cpp +++ source/lldb.cpp @@ -7,372 +7,11 @@ // //===----------------------------------------------------------------------===// -#include "lldb/lldb-python.h" - #include "lldb/lldb-private.h" -#include "lldb/Core/ArchSpec.h" -#include "lldb/Core/Debugger.h" -#include "lldb/Core/Log.h" -#include "lldb/Core/PluginManager.h" -#include "lldb/Core/RegularExpression.h" -#include "lldb/Core/Timer.h" -#include "lldb/Host/Host.h" -#include "lldb/Host/HostInfo.h" -#include "lldb/Host/Mutex.h" -#include "lldb/Interpreter/ScriptInterpreterPython.h" -#include "lldb/Target/Target.h" -#include "lldb/Target/Thread.h" - -#include "llvm/ADT/StringRef.h" -#include "llvm/Support/TargetSelect.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/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h" -#include "Plugins/Instruction/ARM/EmulateInstructionARM.h" -#include "Plugins/Instruction/ARM64/EmulateInstructionARM64.h" -#include "Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h" -#include "Plugins/JITLoader/GDB/JITLoaderGDB.h" -#include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h" -#include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h" -#include "Plugins/ObjectFile/ELF/ObjectFileELF.h" -#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h" -#include "Plugins/Platform/Android/PlatformAndroid.h" -#include "Plugins/Platform/FreeBSD/PlatformFreeBSD.h" -#include "Plugins/Platform/Linux/PlatformLinux.h" -#include "Plugins/Platform/Windows/PlatformWindows.h" -#include "Plugins/Platform/Kalimba/PlatformKalimba.h" -#include "Plugins/Process/elf-core/ProcessElfCore.h" -#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h" -#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h" -#include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h" -#include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h" -#include "Plugins/UnwindAssembly/x86/UnwindAssembly-x86.h" -#include "Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h" - -#ifndef LLDB_DISABLE_PYTHON -#include "Plugins/OperatingSystem/Python/OperatingSystemPython.h" -#endif - -#include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h" -#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h" -#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h" -#include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h" -#include "Plugins/Platform/MacOSX/PlatformMacOSX.h" -#include "Plugins/Platform/MacOSX/PlatformRemoteiOS.h" -#include "Plugins/Platform/MacOSX/PlatformiOSSimulator.h" -#include "Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.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 (__linux__) -#include "Plugins/Process/Linux/ProcessLinux.h" -#include "Plugins/Process/POSIX/ProcessPOSIXLog.h" -#endif - -#if defined (_WIN32) -#include "lldb/Host/windows/windows.h" -#include "Plugins/Process/Windows/DynamicLoaderWindows.h" -#include "Plugins/Process/Windows/ProcessWindows.h" -#endif - -#if defined (__FreeBSD__) -#include "Plugins/Process/POSIX/ProcessPOSIX.h" -#include "Plugins/Process/FreeBSD/ProcessFreeBSD.h" -#endif - -#include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h" -#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h" -#include "Plugins/Process/gdb-remote/ProcessGDBRemote.h" -#include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h" -#include "Plugins/MemoryHistory/asan/MemoryHistoryASan.h" -#include "Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.h" using namespace lldb; 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; -void -lldb_private::InitializeForLLGS () -{ - // Make sure we initialize only once - static Mutex g_inited_mutex(Mutex::eMutexTypeRecursive); - - Mutex::Locker locker(g_inited_mutex); - if (!g_inited_for_llgs) - { - 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); - - ProcessGDBRemoteLog::Initialize(); - - // Initialize plug-ins - ObjectContainerBSDArchive::Initialize(); - ObjectFileELF::Initialize(); - ObjectFilePECOFF::Initialize(); - DynamicLoaderPOSIXDYLD::Initialize(); - PlatformFreeBSD::Initialize(); - PlatformLinux::Initialize(); - PlatformWindows::Initialize(); - PlatformKalimba::Initialize(); - 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; -void -lldb_private::Initialize () -{ - // Make sure we initialize only once - static Mutex g_inited_mutex(Mutex::eMutexTypeRecursive); - - InitializeForLLGS(); - Mutex::Locker locker(g_inited_mutex); - if (!g_inited) - { - g_inited = true; - - // 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 - //---------------------------------------------------------------------- - PlatformRemoteGDBServer::Initialize(); - - 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 -lldb_private::WillTerminate() -{ - Host::WillTerminate(); -} - -void -lldb_private::TerminateLLGS () -{ - if (g_inited_for_llgs) - { - g_inited_for_llgs = false; - - Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); - ObjectContainerBSDArchive::Terminate(); - ObjectFileELF::Terminate(); - ObjectFilePECOFF::Terminate (); - DynamicLoaderPOSIXDYLD::Terminate (); - PlatformFreeBSD::Terminate(); - PlatformLinux::Terminate(); - PlatformWindows::Terminate(); - PlatformKalimba::Terminate(); - 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(); - } -} - -void -lldb_private::Terminate () -{ - if (g_inited) - { - 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__) - ProcessLinux::Terminate(); -#endif - -#if defined (__FreeBSD__) - ProcessFreeBSD::Terminate(); -#endif - Debugger::SettingsTerminate (); - - PlatformRemoteGDBServer::Terminate(); - ProcessGDBRemote::Terminate(); - DynamicLoaderStatic::Terminate(); - - TerminateLLGS(); - } -} - #if defined (__APPLE__) extern "C" const unsigned char liblldb_coreVersionString[]; #else Index: tools/lldb-server/lldb-server.cpp =================================================================== --- tools/lldb-server/lldb-server.cpp +++ tools/lldb-server/lldb-server.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +#include "lldb/Application/InitializeLLDB.h" #include "lldb/Core/Debugger.h" #include