|
8 | 8 |
|
9 | 9 | #include "SystemInitializerFull.h" |
10 | 10 | #include "lldb/API/SBCommandInterpreter.h" |
| 11 | +#include "lldb/API/SBDebugger.h" |
11 | 12 | #include "lldb/Core/Debugger.h" |
12 | 13 | #include "lldb/Core/PluginManager.h" |
13 | 14 | #include "lldb/Core/Progress.h" |
@@ -86,10 +87,53 @@ llvm::Error SystemInitializerFull::Initialize() { |
86 | 87 |
|
87 | 88 | LLDB_LOG(GetLog(SystemLog::System), "{0}", GetVersion()); |
88 | 89 |
|
| 90 | + auto LoadPlugin = [](const lldb::DebuggerSP &debugger_sp, |
| 91 | + const FileSpec &spec, |
| 92 | + Status &error) -> llvm::sys::DynamicLibrary { |
| 93 | + llvm::sys::DynamicLibrary dynlib = |
| 94 | + llvm::sys::DynamicLibrary::getPermanentLibrary(spec.GetPath().c_str()); |
| 95 | + if (dynlib.isValid()) { |
| 96 | + typedef bool (*LLDBCommandPluginInit)(lldb::SBDebugger debugger); |
| 97 | + |
| 98 | + lldb::SBDebugger debugger_sb(debugger_sp); |
| 99 | + // This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger) |
| 100 | + // function. |
| 101 | + // TODO: mangle this differently for your system - on OSX, the first |
| 102 | + // underscore needs to be removed and the second one stays |
| 103 | + LLDBCommandPluginInit init_func = |
| 104 | + (LLDBCommandPluginInit)(uintptr_t)dynlib.getAddressOfSymbol( |
| 105 | + "_ZN4lldb16PluginInitializeENS_10SBDebuggerE"); |
| 106 | + if (init_func) { |
| 107 | + if (init_func(debugger_sb)) |
| 108 | + return dynlib; |
| 109 | + else |
| 110 | + error = Status::FromErrorString( |
| 111 | + "plug-in refused to load " |
| 112 | + "(lldb::PluginInitialize(lldb::SBDebugger) " |
| 113 | + "returned false)"); |
| 114 | + } else { |
| 115 | + error = Status::FromErrorString( |
| 116 | + "plug-in is missing the required initialization: " |
| 117 | + "lldb::PluginInitialize(lldb::SBDebugger)"); |
| 118 | + } |
| 119 | + } else { |
| 120 | + if (FileSystem::Instance().Exists(spec)) |
| 121 | + error = Status::FromErrorString( |
| 122 | + "this file does not represent a loadable dylib"); |
| 123 | + else |
| 124 | + error = Status::FromErrorString("no such file"); |
| 125 | + } |
| 126 | + return llvm::sys::DynamicLibrary(); |
| 127 | + }; |
| 128 | + |
| 129 | + Debugger::Initialize(LoadPlugin); |
| 130 | + |
89 | 131 | return llvm::Error::success(); |
90 | 132 | } |
91 | 133 |
|
92 | 134 | void SystemInitializerFull::Terminate() { |
| 135 | + Debugger::Terminate(); |
| 136 | + |
93 | 137 | Debugger::SettingsTerminate(); |
94 | 138 |
|
95 | 139 | // Terminate plug-ins in core LLDB. |
|
0 commit comments