• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revisiónc4dfafabc575f4995a5aa18241adc275e63c846c (tree)
Tiempo2017-09-16 12:51:33
AutorSergio Durigan Junior <sergiodj@redh...>
CommiterSergio Durigan Junior

Log Message

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.

Cambiar Resumen

Diferencia incremental

--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -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+
120 2017-09-15 Simon Marchi <simon.marchi@ericsson.com>
221
322 * inferiors.h (thread_to_gdb_id): Remove.
--- a/gdb/gdbserver/regcache.c
+++ b/gdb/gdbserver/regcache.c
@@ -53,9 +53,8 @@ get_thread_regcache (struct thread_info *thread, int fetch)
5353
5454 current_thread = thread;
5555 /* 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 ());
5958 fetch_inferior_registers (regcache, -1);
6059 current_thread = saved_thread;
6160 regcache->registers_valid = 1;
@@ -146,10 +145,9 @@ init_register_cache (struct regcache *regcache,
146145 = (unsigned char *) xcalloc (1, tdesc->registers_size);
147146 regcache->registers_owned = 1;
148147 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 ());
153151 #else
154152 gdb_assert_not_reached ("can't allocate memory from the heap");
155153 #endif
@@ -206,7 +204,7 @@ regcache_cpy (struct regcache *dst, struct regcache *src)
206204 #ifndef IN_PROCESS_AGENT
207205 if (dst->register_status != NULL && src->register_status != NULL)
208206 memcpy (dst->register_status, src->register_status,
209- VEC_length (tdesc_reg_p, src->tdesc->reg_defs));
207+ src->tdesc->reg_defs.size ());
210208 #endif
211209 dst->registers_valid = src->registers_valid;
212210 }
@@ -219,11 +217,11 @@ registers_to_string (struct regcache *regcache, char *buf)
219217 {
220218 unsigned char *registers = regcache->registers;
221219 const struct target_desc *tdesc = regcache->tdesc;
222- int i;
223- reg *reg;
224220
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)
226222 {
223+ struct reg *reg = tdesc->reg_defs[i];
224+
227225 if (regcache->register_status[i] == REG_VALID)
228226 {
229227 bin2hex (registers, buf, register_size (tdesc, i));
@@ -259,12 +257,13 @@ registers_from_string (struct regcache *regcache, char *buf)
259257 int
260258 find_regno (const struct target_desc *tdesc, const char *name)
261259 {
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];
264263
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+ }
268267 internal_error (__FILE__, __LINE__, "Unknown register %s requested",
269268 name);
270269 }
@@ -274,7 +273,7 @@ find_regno (const struct target_desc *tdesc, const char *name)
274273 struct reg *
275274 find_register_by_number (const struct target_desc *tdesc, int n)
276275 {
277- return VEC_index (tdesc_reg_p, tdesc->reg_defs, n);
276+ return tdesc->reg_defs[n];
278277 }
279278
280279 #ifndef IN_PROCESS_AGENT
@@ -390,7 +389,7 @@ supply_regblock (struct regcache *regcache, const void *buf)
390389 {
391390 int i;
392391
393- for (i = 0; i < VEC_length (tdesc_reg_p, tdesc->reg_defs); i++)
392+ for (i = 0; i < tdesc->reg_defs.size (); i++)
394393 regcache->register_status[i] = REG_VALID;
395394 }
396395 #endif
@@ -404,7 +403,7 @@ supply_regblock (struct regcache *regcache, const void *buf)
404403 {
405404 int i;
406405
407- for (i = 0; i < VEC_length (tdesc_reg_p, tdesc->reg_defs); i++)
406+ for (i = 0; i < tdesc->reg_defs.size (); i++)
408407 regcache->register_status[i] = REG_UNAVAILABLE;
409408 }
410409 #endif
@@ -437,7 +436,7 @@ regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
437436
438437 gdb_assert (regcache != NULL);
439438 gdb_assert (regnum >= 0
440- && regnum < VEC_length (tdesc_reg_p, regcache->tdesc->reg_defs));
439+ && regnum < regcache->tdesc->reg_defs.size ());
441440
442441 size = register_size (regcache->tdesc, regnum);
443442
--- a/gdb/gdbserver/tdesc.c
+++ b/gdb/gdbserver/tdesc.c
@@ -22,11 +22,9 @@
2222 void
2323 init_target_desc (struct target_desc *tdesc)
2424 {
25- int offset, i;
26- struct reg *reg;
25+ int offset = 0;
2726
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)
3028 {
3129 reg->offset = offset;
3230 offset += reg->size;
@@ -193,23 +191,23 @@ tdesc_create_reg (struct tdesc_feature *feature, const char *name,
193191 {
194192 struct target_desc *tdesc = (struct target_desc *) feature;
195193
196- while (VEC_length (tdesc_reg_p, tdesc->reg_defs) < regnum)
194+ while (tdesc->reg_defs.size () < regnum)
197195 {
198196 struct reg *reg = XCNEW (struct reg);
199197
200198 reg->name = "";
201199 reg->size = 0;
202- VEC_safe_push (tdesc_reg_p, tdesc->reg_defs, reg);
200+ tdesc->reg_defs.push_back (reg);
203201 }
204202
205203 gdb_assert (regnum == 0
206- || regnum == VEC_length (tdesc_reg_p, tdesc->reg_defs));
204+ || regnum == tdesc->reg_defs.size ());
207205
208206 struct reg *reg = XCNEW (struct reg);
209207
210208 reg->name = name;
211209 reg->size = bitsize;
212- VEC_safe_push (tdesc_reg_p, tdesc->reg_defs, reg);
210+ tdesc->reg_defs.push_back (reg);
213211 }
214212
215213 /* See arch/tdesc.h. */
--- a/gdb/gdbserver/tdesc.h
+++ b/gdb/gdbserver/tdesc.h
@@ -22,9 +22,7 @@
2222 #include "arch/tdesc.h"
2323
2424 #include "regdef.h"
25-
26-typedef struct reg *tdesc_reg_p;
27-DEF_VEC_P(tdesc_reg_p);
25+#include <vector>
2826
2927 struct tdesc_feature
3028 {};
@@ -36,7 +34,7 @@ struct target_desc : tdesc_feature
3634 {
3735 /* A vector of elements of register definitions that
3836 describe the inferior's register set. */
39- VEC(tdesc_reg_p) *reg_defs;
37+ std::vector<struct reg *> reg_defs;
4038
4139 /* The register cache size, in bytes. */
4240 int registers_size;
@@ -66,17 +64,15 @@ struct target_desc : tdesc_feature
6664
6765 public:
6866 target_desc ()
69- : reg_defs (NULL), registers_size (0)
67+ : registers_size (0)
7068 {}
7169
7270 ~target_desc ()
7371 {
7472 int i;
75- struct reg *reg;
7673
77- for (i = 0; VEC_iterate (tdesc_reg_p, reg_defs, i, reg); i++)
74+ for (reg *reg : reg_defs)
7875 xfree (reg);
79- VEC_free (tdesc_reg_p, reg_defs);
8076
8177 xfree ((char *) arch);
8278 xfree ((char *) osabi);
@@ -90,18 +86,13 @@ public:
9086
9187 bool operator== (const target_desc &other) const
9288 {
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 ())
9590 return false;
9691
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)
10293 {
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];
10596
10697 if (reg != reg2 && *reg != *reg2)
10798 return false;