[llvm] eafa053 - [Debuginfod] Add --debug-file-directory to llvm-debuginfod-find.

Daniel Thornburgh via llvm-commits llvm-commits at lists.llvm.org
Wed May 18 09:57:02 PDT 2022


Author: Daniel Thornburgh
Date: 2022-05-18T16:56:57Z
New Revision: eafa0530417e09755b94d0e94afc0f792b98c80d

URL: https://github.com/llvm/llvm-project/commit/eafa0530417e09755b94d0e94afc0f792b98c80d
DIFF: https://github.com/llvm/llvm-project/commit/eafa0530417e09755b94d0e94afc0f792b98c80d.diff

LOG: [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

Added: 
    llvm/test/tools/llvm-debuginfod-find/local.test

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

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-debuginfod-find/local.test b/llvm/test/tools/llvm-debuginfod-find/local.test
new file mode 100644
index 0000000000000..53438619ae393
--- /dev/null
+++ b/llvm/test/tools/llvm-debuginfod-find/local.test
@@ -0,0 +1,18 @@
+# Test that llvm-debuginfod-find can perform local directory lookups.
+
+# Test depends on POSIX file paths.
+UNSUPPORTED: system-windows
+
+RUN: mkdir -p %t/a/.build-id
+RUN: mkdir -p %t/b/.build-id/00/00000000000000
+RUN: mkdir -p %t/b/.build-id/01/23456789012345.debug
+RUN: mkdir -p %t/b/.build-id/02/22222222222222
+RUN: mkdir -p %t/c/.build-id/
+RUN: llvm-debuginfod-find \
+RUN:   --debug-file-directory %t/a \
+RUN:   --debug-file-directory %t/b \
+RUN:   --debug-file-directory %t/c \
+RUN:   --debuginfo 0123456789012345 > %t.out
+RUN: FileCheck -DT=%t --match-full-lines --implicit-check-not {{.}} %s < %t.out
+
+CHECK: [[T]]/b/.build-id/01/23456789012345.debug

diff  --git a/llvm/tools/llvm-debuginfod-find/llvm-debuginfod-find.cpp b/llvm/tools/llvm-debuginfod-find/llvm-debuginfod-find.cpp
index 65b62bf9ebc9f..373353c226f60 100644
--- a/llvm/tools/llvm-debuginfod-find/llvm-debuginfod-find.cpp
+++ b/llvm/tools/llvm-debuginfod-find/llvm-debuginfod-find.cpp
@@ -15,6 +15,7 @@
 ///
 //===----------------------------------------------------------------------===//
 
+#include "llvm/DebugInfo/Symbolize/DIFetcher.h"
 #include "llvm/Debuginfod/Debuginfod.h"
 #include "llvm/Debuginfod/HTTPClient.h"
 #include "llvm/Support/CommandLine.h"
@@ -53,6 +54,11 @@ static cl::opt<bool>
                           "path to the cached artifact on disk."),
                  cl::cat(DebuginfodFindCategory));
 
+static cl::list<std::string> DebugFileDirectory(
+    "debug-file-directory",
+    cl::desc("Path to directory where to look for debug files."),
+    cl::cat(DebuginfodFindCategory));
+
 [[noreturn]] static void helpExit() {
   errs() << "Must specify exactly one of --executable, "
             "--source=/path/to/file, or --debuginfo.";
@@ -61,6 +67,8 @@ static cl::opt<bool>
 
 ExitOnError ExitOnErr;
 
+static std::string fetchDebugInfo(ArrayRef<uint8_t> BuildID);
+
 int main(int argc, char **argv) {
   InitLLVM X(argc, argv);
   HTTPClient::initialize();
@@ -92,7 +100,7 @@ int main(int argc, char **argv) {
   else if (FetchExecutable)
     Path = ExitOnErr(getCachedOrDownloadExecutable(ID));
   else if (FetchDebuginfo)
-    Path = ExitOnErr(getCachedOrDownloadDebuginfo(ID));
+    Path = fetchDebugInfo(ID);
   else
     llvm_unreachable("We have already checked that exactly one of the above "
                      "conditions is true.");
@@ -107,3 +115,13 @@ int main(int argc, char **argv) {
     // Print the path to the cached artifact file.
     outs() << Path << "\n";
 }
+
+// Find a debug binary in local build ID directories and via debuginfod.
+std::string fetchDebugInfo(ArrayRef<uint8_t> BuildID) {
+  if (!DebugFileDirectory.empty()) {
+    symbolize::LocalDIFetcher Fetcher(DebugFileDirectory);
+    if (Optional<std::string> LocalPath = Fetcher.fetchBuildID(BuildID))
+      return *LocalPath;
+  }
+  return ExitOnErr(getCachedOrDownloadDebuginfo(BuildID));
+}


        


More information about the llvm-commits mailing list