]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add progressfn help messages
authorAaron Merey <amerey@redhat.com>
Fri, 21 Feb 2020 00:16:45 +0000 (19:16 -0500)
committerAaron Merey <amerey@redhat.com>
Fri, 21 Feb 2020 00:16:45 +0000 (19:16 -0500)
gdb/debuginfod-support.c
gdb/debuginfod-support.h
gdb/dwarf2read.c
gdb/elfread.c
gdb/source.c
gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp

index 09704ca712bf1ab3a4cf21c04da3751fda3a2ca6..2c2e7b717ea02ab5f43d48333233fe8180d8cd24 100644 (file)
 
 #include <errno.h>
 #include "defs.h"
+#include "gdbsupport/scoped_fd.h"
 #include "debuginfod-support.h"
 
 #ifndef HAVE_LIBDEBUGINFOD
-int
+scoped_fd
 debuginfod_source_query (const unsigned char *build_id __attribute__((unused)),
                          int build_id_len __attribute__((unused)),
                          const char *srcpath __attribute__((unused)),
                          gdb::unique_xmalloc_ptr<char> *filename __attribute__((unused)))
 {
-  return -ENOSYS;
+  return scoped_fd (-ENOSYS);
 }
 
-int
+scoped_fd
 debuginfod_debuginfo_query (const unsigned char *build_id __attribute__((unused)),
                             int build_id_len __attribute__((unused)),
                             gdb::unique_xmalloc_ptr<char> *filename __attribute__((unused)))
 {
-  return -ENOSYS;
+  return scoped_fd (-ENOSYS);
 }
 #else
 #include <elfutils/debuginfod.h>
 
 static int
-progressfn (debuginfod_client *c,
-             long a __attribute__((unused)),
-             long b __attribute__((unused)))
+progressfn (debuginfod_client *c, long cur, long total)
 {
-  int quit_flag = check_quit_flag ();
-
-  /* Avoid swallowing quit_flag's current value.  */
-  if (quit_flag)
-    set_quit_flag ();
-
-  return quit_flag;
+  if (check_quit_flag ())
+    {
+      printf_unfiltered ("Cancelling download...\n");
+      return 1;
+    }
+
+  printf_unfiltered ("Downloading... %.0f%% (%ld/%ld)%s",
+                     (cur * 100.0f) / total,
+                     cur, total,
+                     (cur == total) ? "\n" : "\r");
+  return 0;
 }
 
 static debuginfod_client *
@@ -67,45 +70,65 @@ debuginfod_init ()
 
 /* See debuginfod-support.h  */
 
-int
+scoped_fd
 debuginfod_source_query (const unsigned char *build_id,
                          int build_id_len,
                          const char *srcpath,
-                         gdb::unique_xmalloc_ptr<char> *filename)
+                         gdb::unique_xmalloc_ptr<char> *destname)
 {
   debuginfod_client *c = debuginfod_init ();
 
   if (c == nullptr)
-    return -ENOMEM;
-
-  char *fname = NULL;
-  int fd = debuginfod_find_source (c,
-                                   build_id,
-                                   build_id_len,
-                                   srcpath,
-                                   &fname);
+    return scoped_fd (-ENOMEM);
+
+  char *dname = nullptr;
+
+  printf_unfiltered ("Attempting to download source file %s\n", srcpath);
+  scoped_fd fd (debuginfod_find_source (c,
+                                        build_id,
+                                        build_id_len,
+                                        srcpath,
+                                        &dname));
+
+  if (fd.get () < 0)
+    printf_unfiltered ("Download unsuccessful. Continuing without source file %s.\n",
+                       srcpath);
+  else
+    printf_unfiltered ("Download successful.\n");
+
+
+  destname->reset (dname);
   debuginfod_end (c);
-  filename->reset (fname);
 
   return fd;
 }
 
 /* See debuginfod-support.h  */
 
-int
+scoped_fd
 debuginfod_debuginfo_query (const unsigned char *build_id,
                             int build_id_len,
-                            gdb::unique_xmalloc_ptr<char> *filename)
+                            const char *filename,
+                            gdb::unique_xmalloc_ptr<char> *destname)
 {
   debuginfod_client *c = debuginfod_init ();
 
   if (c == nullptr)
-    return -ENOMEM;
+    return scoped_fd (-ENOMEM);
+
+  char *dname = nullptr;
+
+  printf_filtered ("Attempting to download debug info for %s\n", filename);
+  scoped_fd fd (debuginfod_find_debuginfo (c, build_id, build_id_len, &dname));
+
+  if (fd.get () < 0)
+    printf_unfiltered ("Download unsuccessful. Continuing without debug info for %s.\n",
+                       filename);
+  else
+    printf_unfiltered ("Download successful.\n");
 
-  char *fname = NULL;
-  int fd = debuginfod_find_debuginfo (c, build_id, build_id_len, &fname);
   debuginfod_end (c);
-  filename->reset (fname);
+  destname->reset (dname);
 
   return fd;
 }
index c5e7b6572147216ddee26e787cae3a84889db35a..b08dd000bfd3008acb5a44aae47f2bdd43e9a3bc 100644 (file)
    is stored in FILENAME. If GDB is not built with debuginfod, this
    function returns -ENOSYS.  */
 
-extern int debuginfod_source_query (const unsigned char *build_id,
-                                    int build_id_len,
-                                    const char *src_path,
-                                    gdb::unique_xmalloc_ptr<char> *filename);
+extern scoped_fd
+debuginfod_source_query (const unsigned char *build_id,
+                         int build_id_len,
+                         const char *src_path,
+                         gdb::unique_xmalloc_ptr<char> *destname);
 
 /* Query debuginfod servers for a debuginfo file with BUILD_ID.
    BUILD_ID can be given as a binary blob or a null-terminated string.
@@ -49,7 +50,10 @@ extern int debuginfod_source_query (const unsigned char *build_id,
    is stored in FILENAME. If GDB is not built with debuginfod, this
    function returns -ENOSYS.  */
 
-extern int debuginfod_debuginfo_query (const unsigned char *build_id,
-                                       int build_id_len,
-                                       gdb::unique_xmalloc_ptr<char> *filename);
+extern scoped_fd
+debuginfod_debuginfo_query (const unsigned char *build_id,
+                            int build_id_len,
+                            const char *filename,
+                            gdb::unique_xmalloc_ptr<char> *destname);
+
 #endif /* DEBUGINFOD_SUPPORT_H */
index 50224dabdadb17f59a010d400f9a5d713c9c19df..51526bc16deef73483c37d1ac970f0ef8be7a53c 100644 (file)
@@ -2750,8 +2750,11 @@ dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
   if (dwz_bfd == nullptr)
     {
       gdb::unique_xmalloc_ptr<char> 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)
index 90be5b10fb759010f0d728add78ce4d8d34a224d..58e259983b048aafe6b31bf331db78e84b3bd3c2 100644 (file)
@@ -1328,6 +1328,7 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
               gdb::unique_xmalloc_ptr<char> symfile_path;
               scoped_fd fd (debuginfod_debuginfo_query (build_id->data,
                                                         build_id->size,
+                                                        objfile->original_name,
                                                         &symfile_path));
 
               if (fd.get () >= 0)
@@ -1335,9 +1336,13 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
                   /* File successfully retrieved from server.  */
                   gdb_bfd_ref_ptr debug_bfd (symfile_bfd_open (symfile_path.get ()));
 
-                  symbol_file_add_separate (debug_bfd.get (), symfile_path.get (),
-                                            symfile_flags, objfile);
-                  has_dwarf2 = true;
+                  if (debug_bfd != nullptr
+                      && build_id_verify (debug_bfd.get (), build_id->size, build_id->data))
+                    {
+                      symbol_file_add_separate (debug_bfd.get (), symfile_path.get (),
+                                                symfile_flags, objfile);
+                      has_dwarf2 = true;
+                    }
                 }
             }
         }
index f4036a3bc1421b1b9321e96152acf038cf496cf9..77a8f42a8204d65fd744303742ca7c55d4209148 100644 (file)
@@ -1163,7 +1163,7 @@ open_source_file (struct symtab *s)
           const objfile *ofp = COMPUNIT_OBJFILE (SYMTAB_COMPUNIT (s));
 
           std::string srcpath;
-          if (IS_DIR_SEPARATOR (s->filename[0]))
+          if (IS_ABSOLUTE_PATH (s->filename))
             srcpath = s->filename;
           else
             {
@@ -1174,17 +1174,12 @@ open_source_file (struct symtab *s)
 
           const struct bfd_build_id *build_id = build_id_bfd_get (ofp->obfd);
 
+          /* Query debuginfod for the source file.  */
           if (build_id != nullptr)
-            {
-              /* Query debuginfod for the source file.  */
-              scoped_fd src_fd (debuginfod_source_query (build_id->data,
-                                                         build_id->size,
-                                                         srcpath.c_str (),
-                                                         &fullname));
-
-              s->fullname = fullname.release ();
-              return src_fd;
-            }
+            fd = debuginfod_source_query (build_id->data,
+                                          build_id->size,
+                                          srcpath.c_str (),
+                                          &fullname);
         }
     }
 
index 482447b5ea7408095d78967b847ae2fb8a124748..0b1fac210d1b7e9cb63fd1648eef0944b6ec88ee 100644 (file)
@@ -211,4 +211,4 @@ gdb_test "l" ".*This program is distributed in the hope.*"
 
 # gdb should now find the debugaltlink file
 clean_restart
-gdb_test "file ${binfile}_alt.o" ".*Reading symbols from ${binfile}_alt.o\.\.\.\[\r\n\]"
+gdb_test "file ${binfile}_alt.o" ".*Reading symbols from ${binfile}_alt.o\.\.\.*"