From 79809e6acdd7c58d1d7b3de0eb960151d1679ff4 Mon Sep 17 00:00:00 2001
From: Zachary Turner <zturner@google.com>
Date: Wed, 18 Mar 2015 13:46:31 -0700
Subject: [PATCH] Move LLDB initialization/shutdown to Application.

This creates a new top-level folder called Application which
is intended to hold code specific to using LLDB as an application.
Currently this holds the Initialize() and Terminate() functions,
as well as the fatal error handler.

This provides a means to break the massive dependency cycle which
is caused by the fact that Debugger depends on Initialize and
Terminate which then depends on the entire LLDB project.  With
this structure, it will be possible for applications to invoke
lldb_private::Initialize() directly, and have that invoke
Debugger::Initialize.
---
 cmake/LLDBDependencies.cmake              |   1 +
 include/lldb/Application/InitializeLLDB.h |  61 +++++
 include/lldb/Core/Debugger.h              |   4 -
 include/lldb/Host/Host.h                  |   3 -
 include/lldb/lldb-forward.h               |   2 +-
 include/lldb/lldb-private-types.h         |  11 +
 include/lldb/lldb-private.h               |  64 -----
 lldb.xcodeproj/project.pbxproj            |  14 ++
 source/Application/CMakeLists.txt         |   3 +
 source/Application/InitializeLLDB.cpp     | 375 ++++++++++++++++++++++++++++++
 source/Application/Makefile               |  14 ++
 source/CMakeLists.txt                     |   4 +-
 source/Core/Debugger.cpp                  |  10 +-
 source/Host/common/Host.cpp               |   5 -
 source/Makefile                           |   2 +-
 source/lldb.cpp                           | 361 ----------------------------
 tools/lldb-server/lldb-server.cpp         |   1 +
 17 files changed, 489 insertions(+), 446 deletions(-)
 create mode 100644 include/lldb/Application/InitializeLLDB.h
 create mode 100644 source/Application/CMakeLists.txt
 create mode 100644 source/Application/InitializeLLDB.cpp
 create mode 100644 source/Application/Makefile

diff --git a/cmake/LLDBDependencies.cmake b/cmake/LLDBDependencies.cmake
index 5aff968..d40875a 100644
--- a/cmake/LLDBDependencies.cmake
+++ b/cmake/LLDBDependencies.cmake
@@ -1,4 +1,5 @@
 set( LLDB_USED_LIBS
+  lldbApplication
   lldbBase
   lldbBreakpoint
   lldbCommands
diff --git a/include/lldb/Application/InitializeLLDB.h b/include/lldb/Application/InitializeLLDB.h
new file mode 100644
index 0000000..537a0fb
--- /dev/null
+++ b/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
diff --git a/include/lldb/Core/Debugger.h b/include/lldb/Core/Debugger.h
index 972c636..c794ea6 100644
--- a/include/lldb/Core/Debugger.h
+++ b/include/lldb/Core/Debugger.h
@@ -55,10 +55,6 @@ friend class SourceManager;  // For GetSourceFileCache.
 
 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);
 
diff --git a/include/lldb/Host/Host.h b/include/lldb/Host/Host.h
index 9ce83e2..860747f 100644
--- a/include/lldb/Host/Host.h
+++ b/include/lldb/Host/Host.h
@@ -133,9 +133,6 @@ public:
     static const char *
     GetSignalAsCString (int signo);
 
-    static void
-    WillTerminate ();
-
     typedef void (*ThreadLocalStorageCleanupCallback) (void *p);
 
     static lldb::thread_key_t
diff --git a/include/lldb/lldb-forward.h b/include/lldb/lldb-forward.h
index 6806f84..04ffa59 100644
--- a/include/lldb/lldb-forward.h
+++ b/include/lldb/lldb-forward.h
@@ -433,7 +433,7 @@ namespace lldb {
     typedef std::shared_ptr<lldb_private::VariableList> VariableListSP;
     typedef std::shared_ptr<lldb_private::ValueObjectList> ValueObjectListSP;
     typedef std::shared_ptr<lldb_private::Watchpoint> WatchpointSP;
-    
+
 } // namespace lldb
 
 
diff --git a/include/lldb/lldb-private-types.h b/include/lldb/lldb-private-types.h
index cd48672..cce637f 100644
--- a/include/lldb/lldb-private-types.h
+++ b/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
diff --git a/include/lldb/lldb-private.h b/include/lldb/lldb-private.h
index a65c6ce..951b22f 100644
--- a/include/lldb/lldb-private.h
+++ b/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 ();
 
diff --git a/lldb.xcodeproj/project.pbxproj b/lldb.xcodeproj/project.pbxproj
index 5a872d2..f6f6ae0 100644
--- a/lldb.xcodeproj/project.pbxproj
+++ b/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 = "<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>"; };
+		3F8169201ABA259F001DA9DF /* InitializeLLDB.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = InitializeLLDB.cpp; path = source/Application/InitializeLLDB.cpp; sourceTree = "<group>"; };
+		3F8169221ABA25AD001DA9DF /* InitializeLLDB.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = InitializeLLDB.h; path = include/lldb/Application/InitializeLLDB.h; sourceTree = "<group>"; };
 		3FDFD6C3199C396E009756A7 /* FileAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileAction.h; path = include/lldb/Target/FileAction.h; sourceTree = "<group>"; };
 		3FDFDDBC199C3A06009756A7 /* FileAction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FileAction.cpp; path = source/Target/FileAction.cpp; sourceTree = "<group>"; };
 		3FDFDDBE199D345E009756A7 /* FileCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FileCache.cpp; path = source/Host/common/FileCache.cpp; sourceTree = "<group>"; };
@@ -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 = "<group>";
 		};
+		3F81691F1ABA256D001DA9DF /* Application */ = {
+			isa = PBXGroup;
+			children = (
+				3F8169221ABA25AD001DA9DF /* InitializeLLDB.h */,
+				3F8169201ABA259F001DA9DF /* InitializeLLDB.cpp */,
+			);
+			name = Application;
+			sourceTree = "<group>";
+		};
 		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;
 		};
diff --git a/source/Application/CMakeLists.txt b/source/Application/CMakeLists.txt
new file mode 100644
index 0000000..a06c5f5
--- /dev/null
+++ b/source/Application/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_lldb_library(lldbApplication
+  InitializeLLDB.cpp
+  )
diff --git a/source/Application/InitializeLLDB.cpp b/source/Application/InitializeLLDB.cpp
new file mode 100644
index 0000000..90fec5d
--- /dev/null
+++ b/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 <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);
+
+    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();
+    }
+}
diff --git a/source/Application/Makefile b/source/Application/Makefile
new file mode 100644
index 0000000..b8aeb38
--- /dev/null
+++ b/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
diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt
index ca57718..2e51637 100644
--- a/source/CMakeLists.txt
+++ b/source/CMakeLists.txt
@@ -29,6 +29,7 @@ add_lldb_library(lldbBase
   lldb.cpp
   )
 
+add_subdirectory(Application)
 add_subdirectory(Breakpoint)
 add_subdirectory(Commands)
 add_subdirectory(Core)
@@ -41,7 +42,8 @@ add_subdirectory(Symbol)
 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
diff --git a/source/Core/Debugger.cpp b/source/Core/Debugger.cpp
index 17eb924..7357e80 100644
--- a/source/Core/Debugger.cpp
+++ b/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 @@ enum
     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 @@ Debugger::TestDebuggerRefCount ()
 
 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 @@ Debugger::Terminate ()
         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();
diff --git a/source/Host/common/Host.cpp b/source/Host/common/Host.cpp
index 32b002f..4584f70 100644
--- a/source/Host/common/Host.cpp
+++ b/source/Host/common/Host.cpp
@@ -423,11 +423,6 @@ Host::GetSignalAsCString (int signo)
 
 #endif
 
-void
-Host::WillTerminate ()
-{
-}
-
 #if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined (__FreeBSD_kernel__) && !defined (__linux__) // see macosx/Host.mm
 
 size_t
diff --git a/source/Makefile b/source/Makefile
index 413cef6..d7ee758 100644
--- a/source/Makefile
+++ b/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
 
diff --git a/source/lldb.cpp b/source/lldb.cpp
index 75b270f..89bb485 100644
--- a/source/lldb.cpp
+++ b/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
diff --git a/tools/lldb-server/lldb-server.cpp b/tools/lldb-server/lldb-server.cpp
index 83e88a8..898a5b2 100644
--- a/tools/lldb-server/lldb-server.cpp
+++ b/tools/lldb-server/lldb-server.cpp
@@ -7,6 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "lldb/Application/InitializeLLDB.h"
 #include "lldb/Core/Debugger.h"
 
 #include <stdio.h>
