Skip to content

Commit 25f1f1e

Browse files
committed
[lldb] Move DownloadObjectAndSymbolFile to SymbolLocator plugin (llvm#71267)
This builds on top of the work started in c3a302d to convert LocateSymbolFile to a SymbolLocator plugin. This commit moves DownloadObjectAndSymbolFile. (cherry picked from commit e7c6147)
1 parent 72c1804 commit 25f1f1e

File tree

16 files changed

+443
-706
lines changed

16 files changed

+443
-706
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
@@ -98,6 +98,9 @@ typedef std::optional<FileSpec> (*SymbolLocatorFindSymbolFileInBundle)(
9898
const FileSpec &dsym_bundle_fspec, const UUID *uuid, const ArchSpec *arch);
9999
typedef std::optional<FileSpec> (*SymbolLocatorLocateExecutableSymbolFile)(
100100
const ModuleSpec &module_spec, const FileSpecList &default_search_paths);
101+
typedef bool (*SymbolLocatorDownloadObjectAndSymbolFile)(
102+
ModuleSpec &module_spec, Status &error, bool force_lookup,
103+
bool copy_executable);
101104
typedef bool (*BreakpointHitCallback)(void *baton,
102105
StoppointCallbackContext *context,
103106
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
@@ -39,6 +39,7 @@
3939
#include "lldb/Core/Disassembler.h"
4040
#include "lldb/Core/Module.h"
4141
#include "lldb/Core/ModuleSpec.h"
42+
#include "lldb/Core/PluginManager.h"
4243
#include "lldb/Core/SearchFilter.h"
4344
#include "lldb/Core/Section.h"
4445
#include "lldb/Core/StructuredDataImpl.h"
@@ -1561,8 +1562,9 @@ lldb::SBModule SBTarget::AddModule(const SBModuleSpec &module_spec) {
15611562
true /* notify */));
15621563
if (!sb_module.IsValid() && module_spec.m_opaque_up->GetUUID().IsValid()) {
15631564
Status error;
1564-
if (Symbols::DownloadObjectAndSymbolFile(*module_spec.m_opaque_up, error,
1565-
/* force_lookup */ true)) {
1565+
if (PluginManager::DownloadObjectAndSymbolFile(*module_spec.m_opaque_up,
1566+
error,
1567+
/* force_lookup */ true)) {
15661568
if (FileSystem::Instance().Exists(
15671569
module_spec.m_opaque_up->GetFileSpec())) {
15681570
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"
@@ -2533,7 +2534,7 @@ class CommandObjectTargetModulesAdd : public CommandObjectParsed {
25332534
module_spec.GetSymbolFileSpec() =
25342535
m_symbol_file.GetOptionValue().GetCurrentValue();
25352536
Status error;
2536-
if (Symbols::DownloadObjectAndSymbolFile(module_spec, error)) {
2537+
if (PluginManager::DownloadObjectAndSymbolFile(module_spec, error)) {
25372538
ModuleSP module_sp(
25382539
target->GetOrCreateModule(module_spec, true /* notify */));
25392540
if (module_sp) {
@@ -4229,7 +4230,7 @@ class CommandObjectTargetSymbolsAdd : public CommandObjectParsed {
42294230
bool DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
42304231
CommandReturnObject &result, bool &flush) {
42314232
Status error;
4232-
if (Symbols::DownloadObjectAndSymbolFile(module_spec, error)) {
4233+
if (PluginManager::DownloadObjectAndSymbolFile(module_spec, error)) {
42334234
if (module_spec.GetSymbolFileSpec())
42344235
return AddModuleSymbols(m_exe_ctx.GetTargetPtr(), module_spec, flush,
42354236
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
@@ -800,8 +800,8 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
800800
Status kernel_search_error;
801801
if (IsKernel() &&
802802
(!m_module_sp || !m_module_sp->GetSymbolFileFileSpec())) {
803-
if (Symbols::DownloadObjectAndSymbolFile(module_spec,
804-
kernel_search_error, true)) {
803+
if (PluginManager::DownloadObjectAndSymbolFile(
804+
module_spec, kernel_search_error, true)) {
805805
if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
806806
m_module_sp = std::make_shared<Module>(module_spec.GetFileSpec(),
807807
target.GetArchitecture());

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

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

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

0 commit comments

Comments
 (0)