13
13
#include " lldb/Host/HostInfo.h"
14
14
#include " lldb/Interpreter/OptionValueProperties.h"
15
15
#include " lldb/Symbol/SaveCoreOptions.h"
16
+ #include " lldb/Symbol/SymbolLocator.h"
16
17
#include " lldb/Target/Process.h"
17
18
#include " lldb/Utility/FileSpec.h"
18
19
#include " lldb/Utility/Status.h"
25
26
#include < map>
26
27
#include < memory>
27
28
#include < mutex>
29
+ #include < queue>
28
30
#include < string>
29
31
#include < utility>
30
32
#include < vector>
@@ -323,6 +325,29 @@ template <typename Instance> class PluginInstances {
323
325
return enabled_instances;
324
326
}
325
327
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
+
326
351
const Instance *GetInstanceAtIndex (uint32_t idx) {
327
352
uint32_t count = 0 ;
328
353
@@ -1223,18 +1248,26 @@ struct SymbolLocatorInstance
1223
1248
SymbolLocatorLocateExecutableSymbolFile locate_executable_symbol_file,
1224
1249
SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file,
1225
1250
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle,
1226
- DebuggerInitializeCallback debugger_init_callback)
1251
+ DebuggerInitializeCallback debugger_init_callback,
1252
+ SymbolLocatorGetPriority get_priority_callback)
1227
1253
: PluginInstance<SymbolLocatorCreateInstance>(
1228
1254
name, description, create_callback, debugger_init_callback),
1229
1255
locate_executable_object_file (locate_executable_object_file),
1230
1256
locate_executable_symbol_file (locate_executable_symbol_file),
1231
1257
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
+ }
1233
1265
1234
1266
SymbolLocatorLocateExecutableObjectFile locate_executable_object_file;
1235
1267
SymbolLocatorLocateExecutableSymbolFile locate_executable_symbol_file;
1236
1268
SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file;
1237
1269
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle;
1270
+ SymbolLocatorGetPriority get_priority_callback;
1238
1271
};
1239
1272
typedef PluginInstances<SymbolLocatorInstance> SymbolLocatorInstances;
1240
1273
@@ -1250,11 +1283,13 @@ bool PluginManager::RegisterPlugin(
1250
1283
SymbolLocatorLocateExecutableSymbolFile locate_executable_symbol_file,
1251
1284
SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file,
1252
1285
SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle,
1253
- DebuggerInitializeCallback debugger_init_callback) {
1286
+ DebuggerInitializeCallback debugger_init_callback,
1287
+ SymbolLocatorGetPriority get_priority_callback) {
1254
1288
return GetSymbolLocatorInstances ().RegisterPlugin (
1255
1289
name, description, create_callback, locate_executable_object_file,
1256
1290
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);
1258
1293
}
1259
1294
1260
1295
bool PluginManager::UnregisterPlugin (
@@ -1270,8 +1305,13 @@ PluginManager::GetSymbolLocatorCreateCallbackAtIndex(uint32_t idx) {
1270
1305
ModuleSpec
1271
1306
PluginManager::LocateExecutableObjectFile (const ModuleSpec &module_spec,
1272
1307
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
+
1275
1315
if (instance.locate_executable_object_file ) {
1276
1316
StatsDuration time;
1277
1317
std::optional<ModuleSpec> result;
@@ -1290,8 +1330,12 @@ PluginManager::LocateExecutableObjectFile(const ModuleSpec &module_spec,
1290
1330
FileSpec PluginManager::LocateExecutableSymbolFile (
1291
1331
const ModuleSpec &module_spec, const FileSpecList &default_search_paths,
1292
1332
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 ();
1295
1339
if (instance.locate_executable_symbol_file ) {
1296
1340
StatsDuration time;
1297
1341
std::optional<FileSpec> result;
0 commit comments