Make delim_string_to_char_ptr_vec return an std::vector
authorSimon Marchi <simon.marchi@polymtl.ca>
Sat, 3 Mar 2018 04:22:06 +0000 (23:22 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Sat, 3 Mar 2018 04:22:07 +0000 (23:22 -0500)
This patch makes delim_string_to_char_ptr_vec and all related functions
use std::vector of gdb::unique_xmalloc_ptr.  This allows getting rid of
make_cleanup_free_char_ptr_vec.  Returning a vector of
unique_xmalloc_ptr instead of std::string allows to minimize the impacts
on the calling code.  We can evaluate later whether we could/should
return a vector of std::strings instead.

gdb/ChangeLog:

* common/gdb_vecs.h (make_cleanup_free_char_ptr_vec): Remove.
(delim_string_to_char_ptr_vec): Return std::vector of
gdb::unique_xmalloc_ptr.
(dirnames_to_char_ptr_vec_append): Take std::vector of
gdb::unique_xmalloc_ptr.
(dirnames_to_char_ptr_vec): Return std::vector of
gdb::unique_xmalloc_ptr.
* common/gdb_vecs.c (delim_string_to_char_ptr_vec_append):
Take std::vector of gdb::unique_xmalloc_ptr, adjust the code.
(delim_string_to_char_ptr_vec): Return an std::vector of
gdb::unique_xmalloc_ptr, adjust the code.
(dirnames_to_char_ptr_vec_append): Take an std::vector of
gdb::unique_xmalloc_ptr, adjust the code.
(dirnames_to_char_ptr_vec): Return an std::vector of
gdb::unique_xmalloc_ptr, adjust the code.
* auto-load.c (auto_load_safe_path_vec): Change type to
std::vector of gdb::unique_xmalloc_ptr.
(auto_load_expand_dir_vars): Return an std::vector of
gdb::unique_xmalloc_ptr, adjust the code.
(auto_load_safe_path_vec_update): Adjust.
(filename_is_in_auto_load_safe_path_vec): Adjust.
(auto_load_objfile_script_1): Adjust.
* build-id.c (build_id_to_debug_bfd): Adjust.
* linux-thread-db.c (thread_db_load_search): Adjust.
* source.c (add_path): Adjust.
(openp): Adjust.
* symfile.c (find_separate_debug_file): Adjust.
* utils.c (do_free_char_ptr_vec): Remove.
(make_cleanup_free_char_ptr_vec): Remove.

gdb/gdbserver/ChangeLog:

* server.c (parse_debug_format_options): Adjust to
delim_string_to_char_ptr_vec changes.
* thread-db.c (thread_db_load_search): Adjust to
dirnames_to_char_ptr_vec changes.

12 files changed:
gdb/ChangeLog
gdb/auto-load.c
gdb/build-id.c
gdb/common/gdb_vecs.c
gdb/common/gdb_vecs.h
gdb/gdbserver/ChangeLog
gdb/gdbserver/server.c
gdb/gdbserver/thread-db.c
gdb/linux-thread-db.c
gdb/source.c
gdb/symfile.c
gdb/utils.c

index 8d3b633f933685ab98c918e25501558759191983..105532d7df55170e5986231f12b5d6d9364f38a8 100644 (file)
@@ -1,3 +1,35 @@
+2018-03-02  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * common/gdb_vecs.h (make_cleanup_free_char_ptr_vec): Remove.
+       (delim_string_to_char_ptr_vec): Return std::vector of
+       gdb::unique_xmalloc_ptr.
+       (dirnames_to_char_ptr_vec_append): Take std::vector of
+       gdb::unique_xmalloc_ptr.
+       (dirnames_to_char_ptr_vec): Return std::vector of
+       gdb::unique_xmalloc_ptr.
+       * common/gdb_vecs.c (delim_string_to_char_ptr_vec_append):
+       Take std::vector of gdb::unique_xmalloc_ptr, adjust the code.
+       (delim_string_to_char_ptr_vec): Return an std::vector of
+       gdb::unique_xmalloc_ptr, adjust the code.
+       (dirnames_to_char_ptr_vec_append): Take an std::vector of
+       gdb::unique_xmalloc_ptr, adjust the code.
+       (dirnames_to_char_ptr_vec): Return an std::vector of
+       gdb::unique_xmalloc_ptr, adjust the code.
+       * auto-load.c (auto_load_safe_path_vec): Change type to
+       std::vector of gdb::unique_xmalloc_ptr.
+       (auto_load_expand_dir_vars): Return an std::vector of
+       gdb::unique_xmalloc_ptr, adjust the code.
+       (auto_load_safe_path_vec_update): Adjust.
+       (filename_is_in_auto_load_safe_path_vec): Adjust.
+       (auto_load_objfile_script_1): Adjust.
+       * build-id.c (build_id_to_debug_bfd): Adjust.
+       * linux-thread-db.c (thread_db_load_search): Adjust.
+       * source.c (add_path): Adjust.
+       (openp): Adjust.
+       * symfile.c (find_separate_debug_file): Adjust.
+       * utils.c (do_free_char_ptr_vec): Remove.
+       (make_cleanup_free_char_ptr_vec): Remove.
+
 2018-03-01  Sergio Durigan Junior  <sergiodj@redhat.com>
 
        PR gdb/22907
index 9dd8754e1a4dd7f077a554ea7eb234254b5d6de7..70bddbc862bbfb75579fcd0d486bd9712445cb68 100644 (file)
@@ -169,19 +169,15 @@ static char *auto_load_safe_path;
 /* Vector of directory elements of AUTO_LOAD_SAFE_PATH with each one normalized
    by tilde_expand and possibly each entries has added its gdb_realpath
    counterpart.  */
-static VEC (char_ptr) *auto_load_safe_path_vec;
+std::vector<gdb::unique_xmalloc_ptr<char>> auto_load_safe_path_vec;
 
 /* Expand $datadir and $debugdir in STRING according to the rules of
-   substitute_path_component.  Return vector from dirnames_to_char_ptr_vec,
-   this vector must be freed by free_char_ptr_vec by the caller.  */
+   substitute_path_component.  */
 
-static VEC (char_ptr) *
+static std::vector<gdb::unique_xmalloc_ptr<char>>
 auto_load_expand_dir_vars (const char *string)
 {
-  VEC (char_ptr) *dir_vec;
-  char *s;
-
-  s = xstrdup (string);
+  char *s = xstrdup (string);
   substitute_path_component (&s, "$datadir", gdb_datadir);
   substitute_path_component (&s, "$debugdir", debug_file_directory);
 
@@ -189,7 +185,8 @@ auto_load_expand_dir_vars (const char *string)
     fprintf_unfiltered (gdb_stdlog,
                        _("auto-load: Expanded $-variables to \"%s\".\n"), s);
 
-  dir_vec = dirnames_to_char_ptr_vec (s);
+  std::vector<gdb::unique_xmalloc_ptr<char>> dir_vec
+    = dirnames_to_char_ptr_vec (s);
   xfree(s);
 
   return dir_vec;
@@ -208,46 +205,42 @@ auto_load_safe_path_vec_update (void)
                        _("auto-load: Updating directories of \"%s\".\n"),
                        auto_load_safe_path);
 
-  free_char_ptr_vec (auto_load_safe_path_vec);
-
   auto_load_safe_path_vec = auto_load_expand_dir_vars (auto_load_safe_path);
-  len = VEC_length (char_ptr, auto_load_safe_path_vec);
 
   /* Apply tilde_expand and gdb_realpath to each AUTO_LOAD_SAFE_PATH_VEC
      element.  */
-  for (ix = 0; ix < len; ix++)
+  for (gdb::unique_xmalloc_ptr<char> &in_vec : auto_load_safe_path_vec)
     {
-      char *dir = VEC_index (char_ptr, auto_load_safe_path_vec, ix);
-      char *expanded = tilde_expand (dir);
-      gdb::unique_xmalloc_ptr<char> real_path = gdb_realpath (expanded);
+      gdb::unique_xmalloc_ptr<char> expanded (tilde_expand (in_vec.get ()));
+      gdb::unique_xmalloc_ptr<char> real_path = gdb_realpath (expanded.get ());
 
-      /* Ensure the current entry is at least tilde_expand-ed.  */
-      VEC_replace (char_ptr, auto_load_safe_path_vec, ix, expanded);
+      /* Ensure the current entry is at least tilde_expand-ed.  ORIGINAL makes
+        sure we free the original string.  */
+      gdb::unique_xmalloc_ptr<char> original = std::move (in_vec);
+      in_vec = std::move (expanded);
 
       if (debug_auto_load)
        {
-         if (strcmp (expanded, dir) == 0)
+         if (strcmp (in_vec.get (), original.get ()) == 0)
            fprintf_unfiltered (gdb_stdlog,
                                _("auto-load: Using directory \"%s\".\n"),
-                               expanded);
+                               in_vec.get ());
          else
            fprintf_unfiltered (gdb_stdlog,
                                _("auto-load: Resolved directory \"%s\" "
                                  "as \"%s\".\n"),
-                               dir, expanded);
+                               original.get (), in_vec.get ());
        }
-      xfree (dir);
 
       /* If gdb_realpath returns a different content, append it.  */
-      if (strcmp (real_path.get (), expanded) != 0)
+      if (strcmp (real_path.get (), in_vec.get ()) != 0)
        {
          if (debug_auto_load)
            fprintf_unfiltered (gdb_stdlog,
                                _("auto-load: And canonicalized as \"%s\".\n"),
                                real_path.get ());
 
-         VEC_safe_push (char_ptr, auto_load_safe_path_vec,
-                        real_path.release ());
+         auto_load_safe_path_vec.push_back (std::move (real_path));
        }
     }
 }
@@ -426,13 +419,14 @@ static int
 filename_is_in_auto_load_safe_path_vec (const char *filename,
                                        gdb::unique_xmalloc_ptr<char> *filename_realp)
 {
-  char *pattern;
-  int ix;
+  const char *pattern = NULL;
 
-  for (ix = 0; VEC_iterate (char_ptr, auto_load_safe_path_vec, ix, pattern);
-       ++ix)
-    if (*filename_realp == NULL && filename_is_in_pattern (filename, pattern))
-      break;
+  for (const gdb::unique_xmalloc_ptr<char> &p : auto_load_safe_path_vec)
+    if (*filename_realp == NULL && filename_is_in_pattern (filename, p.get ()))
+      {
+       pattern = p.get ();
+       break;
+      }
   
   if (pattern == NULL)
     {
@@ -447,10 +441,12 @@ filename_is_in_auto_load_safe_path_vec (const char *filename,
        }
 
       if (strcmp (filename_realp->get (), filename) != 0)
-       for (ix = 0;
-            VEC_iterate (char_ptr, auto_load_safe_path_vec, ix, pattern); ++ix)
-         if (filename_is_in_pattern (filename_realp->get (), pattern))
-           break;
+       for (const gdb::unique_xmalloc_ptr<char> &p : auto_load_safe_path_vec)
+         if (filename_is_in_pattern (filename_realp->get (), p.get ()))
+           {
+             pattern = p.get ();
+             break;
+           }
     }
 
   if (pattern != NULL)
@@ -793,25 +789,22 @@ auto_load_objfile_script_1 (struct objfile *objfile, const char *realname,
 
   if (!input)
     {
-      VEC (char_ptr) *vec;
-      int ix;
-      char *dir;
-
       /* Also try the same file in a subdirectory of gdb's data
         directory.  */
 
-      vec = auto_load_expand_dir_vars (auto_load_dir);
-      make_cleanup_free_char_ptr_vec (vec);
+      std::vector<gdb::unique_xmalloc_ptr<char>> vec
+       = auto_load_expand_dir_vars (auto_load_dir);
 
       if (debug_auto_load)
        fprintf_unfiltered (gdb_stdlog, _("auto-load: Searching 'set auto-load "
                                          "scripts-directory' path \"%s\".\n"),
                            auto_load_dir);
 
-      for (ix = 0; VEC_iterate (char_ptr, vec, ix, dir); ++ix)
+      for (const gdb::unique_xmalloc_ptr<char> &dir : vec)
        {
-         debugfile = (char *) xmalloc (strlen (dir) + strlen (filename) + 1);
-         strcpy (debugfile, dir);
+         debugfile = (char *) xmalloc (strlen (dir.get ())
+                                       + strlen (filename) + 1);
+         strcpy (debugfile, dir.get ());
 
          /* FILENAME is absolute, so we don't need a "/" here.  */
          strcat (debugfile, filename);
index 685a2b0370cd2093e36b6511a3d5a850f1d1b118..57d98c96181f8ef3c6ad36fc0f4085ecce105eb9 100644 (file)
@@ -71,8 +71,6 @@ gdb_bfd_ref_ptr
 build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id)
 {
   char *link, *debugdir;
-  VEC (char_ptr) *debugdir_vec;
-  struct cleanup *back_to;
   int ix;
   gdb_bfd_ref_ptr abfd;
   int alloc_len;
@@ -86,17 +84,17 @@ build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id)
   /* Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will
      cause "/.build-id/..." lookups.  */
 
-  debugdir_vec = dirnames_to_char_ptr_vec (debug_file_directory);
-  back_to = make_cleanup_free_char_ptr_vec (debugdir_vec);
+  std::vector<gdb::unique_xmalloc_ptr<char>> debugdir_vec
+    = dirnames_to_char_ptr_vec (debug_file_directory);
 
-  for (ix = 0; VEC_iterate (char_ptr, debugdir_vec, ix, debugdir); ++ix)
+  for (const gdb::unique_xmalloc_ptr<char> &debugdir : debugdir_vec)
     {
-      size_t debugdir_len = strlen (debugdir);
+      size_t debugdir_len = strlen (debugdir.get ());
       const gdb_byte *data = build_id;
       size_t size = build_id_len;
       char *s;
 
-      memcpy (link, debugdir, debugdir_len);
+      memcpy (link, debugdir.get (), debugdir_len);
       s = &link[debugdir_len];
       s += sprintf (s, "/.build-id/");
       if (size > 0)
@@ -133,7 +131,6 @@ build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id)
       abfd.release ();
     }
 
-  do_cleanups (back_to);
   return abfd;
 }
 
index a2214606255251ac81866aa95fd30d57d13ecc61..a19d238b3ee1e0c53200e2490b3327a95d37b036 100644 (file)
@@ -40,11 +40,12 @@ free_char_ptr_vec (VEC (char_ptr) *char_ptr_vec)
 }
 
 /* Worker function to split character delimiter separated string of fields
-   STR into a CHAR_PTR_VEC.  */
+   STR into a char pointer vector.  */
 
 static void
-delim_string_to_char_ptr_vec_append (VEC (char_ptr) **vecp,
-                                    const char *str, char delimiter)
+delim_string_to_char_ptr_vec_append
+  (std::vector<gdb::unique_xmalloc_ptr<char>> *vecp, const char *str,
+   char delimiter)
 {
   do
     {
@@ -64,49 +65,40 @@ delim_string_to_char_ptr_vec_append (VEC (char_ptr) **vecp,
       this_field = (char *) xmalloc (this_len + 1);
       memcpy (this_field, str, this_len);
       this_field[this_len] = '\0';
-      VEC_safe_push (char_ptr, *vecp, this_field);
+      vecp->emplace_back (this_field);
 
       str = next_field;
     }
   while (str != NULL);
 }
 
-/* Split STR, a list of DELIMITER-separated fields, into a CHAR_PTR_VEC.
+/* See gdb_vecs.h.  */
 
-   You may modify the returned strings.
-   Read free_char_ptr_vec for its cleanup.  */
-
-VEC (char_ptr) *
+std::vector<gdb::unique_xmalloc_ptr<char>>
 delim_string_to_char_ptr_vec (const char *str, char delimiter)
 {
-  VEC (char_ptr) *retval = NULL;
+  std::vector<gdb::unique_xmalloc_ptr<char>> retval;
   
   delim_string_to_char_ptr_vec_append (&retval, str, delimiter);
 
   return retval;
 }
 
-/* Extended version of dirnames_to_char_ptr_vec - additionally if *VECP is
-   non-NULL the new list elements from DIRNAMES are appended to the existing
-   *VECP list of entries.  *VECP address will be updated by this call.  */
+/* See gdb_vecs.h.  */
 
 void
-dirnames_to_char_ptr_vec_append (VEC (char_ptr) **vecp, const char *dirnames)
+dirnames_to_char_ptr_vec_append
+  (std::vector<gdb::unique_xmalloc_ptr<char>> *vecp, const char *dirnames)
 {
   delim_string_to_char_ptr_vec_append (vecp, dirnames, DIRNAME_SEPARATOR);
 }
 
-/* Split DIRNAMES by DIRNAME_SEPARATOR delimiter and return a list of all the
-   elements in their original order.  For empty string ("") DIRNAMES return
-   list of one empty string ("") element.
-   
-   You may modify the returned strings.
-   Read free_char_ptr_vec for its cleanup.  */
+/* See gdb_vecs.h.  */
 
-VEC (char_ptr) *
+std::vector<gdb::unique_xmalloc_ptr<char>>
 dirnames_to_char_ptr_vec (const char *dirnames)
 {
-  VEC (char_ptr) *retval = NULL;
+  std::vector<gdb::unique_xmalloc_ptr<char>> retval;
   
   dirnames_to_char_ptr_vec_append (&retval, dirnames);
 
index 75caf59c000560aca912e4d683cebeef264ee9b0..17ed06c253123d86320344a4f8a8af5cd359fdd2 100644 (file)
@@ -31,15 +31,25 @@ DEF_VEC_P (const_char_ptr);
 
 extern void free_char_ptr_vec (VEC (char_ptr) *char_ptr_vec);
 
-extern struct cleanup *
-  make_cleanup_free_char_ptr_vec (VEC (char_ptr) *char_ptr_vec);
+/* Split STR, a list of DELIMITER-separated fields, into a char pointer vector.
 
-extern VEC (char_ptr) *delim_string_to_char_ptr_vec (const char *str,
-                                                    char delimiter);
+   You may modify the returned strings.  */
 
-extern void dirnames_to_char_ptr_vec_append (VEC (char_ptr) **vecp,
-                                            const char *dirnames);
+extern std::vector<gdb::unique_xmalloc_ptr<char>>
+  delim_string_to_char_ptr_vec (const char *str, char delimiter);
 
-extern VEC (char_ptr) *dirnames_to_char_ptr_vec (const char *dirnames);
+/* Like dirnames_to_char_ptr_vec, but append the directories to *VECP.  */
+
+extern void dirnames_to_char_ptr_vec_append
+  (std::vector<gdb::unique_xmalloc_ptr<char>> *vecp, const char *dirnames);
+
+/* Split DIRNAMES by DIRNAME_SEPARATOR delimiter and return a list of all the
+   elements in their original order.  For empty string ("") DIRNAMES return
+   list of one empty string ("") element.
+
+   You may modify the returned strings.  */
+
+extern std::vector<gdb::unique_xmalloc_ptr<char>>
+  dirnames_to_char_ptr_vec (const char *dirnames);
 
 #endif /* GDB_VECS_H */
index 703bdfb1ba70702c38c992158909a3ed3f5d9946..70a93876db34ba2be706c617f122a0ae19acea23 100644 (file)
@@ -1,3 +1,10 @@
+2018-03-02  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * server.c (parse_debug_format_options): Adjust to
+       delim_string_to_char_ptr_vec changes.
+       * thread-db.c (thread_db_load_search): Adjust to
+       dirnames_to_char_ptr_vec changes.
+
 2018-03-01  Markus Metzger  <markus.t.metzger@intel.com>
 
        * target.h (target_enable_btrace, target_disable_btrace)
index ad327be0280343841ce80c03ee15e55d3e635e30..afdd5049a771da6e41982fbd4d75dd2c400b7fd4 100644 (file)
@@ -1309,8 +1309,8 @@ handle_detach (char *own_buf)
    ARG is the text after "--debug-format=" or "monitor set debug-format".
    IS_MONITOR is non-zero if we're invoked via "monitor set debug-format".
    This triggers calls to monitor_output.
-   The result is NULL if all options were parsed ok, otherwise an error
-   message which the caller must free.
+   The result is an empty string if all options were parsed ok, otherwise an
+   error message which the caller must free.
 
    N.B. These commands affect all debug format settings, they are not
    cumulative.  If a format is not specified, it is turned off.
@@ -1325,10 +1325,6 @@ handle_detach (char *own_buf)
 static std::string
 parse_debug_format_options (const char *arg, int is_monitor)
 {
-  VEC (char_ptr) *options;
-  int ix;
-  char *option;
-
   /* First turn all debug format options off.  */
   debug_timestamp = 0;
 
@@ -1336,23 +1332,24 @@ parse_debug_format_options (const char *arg, int is_monitor)
   while (isspace (*arg))
     ++arg;
 
-  options = delim_string_to_char_ptr_vec (arg, ',');
+  std::vector<gdb::unique_xmalloc_ptr<char>> options
+    = delim_string_to_char_ptr_vec (arg, ',');
 
-  for (ix = 0; VEC_iterate (char_ptr, options, ix, option); ++ix)
+  for (const gdb::unique_xmalloc_ptr<char> &option : options)
     {
-      if (strcmp (option, "all") == 0)
+      if (strcmp (option.get (), "all") == 0)
        {
          debug_timestamp = 1;
          if (is_monitor)
            monitor_output ("All extra debug format options enabled.\n");
        }
-      else if (strcmp (option, "none") == 0)
+      else if (strcmp (option.get (), "none") == 0)
        {
          debug_timestamp = 0;
          if (is_monitor)
            monitor_output ("All extra debug format options disabled.\n");
        }
-      else if (strcmp (option, "timestamp") == 0)
+      else if (strcmp (option.get (), "timestamp") == 0)
        {
          debug_timestamp = 1;
          if (is_monitor)
@@ -1364,16 +1361,10 @@ parse_debug_format_options (const char *arg, int is_monitor)
          continue;
        }
       else
-       {
-         std::string msg
-           = string_printf ("Unknown debug-format argument: \"%s\"\n", option);
-
-         free_char_ptr_vec (options);
-         return msg;
-       }
+       return string_printf ("Unknown debug-format argument: \"%s\"\n",
+                             option.get ());
     }
 
-  free_char_ptr_vec (options);
   return std::string ();
 }
 
index 812aa0f61f1576aaa5bf822209db7efaa1ed3a28..7dda2edba0f7da18342ff7b4683487a1a0f157ce 100644 (file)
@@ -683,17 +683,17 @@ try_thread_db_load_from_dir (const char *dir, size_t dir_len)
 static int
 thread_db_load_search (void)
 {
-  VEC (char_ptr) *dir_vec;
-  char *this_dir;
-  int i, rc = 0;
+  int rc = 0;
 
   if (libthread_db_search_path == NULL)
     libthread_db_search_path = xstrdup (LIBTHREAD_DB_SEARCH_PATH);
 
-  dir_vec = dirnames_to_char_ptr_vec (libthread_db_search_path);
+  std::vector<gdb::unique_xmalloc_ptr<char>> dir_vec
+    = dirnames_to_char_ptr_vec (libthread_db_search_path);
 
-  for (i = 0; VEC_iterate (char_ptr, dir_vec, i, this_dir); ++i)
+  for (const gdb::unique_xmalloc_ptr<char> &this_dir_up : dir_vec)
     {
+      char *this_dir = this_dir_up.get ();
       const int pdir_len = sizeof ("$pdir") - 1;
       size_t this_dir_len;
 
@@ -725,7 +725,6 @@ thread_db_load_search (void)
        }
     }
 
-  free_char_ptr_vec (dir_vec);
   if (debug_threads)
     debug_printf ("thread_db_load_search returning %d\n", rc);
   return rc;
index 10c85f56adbb6491f4414ae30c20c0a311afe6ce..4da27b660084c836c465839f02c4f09474f3e0c5 100644 (file)
@@ -804,16 +804,14 @@ try_thread_db_load_from_dir (const char *dir, size_t dir_len)
 static int
 thread_db_load_search (void)
 {
-  VEC (char_ptr) *dir_vec;
-  struct cleanup *cleanups;
-  char *this_dir;
-  int i, rc = 0;
+  int rc = 0;
 
-  dir_vec = dirnames_to_char_ptr_vec (libthread_db_search_path);
-  cleanups = make_cleanup_free_char_ptr_vec (dir_vec);
+  std::vector<gdb::unique_xmalloc_ptr<char>> dir_vec
+    = dirnames_to_char_ptr_vec (libthread_db_search_path);
 
-  for (i = 0; VEC_iterate (char_ptr, dir_vec, i, this_dir); ++i)
+  for (const gdb::unique_xmalloc_ptr<char> &this_dir_up : dir_vec)
     {
+      const char *this_dir = this_dir_up.get ();
       const int pdir_len = sizeof ("$pdir") - 1;
       size_t this_dir_len;
 
@@ -853,7 +851,6 @@ thread_db_load_search (void)
        }
     }
 
-  do_cleanups (cleanups);
   if (libthread_db_debug)
     fprintf_unfiltered (gdb_stdlog,
                        _("thread_db_load_search returning %d\n"), rc);
index 6979fb2817ddbbb76a22942bc0a87298e541667f..3b4920fe8a4028b0d85a5096d3f4445233fb05b3 100644 (file)
@@ -461,10 +461,7 @@ add_path (const char *dirname, char **which_path, int parse_separators)
 {
   char *old = *which_path;
   int prefix = 0;
-  VEC (char_ptr) *dir_vec = NULL;
-  struct cleanup *back_to;
-  int ix;
-  char *name;
+  std::vector<gdb::unique_xmalloc_ptr<char>> dir_vec;
 
   if (dirname == 0)
     return;
@@ -479,11 +476,13 @@ add_path (const char *dirname, char **which_path, int parse_separators)
        dirnames_to_char_ptr_vec_append (&dir_vec, arg);
     }
   else
-    VEC_safe_push (char_ptr, dir_vec, xstrdup (dirname));
-  back_to = make_cleanup_free_char_ptr_vec (dir_vec);
+    dir_vec.emplace_back (xstrdup (dirname));
 
-  for (ix = 0; VEC_iterate (char_ptr, dir_vec, ix, name); ++ix)
+  struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
+
+  for (const gdb::unique_xmalloc_ptr<char> &name_up : dir_vec)
     {
+      char *name = name_up.get ();
       char *p;
       struct stat st;
 
@@ -709,13 +708,10 @@ openp (const char *path, openp_flags opts, const char *string,
   int fd;
   char *filename;
   int alloclen;
-  VEC (char_ptr) *dir_vec;
-  struct cleanup *back_to;
-  int ix;
-  char *dir;
   /* The errno set for the last name we tried to open (and
      failed).  */
   int last_errno = 0;
+  std::vector<gdb::unique_xmalloc_ptr<char>> dir_vec;
 
   /* The open syscall MODE parameter is not specified.  */
   gdb_assert ((mode & O_CREAT) == 0);
@@ -783,10 +779,10 @@ openp (const char *path, openp_flags opts, const char *string,
   last_errno = ENOENT;
 
   dir_vec = dirnames_to_char_ptr_vec (path);
-  back_to = make_cleanup_free_char_ptr_vec (dir_vec);
 
-  for (ix = 0; VEC_iterate (char_ptr, dir_vec, ix, dir); ++ix)
+  for (const gdb::unique_xmalloc_ptr<char> &dir_up : dir_vec)
     {
+      char *dir = dir_up.get ();
       size_t len = strlen (dir);
       int reg_file_errno;
 
@@ -856,8 +852,6 @@ openp (const char *path, openp_flags opts, const char *string,
        last_errno = reg_file_errno;
     }
 
-  do_cleanups (back_to);
-
 done:
   if (filename_opened)
     {
index 2a1428bc7acd5719472305baedfd03aa136b5146..72bf0d84513ea515658c2e2b154d136471d4cb20 100644 (file)
@@ -1439,12 +1439,8 @@ find_separate_debug_file (const char *dir,
                          const char *debuglink,
                          unsigned long crc32, struct objfile *objfile)
 {
-  char *debugdir;
   char *debugfile;
   int i;
-  VEC (char_ptr) *debugdir_vec;
-  struct cleanup *back_to;
-  int ix;
 
   if (separate_debug_file_debug)
     printf_unfiltered (_("\nLooking for separate debug info (debug link) for "
@@ -1484,21 +1480,18 @@ find_separate_debug_file (const char *dir,
      Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will
      cause "/..." lookups.  */
 
-  debugdir_vec = dirnames_to_char_ptr_vec (debug_file_directory);
-  back_to = make_cleanup_free_char_ptr_vec (debugdir_vec);
+  std::vector<gdb::unique_xmalloc_ptr<char>> debugdir_vec
+    = dirnames_to_char_ptr_vec (debug_file_directory);
 
-  for (ix = 0; VEC_iterate (char_ptr, debugdir_vec, ix, debugdir); ++ix)
+  for (const gdb::unique_xmalloc_ptr<char> &debugdir : debugdir_vec)
     {
-      strcpy (debugfile, debugdir);
+      strcpy (debugfile, debugdir.get ());
       strcat (debugfile, "/");
       strcat (debugfile, dir);
       strcat (debugfile, debuglink);
 
       if (separate_debug_file_exists (debugfile, crc32, objfile))
-       {
-         do_cleanups (back_to);
-         return debugfile;
-       }
+       return debugfile;
 
       /* If the file is in the sysroot, try using its base path in the
         global debugfile directory.  */
@@ -1507,20 +1500,16 @@ find_separate_debug_file (const char *dir,
                            strlen (gdb_sysroot)) == 0
          && IS_DIR_SEPARATOR (canon_dir[strlen (gdb_sysroot)]))
        {
-         strcpy (debugfile, debugdir);
+         strcpy (debugfile, debugdir.get ());
          strcat (debugfile, canon_dir + strlen (gdb_sysroot));
          strcat (debugfile, "/");
          strcat (debugfile, debuglink);
 
          if (separate_debug_file_exists (debugfile, crc32, objfile))
-           {
-             do_cleanups (back_to);
-             return debugfile;
-           }
+           return debugfile;
        }
     }
 
-  do_cleanups (back_to);
   xfree (debugfile);
   return NULL;
 }
index 577f9df4ecc6d0a5838daaa9c20a6e2d9ecca7a6..b99d444a6e472e97d582657cc049f47520b6d6c7 100644 (file)
@@ -3052,30 +3052,6 @@ make_bpstat_clear_actions_cleanup (void)
   return make_cleanup (do_bpstat_clear_actions_cleanup, NULL);
 }
 
-
-/* Helper for make_cleanup_free_char_ptr_vec.  */
-
-static void
-do_free_char_ptr_vec (void *arg)
-{
-  VEC (char_ptr) *char_ptr_vec = (VEC (char_ptr) *) arg;
-
-  free_char_ptr_vec (char_ptr_vec);
-}
-
-/* Make cleanup handler calling xfree for each element of CHAR_PTR_VEC and
-   final VEC_free for CHAR_PTR_VEC itself.
-
-   You must not modify CHAR_PTR_VEC after this cleanup registration as the
-   CHAR_PTR_VEC base address may change on its updates.  Contrary to VEC_free
-   this function does not (cannot) clear the pointer.  */
-
-struct cleanup *
-make_cleanup_free_char_ptr_vec (VEC (char_ptr) *char_ptr_vec)
-{
-  return make_cleanup (do_free_char_ptr_vec, char_ptr_vec);
-}
-
 /* Substitute all occurences of string FROM by string TO in *STRINGP.  *STRINGP
    must come from xrealloc-compatible allocator and it may be updated.  FROM
    needs to be delimited by IS_DIR_SEPARATOR or DIRNAME_SEPARATOR (or be
This page took 0.038139 seconds and 4 git commands to generate.