Skip to content

Commit e7c6147

Browse files
authored
[lldb] Move DownloadObjectAndSymbolFile to SymbolLocator plugin (#71267)
This builds on top of the work started in c3a302d to convert LocateSymbolFile to a SymbolLocator plugin. This commit moves DownloadObjectAndSymbolFile.
1 parent 9e90027 commit e7c6147

File tree

17 files changed

+445
-708
lines changed

17 files changed

+445
-708
lines changed

lldb/include/lldb/Core/PluginManager.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ class PluginManager {
353353
nullptr,
354354
SymbolLocatorLocateExecutableSymbolFile locate_executable_symbol_file =
355355
nullptr,
356+
SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file =
357+
nullptr,
356358
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle = nullptr);
357359

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

371+
static bool DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
372+
Status &error,
373+
bool force_lookup = true,
374+
bool copy_executable = true);
375+
369376
static FileSpec FindSymbolFileInBundle(const FileSpec &dsym_bundle_fspec,
370377
const UUID *uuid,
371378
const ArchSpec *arch);

lldb/include/lldb/Symbol/LocateSymbolFile.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,6 @@ class UUID;
2424

2525
class Symbols {
2626
public:
27-
// Locate the object and symbol file given a module specification.
28-
//
29-
// Locating the file can try to download the file from a corporate build
30-
// repository, or using any other means necessary to locate both the
31-
// unstripped object file and the debug symbols. The force_lookup argument
32-
// controls whether the external program is called unconditionally to find
33-
// the symbol file, or if the user's settings are checked to see if they've
34-
// enabled the external program before calling.
35-
//
36-
static bool DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
37-
Status &error,
38-
bool force_lookup = true,
39-
bool copy_executable = true);
40-
4127
/// Locate the symbol file for the given UUID on a background thread. This
4228
/// function returns immediately. Under the hood it uses the debugger's
4329
/// thread pool to call DownloadObjectAndSymbolFile. If a symbol file is

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ typedef std::optional<FileSpec> (*SymbolLocatorFindSymbolFileInBundle)(
9696
const FileSpec &dsym_bundle_fspec, const UUID *uuid, const ArchSpec *arch);
9797
typedef std::optional<FileSpec> (*SymbolLocatorLocateExecutableSymbolFile)(
9898
const ModuleSpec &module_spec, const FileSpecList &default_search_paths);
99+
typedef bool (*SymbolLocatorDownloadObjectAndSymbolFile)(
100+
ModuleSpec &module_spec, Status &error, bool force_lookup,
101+
bool copy_executable);
99102
typedef bool (*BreakpointHitCallback)(void *baton,
100103
StoppointCallbackContext *context,
101104
lldb::user_id_t break_id,

lldb/source/API/SBTarget.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "lldb/Core/Disassembler.h"
3939
#include "lldb/Core/Module.h"
4040
#include "lldb/Core/ModuleSpec.h"
41+
#include "lldb/Core/PluginManager.h"
4142
#include "lldb/Core/SearchFilter.h"
4243
#include "lldb/Core/Section.h"
4344
#include "lldb/Core/StructuredDataImpl.h"
@@ -1525,8 +1526,9 @@ lldb::SBModule SBTarget::AddModule(const SBModuleSpec &module_spec) {
15251526
true /* notify */));
15261527
if (!sb_module.IsValid() && module_spec.m_opaque_up->GetUUID().IsValid()) {
15271528
Status error;
1528-
if (Symbols::DownloadObjectAndSymbolFile(*module_spec.m_opaque_up, error,
1529-
/* force_lookup */ true)) {
1529+
if (PluginManager::DownloadObjectAndSymbolFile(*module_spec.m_opaque_up,
1530+
error,
1531+
/* force_lookup */ true)) {
15301532
if (FileSystem::Instance().Exists(
15311533
module_spec.m_opaque_up->GetFileSpec())) {
15321534
sb_module.SetSP(target_sp->GetOrCreateModule(*module_spec.m_opaque_up,

lldb/source/Commands/CommandObjectTarget.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "lldb/Core/IOHandler.h"
1313
#include "lldb/Core/Module.h"
1414
#include "lldb/Core/ModuleSpec.h"
15+
#include "lldb/Core/PluginManager.h"
1516
#include "lldb/Core/Section.h"
1617
#include "lldb/Core/ValueObjectVariable.h"
1718
#include "lldb/DataFormatters/ValueObjectPrinter.h"
@@ -2801,7 +2802,7 @@ class CommandObjectTargetModulesAdd : public CommandObjectParsed {
28012802
module_spec.GetSymbolFileSpec() =
28022803
m_symbol_file.GetOptionValue().GetCurrentValue();
28032804
Status error;
2804-
if (Symbols::DownloadObjectAndSymbolFile(module_spec, error)) {
2805+
if (PluginManager::DownloadObjectAndSymbolFile(module_spec, error)) {
28052806
ModuleSP module_sp(
28062807
target->GetOrCreateModule(module_spec, true /* notify */));
28072808
if (module_sp) {
@@ -4497,7 +4498,7 @@ class CommandObjectTargetSymbolsAdd : public CommandObjectParsed {
44974498
bool DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
44984499
CommandReturnObject &result, bool &flush) {
44994500
Status error;
4500-
if (Symbols::DownloadObjectAndSymbolFile(module_spec, error)) {
4501+
if (PluginManager::DownloadObjectAndSymbolFile(module_spec, error)) {
45014502
if (module_spec.GetSymbolFileSpec())
45024503
return AddModuleSymbols(m_exe_ctx.GetTargetPtr(), module_spec, flush,
45034504
result);

lldb/source/Core/DynamicLoader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ ModuleSP DynamicLoader::LoadBinaryWithUUIDAndAddress(
232232
// If we haven't found a binary, or we don't have a SymbolFile, see
233233
// if there is an external search tool that can find it.
234234
if (!module_sp || !module_sp->GetSymbolFileFileSpec()) {
235-
Symbols::DownloadObjectAndSymbolFile(module_spec, error,
236-
force_symbol_search);
235+
PluginManager::DownloadObjectAndSymbolFile(module_spec, error,
236+
force_symbol_search);
237237
if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
238238
module_sp = std::make_shared<Module>(module_spec);
239239
} else if (force_symbol_search && error.AsCString("") &&

lldb/source/Core/PluginManager.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,15 +1090,18 @@ struct SymbolLocatorInstance
10901090
CallbackType create_callback,
10911091
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file,
10921092
SymbolLocatorLocateExecutableSymbolFile locate_executable_symbol_file,
1093+
SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file,
10931094
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle)
10941095
: PluginInstance<SymbolLocatorCreateInstance>(name, description,
10951096
create_callback),
10961097
locate_executable_object_file(locate_executable_object_file),
10971098
locate_executable_symbol_file(locate_executable_symbol_file),
1099+
download_object_symbol_file(download_object_symbol_file),
10981100
find_symbol_file_in_bundle(find_symbol_file_in_bundle) {}
10991101

11001102
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file;
11011103
SymbolLocatorLocateExecutableSymbolFile locate_executable_symbol_file;
1104+
SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file;
11021105
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle;
11031106
};
11041107
typedef PluginInstances<SymbolLocatorInstance> SymbolLocatorInstances;
@@ -1113,10 +1116,12 @@ bool PluginManager::RegisterPlugin(
11131116
SymbolLocatorCreateInstance create_callback,
11141117
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file,
11151118
SymbolLocatorLocateExecutableSymbolFile locate_executable_symbol_file,
1119+
SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file,
11161120
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle) {
11171121
return GetSymbolLocatorInstances().RegisterPlugin(
11181122
name, description, create_callback, locate_executable_object_file,
1119-
locate_executable_symbol_file, find_symbol_file_in_bundle);
1123+
locate_executable_symbol_file, download_object_symbol_file,
1124+
find_symbol_file_in_bundle);
11201125
}
11211126

11221127
bool PluginManager::UnregisterPlugin(
@@ -1157,6 +1162,21 @@ FileSpec PluginManager::LocateExecutableSymbolFile(
11571162
return {};
11581163
}
11591164

1165+
bool PluginManager::DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
1166+
Status &error,
1167+
bool force_lookup,
1168+
bool copy_executable) {
1169+
auto &instances = GetSymbolLocatorInstances().GetInstances();
1170+
for (auto &instance : instances) {
1171+
if (instance.download_object_symbol_file) {
1172+
if (instance.download_object_symbol_file(module_spec, error, force_lookup,
1173+
copy_executable))
1174+
return true;
1175+
}
1176+
}
1177+
return false;
1178+
}
1179+
11601180
FileSpec PluginManager::FindSymbolFileInBundle(const FileSpec &symfile_bundle,
11611181
const UUID *uuid,
11621182
const ArchSpec *arch) {

lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,8 +798,8 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
798798
Status kernel_search_error;
799799
if (IsKernel() &&
800800
(!m_module_sp || !m_module_sp->GetSymbolFileFileSpec())) {
801-
if (Symbols::DownloadObjectAndSymbolFile(module_spec,
802-
kernel_search_error, true)) {
801+
if (PluginManager::DownloadObjectAndSymbolFile(
802+
module_spec, kernel_search_error, true)) {
803803
if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
804804
m_module_sp = std::make_shared<Module>(module_spec.GetFileSpec(),
805805
target.GetArchitecture());

lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ bool DynamicLoaderFreeBSDKernel::KModImageInfo::LoadImageUsingMemoryModule(
345345
ModuleSpec module_spec(FileSpec(GetPath()), target.GetArchitecture());
346346
if (IsKernel()) {
347347
Status error;
348-
if (Symbols::DownloadObjectAndSymbolFile(module_spec, error, true)) {
348+
if (PluginManager::DownloadObjectAndSymbolFile(module_spec, error,
349+
true)) {
349350
if (FileSystem::Instance().Exists(module_spec.GetFileSpec()))
350351
m_module_sp = std::make_shared<Module>(module_spec.GetFileSpec(),
351352
target.GetArchitecture());

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ Status ProcessKDP::DoConnectRemote(llvm::StringRef remote_url) {
292292
if (!module_spec.GetSymbolFileSpec() ||
293293
!module_spec.GetSymbolFileSpec()) {
294294
Status symbl_error;
295-
Symbols::DownloadObjectAndSymbolFile(module_spec, symbl_error,
296-
true);
295+
PluginManager::DownloadObjectAndSymbolFile(module_spec,
296+
symbl_error, true);
297297
}
298298

299299
if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {

0 commit comments

Comments
 (0)