[llvm] 694f384 - [Debuginfod] Flag-determine debuginfod lookups in llvm-symbolizer.

Daniel Thornburgh via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 9 14:21:00 PST 2022


Author: Daniel Thornburgh
Date: 2022-02-09T22:20:54Z
New Revision: 694f38455348e4e5c728a45e5b52ebf76a256133

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

LOG: [Debuginfod] Flag-determine debuginfod lookups in llvm-symbolizer.

This change adds a pair of flags controlling whether llvm-symbolizer
attempts debuginfod lookups. Lookups are attempted if --debuginfod is
passed and disabled if --no-debuginfod is passed.

The default behavior is made more nuanced: debuginfod lookups are now
only attempted if an HTTP client is compiled in and at least one backing
debuginfod URL was configured via environment variable. Previously,
debuginfod lookups would always be attempted, even if there were no
chance that they could succeed.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D118665

Added: 
    

Modified: 
    llvm/docs/CommandGuide/llvm-symbolizer.rst
    llvm/test/tools/llvm-symbolizer/debuginfod.test
    llvm/tools/llvm-symbolizer/Opts.td
    llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/docs/CommandGuide/llvm-symbolizer.rst b/llvm/docs/CommandGuide/llvm-symbolizer.rst
index 72ebbf8f59ed1..271bf90e7d8df 100644
--- a/llvm/docs/CommandGuide/llvm-symbolizer.rst
+++ b/llvm/docs/CommandGuide/llvm-symbolizer.rst
@@ -188,6 +188,13 @@ OPTIONS
   Look up the object using the given build ID, specified as a hexadecimal
   string. Mutually exclusive with :option:`--obj`.
 
+.. option:: --debuginfod, --no-debuginfod
+
+  Whether or not to try debuginfod lookups for debug binaries. Unless specified,
+  debuginfod is only enabled if libcurl was compiled in (``LLVM_ENABLE_CURL``)
+  and at least one server URL was provided by the environment variable
+  ``DEBUGINFOD_URLS``.
+
 .. _llvm-symbolizer-opt-C:
 
 .. option:: --demangle, -C

diff  --git a/llvm/test/tools/llvm-symbolizer/debuginfod.test b/llvm/test/tools/llvm-symbolizer/debuginfod.test
index fb9aea377096a..34310c48c5103 100644
--- a/llvm/test/tools/llvm-symbolizer/debuginfod.test
+++ b/llvm/test/tools/llvm-symbolizer/debuginfod.test
@@ -23,10 +23,15 @@ RUN:   %t/llvmcache-9800707741016212219
 # The symbolizer should call the debuginfod client library, which finds the
 # debuginfo placed in the cache, enabling symbolization of the address.
 RUN: env DEBUGINFOD_CACHE_PATH=%t llvm-symbolizer \
-RUN:   --obj=%t/addr.exe 0x40054d | FileCheck %s --check-prefix=FOUND
+RUN:   --obj=%t/addr.exe 0x40054d --debuginfod | \
+RUN:   FileCheck %s --check-prefix=FOUND
 FOUND: {{[/\]+}}tmp{{[/\]+}}x.c:14:0
 
 # This should also work if the build ID is provided.
 RUN: env DEBUGINFOD_CACHE_PATH=%t llvm-symbolizer \
 RUN:   --build-id=127da749021c1fc1a58cba734a1f542cbe2b7ce4 0x40054d | \
 RUN:   FileCheck %s --check-prefix=FOUND
+
+# The symbolizer shouldn't call the debuginfod library by default with no URLs.
+RUN: env DEBUGINFOD_CACHE_PATH=%t llvm-symbolizer --print-address \
+RUN:   --obj=%t/addr.exe 0x40054d | FileCheck %s --check-prefix=NOTFOUND

diff  --git a/llvm/tools/llvm-symbolizer/Opts.td b/llvm/tools/llvm-symbolizer/Opts.td
index c07be62cac03c..b21af7a9fb203 100644
--- a/llvm/tools/llvm-symbolizer/Opts.td
+++ b/llvm/tools/llvm-symbolizer/Opts.td
@@ -23,6 +23,7 @@ defm adjust_vma
 def basenames : Flag<["--"], "basenames">, HelpText<"Strip directory names from paths">;
 defm build_id : Eq<"build-id", "Build ID used to look up the object file">;
 defm debug_file_directory : Eq<"debug-file-directory", "Path to directory where to look for debug files">, MetaVarName<"<dir>">;
+defm debuginfod : B<"debuginfod", "Use debuginfod to find debug binaries", "Don't use debuginfod to find debug binaries">;
 defm default_arch
     : Eq<"default-arch", "Default architecture (for multi-arch objects)">,
       Group<grp_mach_o>;

diff  --git a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
index e036a075e97b2..02c6e0be3d32d 100644
--- a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
+++ b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
@@ -21,6 +21,7 @@
 #include "llvm/DebugInfo/Symbolize/DIPrinter.h"
 #include "llvm/DebugInfo/Symbolize/Symbolize.h"
 #include "llvm/Debuginfod/DIFetcher.h"
+#include "llvm/Debuginfod/Debuginfod.h"
 #include "llvm/Debuginfod/HTTPClient.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -296,6 +297,27 @@ SmallVector<uint8_t> parseBuildIDArg(const opt::InputArgList &Args, int ID) {
   return {};
 }
 
+ExitOnError ExitOnErr;
+
+static bool shouldUseDebuginfodByDefault(ArrayRef<uint8_t> BuildID) {
+  // If the user explicitly specified a build ID, the usual way to find it is
+  // debuginfod.
+  if (!BuildID.empty())
+    return true;
+
+  // A debuginfod lookup could succeed if a HTTP client is available and at
+  // least one backing URL is configured.
+  if (HTTPClient::isAvailable() &&
+      !ExitOnErr(getDefaultDebuginfodUrls()).empty())
+    return true;
+
+  // A debuginfod lookup could also succeed if something were present in the
+  // cache directory, but it would be surprising to enable debuginfod on this
+  // basis alone. To use existing caches in an "offline" fashion, the debuginfod
+  // flag must be set.
+  return false;
+}
+
 int main(int argc, char **argv) {
   InitLLVM X(argc, argv);
   sys::InitializeCOMRAII COM(sys::COMThreadingMode::MultiThreaded);
@@ -371,10 +393,13 @@ int main(int argc, char **argv) {
 
   LLVMSymbolizer Symbolizer(Opts);
 
-  // Look up symbols using the debuginfod client.
-  Symbolizer.addDIFetcher(std::make_unique<DebuginfodDIFetcher>());
-  // The HTTPClient must be initialized for use by the debuginfod client.
-  HTTPClient::initialize();
+  if (Args.hasFlag(OPT_debuginfod, OPT_no_debuginfod,
+                   shouldUseDebuginfodByDefault(BuildID))) {
+    // Look up symbols using the debuginfod client.
+    Symbolizer.addDIFetcher(std::make_unique<DebuginfodDIFetcher>());
+    // The HTTPClient must be initialized for use by the debuginfod client.
+    HTTPClient::initialize();
+  }
 
   std::unique_ptr<DIPrinter> Printer;
   if (Style == OutputStyle::GNU)


        


More information about the llvm-commits mailing list