llvm-project/lldb/source/Symbol/SymbolLocator.cpp
Jonas Devlieghere 5f4b40c90a
[lldb] Expand background symbol download (#80890)
LLDB has a setting (symbols.enable-background-lookup) that calls
dsymForUUID on a background thread for images as they appear in the
current backtrace. Originally, the laziness of only looking up symbols
for images in the backtrace only existed to bring the number of
dsymForUUID calls down to a manageable number.

Users have requesting the same functionality but blocking. This gives
them the same user experience as enabling dsymForUUID globally, but
without the massive upfront cost of having to download all the images,
the majority of which they'll likely not need.

This patch renames the setting to have a more generic name
(symbols.auto-download) and changes its values from a boolean to an
enum. Users can now specify "off", "background" and "foreground". The
default remains "off" although I'll probably change that in the near
future.
2024-02-08 12:39:04 -08:00

58 lines
1.6 KiB
C++

//===-- symbolLocator.cpp -------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "lldb/Symbol/SymbolLocator.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Host/Host.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/Support/ThreadPool.h"
using namespace lldb;
using namespace lldb_private;
void SymbolLocator::DownloadSymbolFileAsync(const UUID &uuid) {
static llvm::SmallSet<UUID, 8> g_seen_uuids;
static std::mutex g_mutex;
auto lookup = [=]() {
{
std::lock_guard<std::mutex> guard(g_mutex);
if (g_seen_uuids.count(uuid))
return;
g_seen_uuids.insert(uuid);
}
Status error;
ModuleSpec module_spec;
module_spec.GetUUID() = uuid;
if (!PluginManager::DownloadObjectAndSymbolFile(module_spec, error,
/*force_lookup=*/true,
/*copy_executable=*/true))
return;
if (error.Fail())
return;
Debugger::ReportSymbolChange(module_spec);
};
switch (ModuleList::GetGlobalModuleListProperties().GetSymbolAutoDownload()) {
case eSymbolDownloadOff:
break;
case eSymbolDownloadBackground:
Debugger::GetThreadPool().async(lookup);
break;
case eSymbolDownloadForeground:
lookup();
break;
};
}