From: Aaron Merey Date: Fri, 21 Feb 2020 00:16:45 +0000 (-0500) Subject: Add progressfn help messages X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1cbbbf89e103483b16e57ac63e94d38e9644abf7;p=thirdparty%2Fbinutils-gdb.git Add progressfn help messages --- diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c index 09704ca712b..2c2e7b717ea 100644 --- a/gdb/debuginfod-support.c +++ b/gdb/debuginfod-support.c @@ -18,40 +18,43 @@ #include #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 *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 *filename __attribute__((unused))) { - return -ENOSYS; + return scoped_fd (-ENOSYS); } #else #include 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 *filename) + gdb::unique_xmalloc_ptr *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 *filename) + const char *filename, + gdb::unique_xmalloc_ptr *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; } diff --git a/gdb/debuginfod-support.h b/gdb/debuginfod-support.h index c5e7b657214..b08dd000bfd 100644 --- a/gdb/debuginfod-support.h +++ b/gdb/debuginfod-support.h @@ -35,10 +35,11 @@ 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 *filename); +extern scoped_fd +debuginfod_source_query (const unsigned char *build_id, + int build_id_len, + const char *src_path, + gdb::unique_xmalloc_ptr *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 *filename); +extern scoped_fd +debuginfod_debuginfo_query (const unsigned char *build_id, + int build_id_len, + const char *filename, + gdb::unique_xmalloc_ptr *destname); + #endif /* DEBUGINFOD_SUPPORT_H */ diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 50224dabdad..51526bc16de 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -2750,8 +2750,11 @@ dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile) 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) diff --git a/gdb/elfread.c b/gdb/elfread.c index 90be5b10fb7..58e259983b0 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -1328,6 +1328,7 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) gdb::unique_xmalloc_ptr 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; + } } } } diff --git a/gdb/source.c b/gdb/source.c index f4036a3bc14..77a8f42a820 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -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); } } diff --git a/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp b/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp index 482447b5ea7..0b1fac210d1 100644 --- a/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp +++ b/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp @@ -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\.\.\.*"