From: Aaron Merey <amerey@redhat.com>
To: "Frank Ch. Eigler" <fche@redhat.com>
Cc: Simon Marchi <simark@simark.ca>, Tom Tromey <tom@tromey.com>,
Christian Biesinger via gdb-patches <gdb-patches@sourceware.org>,
Christian Biesinger <cbiesinger@google.com>
Subject: Re: [RFC PATCH] Support debuginfo and source file fetching via debuginfo server
Date: Tue, 05 Nov 2019 01:59:00 -0000 [thread overview]
Message-ID: <CAJDtP-S6DpxEGG=T01h5_O8nbYYme1+ErJhcfJEomHBm2OObKQ@mail.gmail.com> (raw)
In-Reply-To: <20191104162616.GA13319@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 744 bytes --]
On Mon, Nov 4, 2019 at 11:26 AM Frank Ch. Eigler <fche@redhat.com> wrote:
>
> Hi -
>
> > I haven't followed this thread closely, so it might be an obvious "no", but
> > I was wondering if the library could offer to install a callback that is call
> > relatively often, allowing GDB to interrupt the operation [...]
>
> That could also work, at the cost of extending the API. Will play with it.
>
> - FChE
Attached is the updated debuginfo and source lookup code, using the
callback idea that Simon suggested. Downloads are now cancelled upon
SIGINT and the callback can be modified with code that prints progress
messages (the a and b parameters in the callback represent the
numerator and denominator of the download's completion fraction).
[-- Attachment #2: debuginfo_and_source_lookups.patch --]
[-- Type: text/x-patch, Size: 3913 bytes --]
gdb/elfread.c | 36 +++++++++++++++++++++++++++++++++++-
gdb/source.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 82 insertions(+), 1 deletion(-)
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 226e3f09d3..e24bca610f 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -48,7 +48,11 @@
#include "auxv.h"
#include "mdebugread.h"
#include "ctfread.h"
+#include "gdbsupport/scoped_fd.h"
#include "gdbsupport/gdb_string_view.h"
+#if HAVE_LIBDEBUGINFOD
+#include <elfutils/debuginfod.h>
+#endif
/* Forward declarations. */
extern const struct sym_fns elf_sym_fns_gdb_index;
@@ -1311,8 +1315,38 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
symbol_file_add_separate (debug_bfd.get (), debugfile.c_str (),
symfile_flags, objfile);
}
- else
+ else
+ {
has_dwarf2 = false;
+
+#if HAVE_LIBDEBUGINFOD
+ const struct bfd_build_id *build_id;
+ char *symfile_path;
+
+ build_id = build_id_bfd_get (objfile->obfd);
+
+ /* Allow debuginfod to abort the download if SIGINT is raised. */
+ debuginfod_set_progressfn (
+ [] (long a, long b) { return 1 ? check_quit_flag () : 0; }
+ );
+
+ /* Query debuginfod servers for symfile. */
+ scoped_fd fd (debuginfod_find_debuginfo (build_id->data,
+ build_id->size,
+ &symfile_path));
+
+ if (fd.get () >= 0)
+ {
+ /* file successfully retrieved from server. */
+ gdb_bfd_ref_ptr debug_bfd (symfile_bfd_open (symfile_path));
+
+ symbol_file_add_separate (debug_bfd.get (), symfile_path,
+ symfile_flags, objfile);
+ xfree (symfile_path);
+ has_dwarf2 = true;
+ }
+#endif /* LIBDEBUGINFOD */
+ }
}
/* Read the CTF section only if there is no DWARF info. */
diff --git a/gdb/source.c b/gdb/source.c
index 9f53d654f3..4e8a6558b7 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -30,6 +30,10 @@
#include <sys/types.h>
#include <fcntl.h>
+#include "build-id.h"
+#ifdef HAVE_LIBDEBUGINFOD
+#include <elfutils/debuginfod.h>
+#endif
#include "gdbcore.h"
#include "gdb_regex.h"
#include "symfile.h"
@@ -1127,6 +1131,49 @@ open_source_file (struct symtab *s)
s->fullname = NULL;
scoped_fd fd = find_and_open_source (s->filename, SYMTAB_DIRNAME (s),
&fullname);
+
+#if HAVE_LIBDEBUGINFOD
+ if (fd.get () < 0 && SYMTAB_COMPUNIT (s) != NULL)
+ {
+ const struct bfd_build_id *build_id;
+ const objfile *ofp = COMPUNIT_OBJFILE (SYMTAB_COMPUNIT (s));
+
+ std::string srcpath;
+ if (IS_DIR_SEPARATOR (s->filename[0]))
+ srcpath = s->filename;
+ else
+ {
+ srcpath = SYMTAB_DIRNAME (s);
+ srcpath += SLASH_STRING;
+ srcpath += s->filename;
+ }
+
+ build_id = build_id_bfd_get (ofp->obfd);
+
+ /* Query debuginfod for the source file. */
+ if (build_id != NULL)
+ {
+ char *name_in_cache;
+
+ /* Allow debuginfod to abort the download if SIGINT is raised. */
+ debuginfod_set_progressfn (
+ [] (long a, long b) { return 1 ? check_quit_flag () : 0; }
+ );
+
+ scoped_fd src_fd (debuginfod_find_source (build_id->data,
+ build_id->size,
+ srcpath.c_str (),
+ &name_in_cache));
+
+ if (src_fd.get () >= 0)
+ fullname.reset (name_in_cache);
+
+ s->fullname = fullname.release ();
+ return src_fd;
+ }
+ }
+#endif /* HAVE_LIBDEBUGINFOD */
+
s->fullname = fullname.release ();
return fd;
}
next prev parent reply other threads:[~2019-11-05 1:59 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-20 20:28 Aaron Merey
2019-09-13 21:03 ` Tom Tromey
2019-09-22 3:53 ` Christian Biesinger via gdb-patches
2019-10-09 14:55 ` Tom Tromey
2019-10-28 20:34 ` Aaron Merey
2019-11-01 19:31 ` Tom Tromey
2019-11-01 21:03 ` Aaron Merey
2019-11-02 14:05 ` Frank Ch. Eigler
2019-11-04 15:03 ` Frank Ch. Eigler
2019-11-04 15:46 ` Simon Marchi
2019-11-04 16:26 ` Frank Ch. Eigler
2019-11-05 1:59 ` Aaron Merey [this message]
2019-11-05 5:27 ` Simon Marchi
2019-11-05 10:25 ` Frank Ch. Eigler
2019-11-05 15:19 ` Simon Marchi
2019-11-05 15:50 ` Frank Ch. Eigler
2019-11-05 5:35 ` Simon Marchi
2019-11-07 23:24 ` Aaron Merey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAJDtP-S6DpxEGG=T01h5_O8nbYYme1+ErJhcfJEomHBm2OObKQ@mail.gmail.com' \
--to=amerey@redhat.com \
--cc=cbiesinger@google.com \
--cc=fche@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=simark@simark.ca \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox