1 //===-- SystemInitializerFull.cpp -----------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "SystemInitializerFull.h" 10 #include "lldb/API/SBCommandInterpreter.h" 11 #include "lldb/Core/Debugger.h" 12 #include "lldb/Core/PluginManager.h" 13 #include "lldb/Core/Progress.h" 14 #include "lldb/Host/Config.h" 15 #include "lldb/Host/Host.h" 16 #include "lldb/Initialization/SystemInitializerCommon.h" 17 #include "lldb/Interpreter/CommandInterpreter.h" 18 #include "lldb/Target/ProcessTrace.h" 19 #include "lldb/Utility/Timer.h" 20 #include "lldb/Version/Version.h" 21 #include "llvm/Support/CommandLine.h" 22 #include "llvm/Support/TargetSelect.h" 23 24 #pragma clang diagnostic push 25 #pragma clang diagnostic ignored "-Wglobal-constructors" 26 #include "llvm/ExecutionEngine/MCJIT.h" 27 #pragma clang diagnostic pop 28 29 #include <string> 30 31 #define LLDB_PLUGIN(p) LLDB_PLUGIN_DECLARE(p) 32 #include "Plugins/Plugins.def" 33 34 #if LLDB_ENABLE_PYTHON 35 #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h" 36 37 constexpr lldb_private::HostInfo::SharedLibraryDirectoryHelper 38 *g_shlib_dir_helper = 39 lldb_private::ScriptInterpreterPython::SharedLibraryDirectoryHelper; 40 41 #else 42 constexpr lldb_private::HostInfo::SharedLibraryDirectoryHelper 43 *g_shlib_dir_helper = nullptr; 44 #endif 45 46 using namespace lldb_private; 47 48 SystemInitializerFull::SystemInitializerFull() 49 : SystemInitializerCommon(g_shlib_dir_helper) {} 50 SystemInitializerFull::~SystemInitializerFull() = default; 51 52 llvm::Error SystemInitializerFull::Initialize() { 53 llvm::Error error = SystemInitializerCommon::Initialize(); 54 if (error) 55 return error; 56 57 // Initialize LLVM and Clang 58 llvm::InitializeAllTargets(); 59 llvm::InitializeAllAsmPrinters(); 60 llvm::InitializeAllTargetMCs(); 61 llvm::InitializeAllDisassemblers(); 62 63 // Initialize the command line parser in LLVM. This usually isn't necessary 64 // as we aren't dealing with command line options here, but otherwise some 65 // other code in Clang/LLVM might be tempted to call this function from a 66 // different thread later on which won't work (as the function isn't 67 // thread-safe). 68 const char *arg0 = "lldb"; 69 llvm::cl::ParseCommandLineOptions(1, &arg0); 70 71 // Initialize the progress manager. 72 ProgressManager::Initialize(); 73 74 #define LLDB_PLUGIN(p) LLDB_PLUGIN_INITIALIZE(p); 75 #include "Plugins/Plugins.def" 76 77 // Scan for any system or user LLDB plug-ins. 78 PluginManager::Initialize(); 79 80 // The process settings need to know about installed plug-ins, so the 81 // Settings must be initialized AFTER PluginManager::Initialize is called. 82 Debugger::SettingsInitialize(); 83 84 // Use the Debugger's LLDBAssert callback. 85 SetLLDBAssertCallback(Debugger::AssertCallback); 86 87 // Use the system log to report errors that would otherwise get dropped. 88 SetLLDBErrorLog(GetLog(SystemLog::System)); 89 90 LLDB_LOG(GetLog(SystemLog::System), "{0}", GetVersion()); 91 92 return llvm::Error::success(); 93 } 94 95 void SystemInitializerFull::Terminate() { 96 Debugger::SettingsTerminate(); 97 98 // Terminate plug-ins in core LLDB. 99 ProcessTrace::Terminate(); 100 101 // Terminate and unload and loaded system or user LLDB plug-ins. 102 PluginManager::Terminate(); 103 104 #define LLDB_PLUGIN(p) LLDB_PLUGIN_TERMINATE(p); 105 #include "Plugins/Plugins.def" 106 107 // Terminate the progress manager. 108 ProgressManager::Terminate(); 109 110 // Now shutdown the common parts, in reverse order. 111 SystemInitializerCommon::Terminate(); 112 } 113