LLDB mainline
SystemInitializerFull.cpp
Go to the documentation of this file.
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
11#include "lldb/API/SBDebugger.h"
12#include "lldb/Core/Debugger.h"
14#include "lldb/Core/Progress.h"
15#include "lldb/Host/Config.h"
16#include "lldb/Host/Host.h"
20#include "lldb/Utility/Timer.h"
22#include "llvm/Support/CommandLine.h"
23#include "llvm/Support/TargetSelect.h"
24
25#pragma clang diagnostic push
26#pragma clang diagnostic ignored "-Wglobal-constructors"
27#include "llvm/ExecutionEngine/MCJIT.h"
28#pragma clang diagnostic pop
29
30#include <string>
31
32#define LLDB_PLUGIN(p) LLDB_PLUGIN_DECLARE(p)
33#include "Plugins/Plugins.def"
34
35using namespace lldb_private;
36
39
42 if (error)
43 return error;
44
45 // Initialize LLVM and Clang
46 llvm::InitializeAllTargets();
47 llvm::InitializeAllAsmPrinters();
48 llvm::InitializeAllTargetMCs();
49 llvm::InitializeAllDisassemblers();
50
51 // Initialize the command line parser in LLVM. This usually isn't necessary
52 // as we aren't dealing with command line options here, but otherwise some
53 // other code in Clang/LLVM might be tempted to call this function from a
54 // different thread later on which won't work (as the function isn't
55 // thread-safe).
56 const char *arg0 = "lldb";
57 llvm::cl::ParseCommandLineOptions(1, &arg0);
58
59#define LLDB_PLUGIN(p) LLDB_PLUGIN_INITIALIZE(p);
60#include "Plugins/Plugins.def"
61
62 // Scan for any system or user LLDB plug-ins.
64
65 // The process settings need to know about installed plug-ins, so the
66 // Settings must be initialized AFTER PluginManager::Initialize is called.
68
69 // Use the Debugger's LLDBAssert callback.
71
72 // Use the system log to report errors that would otherwise get dropped.
74
76
77 auto LoadPlugin = [](const lldb::DebuggerSP &debugger_sp,
78 const FileSpec &spec,
79 Status &error) -> llvm::sys::DynamicLibrary {
80 llvm::sys::DynamicLibrary dynlib =
81 llvm::sys::DynamicLibrary::getPermanentLibrary(spec.GetPath().c_str());
82 if (dynlib.isValid()) {
83 typedef bool (*LLDBCommandPluginInit)(lldb::SBDebugger debugger);
84
85 lldb::SBDebugger debugger_sb(debugger_sp);
86 // This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger)
87 // function.
88 // TODO: mangle this differently for your system - on OSX, the first
89 // underscore needs to be removed and the second one stays
90 LLDBCommandPluginInit init_func =
91 (LLDBCommandPluginInit)(uintptr_t)dynlib.getAddressOfSymbol(
92 "_ZN4lldb16PluginInitializeENS_10SBDebuggerE");
93 if (init_func) {
94 if (init_func(debugger_sb))
95 return dynlib;
96 else
98 "plug-in refused to load "
99 "(lldb::PluginInitialize(lldb::SBDebugger) "
100 "returned false)");
101 } else {
103 "plug-in is missing the required initialization: "
104 "lldb::PluginInitialize(lldb::SBDebugger)");
105 }
106 } else {
107 if (FileSystem::Instance().Exists(spec))
109 "this file does not represent a loadable dylib");
110 else
111 error = Status::FromErrorString("no such file");
112 }
113 return llvm::sys::DynamicLibrary();
114 };
115
116 Debugger::Initialize(LoadPlugin);
117
118 return llvm::Error::success();
119}
120
123
125
126 // Terminate plug-ins in core LLDB.
128
129 // Terminate and unload and loaded system or user LLDB plug-ins.
131
132#define LLDB_PLUGIN(p) LLDB_PLUGIN_TERMINATE(p);
133#include "Plugins/Plugins.def"
134
135 // Now shutdown the common parts, in reverse order.
137}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:369
static void AssertCallback(llvm::StringRef message, llvm::StringRef backtrace, llvm::StringRef prompt)
static void Terminate()
Definition Debugger.cpp:760
static void SettingsInitialize()
Definition Debugger.cpp:789
static void Initialize(LoadPluginCallbackType load_plugin_callback)
Definition Debugger.cpp:751
static void SettingsTerminate()
Definition Debugger.cpp:791
A file utility class.
Definition FileSpec.h:57
static FileSystem & Instance()
An error handling class.
Definition Status.h:118
static Status FromErrorString(const char *str)
Definition Status.h:141
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:332
void SetLLDBAssertCallback(LLDBAssertCallback callback)
Replace the LLDB assert callback.
const char * GetVersion()
Retrieves a string representing the complete LLDB version, which includes the lldb version number,...
Definition Version.cpp:38
void SetLLDBErrorLog(Log *log)
Getter and setter for the error log (see g_error_log).
Definition Log.cpp:468
std::shared_ptr< lldb_private::Debugger > DebuggerSP