GNU Binutils with patches for OS216
Revisión | c4dfafabc575f4995a5aa18241adc275e63c846c (tree) |
---|---|
Tiempo | 2017-09-16 12:51:33 |
Autor | Sergio Durigan Junior <sergiodj@redh...> |
Commiter | Sergio Durigan Junior |
Use std::vector on tdesc->reg_defs (gdbserver/tdesc.h)
This is a followup patch to the build breakage fix on AArch64. While
doing the fix, I found it better to convert tdesc->reg_defs (on
gdbserver/tdesc.h) from using VEC to using std::vector. This makes
the code easier to read and maintain, and also is one more step
towards the C++fication.
Regtested on BuildBot.
2017-09-16 Sergio Durigan Junior <sergiodj@redhat.com>
* regcache.c (get_thread_regcache): Update code to use "std::vector"
instead of "VEC" for "target_desc.reg_defs".
(regcache_cpy): Likewise.
(registers_to_string): Likewise.
(registers_from_string): Likewise.
(find_regno): Likewise.
(supply_regblock): Likewise.
(regcache_raw_read_unsigned): Likewise.
* tdesc.c (init_target_desc): Likewise.
(tdesc_create_reg): Likewise.
* tdesc.h: Remove declaration of "tdesc_reg_p". Include <vector>.
(struct target_desc) <reg_defs>: Convert to "std::vector".
(target_desc): Do not initialize "reg_defs".
(~target_desc): Update code to use "std::vector" instead of "VEC"
for "target_desc.reg_defs".
(operator==): Likewise.
@@ -1,3 +1,22 @@ | ||
1 | +2017-09-16 Sergio Durigan Junior <sergiodj@redhat.com> | |
2 | + | |
3 | + * regcache.c (get_thread_regcache): Update code to use "std::vector" | |
4 | + instead of "VEC" for "target_desc.reg_defs". | |
5 | + (regcache_cpy): Likewise. | |
6 | + (registers_to_string): Likewise. | |
7 | + (registers_from_string): Likewise. | |
8 | + (find_regno): Likewise. | |
9 | + (supply_regblock): Likewise. | |
10 | + (regcache_raw_read_unsigned): Likewise. | |
11 | + * tdesc.c (init_target_desc): Likewise. | |
12 | + (tdesc_create_reg): Likewise. | |
13 | + * tdesc.h: Remove declaration of "tdesc_reg_p". Include <vector>. | |
14 | + (struct target_desc) <reg_defs>: Convert to "std::vector". | |
15 | + (target_desc): Do not initialize "reg_defs". | |
16 | + (~target_desc): Update code to use "std::vector" instead of "VEC" | |
17 | + for "target_desc.reg_defs". | |
18 | + (operator==): Likewise. | |
19 | + | |
1 | 20 | 2017-09-15 Simon Marchi <simon.marchi@ericsson.com> |
2 | 21 | |
3 | 22 | * inferiors.h (thread_to_gdb_id): Remove. |
@@ -53,9 +53,8 @@ get_thread_regcache (struct thread_info *thread, int fetch) | ||
53 | 53 | |
54 | 54 | current_thread = thread; |
55 | 55 | /* Invalidate all registers, to prevent stale left-overs. */ |
56 | - if (!VEC_empty (tdesc_reg_p, regcache->tdesc->reg_defs)) | |
57 | - memset (regcache->register_status, REG_UNAVAILABLE, | |
58 | - VEC_length (tdesc_reg_p, regcache->tdesc->reg_defs)); | |
56 | + memset (regcache->register_status, REG_UNAVAILABLE, | |
57 | + regcache->tdesc->reg_defs.size ()); | |
59 | 58 | fetch_inferior_registers (regcache, -1); |
60 | 59 | current_thread = saved_thread; |
61 | 60 | regcache->registers_valid = 1; |
@@ -146,10 +145,9 @@ init_register_cache (struct regcache *regcache, | ||
146 | 145 | = (unsigned char *) xcalloc (1, tdesc->registers_size); |
147 | 146 | regcache->registers_owned = 1; |
148 | 147 | regcache->register_status |
149 | - = (unsigned char *) xmalloc (VEC_length (tdesc_reg_p, tdesc->reg_defs)); | |
150 | - if (!VEC_empty (tdesc_reg_p, tdesc->reg_defs)) | |
151 | - memset ((void *) regcache->register_status, REG_UNAVAILABLE, | |
152 | - VEC_length (tdesc_reg_p, tdesc->reg_defs)); | |
148 | + = (unsigned char *) xmalloc (tdesc->reg_defs.size ()); | |
149 | + memset ((void *) regcache->register_status, REG_UNAVAILABLE, | |
150 | + tdesc->reg_defs.size ()); | |
153 | 151 | #else |
154 | 152 | gdb_assert_not_reached ("can't allocate memory from the heap"); |
155 | 153 | #endif |
@@ -206,7 +204,7 @@ regcache_cpy (struct regcache *dst, struct regcache *src) | ||
206 | 204 | #ifndef IN_PROCESS_AGENT |
207 | 205 | if (dst->register_status != NULL && src->register_status != NULL) |
208 | 206 | memcpy (dst->register_status, src->register_status, |
209 | - VEC_length (tdesc_reg_p, src->tdesc->reg_defs)); | |
207 | + src->tdesc->reg_defs.size ()); | |
210 | 208 | #endif |
211 | 209 | dst->registers_valid = src->registers_valid; |
212 | 210 | } |
@@ -219,11 +217,11 @@ registers_to_string (struct regcache *regcache, char *buf) | ||
219 | 217 | { |
220 | 218 | unsigned char *registers = regcache->registers; |
221 | 219 | const struct target_desc *tdesc = regcache->tdesc; |
222 | - int i; | |
223 | - reg *reg; | |
224 | 220 | |
225 | - for (i = 0; VEC_iterate (tdesc_reg_p, tdesc->reg_defs, i, reg); i++) | |
221 | + for (int i = 0; i < tdesc->reg_defs.size (); ++i) | |
226 | 222 | { |
223 | + struct reg *reg = tdesc->reg_defs[i]; | |
224 | + | |
227 | 225 | if (regcache->register_status[i] == REG_VALID) |
228 | 226 | { |
229 | 227 | bin2hex (registers, buf, register_size (tdesc, i)); |
@@ -259,12 +257,13 @@ registers_from_string (struct regcache *regcache, char *buf) | ||
259 | 257 | int |
260 | 258 | find_regno (const struct target_desc *tdesc, const char *name) |
261 | 259 | { |
262 | - int i; | |
263 | - reg *reg; | |
260 | + for (int i = 0; i < tdesc->reg_defs.size (); ++i) | |
261 | + { | |
262 | + struct reg *reg = tdesc->reg_defs[i]; | |
264 | 263 | |
265 | - for (i = 0; VEC_iterate (tdesc_reg_p, tdesc->reg_defs, i, reg); i++) | |
266 | - if (strcmp (name, reg->name) == 0) | |
267 | - return i; | |
264 | + if (strcmp (name, reg->name) == 0) | |
265 | + return i; | |
266 | + } | |
268 | 267 | internal_error (__FILE__, __LINE__, "Unknown register %s requested", |
269 | 268 | name); |
270 | 269 | } |
@@ -274,7 +273,7 @@ find_regno (const struct target_desc *tdesc, const char *name) | ||
274 | 273 | struct reg * |
275 | 274 | find_register_by_number (const struct target_desc *tdesc, int n) |
276 | 275 | { |
277 | - return VEC_index (tdesc_reg_p, tdesc->reg_defs, n); | |
276 | + return tdesc->reg_defs[n]; | |
278 | 277 | } |
279 | 278 | |
280 | 279 | #ifndef IN_PROCESS_AGENT |
@@ -390,7 +389,7 @@ supply_regblock (struct regcache *regcache, const void *buf) | ||
390 | 389 | { |
391 | 390 | int i; |
392 | 391 | |
393 | - for (i = 0; i < VEC_length (tdesc_reg_p, tdesc->reg_defs); i++) | |
392 | + for (i = 0; i < tdesc->reg_defs.size (); i++) | |
394 | 393 | regcache->register_status[i] = REG_VALID; |
395 | 394 | } |
396 | 395 | #endif |
@@ -404,7 +403,7 @@ supply_regblock (struct regcache *regcache, const void *buf) | ||
404 | 403 | { |
405 | 404 | int i; |
406 | 405 | |
407 | - for (i = 0; i < VEC_length (tdesc_reg_p, tdesc->reg_defs); i++) | |
406 | + for (i = 0; i < tdesc->reg_defs.size (); i++) | |
408 | 407 | regcache->register_status[i] = REG_UNAVAILABLE; |
409 | 408 | } |
410 | 409 | #endif |
@@ -437,7 +436,7 @@ regcache_raw_read_unsigned (struct regcache *regcache, int regnum, | ||
437 | 436 | |
438 | 437 | gdb_assert (regcache != NULL); |
439 | 438 | gdb_assert (regnum >= 0 |
440 | - && regnum < VEC_length (tdesc_reg_p, regcache->tdesc->reg_defs)); | |
439 | + && regnum < regcache->tdesc->reg_defs.size ()); | |
441 | 440 | |
442 | 441 | size = register_size (regcache->tdesc, regnum); |
443 | 442 |
@@ -22,11 +22,9 @@ | ||
22 | 22 | void |
23 | 23 | init_target_desc (struct target_desc *tdesc) |
24 | 24 | { |
25 | - int offset, i; | |
26 | - struct reg *reg; | |
25 | + int offset = 0; | |
27 | 26 | |
28 | - offset = 0; | |
29 | - for (i = 0; VEC_iterate (tdesc_reg_p, tdesc->reg_defs, i, reg); i++) | |
27 | + for (reg *reg : tdesc->reg_defs) | |
30 | 28 | { |
31 | 29 | reg->offset = offset; |
32 | 30 | offset += reg->size; |
@@ -193,23 +191,23 @@ tdesc_create_reg (struct tdesc_feature *feature, const char *name, | ||
193 | 191 | { |
194 | 192 | struct target_desc *tdesc = (struct target_desc *) feature; |
195 | 193 | |
196 | - while (VEC_length (tdesc_reg_p, tdesc->reg_defs) < regnum) | |
194 | + while (tdesc->reg_defs.size () < regnum) | |
197 | 195 | { |
198 | 196 | struct reg *reg = XCNEW (struct reg); |
199 | 197 | |
200 | 198 | reg->name = ""; |
201 | 199 | reg->size = 0; |
202 | - VEC_safe_push (tdesc_reg_p, tdesc->reg_defs, reg); | |
200 | + tdesc->reg_defs.push_back (reg); | |
203 | 201 | } |
204 | 202 | |
205 | 203 | gdb_assert (regnum == 0 |
206 | - || regnum == VEC_length (tdesc_reg_p, tdesc->reg_defs)); | |
204 | + || regnum == tdesc->reg_defs.size ()); | |
207 | 205 | |
208 | 206 | struct reg *reg = XCNEW (struct reg); |
209 | 207 | |
210 | 208 | reg->name = name; |
211 | 209 | reg->size = bitsize; |
212 | - VEC_safe_push (tdesc_reg_p, tdesc->reg_defs, reg); | |
210 | + tdesc->reg_defs.push_back (reg); | |
213 | 211 | } |
214 | 212 | |
215 | 213 | /* See arch/tdesc.h. */ |
@@ -22,9 +22,7 @@ | ||
22 | 22 | #include "arch/tdesc.h" |
23 | 23 | |
24 | 24 | #include "regdef.h" |
25 | - | |
26 | -typedef struct reg *tdesc_reg_p; | |
27 | -DEF_VEC_P(tdesc_reg_p); | |
25 | +#include <vector> | |
28 | 26 | |
29 | 27 | struct tdesc_feature |
30 | 28 | {}; |
@@ -36,7 +34,7 @@ struct target_desc : tdesc_feature | ||
36 | 34 | { |
37 | 35 | /* A vector of elements of register definitions that |
38 | 36 | describe the inferior's register set. */ |
39 | - VEC(tdesc_reg_p) *reg_defs; | |
37 | + std::vector<struct reg *> reg_defs; | |
40 | 38 | |
41 | 39 | /* The register cache size, in bytes. */ |
42 | 40 | int registers_size; |
@@ -66,17 +64,15 @@ struct target_desc : tdesc_feature | ||
66 | 64 | |
67 | 65 | public: |
68 | 66 | target_desc () |
69 | - : reg_defs (NULL), registers_size (0) | |
67 | + : registers_size (0) | |
70 | 68 | {} |
71 | 69 | |
72 | 70 | ~target_desc () |
73 | 71 | { |
74 | 72 | int i; |
75 | - struct reg *reg; | |
76 | 73 | |
77 | - for (i = 0; VEC_iterate (tdesc_reg_p, reg_defs, i, reg); i++) | |
74 | + for (reg *reg : reg_defs) | |
78 | 75 | xfree (reg); |
79 | - VEC_free (tdesc_reg_p, reg_defs); | |
80 | 76 | |
81 | 77 | xfree ((char *) arch); |
82 | 78 | xfree ((char *) osabi); |
@@ -90,18 +86,13 @@ public: | ||
90 | 86 | |
91 | 87 | bool operator== (const target_desc &other) const |
92 | 88 | { |
93 | - if (VEC_length (tdesc_reg_p, reg_defs) | |
94 | - != VEC_length (tdesc_reg_p, other.reg_defs)) | |
89 | + if (reg_defs.size () != other.reg_defs.size ()) | |
95 | 90 | return false; |
96 | 91 | |
97 | - struct reg *reg; | |
98 | - | |
99 | - for (int ix = 0; | |
100 | - VEC_iterate (tdesc_reg_p, reg_defs, ix, reg); | |
101 | - ix++) | |
92 | + for (int i = 0; i < reg_defs.size (); ++i) | |
102 | 93 | { |
103 | - struct reg *reg2 | |
104 | - = VEC_index (tdesc_reg_p, other.reg_defs, ix); | |
94 | + struct reg *reg = reg_defs[i]; | |
95 | + struct reg *reg2 = other.reg_defs[i]; | |
105 | 96 | |
106 | 97 | if (reg != reg2 && *reg != *reg2) |
107 | 98 | return false; |