diff mbox

[RFC] Support debuginfo and source file fetching via debuginfo server

Message ID CAJDtP-Q9gET5cn-qphbkgT0MsPx-a1mDGA6HxTzScUtGDC3Vsg@mail.gmail.com
State New
Headers show

Commit Message

Aaron Merey Nov. 7, 2019, 11:24 p.m. UTC
Here's a patch that adds debuginfod queries for dwz files when they
otherwise cannot be found. It's very similar to the normal debuginfo
lookup code. With this libdebuginfod now hooks into three functions
in gdb: dwarf2_get_dwz_file, open_source_file and elf_symfile_read.
Does anyone know of any code paths that gdb might take when
searching for dwz, source files, or separate DWARF debuginfo that
bypass all of the current libdebuginfod calls?

Aaron
diff mbox

Patch

---
 gdb/dwarf2read.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 0a7a033420..d0cc5f327b 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -77,6 +77,9 @@ 
 #include "gdbsupport/selftest.h"
 #include "rust-lang.h"
 #include "gdbsupport/pathstuff.h"
+#if HAVE_LIBDEBUGINFOD
+#include "elfutils/debuginfod.h"
+#endif
 
 /* When == 1, print basic high level tracing messages.
    When > 1, be more verbose.
@@ -2714,6 +2717,38 @@  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 HAVE_LIBDEBUGINFOD
+  if (dwz_bfd == NULL)
+    {
+      /* Query debuginfod servers for the dwz file.  */
+      char *alt_filename;
+
+      /* 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 (buildid,
+                                               buildid_len,
+                                               &alt_filename));
+
+      if (fd.get () >= 0)
+        {
+          /* File successfully retrieved from server.  */
+          dwz_bfd = gdb_bfd_open (alt_filename, gnutarget, -1);
+
+          if(dwz_bfd != NULL)
+            {
+              if (!build_id_verify (dwz_bfd.get (), buildid_len, buildid))
+                dwz_bfd.reset (nullptr);
+            }
+
+          xfree (alt_filename);
+        }
+    }
+#endif /* HAVE_LIBDEBUGINFOD */
+
   if (dwz_bfd == NULL)
     error (_("could not find '.gnu_debugaltlink' file for %s"),
 	   objfile_name (dwarf2_per_objfile->objfile));
-- 
2.21.0