xref: /src/contrib/llvm-project/lldb/source/API/SystemInitializerFull.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1cfca06d7SDimitry Andric //===-- SystemInitializerFull.cpp -----------------------------------------===//
25e95aa85SEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65e95aa85SEd Maste //
75e95aa85SEd Maste //===----------------------------------------------------------------------===//
85e95aa85SEd Maste 
9f73363f1SDimitry Andric #include "SystemInitializerFull.h"
10e81d9d49SDimitry Andric #include "lldb/API/SBCommandInterpreter.h"
115e95aa85SEd Maste #include "lldb/Core/Debugger.h"
12cfca06d7SDimitry Andric #include "lldb/Core/PluginManager.h"
13ac9a064cSDimitry Andric #include "lldb/Core/Progress.h"
14cfca06d7SDimitry Andric #include "lldb/Host/Config.h"
155e95aa85SEd Maste #include "lldb/Host/Host.h"
165e95aa85SEd Maste #include "lldb/Initialization/SystemInitializerCommon.h"
17e81d9d49SDimitry Andric #include "lldb/Interpreter/CommandInterpreter.h"
18b60736ecSDimitry Andric #include "lldb/Target/ProcessTrace.h"
191b306c26SDimitry Andric #include "lldb/Utility/Timer.h"
20344a3780SDimitry Andric #include "llvm/Support/CommandLine.h"
215e95aa85SEd Maste #include "llvm/Support/TargetSelect.h"
225e95aa85SEd Maste 
235f29bb8aSDimitry Andric #pragma clang diagnostic push
245f29bb8aSDimitry Andric #pragma clang diagnostic ignored "-Wglobal-constructors"
255f29bb8aSDimitry Andric #include "llvm/ExecutionEngine/MCJIT.h"
265f29bb8aSDimitry Andric #pragma clang diagnostic pop
275f29bb8aSDimitry Andric 
285e95aa85SEd Maste #include <string>
295e95aa85SEd Maste 
30cfca06d7SDimitry Andric #define LLDB_PLUGIN(p) LLDB_PLUGIN_DECLARE(p)
31cfca06d7SDimitry Andric #include "Plugins/Plugins.def"
32cfca06d7SDimitry Andric 
33344a3780SDimitry Andric #if LLDB_ENABLE_PYTHON
34344a3780SDimitry Andric #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h"
35344a3780SDimitry Andric 
36344a3780SDimitry Andric constexpr lldb_private::HostInfo::SharedLibraryDirectoryHelper
37344a3780SDimitry Andric     *g_shlib_dir_helper =
38344a3780SDimitry Andric         lldb_private::ScriptInterpreterPython::SharedLibraryDirectoryHelper;
39344a3780SDimitry Andric 
40344a3780SDimitry Andric #else
41344a3780SDimitry Andric constexpr lldb_private::HostInfo::SharedLibraryDirectoryHelper
426f8fc217SDimitry Andric     *g_shlib_dir_helper = nullptr;
43344a3780SDimitry Andric #endif
44344a3780SDimitry Andric 
455e95aa85SEd Maste using namespace lldb_private;
465e95aa85SEd Maste 
SystemInitializerFull()47344a3780SDimitry Andric SystemInitializerFull::SystemInitializerFull()
48344a3780SDimitry Andric     : SystemInitializerCommon(g_shlib_dir_helper) {}
49cfca06d7SDimitry Andric SystemInitializerFull::~SystemInitializerFull() = default;
50ead24645SDimitry Andric 
Initialize()515f29bb8aSDimitry Andric llvm::Error SystemInitializerFull::Initialize() {
52b60736ecSDimitry Andric   llvm::Error error = SystemInitializerCommon::Initialize();
5377fc4c14SDimitry Andric   if (error)
54b60736ecSDimitry Andric     return error;
55f73363f1SDimitry Andric 
565e95aa85SEd Maste   // Initialize LLVM and Clang
575e95aa85SEd Maste   llvm::InitializeAllTargets();
585e95aa85SEd Maste   llvm::InitializeAllAsmPrinters();
595e95aa85SEd Maste   llvm::InitializeAllTargetMCs();
605e95aa85SEd Maste   llvm::InitializeAllDisassemblers();
61ac9a064cSDimitry Andric 
62344a3780SDimitry Andric   // Initialize the command line parser in LLVM. This usually isn't necessary
63344a3780SDimitry Andric   // as we aren't dealing with command line options here, but otherwise some
64344a3780SDimitry Andric   // other code in Clang/LLVM might be tempted to call this function from a
65344a3780SDimitry Andric   // different thread later on which won't work (as the function isn't
66344a3780SDimitry Andric   // thread-safe).
67344a3780SDimitry Andric   const char *arg0 = "lldb";
68344a3780SDimitry Andric   llvm::cl::ParseCommandLineOptions(1, &arg0);
695e95aa85SEd Maste 
70ac9a064cSDimitry Andric   // Initialize the progress manager.
71ac9a064cSDimitry Andric   ProgressManager::Initialize();
72ac9a064cSDimitry Andric 
73cfca06d7SDimitry Andric #define LLDB_PLUGIN(p) LLDB_PLUGIN_INITIALIZE(p);
74cfca06d7SDimitry Andric #include "Plugins/Plugins.def"
755e95aa85SEd Maste 
76ac9a064cSDimitry Andric   // Scan for any system or user LLDB plug-ins.
775e95aa85SEd Maste   PluginManager::Initialize();
785e95aa85SEd Maste 
79f73363f1SDimitry Andric   // The process settings need to know about installed plug-ins, so the
80cfca06d7SDimitry Andric   // Settings must be initialized AFTER PluginManager::Initialize is called.
815e95aa85SEd Maste   Debugger::SettingsInitialize();
8294994d37SDimitry Andric 
837fa27ce4SDimitry Andric   // Use the Debugger's LLDBAssert callback.
847fa27ce4SDimitry Andric   SetLLDBAssertCallback(Debugger::AssertCallback);
857fa27ce4SDimitry Andric 
8694994d37SDimitry Andric   return llvm::Error::success();
875e95aa85SEd Maste }
885e95aa85SEd Maste 
Terminate()8914f1b3e8SDimitry Andric void SystemInitializerFull::Terminate() {
905e95aa85SEd Maste   Debugger::SettingsTerminate();
915e95aa85SEd Maste 
92ac9a064cSDimitry Andric   // Terminate plug-ins in core LLDB.
93b60736ecSDimitry Andric   ProcessTrace::Terminate();
94b60736ecSDimitry Andric 
95ac9a064cSDimitry Andric   // Terminate and unload and loaded system or user LLDB plug-ins.
965e95aa85SEd Maste   PluginManager::Terminate();
97e81d9d49SDimitry Andric 
98cfca06d7SDimitry Andric #define LLDB_PLUGIN(p) LLDB_PLUGIN_TERMINATE(p);
99cfca06d7SDimitry Andric #include "Plugins/Plugins.def"
1005f29bb8aSDimitry Andric 
101ac9a064cSDimitry Andric   // Terminate the progress manager.
102ac9a064cSDimitry Andric   ProgressManager::Terminate();
103ac9a064cSDimitry Andric 
1045e95aa85SEd Maste   // Now shutdown the common parts, in reverse order.
1055e95aa85SEd Maste   SystemInitializerCommon::Terminate();
1065e95aa85SEd Maste }
107