OLD | NEW |
1 /* Support routines for manipulating internal types for GDB. | 1 /* Support routines for manipulating internal types for GDB. |
2 | 2 |
3 Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. | 3 Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. |
4 | 4 |
5 Contributed by Cygnus Support, using pieces from other GDB modules. | 5 Contributed by Cygnus Support, using pieces from other GDB modules. |
6 | 6 |
7 This file is part of GDB. | 7 This file is part of GDB. |
8 | 8 |
9 This program is free software; you can redistribute it and/or modify | 9 This program is free software; you can redistribute it and/or modify |
10 it under the terms of the GNU General Public License as published by | 10 it under the terms of the GNU General Public License as published by |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "symfile.h" | 26 #include "symfile.h" |
27 #include "objfiles.h" | 27 #include "objfiles.h" |
28 #include "gdbtypes.h" | 28 #include "gdbtypes.h" |
29 #include "expression.h" | 29 #include "expression.h" |
30 #include "language.h" | 30 #include "language.h" |
31 #include "target.h" | 31 #include "target.h" |
32 #include "value.h" | 32 #include "value.h" |
33 #include "demangle.h" | 33 #include "demangle.h" |
34 #include "complaints.h" | 34 #include "complaints.h" |
35 #include "gdbcmd.h" | 35 #include "gdbcmd.h" |
36 #include "wrapper.h" | |
37 #include "cp-abi.h" | 36 #include "cp-abi.h" |
38 #include "gdb_assert.h" | 37 #include "gdb_assert.h" |
39 #include "hashtab.h" | 38 #include "hashtab.h" |
40 | 39 #include "exceptions.h" |
41 | 40 |
42 /* Initialize BADNESS constants. */ | 41 /* Initialize BADNESS constants. */ |
43 | 42 |
44 const struct rank LENGTH_MISMATCH_BADNESS = {100,0}; | 43 const struct rank LENGTH_MISMATCH_BADNESS = {100,0}; |
45 | 44 |
46 const struct rank TOO_FEW_PARAMS_BADNESS = {100,0}; | 45 const struct rank TOO_FEW_PARAMS_BADNESS = {100,0}; |
47 const struct rank INCOMPATIBLE_TYPE_BADNESS = {100,0}; | 46 const struct rank INCOMPATIBLE_TYPE_BADNESS = {100,0}; |
48 | 47 |
49 const struct rank EXACT_MATCH_BADNESS = {0,0}; | 48 const struct rank EXACT_MATCH_BADNESS = {0,0}; |
50 | 49 |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 | 455 |
457 /* Given a type TYPE, return a type of functions that return that type. | 456 /* Given a type TYPE, return a type of functions that return that type. |
458 May need to construct such a type if this is the first use. */ | 457 May need to construct such a type if this is the first use. */ |
459 | 458 |
460 struct type * | 459 struct type * |
461 lookup_function_type (struct type *type) | 460 lookup_function_type (struct type *type) |
462 { | 461 { |
463 return make_function_type (type, (struct type **) 0); | 462 return make_function_type (type, (struct type **) 0); |
464 } | 463 } |
465 | 464 |
| 465 /* Given a type TYPE and argument types, return the appropriate |
| 466 function type. If the final type in PARAM_TYPES is NULL, make a |
| 467 varargs function. */ |
| 468 |
| 469 struct type * |
| 470 lookup_function_type_with_arguments (struct type *type, |
| 471 int nparams, |
| 472 struct type **param_types) |
| 473 { |
| 474 struct type *fn = make_function_type (type, (struct type **) 0); |
| 475 int i; |
| 476 |
| 477 if (nparams > 0) |
| 478 { |
| 479 if (param_types[nparams - 1] == NULL) |
| 480 { |
| 481 --nparams; |
| 482 TYPE_VARARGS (fn) = 1; |
| 483 } |
| 484 else if (TYPE_CODE (check_typedef (param_types[nparams - 1])) |
| 485 == TYPE_CODE_VOID) |
| 486 { |
| 487 --nparams; |
| 488 /* Caller should have ensured this. */ |
| 489 gdb_assert (nparams == 0); |
| 490 TYPE_PROTOTYPED (fn) = 1; |
| 491 } |
| 492 } |
| 493 |
| 494 TYPE_NFIELDS (fn) = nparams; |
| 495 TYPE_FIELDS (fn) = TYPE_ZALLOC (fn, nparams * sizeof (struct field)); |
| 496 for (i = 0; i < nparams; ++i) |
| 497 TYPE_FIELD_TYPE (fn, i) = param_types[i]; |
| 498 |
| 499 return fn; |
| 500 } |
| 501 |
466 /* Identify address space identifier by name -- | 502 /* Identify address space identifier by name -- |
467 return the integer flag defined in gdbtypes.h. */ | 503 return the integer flag defined in gdbtypes.h. */ |
468 extern int | 504 extern int |
469 address_space_name_to_int (struct gdbarch *gdbarch, char *space_identifier) | 505 address_space_name_to_int (struct gdbarch *gdbarch, char *space_identifier) |
470 { | 506 { |
471 int type_flags; | 507 int type_flags; |
472 | 508 |
473 /* Check for known address space delimiters. */ | 509 /* Check for known address space delimiters. */ |
474 if (!strcmp (space_identifier, "code")) | 510 if (!strcmp (space_identifier, "code")) |
475 return TYPE_INSTANCE_FLAG_CODE_SPACE; | 511 return TYPE_INSTANCE_FLAG_CODE_SPACE; |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 *lowp = TYPE_LOW_BOUND (type); | 805 *lowp = TYPE_LOW_BOUND (type); |
770 *highp = TYPE_HIGH_BOUND (type); | 806 *highp = TYPE_HIGH_BOUND (type); |
771 return 1; | 807 return 1; |
772 case TYPE_CODE_ENUM: | 808 case TYPE_CODE_ENUM: |
773 if (TYPE_NFIELDS (type) > 0) | 809 if (TYPE_NFIELDS (type) > 0) |
774 { | 810 { |
775 /* The enums may not be sorted by value, so search all | 811 /* The enums may not be sorted by value, so search all |
776 entries. */ | 812 entries. */ |
777 int i; | 813 int i; |
778 | 814 |
779 » *lowp = *highp = TYPE_FIELD_BITPOS (type, 0); | 815 » *lowp = *highp = TYPE_FIELD_ENUMVAL (type, 0); |
780 for (i = 0; i < TYPE_NFIELDS (type); i++) | 816 for (i = 0; i < TYPE_NFIELDS (type); i++) |
781 { | 817 { |
782 » if (TYPE_FIELD_BITPOS (type, i) < *lowp) | 818 » if (TYPE_FIELD_ENUMVAL (type, i) < *lowp) |
783 » » *lowp = TYPE_FIELD_BITPOS (type, i); | 819 » » *lowp = TYPE_FIELD_ENUMVAL (type, i); |
784 » if (TYPE_FIELD_BITPOS (type, i) > *highp) | 820 » if (TYPE_FIELD_ENUMVAL (type, i) > *highp) |
785 » » *highp = TYPE_FIELD_BITPOS (type, i); | 821 » » *highp = TYPE_FIELD_ENUMVAL (type, i); |
786 } | 822 } |
787 | 823 |
788 /* Set unsigned indicator if warranted. */ | 824 /* Set unsigned indicator if warranted. */ |
789 if (*lowp >= 0) | 825 if (*lowp >= 0) |
790 { | 826 { |
791 TYPE_UNSIGNED (type) = 1; | 827 TYPE_UNSIGNED (type) = 1; |
792 } | 828 } |
793 } | 829 } |
794 else | 830 else |
795 { | 831 { |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 TYPE_NFIELDS (type) = nargs; | 1122 TYPE_NFIELDS (type) = nargs; |
1087 if (varargs) | 1123 if (varargs) |
1088 TYPE_VARARGS (type) = 1; | 1124 TYPE_VARARGS (type) = 1; |
1089 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */ | 1125 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */ |
1090 TYPE_CODE (type) = TYPE_CODE_METHOD; | 1126 TYPE_CODE (type) = TYPE_CODE_METHOD; |
1091 } | 1127 } |
1092 | 1128 |
1093 /* Return a typename for a struct/union/enum type without "struct ", | 1129 /* Return a typename for a struct/union/enum type without "struct ", |
1094 "union ", or "enum ". If the type has a NULL name, return NULL. */ | 1130 "union ", or "enum ". If the type has a NULL name, return NULL. */ |
1095 | 1131 |
1096 char * | 1132 const char * |
1097 type_name_no_tag (const struct type *type) | 1133 type_name_no_tag (const struct type *type) |
1098 { | 1134 { |
1099 if (TYPE_TAG_NAME (type) != NULL) | 1135 if (TYPE_TAG_NAME (type) != NULL) |
1100 return TYPE_TAG_NAME (type); | 1136 return TYPE_TAG_NAME (type); |
1101 | 1137 |
1102 /* Is there code which expects this to return the name if there is | 1138 /* Is there code which expects this to return the name if there is |
1103 no tag name? My guess is that this is mainly used for C++ in | 1139 no tag name? My guess is that this is mainly used for C++ in |
1104 cases where the two will always be the same. */ | 1140 cases where the two will always be the same. */ |
1105 return TYPE_NAME (type); | 1141 return TYPE_NAME (type); |
1106 } | 1142 } |
(...skipping 27 matching lines...) Expand all Loading... |
1134 /* Lookup a typedef or primitive type named NAME, visible in lexical | 1170 /* Lookup a typedef or primitive type named NAME, visible in lexical |
1135 block BLOCK. If NOERR is nonzero, return zero if NAME is not | 1171 block BLOCK. If NOERR is nonzero, return zero if NAME is not |
1136 suitably defined. */ | 1172 suitably defined. */ |
1137 | 1173 |
1138 struct type * | 1174 struct type * |
1139 lookup_typename (const struct language_defn *language, | 1175 lookup_typename (const struct language_defn *language, |
1140 struct gdbarch *gdbarch, const char *name, | 1176 struct gdbarch *gdbarch, const char *name, |
1141 const struct block *block, int noerr) | 1177 const struct block *block, int noerr) |
1142 { | 1178 { |
1143 struct symbol *sym; | 1179 struct symbol *sym; |
1144 struct type *tmp; | 1180 struct type *type; |
1145 | 1181 |
1146 sym = lookup_symbol (name, block, VAR_DOMAIN, 0); | 1182 sym = lookup_symbol (name, block, VAR_DOMAIN, 0); |
1147 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF) | 1183 if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF) |
1148 { | 1184 return SYMBOL_TYPE (sym); |
1149 tmp = language_lookup_primitive_type_by_name (language, gdbarch, name); | 1185 |
1150 if (tmp) | 1186 type = language_lookup_primitive_type_by_name (language, gdbarch, name); |
1151 » { | 1187 if (type) |
1152 » return tmp; | 1188 return type; |
1153 » } | 1189 |
1154 else if (!tmp && noerr) | 1190 if (noerr) |
1155 » { | 1191 return NULL; |
1156 » return NULL; | 1192 error (_("No type named %s."), name); |
1157 » } | |
1158 else | |
1159 » { | |
1160 » error (_("No type named %s."), name); | |
1161 » } | |
1162 } | |
1163 return (SYMBOL_TYPE (sym)); | |
1164 } | 1193 } |
1165 | 1194 |
1166 struct type * | 1195 struct type * |
1167 lookup_unsigned_typename (const struct language_defn *language, | 1196 lookup_unsigned_typename (const struct language_defn *language, |
1168 » » » struct gdbarch *gdbarch, char *name) | 1197 » » » struct gdbarch *gdbarch, const char *name) |
1169 { | 1198 { |
1170 char *uns = alloca (strlen (name) + 10); | 1199 char *uns = alloca (strlen (name) + 10); |
1171 | 1200 |
1172 strcpy (uns, "unsigned "); | 1201 strcpy (uns, "unsigned "); |
1173 strcpy (uns + 9, name); | 1202 strcpy (uns + 9, name); |
1174 return lookup_typename (language, gdbarch, uns, (struct block *) NULL, 0); | 1203 return lookup_typename (language, gdbarch, uns, (struct block *) NULL, 0); |
1175 } | 1204 } |
1176 | 1205 |
1177 struct type * | 1206 struct type * |
1178 lookup_signed_typename (const struct language_defn *language, | 1207 lookup_signed_typename (const struct language_defn *language, |
1179 » » » struct gdbarch *gdbarch, char *name) | 1208 » » » struct gdbarch *gdbarch, const char *name) |
1180 { | 1209 { |
1181 struct type *t; | 1210 struct type *t; |
1182 char *uns = alloca (strlen (name) + 8); | 1211 char *uns = alloca (strlen (name) + 8); |
1183 | 1212 |
1184 strcpy (uns, "signed "); | 1213 strcpy (uns, "signed "); |
1185 strcpy (uns + 7, name); | 1214 strcpy (uns + 7, name); |
1186 t = lookup_typename (language, gdbarch, uns, (struct block *) NULL, 1); | 1215 t = lookup_typename (language, gdbarch, uns, (struct block *) NULL, 1); |
1187 /* If we don't find "signed FOO" just try again with plain "FOO". */ | 1216 /* If we don't find "signed FOO" just try again with plain "FOO". */ |
1188 if (t != NULL) | 1217 if (t != NULL) |
1189 return t; | 1218 return t; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1332 char *typename; | 1361 char *typename; |
1333 | 1362 |
1334 typename = type_name_no_tag (type); | 1363 typename = type_name_no_tag (type); |
1335 if (typename != NULL && strcmp (typename, name) == 0) | 1364 if (typename != NULL && strcmp (typename, name) == 0) |
1336 return type; | 1365 return type; |
1337 } | 1366 } |
1338 #endif | 1367 #endif |
1339 | 1368 |
1340 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--) | 1369 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--) |
1341 { | 1370 { |
1342 char *t_field_name = TYPE_FIELD_NAME (type, i); | 1371 const char *t_field_name = TYPE_FIELD_NAME (type, i); |
1343 | 1372 |
1344 if (t_field_name && (strcmp_iw (t_field_name, name) == 0)) | 1373 if (t_field_name && (strcmp_iw (t_field_name, name) == 0)) |
1345 { | 1374 { |
1346 return TYPE_FIELD_TYPE (type, i); | 1375 return TYPE_FIELD_TYPE (type, i); |
1347 } | 1376 } |
1348 else if (!t_field_name || *t_field_name == '\0') | 1377 else if (!t_field_name || *t_field_name == '\0') |
1349 { | 1378 { |
1350 struct type *subtype | 1379 struct type *subtype |
1351 = lookup_struct_elt_type (TYPE_FIELD_TYPE (type, i), name, 1); | 1380 = lookup_struct_elt_type (TYPE_FIELD_TYPE (type, i), name, 1); |
1352 | 1381 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1474 /* While we're removing typedefs, we don't want to lose qualifiers. | 1503 /* While we're removing typedefs, we don't want to lose qualifiers. |
1475 E.g., const/volatile. */ | 1504 E.g., const/volatile. */ |
1476 int instance_flags = TYPE_INSTANCE_FLAGS (type); | 1505 int instance_flags = TYPE_INSTANCE_FLAGS (type); |
1477 | 1506 |
1478 gdb_assert (type); | 1507 gdb_assert (type); |
1479 | 1508 |
1480 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) | 1509 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) |
1481 { | 1510 { |
1482 if (!TYPE_TARGET_TYPE (type)) | 1511 if (!TYPE_TARGET_TYPE (type)) |
1483 { | 1512 { |
1484 » char *name; | 1513 » const char *name; |
1485 struct symbol *sym; | 1514 struct symbol *sym; |
1486 | 1515 |
1487 /* It is dangerous to call lookup_symbol if we are currently | 1516 /* It is dangerous to call lookup_symbol if we are currently |
1488 reading a symtab. Infinite recursion is one danger. */ | 1517 reading a symtab. Infinite recursion is one danger. */ |
1489 if (currently_reading_symtab) | 1518 if (currently_reading_symtab) |
1490 return make_qualified_type (type, instance_flags, NULL); | 1519 return make_qualified_type (type, instance_flags, NULL); |
1491 | 1520 |
1492 name = type_name_no_tag (type); | 1521 name = type_name_no_tag (type); |
1493 /* FIXME: shouldn't we separately check the TYPE_NAME and | 1522 /* FIXME: shouldn't we separately check the TYPE_NAME and |
1494 the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or | 1523 the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1537 /* If this is a struct/class/union with no fields, then check | 1566 /* If this is a struct/class/union with no fields, then check |
1538 whether a full definition exists somewhere else. This is for | 1567 whether a full definition exists somewhere else. This is for |
1539 systems where a type definition with no fields is issued for such | 1568 systems where a type definition with no fields is issued for such |
1540 types, instead of identifying them as stub types in the first | 1569 types, instead of identifying them as stub types in the first |
1541 place. */ | 1570 place. */ |
1542 | 1571 |
1543 if (TYPE_IS_OPAQUE (type) | 1572 if (TYPE_IS_OPAQUE (type) |
1544 && opaque_type_resolution | 1573 && opaque_type_resolution |
1545 && !currently_reading_symtab) | 1574 && !currently_reading_symtab) |
1546 { | 1575 { |
1547 char *name = type_name_no_tag (type); | 1576 const char *name = type_name_no_tag (type); |
1548 struct type *newtype; | 1577 struct type *newtype; |
1549 | 1578 |
1550 if (name == NULL) | 1579 if (name == NULL) |
1551 { | 1580 { |
1552 stub_noname_complaint (); | 1581 stub_noname_complaint (); |
1553 return make_qualified_type (type, instance_flags, NULL); | 1582 return make_qualified_type (type, instance_flags, NULL); |
1554 } | 1583 } |
1555 newtype = lookup_transparent_type (name); | 1584 newtype = lookup_transparent_type (name); |
1556 | 1585 |
1557 if (newtype) | 1586 if (newtype) |
(...skipping 13 matching lines...) Expand all Loading... |
1571 TYPE_INSTANCE_FLAGS (type), | 1600 TYPE_INSTANCE_FLAGS (type), |
1572 type); | 1601 type); |
1573 else | 1602 else |
1574 type = newtype; | 1603 type = newtype; |
1575 } | 1604 } |
1576 } | 1605 } |
1577 /* Otherwise, rely on the stub flag being set for opaque/stubbed | 1606 /* Otherwise, rely on the stub flag being set for opaque/stubbed |
1578 types. */ | 1607 types. */ |
1579 else if (TYPE_STUB (type) && !currently_reading_symtab) | 1608 else if (TYPE_STUB (type) && !currently_reading_symtab) |
1580 { | 1609 { |
1581 char *name = type_name_no_tag (type); | 1610 const char *name = type_name_no_tag (type); |
1582 /* FIXME: shouldn't we separately check the TYPE_NAME and the | 1611 /* FIXME: shouldn't we separately check the TYPE_NAME and the |
1583 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN | 1612 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN |
1584 as appropriate? (this code was written before TYPE_NAME and | 1613 as appropriate? (this code was written before TYPE_NAME and |
1585 TYPE_TAG_NAME were separate). */ | 1614 TYPE_TAG_NAME were separate). */ |
1586 struct symbol *sym; | 1615 struct symbol *sym; |
1587 | 1616 |
1588 if (name == NULL) | 1617 if (name == NULL) |
1589 { | 1618 { |
1590 stub_noname_complaint (); | 1619 stub_noname_complaint (); |
1591 return make_qualified_type (type, instance_flags, NULL); | 1620 return make_qualified_type (type, instance_flags, NULL); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1668 return type; | 1697 return type; |
1669 } | 1698 } |
1670 | 1699 |
1671 /* Parse a type expression in the string [P..P+LENGTH). If an error | 1700 /* Parse a type expression in the string [P..P+LENGTH). If an error |
1672 occurs, silently return a void type. */ | 1701 occurs, silently return a void type. */ |
1673 | 1702 |
1674 static struct type * | 1703 static struct type * |
1675 safe_parse_type (struct gdbarch *gdbarch, char *p, int length) | 1704 safe_parse_type (struct gdbarch *gdbarch, char *p, int length) |
1676 { | 1705 { |
1677 struct ui_file *saved_gdb_stderr; | 1706 struct ui_file *saved_gdb_stderr; |
1678 struct type *type; | 1707 struct type *type = NULL; /* Initialize to keep gcc happy. */ |
| 1708 volatile struct gdb_exception except; |
1679 | 1709 |
1680 /* Suppress error messages. */ | 1710 /* Suppress error messages. */ |
1681 saved_gdb_stderr = gdb_stderr; | 1711 saved_gdb_stderr = gdb_stderr; |
1682 gdb_stderr = ui_file_new (); | 1712 gdb_stderr = ui_file_new (); |
1683 | 1713 |
1684 /* Call parse_and_eval_type() without fear of longjmp()s. */ | 1714 /* Call parse_and_eval_type() without fear of longjmp()s. */ |
1685 if (!gdb_parse_and_eval_type (p, length, &type)) | 1715 TRY_CATCH (except, RETURN_MASK_ERROR) |
| 1716 { |
| 1717 type = parse_and_eval_type (p, length); |
| 1718 } |
| 1719 |
| 1720 if (except.reason < 0) |
1686 type = builtin_type (gdbarch)->builtin_void; | 1721 type = builtin_type (gdbarch)->builtin_void; |
1687 | 1722 |
1688 /* Stop suppressing error messages. */ | 1723 /* Stop suppressing error messages. */ |
1689 ui_file_delete (gdb_stderr); | 1724 ui_file_delete (gdb_stderr); |
1690 gdb_stderr = saved_gdb_stderr; | 1725 gdb_stderr = saved_gdb_stderr; |
1691 | 1726 |
1692 return type; | 1727 return type; |
1693 } | 1728 } |
1694 | 1729 |
1695 /* Ugly hack to convert method stubs into method types. | 1730 /* Ugly hack to convert method stubs into method types. |
(...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2885 TYPE_FN_FIELD_STUB (f, overload_idx)); | 2920 TYPE_FN_FIELD_STUB (f, overload_idx)); |
2886 printfi_filtered (spaces + 8, "voffset %u\n", | 2921 printfi_filtered (spaces + 8, "voffset %u\n", |
2887 TYPE_FN_FIELD_VOFFSET (f, overload_idx)); | 2922 TYPE_FN_FIELD_VOFFSET (f, overload_idx)); |
2888 } | 2923 } |
2889 } | 2924 } |
2890 } | 2925 } |
2891 | 2926 |
2892 static void | 2927 static void |
2893 print_cplus_stuff (struct type *type, int spaces) | 2928 print_cplus_stuff (struct type *type, int spaces) |
2894 { | 2929 { |
error: old chunk mismatch |
None
OLD | NEW |