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"
16#include "lldb/Host/Config.h"
17#include "lldb/Host/Host.h"
22#include "lldb/Utility/Timer.h"
23#include "llvm/Support/CommandLine.h"
24#include "llvm/Support/TargetSelect.h"
25
26#if LLDB_ENABLE_PYTHON
29#endif
30
31#pragma clang diagnostic push
32#pragma clang diagnostic ignored "-Wglobal-constructors"
33#include "llvm/ExecutionEngine/MCJIT.h"
34#pragma clang diagnostic pop
35
36#include <string>
37
38#define LLDB_PLUGIN(p) LLDB_PLUGIN_DECLARE(p)
39#include "Plugins/Plugins.def"
40
41using namespace lldb_private;
42
47
50 if (error)
51 return error;
52
53#if LLDB_ENABLE_PYTHON
54 // The dynamic script interpreter plugin references Python data symbols (type
55 // and exception objects), which can't be bound lazily, so Python must be
56 // mapped before loading the plugin. Failure isn't fatal. Without the plugin,
57 // ScriptInterpreterNone reports the recorded error in its place.
58 llvm::Expected<ScriptInterpreterRuntimeLoader &> python_loader =
60 if (llvm::Error python_error =
61 python_loader ? python_loader->Load() : python_loader.takeError())
63 std::move(python_error));
64#endif
65
66 // Initialize LLVM and Clang
67 llvm::InitializeAllTargets();
68 llvm::InitializeAllAsmPrinters();
69 llvm::InitializeAllTargetMCs();
70 llvm::InitializeAllDisassemblers();
71
72 // Initialize the command line parser in LLVM. This usually isn't necessary
73 // as we aren't dealing with command line options here, but otherwise some
74 // other code in Clang/LLVM might be tempted to call this function from a
75 // different thread later on which won't work (as the function isn't
76 // thread-safe).
77 const char *arg0 = "lldb";
78 llvm::cl::ParseCommandLineOptions(1, &arg0);
79
80#define LLDB_PLUGIN(p) LLDB_PLUGIN_INITIALIZE(p);
81#include "Plugins/Plugins.def"
82
83 // Scan for any system or user LLDB plug-ins.
85
86 // The process settings need to know about installed plug-ins, so the
87 // Settings must be initialized AFTER PluginManager::Initialize is called.
89
90 // Use the Debugger's LLDBAssert callback.
92
93 // Use the system log to report errors that would otherwise get dropped.
95
98
99 auto LoadPlugin = [](const lldb::DebuggerSP &debugger_sp,
100 const FileSpec &spec,
101 Status &error) -> llvm::sys::DynamicLibrary {
102 llvm::sys::DynamicLibrary dynlib =
103 llvm::sys::DynamicLibrary::getPermanentLibrary(spec.GetPath().c_str());
104 if (dynlib.isValid()) {
105 typedef bool (*LLDBCommandPluginInit)(lldb::SBDebugger debugger);
106
107 lldb::SBDebugger debugger_sb(debugger_sp);
108 // This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger)
109 // function.
110 // TODO: mangle this differently for your system - on OSX, the first
111 // underscore needs to be removed and the second one stays
112 LLDBCommandPluginInit init_func =
113 (LLDBCommandPluginInit)(uintptr_t)dynlib.getAddressOfSymbol(
114 "_ZN4lldb16PluginInitializeENS_10SBDebuggerE");
115 if (init_func) {
116 if (init_func(debugger_sb))
117 return dynlib;
118 else
120 "plug-in refused to load "
121 "(lldb::PluginInitialize(lldb::SBDebugger) "
122 "returned false)");
123 } else {
125 "plug-in is missing the required initialization: "
126 "lldb::PluginInitialize(lldb::SBDebugger)");
127 }
128 } else {
129 if (FileSystem::Instance().Exists(spec))
131 "this file does not represent a loadable dylib");
132 else
133 error = Status::FromErrorString("no such file");
134 }
135 return llvm::sys::DynamicLibrary();
136 };
137
138 Debugger::Initialize(LoadPlugin);
139
140 // Warm up DataVisualization and common language categories ahead of time.
141 [[maybe_unused]] lldb::TypeCategoryImplSP entry;
143 entry);
145 entry);
148 return llvm::Error::success();
149}
150
153
155
156 // Terminate plug-ins in core LLDB.
158
159 // Terminate and unload and loaded system or user LLDB plug-ins.
161
162#define LLDB_PLUGIN(p) LLDB_PLUGIN_TERMINATE(p);
163#include "Plugins/Plugins.def"
164
165 // Now shutdown the common parts, in reverse order.
167}
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:375
static bool GetCategory(llvm::StringRef category, lldb::TypeCategoryImplSP &entry, bool allow_create=true)
static void AssertCallback(llvm::StringRef message, llvm::StringRef backtrace, llvm::StringRef prompt)
static void Terminate()
Definition Debugger.cpp:857
static void SettingsInitialize()
Definition Debugger.cpp:886
static void Initialize(LoadPluginCallbackType load_plugin_callback)
Definition Debugger.cpp:848
static void SettingsTerminate()
Definition Debugger.cpp:888
A file utility class.
Definition FileSpec.h:56
static FileSystem & Instance()
static std::string GetVersionWithLanguageInfo()
Returns lldb_private::GetVersion(), followed by the GetVersionInfo() of each registered language plug...
Definition Language.cpp:117
static void SetScriptInterpreterError(lldb::ScriptLanguage script_lang, llvm::Error error)
Records why no script interpreter for script_lang could be registered, for the fallback interpreter t...
static llvm::Expected< ScriptInterpreterRuntimeLoader & > Get(lldb::ScriptLanguage language)
Returns the loader for language.
An error handling class.
Definition Status.h:118
static Status FromErrorString(const char *str)
Definition Status.h:141
SystemInitializerFull(const InitializationOptions &options)
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:338
void SetLLDBAssertCallback(LLDBAssertCallback callback)
Replace the LLDB assert callback.
void SetLLDBErrorLog(Log *log)
Getter and setter for the error log (see g_error_log).
Definition Log.cpp:524
@ eScriptLanguagePython
@ eLanguageTypeObjC_plus_plus
Objective-C++.
@ eLanguageTypeSwift
Swift.
@ eLanguageTypeObjC
Objective-C.
@ eLanguageTypeC_plus_plus
ISO C++:1998.
std::shared_ptr< lldb_private::Debugger > DebuggerSP
std::shared_ptr< lldb_private::TypeCategoryImpl > TypeCategoryImplSP