Skip to content

Commit eafa053

Browse files
committed
[Debuginfod] Add --debug-file-directory to llvm-debuginfod-find.
This allows llvm-debuginfod-find to locate binaries in local build ID directories configured via --debug-file-directory, the same flag used for this purpose by llvm-symbolizer. This provides a consistent lookup semantics between the two tools when configured the same way, in particular when debug binaries may be located either locally or remotely. Reviewed By: phosek Differential Revision: https://reviews.llvm.org/D125864
1 parent 47b8424 commit eafa053

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Test that llvm-debuginfod-find can perform local directory lookups.
2+
3+
# Test depends on POSIX file paths.
4+
UNSUPPORTED: system-windows
5+
6+
RUN: mkdir -p %t/a/.build-id
7+
RUN: mkdir -p %t/b/.build-id/00/00000000000000
8+
RUN: mkdir -p %t/b/.build-id/01/23456789012345.debug
9+
RUN: mkdir -p %t/b/.build-id/02/22222222222222
10+
RUN: mkdir -p %t/c/.build-id/
11+
RUN: llvm-debuginfod-find \
12+
RUN: --debug-file-directory %t/a \
13+
RUN: --debug-file-directory %t/b \
14+
RUN: --debug-file-directory %t/c \
15+
RUN: --debuginfo 0123456789012345 > %t.out
16+
RUN: FileCheck -DT=%t --match-full-lines --implicit-check-not {{.}} %s < %t.out
17+
18+
CHECK: [[T]]/b/.build-id/01/23456789012345.debug

llvm/tools/llvm-debuginfod-find/llvm-debuginfod-find.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
///
1616
//===----------------------------------------------------------------------===//
1717

18+
#include "llvm/DebugInfo/Symbolize/DIFetcher.h"
1819
#include "llvm/Debuginfod/Debuginfod.h"
1920
#include "llvm/Debuginfod/HTTPClient.h"
2021
#include "llvm/Support/CommandLine.h"
@@ -53,6 +54,11 @@ static cl::opt<bool>
5354
"path to the cached artifact on disk."),
5455
cl::cat(DebuginfodFindCategory));
5556

57+
static cl::list<std::string> DebugFileDirectory(
58+
"debug-file-directory",
59+
cl::desc("Path to directory where to look for debug files."),
60+
cl::cat(DebuginfodFindCategory));
61+
5662
[[noreturn]] static void helpExit() {
5763
errs() << "Must specify exactly one of --executable, "
5864
"--source=/path/to/file, or --debuginfo.";
@@ -61,6 +67,8 @@ static cl::opt<bool>
6167

6268
ExitOnError ExitOnErr;
6369

70+
static std::string fetchDebugInfo(ArrayRef<uint8_t> BuildID);
71+
6472
int main(int argc, char **argv) {
6573
InitLLVM X(argc, argv);
6674
HTTPClient::initialize();
@@ -92,7 +100,7 @@ int main(int argc, char **argv) {
92100
else if (FetchExecutable)
93101
Path = ExitOnErr(getCachedOrDownloadExecutable(ID));
94102
else if (FetchDebuginfo)
95-
Path = ExitOnErr(getCachedOrDownloadDebuginfo(ID));
103+
Path = fetchDebugInfo(ID);
96104
else
97105
llvm_unreachable("We have already checked that exactly one of the above "
98106
"conditions is true.");
@@ -107,3 +115,13 @@ int main(int argc, char **argv) {
107115
// Print the path to the cached artifact file.
108116
outs() << Path << "\n";
109117
}
118+
119+
// Find a debug binary in local build ID directories and via debuginfod.
120+
std::string fetchDebugInfo(ArrayRef<uint8_t> BuildID) {
121+
if (!DebugFileDirectory.empty()) {
122+
symbolize::LocalDIFetcher Fetcher(DebugFileDirectory);
123+
if (Optional<std::string> LocalPath = Fetcher.fetchBuildID(BuildID))
124+
return *LocalPath;
125+
}
126+
return ExitOnErr(getCachedOrDownloadDebuginfo(BuildID));
127+
}

0 commit comments

Comments
 (0)