Skip to content

Commit 69f0b20

Browse files
author
George Hu
committed
[lldb] Implement priority system for symbol locator plugin
1 parent 267b859 commit 69f0b20

File tree

6 files changed

+80
-10
lines changed

6 files changed

+80
-10
lines changed

lldb/include/lldb/Core/PluginManager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,8 @@ class PluginManager {
431431
SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file =
432432
nullptr,
433433
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle = nullptr,
434-
DebuggerInitializeCallback debugger_init_callback = nullptr);
434+
DebuggerInitializeCallback debugger_init_callback = nullptr,
435+
SymbolLocatorGetPriority get_priority_callback = nullptr);
435436

436437
static bool UnregisterPlugin(SymbolLocatorCreateInstance create_callback);
437438

lldb/include/lldb/Symbol/SymbolLocator.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
namespace lldb_private {
1616

17+
// Default priority for symbol locator plugins. Lower values are favored first.
18+
static constexpr uint32_t kDefaultSymbolLocatorPriority = 2;
19+
1720
class SymbolLocator : public PluginInterface {
1821
public:
1922
SymbolLocator() = default;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ typedef std::optional<FileSpec> (*SymbolLocatorLocateExecutableSymbolFile)(
100100
typedef bool (*SymbolLocatorDownloadObjectAndSymbolFile)(
101101
ModuleSpec &module_spec, Status &error, bool force_lookup,
102102
bool copy_executable);
103+
typedef uint64_t (*SymbolLocatorGetPriority)();
103104
using BreakpointHitCallback =
104105
std::function<bool(void *baton, StoppointCallbackContext *context,
105106
lldb::user_id_t break_id, lldb::user_id_t break_loc_id)>;

lldb/source/Core/PluginManager.cpp

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "lldb/Host/HostInfo.h"
1414
#include "lldb/Interpreter/OptionValueProperties.h"
1515
#include "lldb/Symbol/SaveCoreOptions.h"
16+
#include "lldb/Symbol/SymbolLocator.h"
1617
#include "lldb/Target/Process.h"
1718
#include "lldb/Utility/FileSpec.h"
1819
#include "lldb/Utility/Status.h"
@@ -25,6 +26,7 @@
2526
#include <map>
2627
#include <memory>
2728
#include <mutex>
29+
#include <queue>
2830
#include <string>
2931
#include <utility>
3032
#include <vector>
@@ -323,6 +325,29 @@ template <typename Instance> class PluginInstances {
323325
return enabled_instances;
324326
}
325327

328+
// Return a priority queue of all enabled instances, ordered by priority
329+
// (lower priority values = higher priority in queue)
330+
template <typename PriorityGetter>
331+
std::priority_queue<Instance, std::vector<Instance>,
332+
std::function<bool(const Instance &, const Instance &)>>
333+
GetPriorityQueue(PriorityGetter get_priority) {
334+
// Create comparator that orders by priority (lower values = higher
335+
// priority)
336+
auto comparator = [get_priority](const Instance &a, const Instance &b) {
337+
return get_priority(a) > get_priority(b); // Reverse for min-heap behavior
338+
};
339+
340+
std::priority_queue<Instance, std::vector<Instance>,
341+
std::function<bool(const Instance &, const Instance &)>>
342+
pq(comparator);
343+
344+
for (const auto &instance : m_instances) {
345+
if (instance.enabled)
346+
pq.push(instance);
347+
}
348+
return pq;
349+
}
350+
326351
const Instance *GetInstanceAtIndex(uint32_t idx) {
327352
uint32_t count = 0;
328353

@@ -1223,18 +1248,26 @@ struct SymbolLocatorInstance
12231248
SymbolLocatorLocateExecutableSymbolFile locate_executable_symbol_file,
12241249
SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file,
12251250
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle,
1226-
DebuggerInitializeCallback debugger_init_callback)
1251+
DebuggerInitializeCallback debugger_init_callback,
1252+
SymbolLocatorGetPriority get_priority_callback)
12271253
: PluginInstance<SymbolLocatorCreateInstance>(
12281254
name, description, create_callback, debugger_init_callback),
12291255
locate_executable_object_file(locate_executable_object_file),
12301256
locate_executable_symbol_file(locate_executable_symbol_file),
12311257
download_object_symbol_file(download_object_symbol_file),
1232-
find_symbol_file_in_bundle(find_symbol_file_in_bundle) {}
1258+
find_symbol_file_in_bundle(find_symbol_file_in_bundle),
1259+
get_priority_callback(get_priority_callback) {}
1260+
1261+
uint64_t GetPriority() const {
1262+
return get_priority_callback ? get_priority_callback()
1263+
: kDefaultSymbolLocatorPriority;
1264+
}
12331265

12341266
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file;
12351267
SymbolLocatorLocateExecutableSymbolFile locate_executable_symbol_file;
12361268
SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file;
12371269
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle;
1270+
SymbolLocatorGetPriority get_priority_callback;
12381271
};
12391272
typedef PluginInstances<SymbolLocatorInstance> SymbolLocatorInstances;
12401273

@@ -1250,11 +1283,13 @@ bool PluginManager::RegisterPlugin(
12501283
SymbolLocatorLocateExecutableSymbolFile locate_executable_symbol_file,
12511284
SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file,
12521285
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle,
1253-
DebuggerInitializeCallback debugger_init_callback) {
1286+
DebuggerInitializeCallback debugger_init_callback,
1287+
SymbolLocatorGetPriority get_priority_callback) {
12541288
return GetSymbolLocatorInstances().RegisterPlugin(
12551289
name, description, create_callback, locate_executable_object_file,
12561290
locate_executable_symbol_file, download_object_symbol_file,
1257-
find_symbol_file_in_bundle, debugger_init_callback);
1291+
find_symbol_file_in_bundle, debugger_init_callback,
1292+
get_priority_callback);
12581293
}
12591294

12601295
bool PluginManager::UnregisterPlugin(
@@ -1270,8 +1305,13 @@ PluginManager::GetSymbolLocatorCreateCallbackAtIndex(uint32_t idx) {
12701305
ModuleSpec
12711306
PluginManager::LocateExecutableObjectFile(const ModuleSpec &module_spec,
12721307
StatisticsMap &map) {
1273-
auto instances = GetSymbolLocatorInstances().GetSnapshot();
1274-
for (auto &instance : instances) {
1308+
auto pq = GetSymbolLocatorInstances().GetPriorityQueue(
1309+
[](const auto &instance) { return instance.GetPriority(); });
1310+
1311+
while (!pq.empty()) {
1312+
auto instance = pq.top();
1313+
pq.pop();
1314+
12751315
if (instance.locate_executable_object_file) {
12761316
StatsDuration time;
12771317
std::optional<ModuleSpec> result;
@@ -1290,8 +1330,12 @@ PluginManager::LocateExecutableObjectFile(const ModuleSpec &module_spec,
12901330
FileSpec PluginManager::LocateExecutableSymbolFile(
12911331
const ModuleSpec &module_spec, const FileSpecList &default_search_paths,
12921332
StatisticsMap &map) {
1293-
auto instances = GetSymbolLocatorInstances().GetSnapshot();
1294-
for (auto &instance : instances) {
1333+
auto pq = GetSymbolLocatorInstances().GetPriorityQueue(
1334+
[](const auto &instance) { return instance.GetPriority(); });
1335+
1336+
while (!pq.empty()) {
1337+
auto instance = pq.top();
1338+
pq.pop();
12951339
if (instance.locate_executable_symbol_file) {
12961340
StatsDuration time;
12971341
std::optional<FileSpec> result;

lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ class PluginProperties : public Properties {
8383
}
8484
}
8585

86+
uint32_t GetPriority() const {
87+
std::optional<uint32_t> priority =
88+
m_collection_sp->GetPropertyAtIndexAs<uint64_t>(ePropertyPriority);
89+
if (priority && *priority >= 0) {
90+
return priority.value();
91+
} else {
92+
return kDefaultSymbolLocatorPriority;
93+
}
94+
}
95+
8696
private:
8797
void ServerURLsChangedCallback() {
8898
m_server_urls = GetDebugInfoDURLs();
@@ -103,6 +113,13 @@ static PluginProperties &GetGlobalPluginProperties() {
103113
return g_settings;
104114
}
105115

116+
static uint64_t GetDebuginfodPriority() {
117+
// Grab LLDB's Debuginfod overrides from the
118+
// plugin.symbol-locator.debuginfod.* settings.
119+
PluginProperties &plugin_props = GetGlobalPluginProperties();
120+
return plugin_props.GetPriority();
121+
}
122+
106123
SymbolLocatorDebuginfod::SymbolLocatorDebuginfod() : SymbolLocator() {}
107124

108125
void SymbolLocatorDebuginfod::Initialize() {
@@ -112,7 +129,8 @@ void SymbolLocatorDebuginfod::Initialize() {
112129
PluginManager::RegisterPlugin(
113130
GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance,
114131
LocateExecutableObjectFile, LocateExecutableSymbolFile, nullptr,
115-
nullptr, SymbolLocatorDebuginfod::DebuggerInitialize);
132+
nullptr, SymbolLocatorDebuginfod::DebuggerInitialize,
133+
GetDebuginfodPriority);
116134
llvm::HTTPClient::initialize();
117135
});
118136
}

lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfodProperties.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ let Definition = "symbollocatordebuginfod" in {
1010
def Timeout : Property<"timeout", "UInt64">,
1111
DefaultUnsignedValue<0>,
1212
Desc<"Timeout (in seconds) for requests made to a DEBUGINFOD server. A value of zero means we use the debuginfod default timeout: DEBUGINFOD_TIMEOUT if the environment variable is set and 90 seconds otherwise.">;
13+
def Priority : Property<"priority", "UInt64">,
14+
DefaultUnsignedValue<2>,
15+
Desc<"The priority order for this symbol locator plugin when multiple symbol locators are available. Lower values indicate higher priority. The default symbol locator priority is 2">;
1316
}

0 commit comments

Comments
 (0)