2012-01-24 22:36:37 +01:00
|
|
|
/* Some commonly-used VEC types.
|
|
|
|
|
2018-01-01 05:43:02 +01:00
|
|
|
Copyright (C) 2012-2018 Free Software Foundation, Inc.
|
2012-01-24 22:36:37 +01: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/>. */
|
|
|
|
|
|
|
|
#ifndef GDB_VECS_H
|
|
|
|
#define GDB_VECS_H
|
|
|
|
|
|
|
|
#include "vec.h"
|
|
|
|
|
2018-03-03 05:22:06 +01: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 17:47:09 +02:00
|
|
|
|
2018-03-03 05:22:06 +01:00
|
|
|
You may modify the returned strings. */
|
2014-01-17 19:23:29 +01:00
|
|
|
|
2018-03-03 05:22:06 +01: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 17:47:09 +02:00
|
|
|
|
2018-03-03 05:22:06 +01: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 17:47:09 +02:00
|
|
|
|
2018-04-09 21:40:45 +02: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);
|
|
|
|
*it = std::move (vec.back ());
|
|
|
|
vec.pop_back ();
|
|
|
|
|
|
|
|
return removed;
|
|
|
|
}
|
|
|
|
|
2018-03-06 15:51:33 +01: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-09 21:40:45 +02:00
|
|
|
return unordered_remove (vec, vec.begin () + ix);
|
2018-03-06 15:51:33 +01: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;
|
|
|
|
}
|
|
|
|
|
2012-01-24 22:36:37 +01:00
|
|
|
#endif /* GDB_VECS_H */
|