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