Skip to content

Commit af0e861

Browse files
committed
[lldb] Move FindSymbolFileInBundle to SymbolLocator plugin (llvm#71247)
This builds on top of the work started in c3a302d to convert LocateSymbolFile to a SymbolLocator plugin. This commit moves FindSymbolFileInBundle. (cherry picked from commit 9b2246d)
1 parent f35a9c2 commit af0e861

File tree

9 files changed

+88
-67
lines changed

9 files changed

+88
-67
lines changed

lldb/include/lldb/Core/PluginManager.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,12 @@ class PluginManager {
346346
GetSymbolVendorCreateCallbackAtIndex(uint32_t idx);
347347

348348
// SymbolLocator
349-
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
350-
SymbolLocatorCreateInstance create_callback,
351-
SymbolLocatorLocateExecutableObjectFile
352-
locate_executable_object_file = nullptr);
349+
static bool RegisterPlugin(
350+
llvm::StringRef name, llvm::StringRef description,
351+
SymbolLocatorCreateInstance create_callback,
352+
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file =
353+
nullptr,
354+
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle = nullptr);
353355

354356
static bool UnregisterPlugin(SymbolLocatorCreateInstance create_callback);
355357

@@ -358,6 +360,10 @@ class PluginManager {
358360

359361
static ModuleSpec LocateExecutableObjectFile(const ModuleSpec &module_spec);
360362

363+
static FileSpec FindSymbolFileInBundle(const FileSpec &dsym_bundle_fspec,
364+
const UUID *uuid,
365+
const ArchSpec *arch);
366+
361367
// Trace
362368
static bool RegisterPlugin(
363369
llvm::StringRef name, llvm::StringRef description,

lldb/include/lldb/Symbol/LocateSymbolFile.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ class Symbols {
3232
LocateExecutableSymbolFile(const ModuleSpec &module_spec,
3333
const FileSpecList &default_search_paths);
3434

35-
static FileSpec FindSymbolFileInBundle(const FileSpec &dsym_bundle_fspec,
36-
const lldb_private::UUID *uuid,
37-
const ArchSpec *arch);
38-
3935
// Locate the object and symbol file given a module specification.
4036
//
4137
// Locating the file can try to download the file from a corporate build

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ typedef SymbolVendor *(*SymbolVendorCreateInstance)(
9494
typedef SymbolLocator *(*SymbolLocatorCreateInstance)();
9595
typedef std::optional<ModuleSpec> (*SymbolLocatorLocateExecutableObjectFile)(
9696
const ModuleSpec &module_spec);
97+
typedef std::optional<FileSpec> (*SymbolLocatorFindSymbolFileInBundle)(
98+
const FileSpec &dsym_bundle_fspec, const UUID *uuid, const ArchSpec *arch);
9799
typedef bool (*BreakpointHitCallback)(void *baton,
98100
StoppointCallbackContext *context,
99101
lldb::user_id_t break_id,

lldb/source/Core/PluginManager.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,12 +1088,15 @@ struct SymbolLocatorInstance
10881088
SymbolLocatorInstance(
10891089
llvm::StringRef name, llvm::StringRef description,
10901090
CallbackType create_callback,
1091-
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file)
1091+
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file,
1092+
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle)
10921093
: PluginInstance<SymbolLocatorCreateInstance>(name, description,
10931094
create_callback),
1094-
locate_executable_object_file(locate_executable_object_file) {}
1095+
locate_executable_object_file(locate_executable_object_file),
1096+
find_symbol_file_in_bundle(find_symbol_file_in_bundle) {}
10951097

10961098
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file;
1099+
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle;
10971100
};
10981101
typedef PluginInstances<SymbolLocatorInstance> SymbolLocatorInstances;
10991102

@@ -1105,9 +1108,11 @@ static SymbolLocatorInstances &GetSymbolLocatorInstances() {
11051108
bool PluginManager::RegisterPlugin(
11061109
llvm::StringRef name, llvm::StringRef description,
11071110
SymbolLocatorCreateInstance create_callback,
1108-
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file) {
1111+
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file,
1112+
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle) {
11091113
return GetSymbolLocatorInstances().RegisterPlugin(
1110-
name, description, create_callback, locate_executable_object_file);
1114+
name, description, create_callback, locate_executable_object_file,
1115+
find_symbol_file_in_bundle);
11111116
}
11121117

11131118
bool PluginManager::UnregisterPlugin(
@@ -1134,6 +1139,21 @@ PluginManager::LocateExecutableObjectFile(const ModuleSpec &module_spec) {
11341139
return {};
11351140
}
11361141

1142+
FileSpec PluginManager::FindSymbolFileInBundle(const FileSpec &symfile_bundle,
1143+
const UUID *uuid,
1144+
const ArchSpec *arch) {
1145+
auto &instances = GetSymbolLocatorInstances().GetInstances();
1146+
for (auto &instance : instances) {
1147+
if (instance.find_symbol_file_in_bundle) {
1148+
std::optional<FileSpec> result =
1149+
instance.find_symbol_file_in_bundle(symfile_bundle, uuid, arch);
1150+
if (result)
1151+
return *result;
1152+
}
1153+
}
1154+
return {};
1155+
}
1156+
11371157
#pragma mark Trace
11381158

11391159
struct TraceInstance

lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ Status PlatformDarwin::ResolveSymbolFile(Target &target,
320320
FileSpec &sym_file) {
321321
sym_file = sym_spec.GetSymbolFileSpec();
322322
if (FileSystem::Instance().IsDirectory(sym_file)) {
323-
sym_file = Symbols::FindSymbolFileInBundle(sym_file, sym_spec.GetUUIDPtr(),
324-
sym_spec.GetArchitecturePtr());
323+
sym_file = PluginManager::FindSymbolFileInBundle(
324+
sym_file, sym_spec.GetUUIDPtr(), sym_spec.GetArchitecturePtr());
325325
}
326326
return {};
327327
}

lldb/source/Plugins/SymbolLocator/DebugSymbols/SymbolLocatorDebugSymbols.cpp

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ LLDB_PLUGIN_DEFINE(SymbolLocatorDebugSymbols)
6363
SymbolLocatorDebugSymbols::SymbolLocatorDebugSymbols() : SymbolLocator() {}
6464

6565
void SymbolLocatorDebugSymbols::Initialize() {
66-
PluginManager::RegisterPlugin(GetPluginNameStatic(),
67-
GetPluginDescriptionStatic(), CreateInstance,
68-
LocateExecutableObjectFile);
66+
PluginManager::RegisterPlugin(
67+
GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance,
68+
LocateExecutableObjectFile, FindSymbolFileInBundle);
6969
}
7070

7171
void SymbolLocatorDebugSymbols::Terminate() {
@@ -153,8 +153,8 @@ std::optional<ModuleSpec> SymbolLocatorDebugSymbols::LocateExecutableObjectFile(
153153
FileSystem::Instance().Resolve(dsym_filespec);
154154

155155
if (FileSystem::Instance().IsDirectory(dsym_filespec)) {
156-
dsym_filespec =
157-
Symbols::FindSymbolFileInBundle(dsym_filespec, uuid, arch);
156+
dsym_filespec = PluginManager::FindSymbolFileInBundle(
157+
dsym_filespec, uuid, arch);
158158
++items_found;
159159
} else {
160160
++items_found;
@@ -325,3 +325,41 @@ std::optional<ModuleSpec> SymbolLocatorDebugSymbols::LocateExecutableObjectFile(
325325

326326
return {};
327327
}
328+
329+
std::optional<FileSpec> SymbolLocatorDebugSymbols::FindSymbolFileInBundle(
330+
const FileSpec &dsym_bundle_fspec, const UUID *uuid, const ArchSpec *arch) {
331+
std::string dsym_bundle_path = dsym_bundle_fspec.GetPath();
332+
llvm::SmallString<128> buffer(dsym_bundle_path);
333+
llvm::sys::path::append(buffer, "Contents", "Resources", "DWARF");
334+
335+
std::error_code EC;
336+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs =
337+
FileSystem::Instance().GetVirtualFileSystem();
338+
llvm::vfs::recursive_directory_iterator Iter(*vfs, buffer.str(), EC);
339+
llvm::vfs::recursive_directory_iterator End;
340+
for (; Iter != End && !EC; Iter.increment(EC)) {
341+
llvm::ErrorOr<llvm::vfs::Status> Status = vfs->status(Iter->path());
342+
if (Status->isDirectory())
343+
continue;
344+
345+
FileSpec dsym_fspec(Iter->path());
346+
ModuleSpecList module_specs;
347+
if (ObjectFile::GetModuleSpecifications(dsym_fspec, 0, 0, module_specs)) {
348+
ModuleSpec spec;
349+
for (size_t i = 0; i < module_specs.GetSize(); ++i) {
350+
bool got_spec = module_specs.GetModuleSpecAtIndex(i, spec);
351+
assert(got_spec); // The call has side-effects so can't be inlined.
352+
UNUSED_IF_ASSERT_DISABLED(got_spec);
353+
if ((uuid == nullptr ||
354+
(spec.GetUUIDPtr() && spec.GetUUID() == *uuid)) &&
355+
(arch == nullptr ||
356+
(spec.GetArchitecturePtr() &&
357+
spec.GetArchitecture().IsCompatibleMatch(*arch)))) {
358+
return dsym_fspec;
359+
}
360+
}
361+
}
362+
}
363+
364+
return {};
365+
}

lldb/source/Plugins/SymbolLocator/DebugSymbols/SymbolLocatorDebugSymbols.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ class SymbolLocatorDebugSymbols : public SymbolLocator {
3737
// current computers global settings.
3838
static std::optional<ModuleSpec>
3939
LocateExecutableObjectFile(const ModuleSpec &module_spec);
40+
41+
static std::optional<FileSpec>
42+
FindSymbolFileInBundle(const FileSpec &dsym_bundle_fspec, const UUID *uuid,
43+
const ArchSpec *arch);
4044
};
4145

4246
} // namespace lldb_private

lldb/source/Symbol/LocateSymbolFile.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,6 @@ void Symbols::DownloadSymbolFileAsync(const UUID &uuid) {
407407

408408
#if !defined(__APPLE__)
409409

410-
FileSpec Symbols::FindSymbolFileInBundle(const FileSpec &symfile_bundle,
411-
const lldb_private::UUID *uuid,
412-
const ArchSpec *arch) {
413-
// FIXME
414-
return FileSpec();
415-
}
416-
417410
bool Symbols::DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
418411
Status &error, bool force_lookup,
419412
bool copy_executable) {

lldb/source/Symbol/LocateSymbolFileMacOSX.cpp

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "lldb/Core/Module.h"
2222
#include "lldb/Core/ModuleList.h"
2323
#include "lldb/Core/ModuleSpec.h"
24+
#include "lldb/Core/PluginManager.h"
2425
#include "lldb/Host/Host.h"
2526
#include "lldb/Host/HostInfo.h"
2627
#include "lldb/Symbol/ObjectFile.h"
@@ -119,8 +120,8 @@ int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec &module_spec,
119120
FileSystem::Instance().Resolve(dsym_filespec);
120121

121122
if (FileSystem::Instance().IsDirectory(dsym_filespec)) {
122-
dsym_filespec =
123-
Symbols::FindSymbolFileInBundle(dsym_filespec, uuid, arch);
123+
dsym_filespec = PluginManager::FindSymbolFileInBundle(
124+
dsym_filespec, uuid, arch);
124125
++items_found;
125126
} else {
126127
++items_found;
@@ -289,45 +290,6 @@ int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec &module_spec,
289290
return items_found;
290291
}
291292

292-
FileSpec Symbols::FindSymbolFileInBundle(const FileSpec &dsym_bundle_fspec,
293-
const lldb_private::UUID *uuid,
294-
const ArchSpec *arch) {
295-
std::string dsym_bundle_path = dsym_bundle_fspec.GetPath();
296-
llvm::SmallString<128> buffer(dsym_bundle_path);
297-
llvm::sys::path::append(buffer, "Contents", "Resources", "DWARF");
298-
299-
std::error_code EC;
300-
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs =
301-
FileSystem::Instance().GetVirtualFileSystem();
302-
llvm::vfs::recursive_directory_iterator Iter(*vfs, buffer.str(), EC);
303-
llvm::vfs::recursive_directory_iterator End;
304-
for (; Iter != End && !EC; Iter.increment(EC)) {
305-
llvm::ErrorOr<llvm::vfs::Status> Status = vfs->status(Iter->path());
306-
if (Status->isDirectory())
307-
continue;
308-
309-
FileSpec dsym_fspec(Iter->path());
310-
ModuleSpecList module_specs;
311-
if (ObjectFile::GetModuleSpecifications(dsym_fspec, 0, 0, module_specs)) {
312-
ModuleSpec spec;
313-
for (size_t i = 0; i < module_specs.GetSize(); ++i) {
314-
bool got_spec = module_specs.GetModuleSpecAtIndex(i, spec);
315-
assert(got_spec); // The call has side-effects so can't be inlined.
316-
UNUSED_IF_ASSERT_DISABLED(got_spec);
317-
if ((uuid == nullptr ||
318-
(spec.GetUUIDPtr() && spec.GetUUID() == *uuid)) &&
319-
(arch == nullptr ||
320-
(spec.GetArchitecturePtr() &&
321-
spec.GetArchitecture().IsCompatibleMatch(*arch)))) {
322-
return dsym_fspec;
323-
}
324-
}
325-
}
326-
}
327-
328-
return {};
329-
}
330-
331293
static bool GetModuleSpecInfoFromUUIDDictionary(CFDictionaryRef uuid_dict,
332294
ModuleSpec &module_spec,
333295
Status &error,

0 commit comments

Comments
 (0)