[lldb] Move FindSymbolFileInBundle to SymbolLocator plugin (#71247)

This builds on top of the work started in c3a302d to convert
LocateSymbolFile to a SymbolLocator plugin. This commit moves
FindSymbolFileInBundle.
This commit is contained in:
Jonas Devlieghere 2023-11-03 18:07:57 -07:00 committed by GitHub
parent 466abaf152
commit 9b2246d9fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 88 additions and 67 deletions

View File

@ -346,10 +346,12 @@ public:
GetSymbolVendorCreateCallbackAtIndex(uint32_t idx);
// SymbolLocator
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
static bool RegisterPlugin(
llvm::StringRef name, llvm::StringRef description,
SymbolLocatorCreateInstance create_callback,
SymbolLocatorLocateExecutableObjectFile
locate_executable_object_file = nullptr);
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file =
nullptr,
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle = nullptr);
static bool UnregisterPlugin(SymbolLocatorCreateInstance create_callback);
@ -358,6 +360,10 @@ public:
static ModuleSpec LocateExecutableObjectFile(const ModuleSpec &module_spec);
static FileSpec FindSymbolFileInBundle(const FileSpec &dsym_bundle_fspec,
const UUID *uuid,
const ArchSpec *arch);
// Trace
static bool RegisterPlugin(
llvm::StringRef name, llvm::StringRef description,

View File

@ -32,10 +32,6 @@ public:
LocateExecutableSymbolFile(const ModuleSpec &module_spec,
const FileSpecList &default_search_paths);
static FileSpec FindSymbolFileInBundle(const FileSpec &dsym_bundle_fspec,
const lldb_private::UUID *uuid,
const ArchSpec *arch);
// Locate the object and symbol file given a module specification.
//
// Locating the file can try to download the file from a corporate build

View File

@ -92,6 +92,8 @@ typedef SymbolVendor *(*SymbolVendorCreateInstance)(
typedef SymbolLocator *(*SymbolLocatorCreateInstance)();
typedef std::optional<ModuleSpec> (*SymbolLocatorLocateExecutableObjectFile)(
const ModuleSpec &module_spec);
typedef std::optional<FileSpec> (*SymbolLocatorFindSymbolFileInBundle)(
const FileSpec &dsym_bundle_fspec, const UUID *uuid, const ArchSpec *arch);
typedef bool (*BreakpointHitCallback)(void *baton,
StoppointCallbackContext *context,
lldb::user_id_t break_id,

View File

@ -1088,12 +1088,15 @@ struct SymbolLocatorInstance
SymbolLocatorInstance(
llvm::StringRef name, llvm::StringRef description,
CallbackType create_callback,
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file)
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file,
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle)
: PluginInstance<SymbolLocatorCreateInstance>(name, description,
create_callback),
locate_executable_object_file(locate_executable_object_file) {}
locate_executable_object_file(locate_executable_object_file),
find_symbol_file_in_bundle(find_symbol_file_in_bundle) {}
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file;
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle;
};
typedef PluginInstances<SymbolLocatorInstance> SymbolLocatorInstances;
@ -1105,9 +1108,11 @@ static SymbolLocatorInstances &GetSymbolLocatorInstances() {
bool PluginManager::RegisterPlugin(
llvm::StringRef name, llvm::StringRef description,
SymbolLocatorCreateInstance create_callback,
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file) {
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file,
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle) {
return GetSymbolLocatorInstances().RegisterPlugin(
name, description, create_callback, locate_executable_object_file);
name, description, create_callback, locate_executable_object_file,
find_symbol_file_in_bundle);
}
bool PluginManager::UnregisterPlugin(
@ -1134,6 +1139,21 @@ PluginManager::LocateExecutableObjectFile(const ModuleSpec &module_spec) {
return {};
}
FileSpec PluginManager::FindSymbolFileInBundle(const FileSpec &symfile_bundle,
const UUID *uuid,
const ArchSpec *arch) {
auto &instances = GetSymbolLocatorInstances().GetInstances();
for (auto &instance : instances) {
if (instance.find_symbol_file_in_bundle) {
std::optional<FileSpec> result =
instance.find_symbol_file_in_bundle(symfile_bundle, uuid, arch);
if (result)
return *result;
}
}
return {};
}
#pragma mark Trace
struct TraceInstance

View File

@ -321,8 +321,8 @@ Status PlatformDarwin::ResolveSymbolFile(Target &target,
FileSpec &sym_file) {
sym_file = sym_spec.GetSymbolFileSpec();
if (FileSystem::Instance().IsDirectory(sym_file)) {
sym_file = Symbols::FindSymbolFileInBundle(sym_file, sym_spec.GetUUIDPtr(),
sym_spec.GetArchitecturePtr());
sym_file = PluginManager::FindSymbolFileInBundle(
sym_file, sym_spec.GetUUIDPtr(), sym_spec.GetArchitecturePtr());
}
return {};
}

View File

@ -63,9 +63,9 @@ LLDB_PLUGIN_DEFINE(SymbolLocatorDebugSymbols)
SymbolLocatorDebugSymbols::SymbolLocatorDebugSymbols() : SymbolLocator() {}
void SymbolLocatorDebugSymbols::Initialize() {
PluginManager::RegisterPlugin(GetPluginNameStatic(),
GetPluginDescriptionStatic(), CreateInstance,
LocateExecutableObjectFile);
PluginManager::RegisterPlugin(
GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance,
LocateExecutableObjectFile, FindSymbolFileInBundle);
}
void SymbolLocatorDebugSymbols::Terminate() {
@ -153,8 +153,8 @@ std::optional<ModuleSpec> SymbolLocatorDebugSymbols::LocateExecutableObjectFile(
FileSystem::Instance().Resolve(dsym_filespec);
if (FileSystem::Instance().IsDirectory(dsym_filespec)) {
dsym_filespec =
Symbols::FindSymbolFileInBundle(dsym_filespec, uuid, arch);
dsym_filespec = PluginManager::FindSymbolFileInBundle(
dsym_filespec, uuid, arch);
++items_found;
} else {
++items_found;
@ -325,3 +325,41 @@ std::optional<ModuleSpec> SymbolLocatorDebugSymbols::LocateExecutableObjectFile(
return {};
}
std::optional<FileSpec> SymbolLocatorDebugSymbols::FindSymbolFileInBundle(
const FileSpec &dsym_bundle_fspec, const UUID *uuid, const ArchSpec *arch) {
std::string dsym_bundle_path = dsym_bundle_fspec.GetPath();
llvm::SmallString<128> buffer(dsym_bundle_path);
llvm::sys::path::append(buffer, "Contents", "Resources", "DWARF");
std::error_code EC;
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs =
FileSystem::Instance().GetVirtualFileSystem();
llvm::vfs::recursive_directory_iterator Iter(*vfs, buffer.str(), EC);
llvm::vfs::recursive_directory_iterator End;
for (; Iter != End && !EC; Iter.increment(EC)) {
llvm::ErrorOr<llvm::vfs::Status> Status = vfs->status(Iter->path());
if (Status->isDirectory())
continue;
FileSpec dsym_fspec(Iter->path());
ModuleSpecList module_specs;
if (ObjectFile::GetModuleSpecifications(dsym_fspec, 0, 0, module_specs)) {
ModuleSpec spec;
for (size_t i = 0; i < module_specs.GetSize(); ++i) {
bool got_spec = module_specs.GetModuleSpecAtIndex(i, spec);
assert(got_spec); // The call has side-effects so can't be inlined.
UNUSED_IF_ASSERT_DISABLED(got_spec);
if ((uuid == nullptr ||
(spec.GetUUIDPtr() && spec.GetUUID() == *uuid)) &&
(arch == nullptr ||
(spec.GetArchitecturePtr() &&
spec.GetArchitecture().IsCompatibleMatch(*arch)))) {
return dsym_fspec;
}
}
}
}
return {};
}

View File

@ -37,6 +37,10 @@ public:
// current computers global settings.
static std::optional<ModuleSpec>
LocateExecutableObjectFile(const ModuleSpec &module_spec);
static std::optional<FileSpec>
FindSymbolFileInBundle(const FileSpec &dsym_bundle_fspec, const UUID *uuid,
const ArchSpec *arch);
};
} // namespace lldb_private

View File

@ -408,13 +408,6 @@ void Symbols::DownloadSymbolFileAsync(const UUID &uuid) {
#if !defined(__APPLE__)
FileSpec Symbols::FindSymbolFileInBundle(const FileSpec &symfile_bundle,
const lldb_private::UUID *uuid,
const ArchSpec *arch) {
// FIXME
return FileSpec();
}
bool Symbols::DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
Status &error, bool force_lookup,
bool copy_executable) {

View File

@ -21,6 +21,7 @@
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleList.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Symbol/ObjectFile.h"
@ -119,8 +120,8 @@ int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec &module_spec,
FileSystem::Instance().Resolve(dsym_filespec);
if (FileSystem::Instance().IsDirectory(dsym_filespec)) {
dsym_filespec =
Symbols::FindSymbolFileInBundle(dsym_filespec, uuid, arch);
dsym_filespec = PluginManager::FindSymbolFileInBundle(
dsym_filespec, uuid, arch);
++items_found;
} else {
++items_found;
@ -289,45 +290,6 @@ int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec &module_spec,
return items_found;
}
FileSpec Symbols::FindSymbolFileInBundle(const FileSpec &dsym_bundle_fspec,
const lldb_private::UUID *uuid,
const ArchSpec *arch) {
std::string dsym_bundle_path = dsym_bundle_fspec.GetPath();
llvm::SmallString<128> buffer(dsym_bundle_path);
llvm::sys::path::append(buffer, "Contents", "Resources", "DWARF");
std::error_code EC;
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs =
FileSystem::Instance().GetVirtualFileSystem();
llvm::vfs::recursive_directory_iterator Iter(*vfs, buffer.str(), EC);
llvm::vfs::recursive_directory_iterator End;
for (; Iter != End && !EC; Iter.increment(EC)) {
llvm::ErrorOr<llvm::vfs::Status> Status = vfs->status(Iter->path());
if (Status->isDirectory())
continue;
FileSpec dsym_fspec(Iter->path());
ModuleSpecList module_specs;
if (ObjectFile::GetModuleSpecifications(dsym_fspec, 0, 0, module_specs)) {
ModuleSpec spec;
for (size_t i = 0; i < module_specs.GetSize(); ++i) {
bool got_spec = module_specs.GetModuleSpecAtIndex(i, spec);
assert(got_spec); // The call has side-effects so can't be inlined.
UNUSED_IF_ASSERT_DISABLED(got_spec);
if ((uuid == nullptr ||
(spec.GetUUIDPtr() && spec.GetUUID() == *uuid)) &&
(arch == nullptr ||
(spec.GetArchitecturePtr() &&
spec.GetArchitecture().IsCompatibleMatch(*arch)))) {
return dsym_fspec;
}
}
}
}
return {};
}
static bool GetModuleSpecInfoFromUUIDDictionary(CFDictionaryRef uuid_dict,
ModuleSpec &module_spec,
Status &error,