]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/source/API/SystemInitializerFull.cpp
Merge llvm-project 12.0.1 release and follow-up fixes
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / source / API / SystemInitializerFull.cpp
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/Reproducer.h"
19 #include "lldb/Utility/Timer.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 using namespace lldb_private;
33
34 SystemInitializerFull::SystemInitializerFull() = default;
35 SystemInitializerFull::~SystemInitializerFull() = default;
36
37 llvm::Error SystemInitializerFull::Initialize() {
38   llvm::Error error = SystemInitializerCommon::Initialize();
39   if (error) {
40     // During active replay, the ::Initialize call is replayed like any other
41     // SB API call and the return value is ignored. Since we can't intercept
42     // this, we terminate here before the uninitialized debugger inevitably
43     // crashes.
44     if (repro::Reproducer::Instance().IsReplaying())
45       llvm::report_fatal_error(std::move(error));
46     return error;
47   }
48
49   // Initialize LLVM and Clang
50   llvm::InitializeAllTargets();
51   llvm::InitializeAllAsmPrinters();
52   llvm::InitializeAllTargetMCs();
53   llvm::InitializeAllDisassemblers();
54
55 #define LLDB_PLUGIN(p) LLDB_PLUGIN_INITIALIZE(p);
56 #include "Plugins/Plugins.def"
57
58   // Initialize plug-ins in core LLDB
59   ProcessTrace::Initialize();
60
61   // Scan for any system or user LLDB plug-ins
62   PluginManager::Initialize();
63
64   // The process settings need to know about installed plug-ins, so the
65   // Settings must be initialized AFTER PluginManager::Initialize is called.
66   Debugger::SettingsInitialize();
67
68   return llvm::Error::success();
69 }
70
71 void SystemInitializerFull::Terminate() {
72   Debugger::SettingsTerminate();
73
74   // Terminate plug-ins in core LLDB
75   ProcessTrace::Terminate();
76
77   // Terminate and unload and loaded system or user LLDB plug-ins
78   PluginManager::Terminate();
79
80 #define LLDB_PLUGIN(p) LLDB_PLUGIN_TERMINATE(p);
81 #include "Plugins/Plugins.def"
82
83   // Now shutdown the common parts, in reverse order.
84   SystemInitializerCommon::Terminate();
85 }