From: Aaron Merey Date: Mon, 10 Feb 2020 21:34:33 +0000 (-0500) Subject: Use unique_xmalloc_ptr instead of char * X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4aac9827d78d3237e86861af652c0408c3ce8741;p=thirdparty%2Fbinutils-gdb.git Use unique_xmalloc_ptr instead of char * --- diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c index 04b55ca1d50..09704ca712b 100644 --- a/gdb/debuginfod-support.c +++ b/gdb/debuginfod-support.c @@ -25,7 +25,7 @@ int 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 *filename __attribute__((unused))) { return -ENOSYS; } @@ -33,7 +33,7 @@ debuginfod_source_query (const unsigned char *build_id __attribute__((unused)), 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 *filename __attribute__((unused))) { return -ENOSYS; } @@ -45,7 +45,13 @@ progressfn (debuginfod_client *c, 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 * @@ -65,19 +71,21 @@ int debuginfod_source_query (const unsigned char *build_id, int build_id_len, const char *srcpath, - char **filename) + gdb::unique_xmalloc_ptr *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; } @@ -87,15 +95,17 @@ debuginfod_source_query (const unsigned char *build_id, int debuginfod_debuginfo_query (const unsigned char *build_id, int build_id_len, - char **filename) + gdb::unique_xmalloc_ptr *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; } diff --git a/gdb/debuginfod-support.h b/gdb/debuginfod-support.h index e3fdeb4526e..c5e7b657214 100644 --- a/gdb/debuginfod-support.h +++ b/gdb/debuginfod-support.h @@ -20,24 +20,36 @@ #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 *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 *filename); #endif /* DEBUGINFOD_SUPPORT_H */ diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 4121789571f..50224dabdad 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -77,9 +77,7 @@ #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. @@ -2749,10 +2747,9 @@ 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 == nullptr) { - char *alt_filename; + gdb::unique_xmalloc_ptr alt_filename; scoped_fd fd (debuginfod_debuginfo_query (buildid, buildid_len, &alt_filename)); @@ -2760,16 +2757,13 @@ dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile) 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"), diff --git a/gdb/elfread.c b/gdb/elfread.c index 84496258df1..90be5b10fb7 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -50,9 +50,7 @@ #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; @@ -1323,13 +1321,11 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) 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 symfile_path; scoped_fd fd (debuginfod_debuginfo_query (build_id->data, build_id->size, &symfile_path)); @@ -1337,15 +1333,13 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) 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 */ } } diff --git a/gdb/source.c b/gdb/source.c index 0513ce6655a..f4036a3bc14 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -49,9 +49,7 @@ #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 @@ -1158,7 +1156,6 @@ open_source_file (struct symtab *s) 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) @@ -1180,22 +1177,16 @@ open_source_file (struct symtab *s) 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;