+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
/* 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);
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;
_("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));
}
}
}
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)
{
}
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)
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);
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;
/* 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)
abfd.release ();
}
- do_cleanups (back_to);
return abfd;
}
}
/* 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
{
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);
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 */
+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)
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.
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;
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)
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 ();
}
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;
}
}
- free_char_ptr_vec (dir_vec);
if (debug_threads)
debug_printf ("thread_db_load_search returning %d\n", rc);
return rc;
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;
}
}
- do_cleanups (cleanups);
if (libthread_db_debug)
fprintf_unfiltered (gdb_stdlog,
_("thread_db_load_search returning %d\n"), rc);
{
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;
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;
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);
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;
last_errno = reg_file_errno;
}
- do_cleanups (back_to);
-
done:
if (filename_opened)
{
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 "
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. */
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;
}
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