2012-01-25 05:36:37 +08:00
|
|
|
/* Some commonly-used VEC types.
|
|
|
|
|
2023-01-01 20:49:04 +08:00
|
|
|
Copyright (C) 2012-2023 Free Software Foundation, Inc.
|
2012-01-25 05:36:37 +08:00
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
2019-01-28 03:51:36 +08:00
|
|
|
#ifndef COMMON_GDB_VECS_H
|
|
|
|
#define COMMON_GDB_VECS_H
|
2012-01-25 05:36:37 +08:00
|
|
|
|
2018-03-03 12:22:06 +08:00
|
|
|
/* Split STR, a list of DELIMITER-separated fields, into a char pointer vector.
|
gdb/
Code cleanup.
* charset.c (find_charset_names): Remove variables ix and elt.
Use free_char_ptr_vec.
* elfread.c (build_id_to_debug_filename): New variables debugdir_vec,
back_to and ix. Use dirnames_to_char_ptr_vec. Remove variable
debugdir_end. New variable debugdir_len.
* gdb_vecs.h (free_char_ptr_vec, make_cleanup_free_char_ptr_vec)
(dirnames_to_char_ptr_vec_append, dirnames_to_char_ptr_vec): New
declarations.
* progspace.c (clear_program_space_solib_cache): Remove variables ix
and elt. Use free_char_ptr_vec.
* source.c (add_path): Remove variables argv, arg and argv_index.
New variables dir_vec, back_to, ix and name.
Use dirnames_to_char_ptr_vec_append. Use freeargv instead of
make_cleanup_freeargv. Remove variable separator. Simplify the code
no longer expecting DIRNAME_SEPARATOR.
(openp): Remove variable p, p1 and len. New variables dir_vec,
back_to, ix and dir. Use dirnames_to_char_ptr_vec. Simplify the code
no longer expecting DIRNAME_SEPARATOR.
* symfile.c (find_separate_debug_file): New variables debugdir_vec,
back_to and ix. Use dirnames_to_char_ptr_vec. Remove variable
debugdir_end.
* utils.c (free_char_ptr_vec, do_free_char_ptr_vec)
(make_cleanup_free_char_ptr_vec, dirnames_to_char_ptr_vec_append)
(dirnames_to_char_ptr_vec): New functions.
2012-04-17 23:47:09 +08:00
|
|
|
|
2018-03-03 12:22:06 +08:00
|
|
|
You may modify the returned strings. */
|
2014-01-18 02:23:29 +08:00
|
|
|
|
2018-03-03 12:22:06 +08:00
|
|
|
extern std::vector<gdb::unique_xmalloc_ptr<char>>
|
|
|
|
delim_string_to_char_ptr_vec (const char *str, char delimiter);
|
gdb/
Code cleanup.
* charset.c (find_charset_names): Remove variables ix and elt.
Use free_char_ptr_vec.
* elfread.c (build_id_to_debug_filename): New variables debugdir_vec,
back_to and ix. Use dirnames_to_char_ptr_vec. Remove variable
debugdir_end. New variable debugdir_len.
* gdb_vecs.h (free_char_ptr_vec, make_cleanup_free_char_ptr_vec)
(dirnames_to_char_ptr_vec_append, dirnames_to_char_ptr_vec): New
declarations.
* progspace.c (clear_program_space_solib_cache): Remove variables ix
and elt. Use free_char_ptr_vec.
* source.c (add_path): Remove variables argv, arg and argv_index.
New variables dir_vec, back_to, ix and name.
Use dirnames_to_char_ptr_vec_append. Use freeargv instead of
make_cleanup_freeargv. Remove variable separator. Simplify the code
no longer expecting DIRNAME_SEPARATOR.
(openp): Remove variable p, p1 and len. New variables dir_vec,
back_to, ix and dir. Use dirnames_to_char_ptr_vec. Simplify the code
no longer expecting DIRNAME_SEPARATOR.
* symfile.c (find_separate_debug_file): New variables debugdir_vec,
back_to and ix. Use dirnames_to_char_ptr_vec. Remove variable
debugdir_end.
* utils.c (free_char_ptr_vec, do_free_char_ptr_vec)
(make_cleanup_free_char_ptr_vec, dirnames_to_char_ptr_vec_append)
(dirnames_to_char_ptr_vec): New functions.
2012-04-17 23:47:09 +08:00
|
|
|
|
2018-03-03 12:22:06 +08:00
|
|
|
/* 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);
|
gdb/
Code cleanup.
* charset.c (find_charset_names): Remove variables ix and elt.
Use free_char_ptr_vec.
* elfread.c (build_id_to_debug_filename): New variables debugdir_vec,
back_to and ix. Use dirnames_to_char_ptr_vec. Remove variable
debugdir_end. New variable debugdir_len.
* gdb_vecs.h (free_char_ptr_vec, make_cleanup_free_char_ptr_vec)
(dirnames_to_char_ptr_vec_append, dirnames_to_char_ptr_vec): New
declarations.
* progspace.c (clear_program_space_solib_cache): Remove variables ix
and elt. Use free_char_ptr_vec.
* source.c (add_path): Remove variables argv, arg and argv_index.
New variables dir_vec, back_to, ix and name.
Use dirnames_to_char_ptr_vec_append. Use freeargv instead of
make_cleanup_freeargv. Remove variable separator. Simplify the code
no longer expecting DIRNAME_SEPARATOR.
(openp): Remove variable p, p1 and len. New variables dir_vec,
back_to, ix and dir. Use dirnames_to_char_ptr_vec. Simplify the code
no longer expecting DIRNAME_SEPARATOR.
* symfile.c (find_separate_debug_file): New variables debugdir_vec,
back_to and ix. Use dirnames_to_char_ptr_vec. Remove variable
debugdir_end.
* utils.c (free_char_ptr_vec, do_free_char_ptr_vec)
(make_cleanup_free_char_ptr_vec, dirnames_to_char_ptr_vec_append)
(dirnames_to_char_ptr_vec): New functions.
2012-04-17 23:47:09 +08:00
|
|
|
|
2018-04-10 03:40:45 +08:00
|
|
|
/* Remove the element pointed by iterator IT from VEC, not preserving the order
|
|
|
|
of the remaining elements. Return the removed element. */
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T
|
|
|
|
unordered_remove (std::vector<T> &vec, typename std::vector<T>::iterator it)
|
|
|
|
{
|
|
|
|
gdb_assert (it >= vec.begin () && it < vec.end ());
|
|
|
|
|
|
|
|
T removed = std::move (*it);
|
2019-11-09 07:39:14 +08:00
|
|
|
if (it != vec.end () - 1)
|
|
|
|
*it = std::move (vec.back ());
|
2018-04-10 03:40:45 +08:00
|
|
|
vec.pop_back ();
|
|
|
|
|
|
|
|
return removed;
|
|
|
|
}
|
|
|
|
|
2018-03-06 22:51:33 +08:00
|
|
|
/* Remove the element at position IX from VEC, not preserving the order of the
|
|
|
|
remaining elements. Return the removed element. */
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T
|
|
|
|
unordered_remove (std::vector<T> &vec, typename std::vector<T>::size_type ix)
|
|
|
|
{
|
|
|
|
gdb_assert (ix < vec.size ());
|
|
|
|
|
2018-04-10 03:40:45 +08:00
|
|
|
return unordered_remove (vec, vec.begin () + ix);
|
2018-03-06 22:51:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove the element at position IX from VEC, preserving the order the
|
|
|
|
remaining elements. Return the removed element. */
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T
|
|
|
|
ordered_remove (std::vector<T> &vec, typename std::vector<T>::size_type ix)
|
|
|
|
{
|
|
|
|
gdb_assert (ix < vec.size ());
|
|
|
|
|
|
|
|
T removed = std::move (vec[ix]);
|
|
|
|
vec.erase (vec.begin () + ix);
|
|
|
|
|
|
|
|
return removed;
|
|
|
|
}
|
|
|
|
|
2019-01-28 03:51:36 +08:00
|
|
|
#endif /* COMMON_GDB_VECS_H */
|