Skip to content

[lldb] Move DownloadObjectAndSymbolFile to SymbolLocator plugin #71267

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 2 commits into from
Nov 5, 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
7 changes: 7 additions & 0 deletions lldb/include/lldb/Core/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ class PluginManager {
nullptr,
SymbolLocatorLocateExecutableSymbolFile locate_executable_symbol_file =
nullptr,
SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file =
nullptr,
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle = nullptr);

static bool UnregisterPlugin(SymbolLocatorCreateInstance create_callback);
Expand All @@ -366,6 +368,11 @@ class PluginManager {
LocateExecutableSymbolFile(const ModuleSpec &module_spec,
const FileSpecList &default_search_paths);

static bool DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
Status &error,
bool force_lookup = true,
bool copy_executable = true);

static FileSpec FindSymbolFileInBundle(const FileSpec &dsym_bundle_fspec,
const UUID *uuid,
const ArchSpec *arch);
Expand Down
14 changes: 0 additions & 14 deletions lldb/include/lldb/Symbol/LocateSymbolFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,6 @@ class UUID;

class Symbols {
public:
// Locate the object and symbol file given a module specification.
//
// Locating the file can try to download the file from a corporate build
// repository, or using any other means necessary to locate both the
// unstripped object file and the debug symbols. The force_lookup argument
// controls whether the external program is called unconditionally to find
// the symbol file, or if the user's settings are checked to see if they've
// enabled the external program before calling.
//
static bool DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
Status &error,
bool force_lookup = true,
bool copy_executable = true);

/// Locate the symbol file for the given UUID on a background thread. This
/// function returns immediately. Under the hood it uses the debugger's
/// thread pool to call DownloadObjectAndSymbolFile. If a symbol file is
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 @@ -96,6 +96,9 @@ typedef std::optional<FileSpec> (*SymbolLocatorFindSymbolFileInBundle)(
const FileSpec &dsym_bundle_fspec, const UUID *uuid, const ArchSpec *arch);
typedef std::optional<FileSpec> (*SymbolLocatorLocateExecutableSymbolFile)(
const ModuleSpec &module_spec, const FileSpecList &default_search_paths);
typedef bool (*SymbolLocatorDownloadObjectAndSymbolFile)(
ModuleSpec &module_spec, Status &error, bool force_lookup,
bool copy_executable);
typedef bool (*BreakpointHitCallback)(void *baton,
StoppointCallbackContext *context,
lldb::user_id_t break_id,
Expand Down
6 changes: 4 additions & 2 deletions lldb/source/API/SBTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "lldb/Core/Disassembler.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/SearchFilter.h"
#include "lldb/Core/Section.h"
#include "lldb/Core/StructuredDataImpl.h"
Expand Down Expand Up @@ -1525,8 +1526,9 @@ lldb::SBModule SBTarget::AddModule(const SBModuleSpec &module_spec) {
true /* notify */));
if (!sb_module.IsValid() && module_spec.m_opaque_up->GetUUID().IsValid()) {
Status error;
if (Symbols::DownloadObjectAndSymbolFile(*module_spec.m_opaque_up, error,
/* force_lookup */ true)) {
if (PluginManager::DownloadObjectAndSymbolFile(*module_spec.m_opaque_up,
error,
/* force_lookup */ true)) {
if (FileSystem::Instance().Exists(
module_spec.m_opaque_up->GetFileSpec())) {
sb_module.SetSP(target_sp->GetOrCreateModule(*module_spec.m_opaque_up,
Expand Down
5 changes: 3 additions & 2 deletions lldb/source/Commands/CommandObjectTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "lldb/Core/IOHandler.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/Section.h"
#include "lldb/Core/ValueObjectVariable.h"
#include "lldb/DataFormatters/ValueObjectPrinter.h"
Expand Down Expand Up @@ -2801,7 +2802,7 @@ class CommandObjectTargetModulesAdd : public CommandObjectParsed {
module_spec.GetSymbolFileSpec() =
m_symbol_file.GetOptionValue().GetCurrentValue();
Status error;
if (Symbols::DownloadObjectAndSymbolFile(module_spec, error)) {
if (PluginManager::DownloadObjectAndSymbolFile(module_spec, error)) {
ModuleSP module_sp(
target->GetOrCreateModule(module_spec, true /* notify */));
if (module_sp) {
Expand Down Expand Up @@ -4497,7 +4498,7 @@ class CommandObjectTargetSymbolsAdd : public CommandObjectParsed {
bool DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
CommandReturnObject &result, bool &flush) {
Status error;
if (Symbols::DownloadObjectAndSymbolFile(module_spec, error)) {
if (PluginManager::DownloadObjectAndSymbolFile(module_spec, error)) {
if (module_spec.GetSymbolFileSpec())
return AddModuleSymbols(m_exe_ctx.GetTargetPtr(), module_spec, flush,
result);
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Core/DynamicLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ ModuleSP DynamicLoader::LoadBinaryWithUUIDAndAddress(
// If we haven't found a binary, or we don't have a SymbolFile, see
// if there is an external search tool that can find it.
if (!module_sp || !module_sp->GetSymbolFileFileSpec()) {
Symbols::DownloadObjectAndSymbolFile(module_spec, error,
force_symbol_search);
PluginManager::DownloadObjectAndSymbolFile(module_spec, error,
force_symbol_search);
if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
module_sp = std::make_shared<Module>(module_spec);
} else if (force_symbol_search && error.AsCString("") &&
Expand Down
22 changes: 21 additions & 1 deletion lldb/source/Core/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1090,15 +1090,18 @@ struct SymbolLocatorInstance
CallbackType create_callback,
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file,
SymbolLocatorLocateExecutableSymbolFile locate_executable_symbol_file,
SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file,
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle)
: PluginInstance<SymbolLocatorCreateInstance>(name, description,
create_callback),
locate_executable_object_file(locate_executable_object_file),
locate_executable_symbol_file(locate_executable_symbol_file),
download_object_symbol_file(download_object_symbol_file),
find_symbol_file_in_bundle(find_symbol_file_in_bundle) {}

SymbolLocatorLocateExecutableObjectFile locate_executable_object_file;
SymbolLocatorLocateExecutableSymbolFile locate_executable_symbol_file;
SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file;
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle;
};
typedef PluginInstances<SymbolLocatorInstance> SymbolLocatorInstances;
Expand All @@ -1113,10 +1116,12 @@ bool PluginManager::RegisterPlugin(
SymbolLocatorCreateInstance create_callback,
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file,
SymbolLocatorLocateExecutableSymbolFile locate_executable_symbol_file,
SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file,
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle) {
return GetSymbolLocatorInstances().RegisterPlugin(
name, description, create_callback, locate_executable_object_file,
locate_executable_symbol_file, find_symbol_file_in_bundle);
locate_executable_symbol_file, download_object_symbol_file,
find_symbol_file_in_bundle);
}

bool PluginManager::UnregisterPlugin(
Expand Down Expand Up @@ -1157,6 +1162,21 @@ FileSpec PluginManager::LocateExecutableSymbolFile(
return {};
}

bool PluginManager::DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
Status &error,
bool force_lookup,
bool copy_executable) {
auto &instances = GetSymbolLocatorInstances().GetInstances();
for (auto &instance : instances) {
if (instance.download_object_symbol_file) {
if (instance.download_object_symbol_file(module_spec, error, force_lookup,
copy_executable))
return true;
}
}
return false;
}

FileSpec PluginManager::FindSymbolFileInBundle(const FileSpec &symfile_bundle,
const UUID *uuid,
const ArchSpec *arch) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,8 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
Status kernel_search_error;
if (IsKernel() &&
(!m_module_sp || !m_module_sp->GetSymbolFileFileSpec())) {
if (Symbols::DownloadObjectAndSymbolFile(module_spec,
kernel_search_error, true)) {
if (PluginManager::DownloadObjectAndSymbolFile(
module_spec, kernel_search_error, true)) {
if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
m_module_sp = std::make_shared<Module>(module_spec.GetFileSpec(),
target.GetArchitecture());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ bool DynamicLoaderFreeBSDKernel::KModImageInfo::LoadImageUsingMemoryModule(
ModuleSpec module_spec(FileSpec(GetPath()), target.GetArchitecture());
if (IsKernel()) {
Status error;
if (Symbols::DownloadObjectAndSymbolFile(module_spec, error, true)) {
if (PluginManager::DownloadObjectAndSymbolFile(module_spec, error,
true)) {
if (FileSystem::Instance().Exists(module_spec.GetFileSpec()))
m_module_sp = std::make_shared<Module>(module_spec.GetFileSpec(),
target.GetArchitecture());
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ Status ProcessKDP::DoConnectRemote(llvm::StringRef remote_url) {
if (!module_spec.GetSymbolFileSpec() ||
!module_spec.GetSymbolFileSpec()) {
Status symbl_error;
Symbols::DownloadObjectAndSymbolFile(module_spec, symbl_error,
true);
PluginManager::DownloadObjectAndSymbolFile(module_spec,
symbl_error, true);
}

if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
Expand Down
Loading