Skip to content

[lldb] Convert LocateSymbolFile into a plugin #71151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lldb/include/lldb/Core/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,19 @@ class PluginManager {
static SymbolVendorCreateInstance
GetSymbolVendorCreateCallbackAtIndex(uint32_t idx);

// SymbolLocator
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
SymbolLocatorCreateInstance create_callback,
SymbolLocatorLocateExecutableObjectFile
locate_executable_object_file = nullptr);

static bool UnregisterPlugin(SymbolLocatorCreateInstance create_callback);

static SymbolLocatorCreateInstance
GetSymbolLocatorCreateCallbackAtIndex(uint32_t idx);

static ModuleSpec LocateExecutableObjectFile(const ModuleSpec &module_spec);

// Trace
static bool RegisterPlugin(
llvm::StringRef name, llvm::StringRef description,
Expand Down
6 changes: 0 additions & 6 deletions lldb/include/lldb/Symbol/LocateSymbolFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ class UUID;

class Symbols {
public:
// Locate the executable file given a module specification.
//
// Locating the file should happen only on the local computer or using the
// current computers global settings.
static ModuleSpec LocateExecutableObjectFile(const ModuleSpec &module_spec);

// Locate the symbol file given a module specification.
//
// Locating the file should happen only on the local computer or using the
Expand Down
23 changes: 23 additions & 0 deletions lldb/include/lldb/Symbol/SymbolLocator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===-- SymbolLocator.h -----------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_SYMBOL_SYMBOLLOCATOR_H
#define LLDB_SYMBOL_SYMBOLLOCATOR_H

#include "lldb/Core/PluginInterface.h"

namespace lldb_private {

class SymbolLocator : public PluginInterface {
public:
SymbolLocator() = default;
};

} // namespace lldb_private

#endif // LLDB_SYMBOL_SYMBOLFILELOCATOR_H
1 change: 1 addition & 0 deletions lldb/include/lldb/lldb-forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ class SymbolContextScope;
class SymbolContextSpecifier;
class SymbolFile;
class SymbolFileType;
class SymbolLocator;
class SymbolVendor;
class Symtab;
class SyntheticChildren;
Expand Down
3 changes: 3 additions & 0 deletions lldb/include/lldb/lldb-private-interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ typedef SymbolVendor *(*SymbolVendorCreateInstance)(
const lldb::ModuleSP &module_sp,
lldb_private::Stream
*feedback_strm); // Module can be NULL for default system symbol vendor
typedef SymbolLocator *(*SymbolLocatorCreateInstance)();
typedef std::optional<ModuleSpec> (*SymbolLocatorLocateExecutableObjectFile)(
const ModuleSpec &module_spec);
typedef bool (*BreakpointHitCallback)(void *baton,
StoppointCallbackContext *context,
lldb::user_id_t break_id,
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Core/DynamicLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ ModuleSP DynamicLoader::LoadBinaryWithUUIDAndAddress(
module_spec.GetSymbolFileSpec() =
Symbols::LocateExecutableSymbolFile(module_spec, search_paths);
ModuleSpec objfile_module_spec =
Symbols::LocateExecutableObjectFile(module_spec);
PluginManager::LocateExecutableObjectFile(module_spec);
module_spec.GetFileSpec() = objfile_module_spec.GetFileSpec();
if (FileSystem::Instance().Exists(module_spec.GetFileSpec()) &&
FileSystem::Instance().Exists(module_spec.GetSymbolFileSpec())) {
Expand Down
3 changes: 2 additions & 1 deletion lldb/source/Core/ModuleList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "lldb/Core/ModuleList.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Interpreter/OptionValueFileSpec.h"
#include "lldb/Interpreter/OptionValueFileSpecList.h"
Expand Down Expand Up @@ -906,7 +907,7 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
// Fixup the incoming path in case the path points to a valid file, yet the
// arch or UUID (if one was passed in) don't match.
ModuleSpec located_binary_modulespec =
Symbols::LocateExecutableObjectFile(module_spec);
PluginManager::LocateExecutableObjectFile(module_spec);

// Don't look for the file if it appears to be the same one we already
// checked for above...
Expand Down
53 changes: 53 additions & 0 deletions lldb/source/Core/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,59 @@ PluginManager::GetSymbolVendorCreateCallbackAtIndex(uint32_t idx) {
return GetSymbolVendorInstances().GetCallbackAtIndex(idx);
}

#pragma mark SymbolLocator

struct SymbolLocatorInstance
: public PluginInstance<SymbolLocatorCreateInstance> {
SymbolLocatorInstance(
llvm::StringRef name, llvm::StringRef description,
CallbackType create_callback,
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file)
: PluginInstance<SymbolLocatorCreateInstance>(name, description,
create_callback),
locate_executable_object_file(locate_executable_object_file) {}

SymbolLocatorLocateExecutableObjectFile locate_executable_object_file;
};
typedef PluginInstances<SymbolLocatorInstance> SymbolLocatorInstances;

static SymbolLocatorInstances &GetSymbolLocatorInstances() {
static SymbolLocatorInstances g_instances;
return g_instances;
}

bool PluginManager::RegisterPlugin(
llvm::StringRef name, llvm::StringRef description,
SymbolLocatorCreateInstance create_callback,
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file) {
return GetSymbolLocatorInstances().RegisterPlugin(
name, description, create_callback, locate_executable_object_file);
}

bool PluginManager::UnregisterPlugin(
SymbolLocatorCreateInstance create_callback) {
return GetSymbolLocatorInstances().UnregisterPlugin(create_callback);
}

SymbolLocatorCreateInstance
PluginManager::GetSymbolLocatorCreateCallbackAtIndex(uint32_t idx) {
return GetSymbolLocatorInstances().GetCallbackAtIndex(idx);
}

ModuleSpec
PluginManager::LocateExecutableObjectFile(const ModuleSpec &module_spec) {
auto &instances = GetSymbolLocatorInstances().GetInstances();
for (auto &instance : instances) {
if (instance.locate_executable_object_file) {
std::optional<ModuleSpec> result =
instance.locate_executable_object_file(module_spec);
if (result)
return *result;
}
}
return {};
}

#pragma mark Trace

struct TraceInstance
Expand Down
1 change: 1 addition & 0 deletions lldb/source/Plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ add_subdirectory(ScriptInterpreter)
add_subdirectory(StructuredData)
add_subdirectory(SymbolFile)
add_subdirectory(SystemRuntime)
add_subdirectory(SymbolLocator)
add_subdirectory(SymbolVendor)
add_subdirectory(Trace)
add_subdirectory(TraceExporter)
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ Status ProcessKDP::DoConnectRemote(llvm::StringRef remote_url) {
search_paths);
if (module_spec.GetSymbolFileSpec()) {
ModuleSpec executable_module_spec =
Symbols::LocateExecutableObjectFile(module_spec);
PluginManager::LocateExecutableObjectFile(module_spec);
if (FileSystem::Instance().Exists(
executable_module_spec.GetFileSpec())) {
module_spec.GetFileSpec() =
Expand Down
4 changes: 4 additions & 0 deletions lldb/source/Plugins/SymbolLocator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_subdirectory(Default)
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
add_subdirectory(DebugSymbols)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm switching my previous PR to be a "Debuginfod" SymbolLocator plugin, and I think this plugin name is far too general. @clayborg tells me that "DebugSymbols.framework" is a thing on MacOS, but maybe rename this "DebugSymbolsApple" or "MacOSDebugSymbols" or pretty much anything that would indicate to the random developer that this stuff is for (mac|i(Pad)|tv)OS/Apple/Darwin/Sherlock/dSYM symbol lookup.

endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
add_lldb_library(lldbPluginSymbolLocatorDebugSymbols PLUGIN
SymbolLocatorDebugSymbols.cpp

LINK_LIBS
lldbCore
lldbHost
lldbSymbol
)
Loading