• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

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

修訂72ddacb77e3301a0481003a23b2d8dced7116de5 (tree)
時間2017-06-20 19:29:17
作者Yao Qi <yao.qi@lina...>
CommiterYao Qi

Log Message

Class-fy tdesc_reg tdesc_type and tdesc_feature

This patch class-fies them, adding ctor, dtor, and deleting
copy ctor and assignment operator.

gdb:

2017-06-20 Yao Qi <yao.qi@linaro.org>

* target-descriptions.c (tdesc_reg): Add ctor, dtor.
Delete copy ctor and assignment operator.
(tdesc_type): Likewise.
(tdesc_feature): Likewise.
(tdesc_free_reg): Remove.
(tdesc_create_reg): Use new.
(tdesc_free_type): Remove.
(tdesc_create_vector): Use new.
(tdesc_create_union): Likewise.
(tdesc_create_flags): Likewise.
(tdesc_create_enum): Likewise.
(tdesc_free_feature): Delete.
(free_target_description): Use delete.

Change Summary

差異

--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,19 @@
1+2017-06-20 Yao Qi <yao.qi@linaro.org>
2+
3+ * target-descriptions.c (tdesc_reg): Add ctor, dtor.
4+ Delete copy ctor and assignment operator.
5+ (tdesc_type): Likewise.
6+ (tdesc_feature): Likewise.
7+ (tdesc_free_reg): Remove.
8+ (tdesc_create_reg): Use new.
9+ (tdesc_free_type): Remove.
10+ (tdesc_create_vector): Use new.
11+ (tdesc_create_union): Likewise.
12+ (tdesc_create_flags): Likewise.
13+ (tdesc_create_enum): Likewise.
14+ (tdesc_free_feature): Delete.
15+ (free_target_description): Use delete.
16+
117 2017-06-19 John Baldwin <jhb@FreeBSD.org>
218
319 * mips-tdep.c (print_gp_register_row): Don't error for unavailable
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -48,6 +48,31 @@ DEF_VEC_O(property_s);
4848
4949 typedef struct tdesc_reg
5050 {
51+ tdesc_reg (struct tdesc_feature *feature, const char *name_,
52+ int regnum, int save_restore_, const char *group_,
53+ int bitsize_, const char *type_)
54+ : name (xstrdup (name_)), target_regnum (regnum),
55+ save_restore (save_restore_),
56+ group (group_ != NULL ? xstrdup (group_) : NULL),
57+ bitsize (bitsize_),
58+ type (type_ != NULL ? xstrdup (type_) : xstrdup ("<unknown>"))
59+ {
60+ /* If the register's type is target-defined, look it up now. We may not
61+ have easy access to the containing feature when we want it later. */
62+ tdesc_type = tdesc_named_type (feature, type);
63+ }
64+
65+ ~tdesc_reg ()
66+ {
67+ xfree (name);
68+ xfree (type);
69+ xfree (group);
70+ }
71+
72+ /* Disable copying. */
73+ tdesc_reg (const tdesc_reg &) = delete;
74+ tdesc_reg &operator= (const tdesc_reg &) = delete;
75+
5176 /* The name of this register. In standard features, it may be
5277 recognized by the architecture support code, or it may be purely
5378 for the user. */
@@ -128,6 +153,42 @@ enum tdesc_type_kind
128153
129154 typedef struct tdesc_type
130155 {
156+ tdesc_type (const char *name_, enum tdesc_type_kind kind_)
157+ : name (xstrdup (name_)), kind (kind_)
158+ {
159+ memset (&u, 0, sizeof (u));
160+ }
161+
162+ ~tdesc_type ()
163+ {
164+ switch (kind)
165+ {
166+ case TDESC_TYPE_STRUCT:
167+ case TDESC_TYPE_UNION:
168+ case TDESC_TYPE_FLAGS:
169+ case TDESC_TYPE_ENUM:
170+ {
171+ struct tdesc_type_field *f;
172+ int ix;
173+
174+ for (ix = 0;
175+ VEC_iterate (tdesc_type_field, u.u.fields, ix, f);
176+ ix++)
177+ xfree (f->name);
178+
179+ VEC_free (tdesc_type_field, u.u.fields);
180+ }
181+ break;
182+
183+ default:
184+ break;
185+ }
186+ xfree ((char *) name);
187+ }
188+ /* Disable copying. */
189+ tdesc_type (const tdesc_type &) = delete;
190+ tdesc_type &operator= (const tdesc_type &) = delete;
191+
131192 /* The name of this type. If this type is a built-in type, this is
132193 a pointer to a constant string. Otherwise, it's a
133194 malloc-allocated string (and thus must be freed). */
@@ -161,15 +222,40 @@ DEF_VEC_P(tdesc_type_p);
161222
162223 typedef struct tdesc_feature
163224 {
225+ tdesc_feature (const char *name_)
226+ : name (xstrdup (name_))
227+ {}
228+
229+ ~tdesc_feature ()
230+ {
231+ struct tdesc_reg *reg;
232+ struct tdesc_type *type;
233+ int ix;
234+
235+ for (ix = 0; VEC_iterate (tdesc_reg_p, registers, ix, reg); ix++)
236+ delete reg;
237+ VEC_free (tdesc_reg_p, registers);
238+
239+ for (ix = 0; VEC_iterate (tdesc_type_p, types, ix, type); ix++)
240+ delete type;
241+ VEC_free (tdesc_type_p, types);
242+
243+ xfree (name);
244+ }
245+
246+ /* Disable copying. */
247+ tdesc_feature (const tdesc_feature &) = delete;
248+ tdesc_feature &operator= (const tdesc_feature &) = delete;
249+
164250 /* The name of this feature. It may be recognized by the architecture
165251 support code. */
166252 char *name;
167253
168254 /* The registers associated with this feature. */
169- VEC(tdesc_reg_p) *registers;
255+ VEC(tdesc_reg_p) *registers = NULL;
170256
171257 /* The types associated with this feature. */
172- VEC(tdesc_type_p) *types;
258+ VEC(tdesc_type_p) *types = NULL;
173259 } *tdesc_feature_p;
174260 DEF_VEC_P(tdesc_feature_p);
175261
@@ -1274,81 +1360,23 @@ tdesc_use_registers (struct gdbarch *gdbarch,
12741360 }
12751361
12761362
1277-/* Methods for constructing a target description. */
1278-
1279-static void
1280-tdesc_free_reg (struct tdesc_reg *reg)
1281-{
1282- xfree (reg->name);
1283- xfree (reg->type);
1284- xfree (reg->group);
1285- xfree (reg);
1286-}
1287-
12881363 void
12891364 tdesc_create_reg (struct tdesc_feature *feature, const char *name,
12901365 int regnum, int save_restore, const char *group,
12911366 int bitsize, const char *type)
12921367 {
1293- struct tdesc_reg *reg = XCNEW (struct tdesc_reg);
1294-
1295- reg->name = xstrdup (name);
1296- reg->target_regnum = regnum;
1297- reg->save_restore = save_restore;
1298- reg->group = group ? xstrdup (group) : NULL;
1299- reg->bitsize = bitsize;
1300- reg->type = type ? xstrdup (type) : xstrdup ("<unknown>");
1301-
1302- /* If the register's type is target-defined, look it up now. We may not
1303- have easy access to the containing feature when we want it later. */
1304- reg->tdesc_type = tdesc_named_type (feature, reg->type);
1368+ tdesc_reg *reg = new tdesc_reg (feature, name, regnum, save_restore,
1369+ group, bitsize, type);
13051370
13061371 VEC_safe_push (tdesc_reg_p, feature->registers, reg);
13071372 }
13081373
1309-/* Subroutine of tdesc_free_feature to simplify it.
1310- Note: We do not want to free any referenced types here (e.g., types of
1311- fields of a struct). All types of a feature are recorded in
1312- feature->types and are freed that way. */
1313-
1314-static void
1315-tdesc_free_type (struct tdesc_type *type)
1316-{
1317- switch (type->kind)
1318- {
1319- case TDESC_TYPE_STRUCT:
1320- case TDESC_TYPE_UNION:
1321- case TDESC_TYPE_FLAGS:
1322- case TDESC_TYPE_ENUM:
1323- {
1324- struct tdesc_type_field *f;
1325- int ix;
1326-
1327- for (ix = 0;
1328- VEC_iterate (tdesc_type_field, type->u.u.fields, ix, f);
1329- ix++)
1330- xfree (f->name);
1331-
1332- VEC_free (tdesc_type_field, type->u.u.fields);
1333- }
1334- break;
1335-
1336- default:
1337- break;
1338- }
1339-
1340- xfree ((char *) type->name);
1341- xfree (type);
1342-}
1343-
13441374 struct tdesc_type *
13451375 tdesc_create_vector (struct tdesc_feature *feature, const char *name,
13461376 struct tdesc_type *field_type, int count)
13471377 {
1348- struct tdesc_type *type = XCNEW (struct tdesc_type);
1378+ struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_VECTOR);
13491379
1350- type->name = xstrdup (name);
1351- type->kind = TDESC_TYPE_VECTOR;
13521380 type->u.v.type = field_type;
13531381 type->u.v.count = count;
13541382
@@ -1359,10 +1387,7 @@ tdesc_create_vector (struct tdesc_feature *feature, const char *name,
13591387 struct tdesc_type *
13601388 tdesc_create_struct (struct tdesc_feature *feature, const char *name)
13611389 {
1362- struct tdesc_type *type = XCNEW (struct tdesc_type);
1363-
1364- type->name = xstrdup (name);
1365- type->kind = TDESC_TYPE_STRUCT;
1390+ struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_STRUCT);
13661391
13671392 VEC_safe_push (tdesc_type_p, feature->types, type);
13681393 return type;
@@ -1383,10 +1408,7 @@ tdesc_set_struct_size (struct tdesc_type *type, int size)
13831408 struct tdesc_type *
13841409 tdesc_create_union (struct tdesc_feature *feature, const char *name)
13851410 {
1386- struct tdesc_type *type = XCNEW (struct tdesc_type);
1387-
1388- type->name = xstrdup (name);
1389- type->kind = TDESC_TYPE_UNION;
1411+ struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_UNION);
13901412
13911413 VEC_safe_push (tdesc_type_p, feature->types, type);
13921414 return type;
@@ -1396,12 +1418,10 @@ struct tdesc_type *
13961418 tdesc_create_flags (struct tdesc_feature *feature, const char *name,
13971419 int size)
13981420 {
1399- struct tdesc_type *type = XCNEW (struct tdesc_type);
1421+ struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_FLAGS);
14001422
14011423 gdb_assert (size > 0);
14021424
1403- type->name = xstrdup (name);
1404- type->kind = TDESC_TYPE_FLAGS;
14051425 type->u.u.size = size;
14061426
14071427 VEC_safe_push (tdesc_type_p, feature->types, type);
@@ -1412,12 +1432,10 @@ struct tdesc_type *
14121432 tdesc_create_enum (struct tdesc_feature *feature, const char *name,
14131433 int size)
14141434 {
1415- struct tdesc_type *type = XCNEW (struct tdesc_type);
1435+ struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_ENUM);
14161436
14171437 gdb_assert (size > 0);
14181438
1419- type->name = xstrdup (name);
1420- type->kind = TDESC_TYPE_ENUM;
14211439 type->u.u.size = size;
14221440
14231441 VEC_safe_push (tdesc_type_p, feature->types, type);
@@ -1521,31 +1539,10 @@ tdesc_add_enum_value (struct tdesc_type *type, int value,
15211539 VEC_safe_push (tdesc_type_field, type->u.u.fields, &f);
15221540 }
15231541
1524-static void
1525-tdesc_free_feature (struct tdesc_feature *feature)
1526-{
1527- struct tdesc_reg *reg;
1528- struct tdesc_type *type;
1529- int ix;
1530-
1531- for (ix = 0; VEC_iterate (tdesc_reg_p, feature->registers, ix, reg); ix++)
1532- tdesc_free_reg (reg);
1533- VEC_free (tdesc_reg_p, feature->registers);
1534-
1535- for (ix = 0; VEC_iterate (tdesc_type_p, feature->types, ix, type); ix++)
1536- tdesc_free_type (type);
1537- VEC_free (tdesc_type_p, feature->types);
1538-
1539- xfree (feature->name);
1540- xfree (feature);
1541-}
1542-
15431542 struct tdesc_feature *
15441543 tdesc_create_feature (struct target_desc *tdesc, const char *name)
15451544 {
1546- struct tdesc_feature *new_feature = XCNEW (struct tdesc_feature);
1547-
1548- new_feature->name = xstrdup (name);
1545+ struct tdesc_feature *new_feature = new tdesc_feature (name);
15491546
15501547 VEC_safe_push (tdesc_feature_p, tdesc->features, new_feature);
15511548 return new_feature;
@@ -1568,7 +1565,7 @@ free_target_description (void *arg)
15681565 for (ix = 0;
15691566 VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
15701567 ix++)
1571- tdesc_free_feature (feature);
1568+ delete feature;
15721569 VEC_free (tdesc_feature_p, target_desc->features);
15731570
15741571 for (ix = 0;