diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2018-03-02 23:22:06 -0500 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2018-03-02 23:22:07 -0500 |
commit | e80aaf6183c6692ecc167bf26cbdc53f8f1a55f0 (patch) | |
tree | 6964a92dd94620a07a9d63227c69d8662e99d7b0 /gdb/common | |
parent | a6743a5420aa02a0550b0f7be004f6c06e90ce21 (diff) | |
download | gdb-e80aaf6183c6692ecc167bf26cbdc53f8f1a55f0.zip gdb-e80aaf6183c6692ecc167bf26cbdc53f8f1a55f0.tar.gz gdb-e80aaf6183c6692ecc167bf26cbdc53f8f1a55f0.tar.bz2 |
Make delim_string_to_char_ptr_vec return an std::vector
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.
Diffstat (limited to 'gdb/common')
-rw-r--r-- | gdb/common/gdb_vecs.c | 36 | ||||
-rw-r--r-- | gdb/common/gdb_vecs.h | 24 |
2 files changed, 31 insertions, 29 deletions
diff --git a/gdb/common/gdb_vecs.c b/gdb/common/gdb_vecs.c index a221460..a19d238 100644 --- a/gdb/common/gdb_vecs.c +++ b/gdb/common/gdb_vecs.c @@ -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); diff --git a/gdb/common/gdb_vecs.h b/gdb/common/gdb_vecs.h index 75caf59..17ed06c 100644 --- a/gdb/common/gdb_vecs.h +++ b/gdb/common/gdb_vecs.h @@ -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 */ |