diff options
author | Aaron Merey <amerey@redhat.com> | 2020-02-26 17:40:49 -0500 |
---|---|---|
committer | Aaron Merey <amerey@redhat.com> | 2020-02-26 17:40:49 -0500 |
commit | 0d79cdc494d5eb9db26a602d62c92d49f83f407e (patch) | |
tree | c30e35ac87c7ee38f63fe479af9e6940cad8574e /gdb/source.c | |
parent | b65ce565416b950d8730b34106c54779c48efd29 (diff) | |
download | gdb-0d79cdc494d5eb9db26a602d62c92d49f83f407e.zip gdb-0d79cdc494d5eb9db26a602d62c92d49f83f407e.tar.gz gdb-0d79cdc494d5eb9db26a602d62c92d49f83f407e.tar.bz2 |
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 <amerey@redhat.com>
* 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 <amerey@redhat.com>
* gdb.debuginfod: New directory for debuginfod tests.
* gdb.debuginfod/main.c: New test file.
* gdb.debuginfod/fetch_src_and_symbols.exp: New tests.
Diffstat (limited to 'gdb/source.c')
-rw-r--r-- | gdb/source.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/gdb/source.c b/gdb/source.c index 4f889e4..051caf5 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -48,6 +48,8 @@ #include "source-cache.h" #include "cli/cli-style.h" #include "observable.h" +#include "build-id.h" +#include "debuginfod-support.h" #define OPEN_MODE (O_RDONLY | O_BINARY) #define FDOPEN_MODE FOPEN_RB @@ -1148,6 +1150,34 @@ open_source_file (struct symtab *s) s->fullname = NULL; scoped_fd fd = find_and_open_source (s->filename, SYMTAB_DIRNAME (s), &fullname); + + if (fd.get () < 0) + { + if (SYMTAB_COMPUNIT (s) != nullptr) + { + const objfile *ofp = COMPUNIT_OBJFILE (SYMTAB_COMPUNIT (s)); + + std::string srcpath; + if (IS_ABSOLUTE_PATH (s->filename)) + srcpath = s->filename; + else + { + srcpath = SYMTAB_DIRNAME (s); + srcpath += SLASH_STRING; + srcpath += s->filename; + } + + const struct bfd_build_id *build_id = build_id_bfd_get (ofp->obfd); + + /* Query debuginfod for the source file. */ + if (build_id != nullptr) + fd = debuginfod_source_query (build_id->data, + build_id->size, + srcpath.c_str (), + &fullname); + } + } + s->fullname = fullname.release (); return fd; } |