[Lldb-commits] [lldb] [lldb] Move FindSymbolFileInBundle to SymbolLocator plugin (PR #71247)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Fri Nov 3 15:54:36 PDT 2023
https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/71247
This builds on top of the work started in c3a302d to convert LocateSymbolFile to a SymbolLocator plugin. This commit moves FindSymbolFileInBundle.
>From a7ea01aca6b22a5eaf48f29ba162d6f4855a0352 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jonas at devlieghere.com>
Date: Fri, 3 Nov 2023 10:21:25 -0700
Subject: [PATCH] [lldb] Move FindSymbolFileInBundle to SymbolLocator plugin
This builds on top of the work started in c3a302d to convert
LocateSymbolFile to a SymbolLocator plugin. This commit moves
FindSymbolFileInBundle.
---
lldb/include/lldb/Core/PluginManager.h | 14 ++++--
lldb/include/lldb/Symbol/LocateSymbolFile.h | 4 --
lldb/include/lldb/lldb-private-interfaces.h | 2 +
lldb/source/Core/PluginManager.cpp | 28 +++++++++--
.../Platform/MacOSX/PlatformDarwin.cpp | 4 +-
.../SymbolLocatorDebugSymbols.cpp | 48 +++++++++++++++++--
.../DebugSymbols/SymbolLocatorDebugSymbols.h | 4 ++
lldb/source/Symbol/LocateSymbolFile.cpp | 7 ---
lldb/source/Symbol/LocateSymbolFileMacOSX.cpp | 44 ++---------------
9 files changed, 88 insertions(+), 67 deletions(-)
diff --git a/lldb/include/lldb/Core/PluginManager.h b/lldb/include/lldb/Core/PluginManager.h
index feaa351b71fa2df..b69aff9e00651bb 100644
--- a/lldb/include/lldb/Core/PluginManager.h
+++ b/lldb/include/lldb/Core/PluginManager.h
@@ -346,10 +346,12 @@ class PluginManager {
GetSymbolVendorCreateCallbackAtIndex(uint32_t idx);
// SymbolLocator
- static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
- SymbolLocatorCreateInstance create_callback,
- SymbolLocatorLocateExecutableObjectFile
- locate_executable_object_file = nullptr);
+ static bool RegisterPlugin(
+ llvm::StringRef name, llvm::StringRef description,
+ SymbolLocatorCreateInstance create_callback,
+ SymbolLocatorLocateExecutableObjectFile locate_executable_object_file =
+ nullptr,
+ SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle = nullptr);
static bool UnregisterPlugin(SymbolLocatorCreateInstance create_callback);
@@ -358,6 +360,10 @@ class PluginManager {
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,
diff --git a/lldb/include/lldb/Symbol/LocateSymbolFile.h b/lldb/include/lldb/Symbol/LocateSymbolFile.h
index 8cd62cd3f73e706..03d3d9a2d440edf 100644
--- a/lldb/include/lldb/Symbol/LocateSymbolFile.h
+++ b/lldb/include/lldb/Symbol/LocateSymbolFile.h
@@ -32,10 +32,6 @@ class Symbols {
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
diff --git a/lldb/include/lldb/lldb-private-interfaces.h b/lldb/include/lldb/lldb-private-interfaces.h
index a22a3e9792b318d..faf85833fe9f9e3 100644
--- a/lldb/include/lldb/lldb-private-interfaces.h
+++ b/lldb/include/lldb/lldb-private-interfaces.h
@@ -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,
diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp
index 85e3f1cdcf12438..85c6b1d948a2d85 100644
--- a/lldb/source/Core/PluginManager.cpp
+++ b/lldb/source/Core/PluginManager.cpp
@@ -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
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 765902c7cf29b87..ab7012e3d21e2ed 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -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 {};
}
diff --git a/lldb/source/Plugins/SymbolLocator/DebugSymbols/SymbolLocatorDebugSymbols.cpp b/lldb/source/Plugins/SymbolLocator/DebugSymbols/SymbolLocatorDebugSymbols.cpp
index ef19507e87e5da8..217080bfd3ef3b1 100644
--- a/lldb/source/Plugins/SymbolLocator/DebugSymbols/SymbolLocatorDebugSymbols.cpp
+++ b/lldb/source/Plugins/SymbolLocator/DebugSymbols/SymbolLocatorDebugSymbols.cpp
@@ -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 {};
+}
diff --git a/lldb/source/Plugins/SymbolLocator/DebugSymbols/SymbolLocatorDebugSymbols.h b/lldb/source/Plugins/SymbolLocator/DebugSymbols/SymbolLocatorDebugSymbols.h
index a7641b28c0dc88f..256ac9372edd28f 100644
--- a/lldb/source/Plugins/SymbolLocator/DebugSymbols/SymbolLocatorDebugSymbols.h
+++ b/lldb/source/Plugins/SymbolLocator/DebugSymbols/SymbolLocatorDebugSymbols.h
@@ -37,6 +37,10 @@ class SymbolLocatorDebugSymbols : public SymbolLocator {
// 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
diff --git a/lldb/source/Symbol/LocateSymbolFile.cpp b/lldb/source/Symbol/LocateSymbolFile.cpp
index b23b53230a4fff0..d9414ef93aa7135 100644
--- a/lldb/source/Symbol/LocateSymbolFile.cpp
+++ b/lldb/source/Symbol/LocateSymbolFile.cpp
@@ -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) {
diff --git a/lldb/source/Symbol/LocateSymbolFileMacOSX.cpp b/lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
index 943eae7e066fe05..be0bb37bab5350b 100644
--- a/lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
+++ b/lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
@@ -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,
More information about the lldb-commits
mailing list