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 "llvm/Support/CommandLine.h" |
21 | #include "llvm/Support/TargetSelect.h" |
22 | |
23 | #pragma clang diagnostic push |
24 | #pragma clang diagnostic ignored "-Wglobal-constructors" |
25 | #include "llvm/ExecutionEngine/MCJIT.h" |
26 | #pragma clang diagnostic pop |
27 | |
28 | #include <string> |
29 | |
30 | #define LLDB_PLUGIN(p) LLDB_PLUGIN_DECLARE(p) |
31 | #include "Plugins/Plugins.def" |
32 | |
33 | #if LLDB_ENABLE_PYTHON |
34 | #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h" |
35 | |
36 | constexpr lldb_private::HostInfo::SharedLibraryDirectoryHelper |
37 | *g_shlib_dir_helper = |
38 | lldb_private::ScriptInterpreterPython::SharedLibraryDirectoryHelper; |
39 | |
40 | #else |
41 | constexpr lldb_private::HostInfo::SharedLibraryDirectoryHelper |
42 | *g_shlib_dir_helper = nullptr; |
43 | #endif |
44 | |
45 | using namespace lldb_private; |
46 | |
47 | SystemInitializerFull::SystemInitializerFull() |
48 | : SystemInitializerCommon(g_shlib_dir_helper) {} |
49 | SystemInitializerFull::~SystemInitializerFull() = default; |
50 | |
51 | llvm::Error SystemInitializerFull::Initialize() { |
52 | llvm::Error error = SystemInitializerCommon::Initialize(); |
53 | if (error) |
54 | return error; |
55 | |
56 | // Initialize LLVM and Clang |
57 | llvm::InitializeAllTargets(); |
58 | llvm::InitializeAllAsmPrinters(); |
59 | llvm::InitializeAllTargetMCs(); |
60 | llvm::InitializeAllDisassemblers(); |
61 | |
62 | // Initialize the command line parser in LLVM. This usually isn't necessary |
63 | // as we aren't dealing with command line options here, but otherwise some |
64 | // other code in Clang/LLVM might be tempted to call this function from a |
65 | // different thread later on which won't work (as the function isn't |
66 | // thread-safe). |
67 | const char *arg0 = "lldb"; |
68 | llvm::cl::ParseCommandLineOptions(argc: 1, argv: &arg0); |
69 | |
70 | // Initialize the progress manager. |
71 | ProgressManager::Initialize(); |
72 | |
73 | #define LLDB_PLUGIN(p) LLDB_PLUGIN_INITIALIZE(p); |
74 | #include "Plugins/Plugins.def" |
75 | |
76 | // Scan for any system or user LLDB plug-ins. |
77 | PluginManager::Initialize(); |
78 | |
79 | // The process settings need to know about installed plug-ins, so the |
80 | // Settings must be initialized AFTER PluginManager::Initialize is called. |
81 | Debugger::SettingsInitialize(); |
82 | |
83 | // Use the Debugger's LLDBAssert callback. |
84 | SetLLDBAssertCallback(Debugger::AssertCallback); |
85 | |
86 | return llvm::Error::success(); |
87 | } |
88 | |
89 | void SystemInitializerFull::Terminate() { |
90 | Debugger::SettingsTerminate(); |
91 | |
92 | // Terminate plug-ins in core LLDB. |
93 | ProcessTrace::Terminate(); |
94 | |
95 | // Terminate and unload and loaded system or user LLDB plug-ins. |
96 | PluginManager::Terminate(); |
97 | |
98 | #define LLDB_PLUGIN(p) LLDB_PLUGIN_TERMINATE(p); |
99 | #include "Plugins/Plugins.def" |
100 | |
101 | // Terminate the progress manager. |
102 | ProgressManager::Terminate(); |
103 | |
104 | // Now shutdown the common parts, in reverse order. |
105 | SystemInitializerCommon::Terminate(); |
106 | } |
107 |