GNU Binutils with patches for OS216
修訂 | 72ddacb77e3301a0481003a23b2d8dced7116de5 (tree) |
---|---|
時間 | 2017-06-20 19:29:17 |
作者 | Yao Qi <yao.qi@lina...> |
Commiter | Yao Qi |
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.
@@ -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 | + | |
1 | 17 | 2017-06-19 John Baldwin <jhb@FreeBSD.org> |
2 | 18 | |
3 | 19 | * mips-tdep.c (print_gp_register_row): Don't error for unavailable |
@@ -48,6 +48,31 @@ DEF_VEC_O(property_s); | ||
48 | 48 | |
49 | 49 | typedef struct tdesc_reg |
50 | 50 | { |
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 | + | |
51 | 76 | /* The name of this register. In standard features, it may be |
52 | 77 | recognized by the architecture support code, or it may be purely |
53 | 78 | for the user. */ |
@@ -128,6 +153,42 @@ enum tdesc_type_kind | ||
128 | 153 | |
129 | 154 | typedef struct tdesc_type |
130 | 155 | { |
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 | + | |
131 | 192 | /* The name of this type. If this type is a built-in type, this is |
132 | 193 | a pointer to a constant string. Otherwise, it's a |
133 | 194 | malloc-allocated string (and thus must be freed). */ |
@@ -161,15 +222,40 @@ DEF_VEC_P(tdesc_type_p); | ||
161 | 222 | |
162 | 223 | typedef struct tdesc_feature |
163 | 224 | { |
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 | + | |
164 | 250 | /* The name of this feature. It may be recognized by the architecture |
165 | 251 | support code. */ |
166 | 252 | char *name; |
167 | 253 | |
168 | 254 | /* The registers associated with this feature. */ |
169 | - VEC(tdesc_reg_p) *registers; | |
255 | + VEC(tdesc_reg_p) *registers = NULL; | |
170 | 256 | |
171 | 257 | /* The types associated with this feature. */ |
172 | - VEC(tdesc_type_p) *types; | |
258 | + VEC(tdesc_type_p) *types = NULL; | |
173 | 259 | } *tdesc_feature_p; |
174 | 260 | DEF_VEC_P(tdesc_feature_p); |
175 | 261 |
@@ -1274,81 +1360,23 @@ tdesc_use_registers (struct gdbarch *gdbarch, | ||
1274 | 1360 | } |
1275 | 1361 | |
1276 | 1362 | |
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 | - | |
1288 | 1363 | void |
1289 | 1364 | tdesc_create_reg (struct tdesc_feature *feature, const char *name, |
1290 | 1365 | int regnum, int save_restore, const char *group, |
1291 | 1366 | int bitsize, const char *type) |
1292 | 1367 | { |
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); | |
1305 | 1370 | |
1306 | 1371 | VEC_safe_push (tdesc_reg_p, feature->registers, reg); |
1307 | 1372 | } |
1308 | 1373 | |
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 | - | |
1344 | 1374 | struct tdesc_type * |
1345 | 1375 | tdesc_create_vector (struct tdesc_feature *feature, const char *name, |
1346 | 1376 | struct tdesc_type *field_type, int count) |
1347 | 1377 | { |
1348 | - struct tdesc_type *type = XCNEW (struct tdesc_type); | |
1378 | + struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_VECTOR); | |
1349 | 1379 | |
1350 | - type->name = xstrdup (name); | |
1351 | - type->kind = TDESC_TYPE_VECTOR; | |
1352 | 1380 | type->u.v.type = field_type; |
1353 | 1381 | type->u.v.count = count; |
1354 | 1382 |
@@ -1359,10 +1387,7 @@ tdesc_create_vector (struct tdesc_feature *feature, const char *name, | ||
1359 | 1387 | struct tdesc_type * |
1360 | 1388 | tdesc_create_struct (struct tdesc_feature *feature, const char *name) |
1361 | 1389 | { |
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); | |
1366 | 1391 | |
1367 | 1392 | VEC_safe_push (tdesc_type_p, feature->types, type); |
1368 | 1393 | return type; |
@@ -1383,10 +1408,7 @@ tdesc_set_struct_size (struct tdesc_type *type, int size) | ||
1383 | 1408 | struct tdesc_type * |
1384 | 1409 | tdesc_create_union (struct tdesc_feature *feature, const char *name) |
1385 | 1410 | { |
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); | |
1390 | 1412 | |
1391 | 1413 | VEC_safe_push (tdesc_type_p, feature->types, type); |
1392 | 1414 | return type; |
@@ -1396,12 +1418,10 @@ struct tdesc_type * | ||
1396 | 1418 | tdesc_create_flags (struct tdesc_feature *feature, const char *name, |
1397 | 1419 | int size) |
1398 | 1420 | { |
1399 | - struct tdesc_type *type = XCNEW (struct tdesc_type); | |
1421 | + struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_FLAGS); | |
1400 | 1422 | |
1401 | 1423 | gdb_assert (size > 0); |
1402 | 1424 | |
1403 | - type->name = xstrdup (name); | |
1404 | - type->kind = TDESC_TYPE_FLAGS; | |
1405 | 1425 | type->u.u.size = size; |
1406 | 1426 | |
1407 | 1427 | VEC_safe_push (tdesc_type_p, feature->types, type); |
@@ -1412,12 +1432,10 @@ struct tdesc_type * | ||
1412 | 1432 | tdesc_create_enum (struct tdesc_feature *feature, const char *name, |
1413 | 1433 | int size) |
1414 | 1434 | { |
1415 | - struct tdesc_type *type = XCNEW (struct tdesc_type); | |
1435 | + struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_ENUM); | |
1416 | 1436 | |
1417 | 1437 | gdb_assert (size > 0); |
1418 | 1438 | |
1419 | - type->name = xstrdup (name); | |
1420 | - type->kind = TDESC_TYPE_ENUM; | |
1421 | 1439 | type->u.u.size = size; |
1422 | 1440 | |
1423 | 1441 | VEC_safe_push (tdesc_type_p, feature->types, type); |
@@ -1521,31 +1539,10 @@ tdesc_add_enum_value (struct tdesc_type *type, int value, | ||
1521 | 1539 | VEC_safe_push (tdesc_type_field, type->u.u.fields, &f); |
1522 | 1540 | } |
1523 | 1541 | |
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 | - | |
1543 | 1542 | struct tdesc_feature * |
1544 | 1543 | tdesc_create_feature (struct target_desc *tdesc, const char *name) |
1545 | 1544 | { |
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); | |
1549 | 1546 | |
1550 | 1547 | VEC_safe_push (tdesc_feature_p, tdesc->features, new_feature); |
1551 | 1548 | return new_feature; |
@@ -1568,7 +1565,7 @@ free_target_description (void *arg) | ||
1568 | 1565 | for (ix = 0; |
1569 | 1566 | VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature); |
1570 | 1567 | ix++) |
1571 | - tdesc_free_feature (feature); | |
1568 | + delete feature; | |
1572 | 1569 | VEC_free (tdesc_feature_p, target_desc->features); |
1573 | 1570 | |
1574 | 1571 | for (ix = 0; |