#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 *
/* 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;
}
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.
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 */
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)
/* 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;
+ }
}
}
}