Skip to content

Commit f74ee64

Browse files
authored
Merge pull request #8160 from apple/jdevlieghere/symbol-locator
Cherrypick SymbolLocator plugin
2 parents 9f1e7c4 + bdc63a4 commit f74ee64

39 files changed

+1227
-596
lines changed

lldb/include/lldb/Core/ModuleList.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,26 @@ class UUID;
4747
class VariableList;
4848
struct ModuleFunctionSearchOptions;
4949

50+
static constexpr OptionEnumValueElement g_auto_download_enum_values[] = {
51+
{
52+
lldb::eSymbolDownloadOff,
53+
"off",
54+
"Disable automatically downloading symbols.",
55+
},
56+
{
57+
lldb::eSymbolDownloadBackground,
58+
"background",
59+
"Download symbols in the background for images as they appear in the "
60+
"backtrace.",
61+
},
62+
{
63+
lldb::eSymbolDownloadForeground,
64+
"foreground",
65+
"Download symbols in the foreground for images as they appear in the "
66+
"backtrace.",
67+
},
68+
};
69+
5070
class ModuleListProperties : public Properties {
5171
mutable llvm::sys::RWMutex m_symlink_paths_mutex;
5272
PathMappingList m_symlink_paths;
@@ -78,7 +98,6 @@ class ModuleListProperties : public Properties {
7898
bool SetClangModulesCachePath(const FileSpec &path);
7999
bool GetEnableExternalLookup() const;
80100
bool SetEnableExternalLookup(bool new_value);
81-
bool GetEnableBackgroundLookup() const;
82101
bool GetEnableLLDBIndexCache() const;
83102
bool SetEnableLLDBIndexCache(bool new_value);
84103
uint64_t GetLLDBIndexCacheMaxByteSize();
@@ -89,6 +108,8 @@ class ModuleListProperties : public Properties {
89108

90109
bool GetLoadSymbolOnDemand();
91110

111+
lldb::SymbolDownload GetSymbolAutoDownload() const;
112+
92113
PathMappingList GetSymlinkMappings() const;
93114
};
94115

lldb/include/lldb/Core/PluginManager.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,38 @@ class PluginManager {
345345
static SymbolVendorCreateInstance
346346
GetSymbolVendorCreateCallbackAtIndex(uint32_t idx);
347347

348+
// SymbolLocator
349+
static bool RegisterPlugin(
350+
llvm::StringRef name, llvm::StringRef description,
351+
SymbolLocatorCreateInstance create_callback,
352+
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file =
353+
nullptr,
354+
SymbolLocatorLocateExecutableSymbolFile locate_executable_symbol_file =
355+
nullptr,
356+
SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file =
357+
nullptr,
358+
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle = nullptr);
359+
360+
static bool UnregisterPlugin(SymbolLocatorCreateInstance create_callback);
361+
362+
static SymbolLocatorCreateInstance
363+
GetSymbolLocatorCreateCallbackAtIndex(uint32_t idx);
364+
365+
static ModuleSpec LocateExecutableObjectFile(const ModuleSpec &module_spec);
366+
367+
static FileSpec
368+
LocateExecutableSymbolFile(const ModuleSpec &module_spec,
369+
const FileSpecList &default_search_paths);
370+
371+
static bool DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
372+
Status &error,
373+
bool force_lookup = true,
374+
bool copy_executable = true);
375+
376+
static FileSpec FindSymbolFileInBundle(const FileSpec &dsym_bundle_fspec,
377+
const UUID *uuid,
378+
const ArchSpec *arch);
379+
348380
// Trace
349381
static bool RegisterPlugin(
350382
llvm::StringRef name, llvm::StringRef description,

lldb/include/lldb/Symbol/LocateSymbolFile.h

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

2525
class Symbols {
2626
public:
27-
// Locate the executable file given a module specification.
28-
//
29-
// Locating the file should happen only on the local computer or using the
30-
// current computers global settings.
31-
static ModuleSpec LocateExecutableObjectFile(const ModuleSpec &module_spec);
32-
33-
// Locate the symbol file given a module specification.
34-
//
35-
// Locating the file should happen only on the local computer or using the
36-
// current computers global settings.
37-
static FileSpec
38-
LocateExecutableSymbolFile(const ModuleSpec &module_spec,
39-
const FileSpecList &default_search_paths);
40-
41-
static FileSpec FindSymbolFileInBundle(const FileSpec &dsym_bundle_fspec,
42-
const lldb_private::UUID *uuid,
43-
const ArchSpec *arch);
44-
45-
// Locate the object and symbol file given a module specification.
46-
//
47-
// Locating the file can try to download the file from a corporate build
48-
// repository, or using any other means necessary to locate both the
49-
// unstripped object file and the debug symbols. The force_lookup argument
50-
// controls whether the external program is called unconditionally to find
51-
// the symbol file, or if the user's settings are checked to see if they've
52-
// enabled the external program before calling.
53-
//
54-
static bool DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
55-
Status &error,
56-
bool force_lookup = true,
57-
bool copy_executable = true);
58-
5927
/// Locate the symbol file for the given UUID on a background thread. This
6028
/// function returns immediately. Under the hood it uses the debugger's
6129
/// thread pool to call DownloadObjectAndSymbolFile. If a symbol file is
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===-- SymbolLocator.h -----------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLDB_SYMBOL_SYMBOLLOCATOR_H
10+
#define LLDB_SYMBOL_SYMBOLLOCATOR_H
11+
12+
#include "lldb/Core/PluginInterface.h"
13+
#include "lldb/Utility/UUID.h"
14+
15+
namespace lldb_private {
16+
17+
class SymbolLocator : public PluginInterface {
18+
public:
19+
SymbolLocator() = default;
20+
21+
/// Locate the symbol file for the given UUID on a background thread. This
22+
/// function returns immediately. Under the hood it uses the debugger's
23+
/// thread pool to call DownloadObjectAndSymbolFile. If a symbol file is
24+
/// found, this will notify all target which contain the module with the
25+
/// given UUID.
26+
static void DownloadSymbolFileAsync(const UUID &uuid);
27+
};
28+
29+
} // namespace lldb_private
30+
31+
#endif // LLDB_SYMBOL_SYMBOLFILELOCATOR_H

lldb/include/lldb/lldb-enumerations.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,12 @@ enum CompletionType {
13321332
eCustomCompletion = (1u << 25)
13331333
};
13341334

1335+
enum SymbolDownload {
1336+
eSymbolDownloadOff = 0,
1337+
eSymbolDownloadBackground = 1,
1338+
eSymbolDownloadForeground = 2,
1339+
};
1340+
13351341
/// Specifies if children need to be re-computed
13361342
/// after a call to \ref SyntheticChildrenFrontEnd::Update.
13371343
enum class ChildCacheState {

lldb/include/lldb/lldb-forward.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ class SymbolContextScope;
220220
class SymbolContextSpecifier;
221221
class SymbolFile;
222222
class SymbolFileType;
223+
class SymbolLocator;
223224
class SymbolVendor;
224225
class Symtab;
225226
class SyntheticChildren;

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ typedef SymbolVendor *(*SymbolVendorCreateInstance)(
9191
const lldb::ModuleSP &module_sp,
9292
lldb_private::Stream
9393
*feedback_strm); // Module can be NULL for default system symbol vendor
94+
typedef SymbolLocator *(*SymbolLocatorCreateInstance)();
95+
typedef std::optional<ModuleSpec> (*SymbolLocatorLocateExecutableObjectFile)(
96+
const ModuleSpec &module_spec);
97+
typedef std::optional<FileSpec> (*SymbolLocatorFindSymbolFileInBundle)(
98+
const FileSpec &dsym_bundle_fspec, const UUID *uuid, const ArchSpec *arch);
99+
typedef std::optional<FileSpec> (*SymbolLocatorLocateExecutableSymbolFile)(
100+
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);
94104
typedef bool (*BreakpointHitCallback)(void *baton,
95105
StoppointCallbackContext *context,
96106
lldb::user_id_t break_id,

lldb/source/API/SBTarget.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "lldb/API/SBTarget.h"
10-
#include "lldb/Symbol/LocateSymbolFile.h"
1110
#include "lldb/Utility/Instrumentation.h"
1211
#include "lldb/Utility/LLDBLog.h"
1312
#include "lldb/lldb-public.h"
@@ -39,6 +38,7 @@
3938
#include "lldb/Core/Disassembler.h"
4039
#include "lldb/Core/Module.h"
4140
#include "lldb/Core/ModuleSpec.h"
41+
#include "lldb/Core/PluginManager.h"
4242
#include "lldb/Core/SearchFilter.h"
4343
#include "lldb/Core/Section.h"
4444
#include "lldb/Core/StructuredDataImpl.h"
@@ -1561,8 +1561,9 @@ lldb::SBModule SBTarget::AddModule(const SBModuleSpec &module_spec) {
15611561
true /* notify */));
15621562
if (!sb_module.IsValid() && module_spec.m_opaque_up->GetUUID().IsValid()) {
15631563
Status error;
1564-
if (Symbols::DownloadObjectAndSymbolFile(*module_spec.m_opaque_up, error,
1565-
/* force_lookup */ true)) {
1564+
if (PluginManager::DownloadObjectAndSymbolFile(*module_spec.m_opaque_up,
1565+
error,
1566+
/* force_lookup */ true)) {
15661567
if (FileSystem::Instance().Exists(
15671568
module_spec.m_opaque_up->GetFileSpec())) {
15681569
sb_module.SetSP(target_sp->GetOrCreateModule(*module_spec.m_opaque_up,

lldb/source/Commands/CommandObjectTarget.cpp

Lines changed: 3 additions & 3 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"
@@ -35,7 +36,6 @@
3536
#include "lldb/Symbol/CompileUnit.h"
3637
#include "lldb/Symbol/FuncUnwinders.h"
3738
#include "lldb/Symbol/LineTable.h"
38-
#include "lldb/Symbol/LocateSymbolFile.h"
3939
#include "lldb/Symbol/ObjectFile.h"
4040
#include "lldb/Symbol/SymbolFile.h"
4141
#include "lldb/Symbol/UnwindPlan.h"
@@ -2533,7 +2533,7 @@ class CommandObjectTargetModulesAdd : public CommandObjectParsed {
25332533
module_spec.GetSymbolFileSpec() =
25342534
m_symbol_file.GetOptionValue().GetCurrentValue();
25352535
Status error;
2536-
if (Symbols::DownloadObjectAndSymbolFile(module_spec, error)) {
2536+
if (PluginManager::DownloadObjectAndSymbolFile(module_spec, error)) {
25372537
ModuleSP module_sp(
25382538
target->GetOrCreateModule(module_spec, true /* notify */));
25392539
if (module_sp) {
@@ -4229,7 +4229,7 @@ class CommandObjectTargetSymbolsAdd : public CommandObjectParsed {
42294229
bool DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
42304230
CommandReturnObject &result, bool &flush) {
42314231
Status error;
4232-
if (Symbols::DownloadObjectAndSymbolFile(module_spec, error)) {
4232+
if (PluginManager::DownloadObjectAndSymbolFile(module_spec, error)) {
42334233
if (module_spec.GetSymbolFileSpec())
42344234
return AddModuleSymbols(m_exe_ctx.GetTargetPtr(), module_spec, flush,
42354235
result);

lldb/source/Core/CoreProperties.td

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ let Definition = "modulelist" in {
88
def EnableBackgroundLookup: Property<"enable-background-lookup", "Boolean">,
99
Global,
1010
DefaultFalse,
11-
Desc<"On macOS, enable calling dsymForUUID (or an equivalent script/binary) in the background to locate symbol files that weren't found.">;
11+
Desc<"Alias for backward compatibility: when enabled this is the equivalent to 'symbols.download background'.">;
12+
def AutoDownload: Property<"auto-download", "Enum">,
13+
Global,
14+
DefaultEnumValue<"eSymbolDownloadOff">,
15+
EnumValues<"OptionEnumValues(g_auto_download_enum_values)">,
16+
Desc<"On macOS, automatically download symbols with dsymForUUID (or an equivalent script/binary) for relevant images in the debug session.">;
1217
def ClangModulesCachePath: Property<"clang-modules-cache-path", "FileSpec">,
1318
Global,
1419
DefaultStringValue<"">,

lldb/source/Core/DynamicLoader.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "lldb/Core/ModuleSpec.h"
1515
#include "lldb/Core/PluginManager.h"
1616
#include "lldb/Core/Section.h"
17-
#include "lldb/Symbol/LocateSymbolFile.h"
1817
#include "lldb/Symbol/ObjectFile.h"
1918
#include "lldb/Target/MemoryRegionInfo.h"
2019
#include "lldb/Target/Platform.h"
@@ -219,9 +218,9 @@ ModuleSP DynamicLoader::LoadBinaryWithUUIDAndAddress(
219218
if (!module_sp) {
220219
FileSpecList search_paths = Target::GetDefaultDebugFileSearchPaths();
221220
module_spec.GetSymbolFileSpec() =
222-
Symbols::LocateExecutableSymbolFile(module_spec, search_paths);
221+
PluginManager::LocateExecutableSymbolFile(module_spec, search_paths);
223222
ModuleSpec objfile_module_spec =
224-
Symbols::LocateExecutableObjectFile(module_spec);
223+
PluginManager::LocateExecutableObjectFile(module_spec);
225224
module_spec.GetFileSpec() = objfile_module_spec.GetFileSpec();
226225
if (FileSystem::Instance().Exists(module_spec.GetFileSpec()) &&
227226
FileSystem::Instance().Exists(module_spec.GetSymbolFileSpec())) {
@@ -232,8 +231,8 @@ ModuleSP DynamicLoader::LoadBinaryWithUUIDAndAddress(
232231
// If we haven't found a binary, or we don't have a SymbolFile, see
233232
// if there is an external search tool that can find it.
234233
if (!module_sp || !module_sp->GetSymbolFileFileSpec()) {
235-
Symbols::DownloadObjectAndSymbolFile(module_spec, error,
236-
force_symbol_search);
234+
PluginManager::DownloadObjectAndSymbolFile(module_spec, error,
235+
force_symbol_search);
237236
if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
238237
module_sp = std::make_shared<Module>(module_spec);
239238
} else if (force_symbol_search && error.AsCString("") &&

lldb/source/Core/Module.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
#include "lldb/Interpreter/ScriptInterpreter.h"
2424
#include "lldb/Symbol/CompileUnit.h"
2525
#include "lldb/Symbol/Function.h"
26-
#include "lldb/Symbol/LocateSymbolFile.h"
2726
#include "lldb/Symbol/ObjectFile.h"
2827
#include "lldb/Symbol/Symbol.h"
2928
#include "lldb/Symbol/SymbolContext.h"
3029
#include "lldb/Symbol/SymbolFile.h"
30+
#include "lldb/Symbol/SymbolLocator.h"
3131
#include "lldb/Symbol/SymbolVendor.h"
3232
#include "lldb/Symbol/Symtab.h"
3333
#include "lldb/Symbol/Type.h"
@@ -1345,7 +1345,7 @@ UnwindTable &Module::GetUnwindTable() {
13451345
if (!m_unwind_table) {
13461346
m_unwind_table.emplace(*this);
13471347
if (!m_symfile_spec)
1348-
Symbols::DownloadSymbolFileAsync(GetUUID());
1348+
SymbolLocator::DownloadSymbolFileAsync(GetUUID());
13491349
}
13501350
return *m_unwind_table;
13511351
}

lldb/source/Core/ModuleList.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
#include "lldb/Core/ModuleList.h"
1010
#include "lldb/Core/Module.h"
1111
#include "lldb/Core/ModuleSpec.h"
12+
#include "lldb/Core/PluginManager.h"
1213
#include "lldb/Host/FileSystem.h"
1314
#include "lldb/Interpreter/OptionValueFileSpec.h"
1415
#include "lldb/Interpreter/OptionValueFileSpecList.h"
1516
#include "lldb/Interpreter/OptionValueProperties.h"
1617
#include "lldb/Interpreter/Property.h"
17-
#include "lldb/Symbol/LocateSymbolFile.h"
1818
#include "lldb/Symbol/ObjectFile.h"
1919
#include "lldb/Symbol/SymbolContext.h"
2020
#include "lldb/Symbol/TypeList.h"
@@ -137,10 +137,15 @@ bool ModuleListProperties::SetEnableExternalLookup(bool new_value) {
137137
return SetPropertyAtIndex(ePropertyEnableExternalLookup, new_value);
138138
}
139139

140-
bool ModuleListProperties::GetEnableBackgroundLookup() const {
141-
const uint32_t idx = ePropertyEnableBackgroundLookup;
142-
return GetPropertyAtIndexAs<bool>(
143-
idx, g_modulelist_properties[idx].default_uint_value != 0);
140+
SymbolDownload ModuleListProperties::GetSymbolAutoDownload() const {
141+
// Backward compatibility alias.
142+
if (GetPropertyAtIndexAs<bool>(ePropertyEnableBackgroundLookup, false))
143+
return eSymbolDownloadBackground;
144+
145+
const uint32_t idx = ePropertyAutoDownload;
146+
return GetPropertyAtIndexAs<lldb::SymbolDownload>(
147+
idx, static_cast<lldb::SymbolDownload>(
148+
g_modulelist_properties[idx].default_uint_value));
144149
}
145150

146151
FileSpec ModuleListProperties::GetClangModulesCachePath() const {
@@ -1098,7 +1103,7 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
10981103
// Fixup the incoming path in case the path points to a valid file, yet the
10991104
// arch or UUID (if one was passed in) don't match.
11001105
ModuleSpec located_binary_modulespec =
1101-
Symbols::LocateExecutableObjectFile(module_spec);
1106+
PluginManager::LocateExecutableObjectFile(module_spec);
11021107

11031108
// Don't look for the file if it appears to be the same one we already
11041109
// checked for above...

0 commit comments

Comments
 (0)