Skip to content

Commit f35a9c2

Browse files
committed
[lldb] Convert LocateSymbolFile into a plugin (llvm#71151)
This commit contains the initial scaffolding to convert the functionality currently implemented in LocateSymbolFile to a plugin architecture. The plugin approach allows us to easily add new ways to find symbols and fixes some issues with the current implementation. For instance, currently we (ab)use the host OS to include support for querying the DebugSymbols framework on macOS. The plugin approach retains all the benefits (including the ability to compile this out on other platforms) while maintaining a higher level of separation with the platform independent code. To limit the scope of this patch, I've only converted a single function: LocateExecutableObjectFile. Future commits will convert the remaining LocateSymbolFile functions and eventually remove LocateSymbolFile. To make reviewing easier, that will done as follow-ups. (cherry picked from commit c3a302d)
1 parent 8b7dbdf commit f35a9c2

18 files changed

+623
-32
lines changed

lldb/include/lldb/Core/PluginManager.h

+13
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,19 @@ class PluginManager {
345345
static SymbolVendorCreateInstance
346346
GetSymbolVendorCreateCallbackAtIndex(uint32_t idx);
347347

348+
// SymbolLocator
349+
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
350+
SymbolLocatorCreateInstance create_callback,
351+
SymbolLocatorLocateExecutableObjectFile
352+
locate_executable_object_file = nullptr);
353+
354+
static bool UnregisterPlugin(SymbolLocatorCreateInstance create_callback);
355+
356+
static SymbolLocatorCreateInstance
357+
GetSymbolLocatorCreateCallbackAtIndex(uint32_t idx);
358+
359+
static ModuleSpec LocateExecutableObjectFile(const ModuleSpec &module_spec);
360+
348361
// Trace
349362
static bool RegisterPlugin(
350363
llvm::StringRef name, llvm::StringRef description,

lldb/include/lldb/Symbol/LocateSymbolFile.h

-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ class UUID;
2424

2525
class Symbols {
2626
public:
27-
// Locate the executable file given a module specification.
28-
//
29-
// Locating the file should happen only on the local computer or using the
30-
// current computers global settings.
31-
static ModuleSpec LocateExecutableObjectFile(const ModuleSpec &module_spec);
32-
3327
// Locate the symbol file given a module specification.
3428
//
3529
// Locating the file should happen only on the local computer or using the
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===-- SymbolLocator.h -----------------------------------------*- 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+
#ifndef LLDB_SYMBOL_SYMBOLLOCATOR_H
10+
#define LLDB_SYMBOL_SYMBOLLOCATOR_H
11+
12+
#include "lldb/Core/PluginInterface.h"
13+
14+
namespace lldb_private {
15+
16+
class SymbolLocator : public PluginInterface {
17+
public:
18+
SymbolLocator() = default;
19+
};
20+
21+
} // namespace lldb_private
22+
23+
#endif // LLDB_SYMBOL_SYMBOLFILELOCATOR_H

lldb/include/lldb/lldb-forward.h

+1
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ class SymbolContextScope;
220220
class SymbolContextSpecifier;
221221
class SymbolFile;
222222
class SymbolFileType;
223+
class SymbolLocator;
223224
class SymbolVendor;
224225
class Symtab;
225226
class SyntheticChildren;

lldb/include/lldb/lldb-private-interfaces.h

+3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ typedef SymbolVendor *(*SymbolVendorCreateInstance)(
9191
const lldb::ModuleSP &module_sp,
9292
lldb_private::Stream
9393
*feedback_strm); // Module can be NULL for default system symbol vendor
94+
typedef SymbolLocator *(*SymbolLocatorCreateInstance)();
95+
typedef std::optional<ModuleSpec> (*SymbolLocatorLocateExecutableObjectFile)(
96+
const ModuleSpec &module_spec);
9497
typedef bool (*BreakpointHitCallback)(void *baton,
9598
StoppointCallbackContext *context,
9699
lldb::user_id_t break_id,

lldb/source/Core/DynamicLoader.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ ModuleSP DynamicLoader::LoadBinaryWithUUIDAndAddress(
221221
module_spec.GetSymbolFileSpec() =
222222
Symbols::LocateExecutableSymbolFile(module_spec, search_paths);
223223
ModuleSpec objfile_module_spec =
224-
Symbols::LocateExecutableObjectFile(module_spec);
224+
PluginManager::LocateExecutableObjectFile(module_spec);
225225
module_spec.GetFileSpec() = objfile_module_spec.GetFileSpec();
226226
if (FileSystem::Instance().Exists(module_spec.GetFileSpec()) &&
227227
FileSystem::Instance().Exists(module_spec.GetSymbolFileSpec())) {

lldb/source/Core/ModuleList.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "lldb/Core/ModuleList.h"
1010
#include "lldb/Core/Module.h"
1111
#include "lldb/Core/ModuleSpec.h"
12+
#include "lldb/Core/PluginManager.h"
1213
#include "lldb/Host/FileSystem.h"
1314
#include "lldb/Interpreter/OptionValueFileSpec.h"
1415
#include "lldb/Interpreter/OptionValueFileSpecList.h"
@@ -1098,7 +1099,7 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
10981099
// Fixup the incoming path in case the path points to a valid file, yet the
10991100
// arch or UUID (if one was passed in) don't match.
11001101
ModuleSpec located_binary_modulespec =
1101-
Symbols::LocateExecutableObjectFile(module_spec);
1102+
PluginManager::LocateExecutableObjectFile(module_spec);
11021103

11031104
// Don't look for the file if it appears to be the same one we already
11041105
// checked for above...

lldb/source/Core/PluginManager.cpp

+53
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,59 @@ PluginManager::GetSymbolVendorCreateCallbackAtIndex(uint32_t idx) {
10811081
return GetSymbolVendorInstances().GetCallbackAtIndex(idx);
10821082
}
10831083

1084+
#pragma mark SymbolLocator
1085+
1086+
struct SymbolLocatorInstance
1087+
: public PluginInstance<SymbolLocatorCreateInstance> {
1088+
SymbolLocatorInstance(
1089+
llvm::StringRef name, llvm::StringRef description,
1090+
CallbackType create_callback,
1091+
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file)
1092+
: PluginInstance<SymbolLocatorCreateInstance>(name, description,
1093+
create_callback),
1094+
locate_executable_object_file(locate_executable_object_file) {}
1095+
1096+
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file;
1097+
};
1098+
typedef PluginInstances<SymbolLocatorInstance> SymbolLocatorInstances;
1099+
1100+
static SymbolLocatorInstances &GetSymbolLocatorInstances() {
1101+
static SymbolLocatorInstances g_instances;
1102+
return g_instances;
1103+
}
1104+
1105+
bool PluginManager::RegisterPlugin(
1106+
llvm::StringRef name, llvm::StringRef description,
1107+
SymbolLocatorCreateInstance create_callback,
1108+
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file) {
1109+
return GetSymbolLocatorInstances().RegisterPlugin(
1110+
name, description, create_callback, locate_executable_object_file);
1111+
}
1112+
1113+
bool PluginManager::UnregisterPlugin(
1114+
SymbolLocatorCreateInstance create_callback) {
1115+
return GetSymbolLocatorInstances().UnregisterPlugin(create_callback);
1116+
}
1117+
1118+
SymbolLocatorCreateInstance
1119+
PluginManager::GetSymbolLocatorCreateCallbackAtIndex(uint32_t idx) {
1120+
return GetSymbolLocatorInstances().GetCallbackAtIndex(idx);
1121+
}
1122+
1123+
ModuleSpec
1124+
PluginManager::LocateExecutableObjectFile(const ModuleSpec &module_spec) {
1125+
auto &instances = GetSymbolLocatorInstances().GetInstances();
1126+
for (auto &instance : instances) {
1127+
if (instance.locate_executable_object_file) {
1128+
std::optional<ModuleSpec> result =
1129+
instance.locate_executable_object_file(module_spec);
1130+
if (result)
1131+
return *result;
1132+
}
1133+
}
1134+
return {};
1135+
}
1136+
10841137
#pragma mark Trace
10851138

10861139
struct TraceInstance

lldb/source/Plugins/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ add_subdirectory(ScriptInterpreter)
2020
add_subdirectory(StructuredData)
2121
add_subdirectory(SymbolFile)
2222
add_subdirectory(SystemRuntime)
23+
add_subdirectory(SymbolLocator)
2324
add_subdirectory(SymbolVendor)
2425
add_subdirectory(Trace)
2526
add_subdirectory(TraceExporter)

lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ Status ProcessKDP::DoConnectRemote(llvm::StringRef remote_url) {
283283
search_paths);
284284
if (module_spec.GetSymbolFileSpec()) {
285285
ModuleSpec executable_module_spec =
286-
Symbols::LocateExecutableObjectFile(module_spec);
286+
PluginManager::LocateExecutableObjectFile(module_spec);
287287
if (FileSystem::Instance().Exists(
288288
executable_module_spec.GetFileSpec())) {
289289
module_spec.GetFileSpec() =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add_subdirectory(Default)
2+
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
3+
add_subdirectory(DebugSymbols)
4+
endif()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
add_lldb_library(lldbPluginSymbolLocatorDebugSymbols PLUGIN
2+
SymbolLocatorDebugSymbols.cpp
3+
4+
LINK_LIBS
5+
lldbCore
6+
lldbHost
7+
lldbSymbol
8+
)

0 commit comments

Comments
 (0)