xref: /openbsd-src/gnu/llvm/lldb/tools/lldb-test/SystemInitializerTest.cpp (revision d0fc3bb68efd6c434b4053cd7adb29023cbec341)
1 //===-- SystemInitializerTest.cpp -------------------------------*- C++ -*-===//
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 "SystemInitializerTest.h"
10 #include "lldb/Core/Debugger.h"
11 #include "lldb/Core/PluginManager.h"
12 #include "lldb/Host/Host.h"
13 #include "lldb/Initialization/SystemInitializerCommon.h"
14 #include "lldb/Interpreter/CommandInterpreter.h"
15 #include "lldb/Utility/Timer.h"
16 #include "llvm/Support/TargetSelect.h"
17 
18 #include <string>
19 
20 #define LLDB_PLUGIN(p) LLDB_PLUGIN_DECLARE(p)
21 #include "Plugins/Plugins.def"
22 
23 using namespace lldb_private;
24 
25 SystemInitializerTest::SystemInitializerTest() = default;
26 SystemInitializerTest::~SystemInitializerTest() = default;
27 
28 llvm::Error SystemInitializerTest::Initialize() {
29   if (auto e = SystemInitializerCommon::Initialize())
30     return e;
31 
32   // Initialize LLVM and Clang
33   llvm::InitializeAllTargets();
34   llvm::InitializeAllAsmPrinters();
35   llvm::InitializeAllTargetMCs();
36   llvm::InitializeAllDisassemblers();
37 
38 #define LLDB_SCRIPT_PLUGIN(p)
39 #define LLDB_PLUGIN(p) LLDB_PLUGIN_INITIALIZE(p);
40 #include "Plugins/Plugins.def"
41 
42   // We ignored all the script interpreter earlier, so initialize
43   // ScriptInterpreterNone explicitly.
44   LLDB_PLUGIN_INITIALIZE(ScriptInterpreterNone);
45 
46   // Scan for any system or user LLDB plug-ins
47   PluginManager::Initialize();
48 
49   // The process settings need to know about installed plug-ins, so the
50   // Settings must be initialized AFTER PluginManager::Initialize is called.
51   Debugger::SettingsInitialize();
52 
53   return llvm::Error::success();
54 }
55 
56 void SystemInitializerTest::Terminate() {
57   static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
58   Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
59 
60   Debugger::SettingsTerminate();
61 
62   // Terminate and unload and loaded system or user LLDB plug-ins
63   PluginManager::Terminate();
64 
65 #define LLDB_SCRIPT_PLUGIN(p)
66 #define LLDB_PLUGIN(p) LLDB_PLUGIN_TERMINATE(p);
67 #include "Plugins/Plugins.def"
68 
69   // We ignored all the script interpreter earlier, so terminate
70   // ScriptInterpreterNone explicitly.
71   LLDB_PLUGIN_INITIALIZE(ScriptInterpreterNone);
72 
73   // Now shutdown the common parts, in reverse order.
74   SystemInitializerCommon::Terminate();
75 }
76