[PATCH] D118174: [Symbolize][DebugInfoD] Try looking up failed paths as Build IDs.

Daniel Thornburgh via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 25 12:18:38 PST 2022


mysterymath created this revision.
mysterymath added reviewers: mcgrathr, phosek.
Herald added subscribers: rupprecht, hiraditya.
Herald added a reviewer: jhenderson.
mysterymath requested review of this revision.
Herald added subscribers: llvm-commits, MaskRay.
Herald added a project: LLVM.

If a path given to the symbolizer cannot be loaded as a binary file, and
the path string is a 160 character hex, attempt to look up the binary
via DebugInfoD. This will first try cache directories, then an HTTP
lookup if built with libcurl.

This allows Build IDs to be provided to llvm-symbolizer anywhere a path
could be provided: in stdin, via flag, via args, or via environment
variables.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118174

Files:
  llvm/docs/CommandGuide/llvm-symbolizer.rst
  llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
  llvm/test/tools/llvm-symbolizer/debuginfod.test


Index: llvm/test/tools/llvm-symbolizer/debuginfod.test
===================================================================
--- llvm/test/tools/llvm-symbolizer/debuginfod.test
+++ llvm/test/tools/llvm-symbolizer/debuginfod.test
@@ -25,3 +25,8 @@
 RUN: env DEBUGINFOD_CACHE_PATH=%t llvm-symbolizer \
 RUN:   --obj=%t/addr.exe 0x40054d | FileCheck %s --check-prefix=FOUND
 FOUND: {{[/\]+}}tmp{{[/\]+}}x.c:14:0
+
+# This should also work if the Build ID is provided in lieu of a path.
+RUN: env DEBUGINFOD_CACHE_PATH=%t llvm-symbolizer \
+RUN:   --obj=127da749021c1fc1a58cba734a1f542cbe2b7ce4 0x40054d | \
+RUN:   FileCheck %s --check-prefix=FOUND
Index: llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
===================================================================
--- llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
+++ llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
@@ -508,9 +508,30 @@
     Bin = Pair.first->second.getBinary();
   } else {
     Expected<OwningBinary<Binary>> BinOrErr = createBinary(Path);
-    if (!BinOrErr)
-      return BinOrErr.takeError();
-    Pair.first->second = std::move(BinOrErr.get());
+    if (BinOrErr) {
+      Pair.first->second = std::move(BinOrErr.get());
+    } else {
+      ArrayRef<uint8_t> BuildID;
+
+      // If this isn't a path to a valid binary, maybe it's a Build ID.
+      std::string Bytes;
+      if (!tryGetFromHex(Path, Bytes))
+        return BinOrErr.takeError();
+      BuildID = ArrayRef<uint8_t>(
+          reinterpret_cast<const uint8_t *>(Bytes.data()), Bytes.size());
+      if (BuildID.size() != 20)
+        return BinOrErr.takeError();
+
+      std::string PathFromBuildID;
+      if (!findDebugBinary(Opts.DebugFileDirectory, BuildID, PathFromBuildID))
+        return BinOrErr.takeError();
+      Expected<OwningBinary<Binary>> BuildIDBinOrErr =
+          createBinary(PathFromBuildID);
+      if (!BuildIDBinOrErr)
+        return joinErrors(BinOrErr.takeError(), BuildIDBinOrErr.takeError());
+      consumeError(BinOrErr.takeError());
+      Pair.first->second = std::move(BuildIDBinOrErr.get());
+    }
     Bin = Pair.first->second.getBinary();
   }
 
Index: llvm/docs/CommandGuide/llvm-symbolizer.rst
===================================================================
--- llvm/docs/CommandGuide/llvm-symbolizer.rst
+++ llvm/docs/CommandGuide/llvm-symbolizer.rst
@@ -28,6 +28,13 @@
 input or as positional arguments on the command-line, following any "DATA" or
 "CODE" prefix.
 
+wherever a binary filename is accepted, a Build ID can be provided instead to
+search for the binary. Various cache directories are searched first, followed by
+any DebugInfoD servers configured via the ``DEBUGINFOD_URLS`` environment
+variable. For server lookups to work, the tool needs must have been built with
+``LLVM_ENABLE_CURL`` enabled.
+
+
 :program:`llvm-symbolizer` parses options from the environment variable
 ``LLVM_SYMBOLIZER_OPTS`` after parsing options from the command line.
 ``LLVM_SYMBOLIZER_OPTS`` is primarily useful for supplementing the command-line


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118174.402998.patch
Type: text/x-patch
Size: 3021 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220125/75b2b5bc/attachment.bin>


More information about the llvm-commits mailing list