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
45
48 if (error)
49 return error;
50
51#if LLDB_ENABLE_PYTHON
52 // The dynamic script interpreter plugin references Python data symbols (type
53 // and exception objects), which can't be bound lazily, so Python must be
54 // mapped before loading the plugin. Failure isn't fatal. Without the plugin,
55 // ScriptInterpreterNone reports the recorded error in its place.
56 llvm::Expected<ScriptInterpreterRuntimeLoader &> python_loader =
58 if (llvm::Error python_error =
59 python_loader ? python_loader->Load() : python_loader.takeError())
61 std::move(python_error));
62#endif
63
64 // Initialize LLVM and Clang
65 llvm::InitializeAllTargets();
66 llvm::InitializeAllAsmPrinters();
67 llvm::InitializeAllTargetMCs();
68 llvm::InitializeAllDisassemblers();
69
70 // Initialize the command line parser in LLVM. This usually isn't necessary
71 // as we aren't dealing with command line options here, but otherwise some
72 // other code in Clang/LLVM might be tempted to call this function from a
73 // different thread later on which won't work (as the function isn't
74 // thread-safe).
75 const char *arg0 = "lldb";
76 llvm::cl::ParseCommandLineOptions(1, &arg0);
77
78#define LLDB_PLUGIN(p) LLDB_PLUGIN_INITIALIZE(p);
79#include "Plugins/Plugins.def"
80
81 // Scan for any system or user LLDB plug-ins.
83
84 // The process settings need to know about installed plug-ins, so the
85 // Settings must be initialized AFTER PluginManager::Initialize is called.
87
88 // Use the Debugger's LLDBAssert callback.
90
91 // Use the system log to report errors that would otherwise get dropped.
93
96
97 auto LoadPlugin = [](const lldb::DebuggerSP &debugger_sp,
98 const FileSpec &spec,
99 Status &error) -> llvm::sys::DynamicLibrary {
100 llvm::sys::DynamicLibrary dynlib =
101 llvm::sys::DynamicLibrary::getPermanentLibrary(spec.GetPath().c_str());
102 if (dynlib.isValid()) {
103 typedef bool (*LLDBCommandPluginInit)(lldb::SBDebugger debugger);
104
105 lldb::SBDebugger debugger_sb(debugger_sp);
106 // This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger)
107 // function.
108 // TODO: mangle this differently for your system - on OSX, the first
109 // underscore needs to be removed and the second one stays
110 LLDBCommandPluginInit init_func =
111 (LLDBCommandPluginInit)(uintptr_t)dynlib.getAddressOfSymbol(
112 "_ZN4lldb16PluginInitializeENS_10SBDebuggerE");
113 if (init_func) {
114 if (init_func(debugger_sb))
115 return dynlib;
116 else
118 "plug-in refused to load "
119 "(lldb::PluginInitialize(lldb::SBDebugger) "
120 "returned false)");
121 } else {
123 "plug-in is missing the required initialization: "
124 "lldb::PluginInitialize(lldb::SBDebugger)");
125 }
126 } else {
127 if (FileSystem::Instance().Exists(spec))
129 "this file does not represent a loadable dylib");
130 else
131 error = Status::FromErrorString("no such file");
132 }
133 return llvm::sys::DynamicLibrary();
134 };
135
136 Debugger::Initialize(LoadPlugin);
137
138 // Warm up DataVisualization and common language categories ahead of time.
139 [[maybe_unused]] lldb::TypeCategoryImplSP entry;
141 entry);
143 entry);
146 return llvm::Error::success();
147}
148
151
153
154 // Terminate plug-ins in core LLDB.
156
157 // Terminate and unload and loaded system or user LLDB plug-ins.
159
160#define LLDB_PLUGIN(p) LLDB_PLUGIN_TERMINATE(p);
161#include "Plugins/Plugins.def"
162
163 // Now shutdown the common parts, in reverse order.
165}
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:185
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
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