]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use unique_xmalloc_ptr instead of char *
authorAaron Merey <amerey@redhat.com>
Mon, 10 Feb 2020 21:34:33 +0000 (16:34 -0500)
committerAaron Merey <amerey@redhat.com>
Mon, 10 Feb 2020 21:34:33 +0000 (16:34 -0500)
gdb/debuginfod-support.c
gdb/debuginfod-support.h
gdb/dwarf2read.c
gdb/elfread.c
gdb/source.c

index 04b55ca1d50a00998bab6491f27f6abda3eecffb..09704ca712bf1ab3a4cf21c04da3751fda3a2ca6 100644 (file)
@@ -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<char> *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<char> *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<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;
 }
@@ -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<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;
 }
index e3fdeb4526e8236fd60a497a2a682110255c6954..c5e7b6572147216ddee26e787cae3a84889db35a 100644 (file)
 #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 */
index 4121789571f0cb37708922eb739515947c6c5748..50224dabdadb17f59a010d400f9a5d713c9c19df 100644 (file)
@@ -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<char> 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"),
index 84496258df12efe5373eaf797b76e0adab0e0c34..90be5b10fb759010f0d728add78ce4d8d34a224d 100644 (file)
@@ -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<char> 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 */
         }
     }
 
index 0513ce6655a8bd441dae04b673bb345f36e26744..f4036a3bc1421b1b9321e96152acf038cf496cf9 100644 (file)
@@ -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;