Index: llvm/lib/DebugInfo/Symbolize/CMakeLists.txt =================================================================== --- llvm/lib/DebugInfo/Symbolize/CMakeLists.txt +++ llvm/lib/DebugInfo/Symbolize/CMakeLists.txt @@ -9,6 +9,7 @@ LINK_COMPONENTS DebugInfoDWARF DebugInfoPDB + Debuginfod Object Support Demangle Index: llvm/lib/DebugInfo/Symbolize/Symbolize.cpp =================================================================== --- llvm/lib/DebugInfo/Symbolize/Symbolize.cpp +++ llvm/lib/DebugInfo/Symbolize/Symbolize.cpp @@ -20,6 +20,7 @@ #include "llvm/DebugInfo/DWARF/DWARFContext.h" #include "llvm/DebugInfo/PDB/PDB.h" #include "llvm/DebugInfo/PDB/PDBContext.h" +#include "llvm/Debuginfod/Debuginfod.h" #include "llvm/Demangle/Demangle.h" #include "llvm/Object/COFF.h" #include "llvm/Object/MachO.h" @@ -384,7 +385,14 @@ } } } - return false; + // Try debuginfod client cache and known servers. + Expected PathOrErr = getCachedOrDownloadDebuginfo(BuildID); + if (!PathOrErr) { + consumeError(PathOrErr.takeError()); + return false; + } + Result = *PathOrErr; + return true; } } // end anonymous namespace Index: llvm/test/lit.cfg.py =================================================================== --- llvm/test/lit.cfg.py +++ llvm/test/lit.cfg.py @@ -394,6 +394,9 @@ if config.have_libxml2: config.available_features.add('libxml2') +if config.have_curl: + config.available_features.add('curl') + if config.have_opt_viewer_modules: config.available_features.add('have_opt_viewer_modules') Index: llvm/test/lit.site.cfg.py.in =================================================================== --- llvm/test/lit.site.cfg.py.in +++ llvm/test/lit.site.cfg.py.in @@ -39,6 +39,7 @@ config.have_zlib = @LLVM_ENABLE_ZLIB@ config.have_libxar = @LLVM_HAVE_LIBXAR@ config.have_libxml2 = @LLVM_ENABLE_LIBXML2@ +config.have_curl = @LLVM_ENABLE_CURL@ config.have_dia_sdk = @LLVM_ENABLE_DIA_SDK@ config.enable_ffi = @LLVM_ENABLE_FFI@ config.build_examples = @LLVM_BUILD_EXAMPLES@ Index: llvm/test/tools/llvm-symbolizer/debuginfod.py =================================================================== --- /dev/null +++ llvm/test/tools/llvm-symbolizer/debuginfod.py @@ -0,0 +1,58 @@ +# REQUIRES: curl +## Uses source from split-debug.test +# RUN: rm -rf %t && mkdir %t +# RUN: llvm-objcopy --strip-debug %p/Inputs/addr.exe %t/addr.exe +# RUN: mkdir -p %t/buildid/127da749021c1fc1a58cba734a1f542cbe2b7ce4/ +# RUN: llvm-objcopy --keep-section=.debug_info %p/Inputs/addr.exe \ +# RUN: %t/buildid/127da749021c1fc1a58cba734a1f542cbe2b7ce4/debuginfo +# RUN: python %S/debuginfod.py %t %t 'llvm-symbolizer --print-address \ +# RUN: --obj=%t/addr.exe 0x40054d' | FileCheck %s + +# CHECK: 0x40054d +# CHECK: {{[/\]+}}tmp{{[/\]+}}x.c:14:0 + + +import threading +import http.server +import functools +import subprocess +import os + + +# Serves files at the serve_path, then runs the tool with specified args. +# Sets the DEBUGINFOD_CACHE_PATH env var to point at given cache_directory. +# Sets the DEBUGINFOD_URLS env var to point at the local server. +def test_tool(serve_path, cache_directory, tool_args) -> int: + httpd = http.server.ThreadingHTTPServer( + ('',0), functools.partial( + http.server.SimpleHTTPRequestHandler, + directory=serve_path)) + port = httpd.server_port + thread = threading.Thread(target=httpd.serve_forever) + try: + thread.start() + process = subprocess.Popen( + tool_args, env={**os.environ, + 'DEBUGINFOD_URLS': f'http://localhost:{port}', + 'DEBUGINFOD_CACHE_PATH': cache_directory}) + if process.wait() != 0: + print('process returned nontrivial error code') + return 1 + finally: + httpd.shutdown() + thread.join() + return 0 + +def main(): + import argparse + parser = argparse.ArgumentParser() + parser.add_argument('serve_path') + parser.add_argument('cache_directory') + parser.add_argument('tool_cmd') + args = parser.parse_args() + result = test_tool(args.serve_path, args.cache_directory, + args.tool_cmd.split()) + os._exit(result) + +if __name__ == '__main__': + main() Index: llvm/test/tools/llvm-symbolizer/lit.local.cfg =================================================================== --- /dev/null +++ llvm/test/tools/llvm-symbolizer/lit.local.cfg @@ -0,0 +1 @@ +config.suffixes.add('.py')