gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / gdbsupport / gdb_vecs.cc
1 /* Some commonly-used VEC types.
2
3 Copyright (C) 2012-2020 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "common-defs.h"
21 #include "gdb_vecs.h"
22 #include "host-defs.h"
23
24 /* Worker function to split character delimiter separated string of fields
25 STR into a char pointer vector. */
26
27 static void
28 delim_string_to_char_ptr_vec_append
29 (std::vector<gdb::unique_xmalloc_ptr<char>> *vecp, const char *str,
30 char delimiter)
31 {
32 do
33 {
34 size_t this_len;
35 const char *next_field;
36 char *this_field;
37
38 next_field = strchr (str, delimiter);
39 if (next_field == NULL)
40 this_len = strlen (str);
41 else
42 {
43 this_len = next_field - str;
44 next_field++;
45 }
46
47 this_field = (char *) xmalloc (this_len + 1);
48 memcpy (this_field, str, this_len);
49 this_field[this_len] = '\0';
50 vecp->emplace_back (this_field);
51
52 str = next_field;
53 }
54 while (str != NULL);
55 }
56
57 /* See gdb_vecs.h. */
58
59 std::vector<gdb::unique_xmalloc_ptr<char>>
60 delim_string_to_char_ptr_vec (const char *str, char delimiter)
61 {
62 std::vector<gdb::unique_xmalloc_ptr<char>> retval;
63
64 delim_string_to_char_ptr_vec_append (&retval, str, delimiter);
65
66 return retval;
67 }
68
69 /* See gdb_vecs.h. */
70
71 void
72 dirnames_to_char_ptr_vec_append
73 (std::vector<gdb::unique_xmalloc_ptr<char>> *vecp, const char *dirnames)
74 {
75 delim_string_to_char_ptr_vec_append (vecp, dirnames, DIRNAME_SEPARATOR);
76 }
77
78 /* See gdb_vecs.h. */
79
80 std::vector<gdb::unique_xmalloc_ptr<char>>
81 dirnames_to_char_ptr_vec (const char *dirnames)
82 {
83 std::vector<gdb::unique_xmalloc_ptr<char>> retval;
84
85 dirnames_to_char_ptr_vec_append (&retval, dirnames);
86
87 return retval;
88 }
This page took 0.030912 seconds and 4 git commands to generate.