From 0d79cdc494d5eb9db26a602d62c92d49f83f407e Mon Sep 17 00:00:00 2001 From: Aaron Merey Date: Wed, 26 Feb 2020 17:40:49 -0500 Subject: Add debuginfod support to GDB debuginfod is a lightweight web service that indexes ELF/DWARF debugging resources by build-id and serves them over HTTP. This patch enables GDB to query debuginfod servers for separate debug files and source code when it is otherwise not able to find them. GDB can be built with debuginfod using the --with-debuginfod configure option. This requires that libdebuginfod be installed and found at configure time. debuginfod is packaged with elfutils, starting with version 0.178. For more information see https://sourceware.org/elfutils/. Tested on x86_64 Fedora 31. gdb/ChangeLog: 2020-02-26 Aaron Merey * Makefile.in: Handle optional debuginfod support. * NEWS: Update. * README: Add --with-debuginfod summary. * config.in: Regenerate. * configure: Regenerate. * configure.ac: Handle optional debuginfod support. * debuginfod-support.c: debuginfod helper functions. * debuginfod-support.h: Ditto. * doc/gdb.texinfo: Add --with-debuginfod to configure options summary. * dwarf2/read.c (dwarf2_get_dwz_file): Query debuginfod servers when a dwz file cannot be found. * elfread.c (elf_symfile_read): Query debuginfod servers when a debuginfo file cannot be found. * source.c (open_source_file): Query debuginfod servers when a source file cannot be found. * top.c (print_gdb_configuration): Include --{with,without}-debuginfod in the output. gdb/testsuite/ChangeLog: 2020-02-26 Aaron Merey * gdb.debuginfod: New directory for debuginfod tests. * gdb.debuginfod/main.c: New test file. * gdb.debuginfod/fetch_src_and_symbols.exp: New tests. --- gdb/dwarf2/read.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'gdb/dwarf2') diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 6849644..d6b34d8 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -83,6 +83,7 @@ #include "rust-lang.h" #include "gdbsupport/pathstuff.h" #include "count-one-bits.h" +#include "debuginfod-support.h" /* When == 1, print basic high level tracing messages. When > 1, be more verbose. @@ -2147,6 +2148,29 @@ dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile) if (dwz_bfd == NULL) dwz_bfd = build_id_to_debug_bfd (buildid_len, buildid); + if (dwz_bfd == nullptr) + { + gdb::unique_xmalloc_ptr alt_filename; + const char *origname = dwarf2_per_objfile->objfile->original_name; + + scoped_fd fd (debuginfod_debuginfo_query (buildid, + buildid_len, + origname, + &alt_filename)); + + if (fd.get () >= 0) + { + /* File successfully retrieved from server. */ + dwz_bfd = gdb_bfd_open (alt_filename.get (), gnutarget, -1); + + if (dwz_bfd == nullptr) + warning (_("File \"%s\" from debuginfod cannot be opened as bfd"), + alt_filename.get ()); + else if (!build_id_verify (dwz_bfd.get (), buildid_len, buildid)) + dwz_bfd.reset (nullptr); + } + } + if (dwz_bfd == NULL) error (_("could not find '.gnu_debugaltlink' file for %s"), objfile_name (dwarf2_per_objfile->objfile)); -- cgit v1.1