[PATCH] D132887: [objdump] [debuginfod] Fetch for very-stripped binaries.

Daniel Thornburgh via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 27 14:50:19 PDT 2022


mysterymath updated this revision to Diff 463343.
mysterymath marked an inline comment as done.
mysterymath added a comment.

Add tests; address review comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132887/new/

https://reviews.llvm.org/D132887

Files:
  llvm/test/tools/llvm-objdump/debuginfod.test
  llvm/tools/llvm-objdump/llvm-objdump.cpp


Index: llvm/tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -1856,6 +1856,22 @@
 }
 
 static void disassembleObject(ObjectFile *Obj, bool InlineRelocs) {
+  // If information useful for showing the disassembly is missing, try to find a
+  // more complete binary and disassemble that instead.
+  OwningBinary<Binary> FetchedBinary;
+  if (Obj->symbols().empty()) {
+    if (Optional<OwningBinary<Binary>> FetchedBinaryOpt =
+            fetchBinaryByBuildID(*Obj)) {
+      if (auto *O = dyn_cast<ObjectFile>(FetchedBinaryOpt->getBinary())) {
+        if (!O->symbols().empty() ||
+            (!O->sections().empty() && Obj->sections().empty())) {
+          FetchedBinary = std::move(*FetchedBinaryOpt);
+          Obj = O;
+        }
+      }
+    }
+  }
+
   const Target *TheTarget = getTarget(Obj);
 
   // Package up features to be passed to target/subtarget
@@ -1959,14 +1975,13 @@
 
   PrettyPrinter &PIP = selectPrettyPrinter(Triple(TripleName));
   ObjectFile *DbgObj = Obj;
-  OwningBinary<Binary> DebugBinary;
-  if (!Obj->hasDebugInfo()) {
+  if (!FetchedBinary.getBinary() && !Obj->hasDebugInfo()) {
     if (Optional<OwningBinary<Binary>> DebugBinaryOpt =
             fetchBinaryByBuildID(*Obj)) {
       if (ObjectFile *FetchedObj =
               dyn_cast<ObjectFile>(DebugBinaryOpt->getBinary())) {
         if (FetchedObj->hasDebugInfo()) {
-          DebugBinary = std::move(*DebugBinaryOpt);
+          FetchedBinary = std::move(*DebugBinaryOpt);
           DbgObj = FetchedObj;
         }
       }
Index: llvm/test/tools/llvm-objdump/debuginfod.test
===================================================================
--- llvm/test/tools/llvm-objdump/debuginfod.test
+++ llvm/test/tools/llvm-objdump/debuginfod.test
@@ -61,5 +61,31 @@
 RUN:   FileCheck %s --check-prefix=NOTFOUND
 RUN: count 0 < %t.err
 
+# Use debuginfod to recover symbols.
+RUN: llvm-strip --strip-sections %t/stripped
+RUN: env DEBUGINFOD_CACHE_PATH=%t llvm-objdump -d --debuginfod \
+RUN:   %t/stripped | \
+RUN:   FileCheck %s --check-prefix=SYMBOLS
+
+# Use debuginfod to recover section headers, but not symbols.
+RUN: mkdir %t/stripped-symbols
+RUN: cp %p/Inputs/embedded-source %t/stripped-symbols/llvmcache-7361776989772977641
+RUN: llvm-strip %t/stripped-symbols/llvmcache-7361776989772977641
+RUN: env DEBUGINFOD_CACHE_PATH=%t/stripped-symbols llvm-objdump -d \
+RUN:   --debuginfod %t/stripped | \
+RUN:   FileCheck %s --check-prefix=SECTIONS
+
+# Don't use debuginfod if neither section headers nor symbols can be recovered.
+RUN: mkdir %t/stripped-sections
+RUN: echo "" | llvm-mc -filetype=obj -triple x86_64 > \
+RUN:   %t/stripped-sections/llvmcache-7361776989772977641
+RUN: llvm-strip --strip-sections %t/stripped-sections/llvmcache-7361776989772977641
+RUN: env DEBUGINFOD_CACHE_PATH=%t/stripped-sections llvm-objdump -d \
+RUN:   --debuginfod %t/stripped | \
+RUN:   FileCheck %s --check-prefix=NOSECTIONS
+
+NOSECTIONS: <>:
+SECTIONS: <.text>:
+SYMBOLS: <main>:
 FOUND: int main(int argc, char *argv[]) {
 NOTFOUND-NOT: int main(int argc, char *argv[]) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132887.463343.patch
Type: text/x-patch
Size: 3219 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220927/d13d64c6/attachment.bin>


More information about the llvm-commits mailing list