debuginfod_source_query (const unsigned char *build_id __attribute__((unused)),
int build_id_len __attribute__((unused)),
const char *srcpath __attribute__((unused)),
- char **filename __attribute__((unused)))
+ gdb::unique_xmalloc_ptr<char> *filename __attribute__((unused)))
{
return -ENOSYS;
}
int
debuginfod_debuginfo_query (const unsigned char *build_id __attribute__((unused)),
int build_id_len __attribute__((unused)),
- char **filename __attribute__((unused)))
+ gdb::unique_xmalloc_ptr<char> *filename __attribute__((unused)))
{
return -ENOSYS;
}
long a __attribute__((unused)),
long b __attribute__((unused)))
{
- return check_quit_flag ();
+ int quit_flag = check_quit_flag ();
+
+ /* Avoid swallowing quit_flag's current value. */
+ if (quit_flag)
+ set_quit_flag ();
+
+ return quit_flag;
}
static debuginfod_client *
debuginfod_source_query (const unsigned char *build_id,
int build_id_len,
const char *srcpath,
- char **filename)
+ gdb::unique_xmalloc_ptr<char> *filename)
{
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,
- filename);
+ &fname);
debuginfod_end (c);
+ filename->reset (fname);
return fd;
}
int
debuginfod_debuginfo_query (const unsigned char *build_id,
int build_id_len,
- char **filename)
+ gdb::unique_xmalloc_ptr<char> *filename)
{
debuginfod_client *c = debuginfod_init ();
if (c == nullptr)
return -ENOMEM;
- int fd = debuginfod_find_debuginfo (c, build_id, build_id_len, filename);
+ char *fname = NULL;
+ int fd = debuginfod_find_debuginfo (c, build_id, build_id_len, &fname);
debuginfod_end (c);
+ filename->reset (fname);
return fd;
}
#define DEBUGINFOD_SUPPORT_H
/* Query debuginfod servers for a source file associated with an
- an executable with build_id. src_path should be the source
- file's absolute path that includes the compilation directory of
- the CU associated with the source file. If the file is
- successfully retrieved, its path on the local machine is stored
- at filename. The caller should free() this value. If GDB is not
- built with debuginfod, this function returns -ENOSYS. */
+ executable with BUILD_ID. BUILD_ID can be given as a binary blob or
+ a null-terminated string. If given as a binary blob, BUILD_ID_LEN
+ should be the number of bytes. If given as a null-terminated string,
+ BUILD_ID_LEN should be 0.
+
+ SRC_PATH should be the source file's absolute path that includes the
+ compilation directory of the CU associated with the source file.
+ For example if a CU's compilation directory is `/my/build` and the
+ source file path is `/my/source/foo.c`, then SRC_PATH should be
+ `/my/build/../source/foo.c`.
+
+ If the file is successfully retrieved, its path on the local machine
+ 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,
- char **filename);
+ gdb::unique_xmalloc_ptr<char> *filename);
+
+/* Query debuginfod servers for a debuginfo file with BUILD_ID.
+ BUILD_ID can be given as a binary blob or a null-terminated string.
+ If given as a binary blob, BUILD_ID_LEN should be the number of bytes.
+ If given as a null-terminated string, BUILD_ID_LEN should be 0.
-/* Query debuginfod servers for a debuginfo file with build_id. If the
- file is successfully retrieved, its path on the local machine is
- stored at filename. The caller should free() this value. If GDB
- is not built with debuginfod, this function returns -ENOSYS. */
+ If the file is successfully retrieved, its path on the local machine
+ 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,
- char **filename);
+ gdb::unique_xmalloc_ptr<char> *filename);
#endif /* DEBUGINFOD_SUPPORT_H */
#include "gdbsupport/selftest.h"
#include "rust-lang.h"
#include "gdbsupport/pathstuff.h"
-#if HAVE_LIBDEBUGINFOD
#include "debuginfod-support.h"
-#endif
/* When == 1, print basic high level tracing messages.
When > 1, be more verbose.
if (dwz_bfd == NULL)
dwz_bfd = build_id_to_debug_bfd (buildid_len, buildid);
-#if HAVE_LIBDEBUGINFOD
if (dwz_bfd == nullptr)
{
- char *alt_filename;
+ gdb::unique_xmalloc_ptr<char> alt_filename;
scoped_fd fd (debuginfod_debuginfo_query (buildid,
buildid_len,
&alt_filename));
if (fd.get () >= 0)
{
/* File successfully retrieved from server. */
- dwz_bfd = gdb_bfd_open (alt_filename, gnutarget, -1);
+ dwz_bfd = gdb_bfd_open (alt_filename.get (), gnutarget, -1);
if (dwz_bfd != nullptr
&& !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"),
#include "ctfread.h"
#include "gdbsupport/gdb_string_view.h"
#include "gdbsupport/scoped_fd.h"
-#if HAVE_LIBDEBUGINFOD
#include "debuginfod-support.h"
-#endif
/* Forward declarations. */
extern const struct sym_fns elf_sym_fns_gdb_index;
else
{
has_dwarf2 = false;
-
-#if HAVE_LIBDEBUGINFOD
const struct bfd_build_id *build_id = build_id_bfd_get (objfile->obfd);
if (build_id != nullptr)
{
- char *symfile_path;
+ gdb::unique_xmalloc_ptr<char> symfile_path;
scoped_fd fd (debuginfod_debuginfo_query (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));
+ gdb_bfd_ref_ptr debug_bfd (symfile_bfd_open (symfile_path.get ()));
- symbol_file_add_separate (debug_bfd.get (), symfile_path,
+ symbol_file_add_separate (debug_bfd.get (), symfile_path.get (),
symfile_flags, objfile);
- xfree (symfile_path);
has_dwarf2 = true;
}
}
-#endif /* HAVE_LIBDEBUGINFOD */
}
}
#include "cli/cli-style.h"
#include "observable.h"
#include "build-id.h"
-#ifdef HAVE_LIBDEBUGINFOD
#include "debuginfod-support.h"
-#endif
#define OPEN_MODE (O_RDONLY | O_BINARY)
#define FDOPEN_MODE FOPEN_RB
scoped_fd fd = find_and_open_source (s->filename, SYMTAB_DIRNAME (s),
&fullname);
-#if HAVE_LIBDEBUGINFOD
if (fd.get () < 0)
{
if (SYMTAB_COMPUNIT (s) != nullptr)
if (build_id != nullptr)
{
/* Query debuginfod for the source file. */
- char *filename;
scoped_fd src_fd (debuginfod_source_query (build_id->data,
build_id->size,
srcpath.c_str (),
- &filename));
-
- if (src_fd.get () >= 0)
- fullname.reset (filename);
+ &fullname));
s->fullname = fullname.release ();
return src_fd;
-
}
}
}
-#endif /* HAVE_LIBDEBUGINFOD */
s->fullname = fullname.release ();
return fd;