diff options
author | Fred Fish <fnf@specifix.com> | 1992-12-15 02:52:11 +0000 |
---|---|---|
committer | Fred Fish <fnf@specifix.com> | 1992-12-15 02:52:11 +0000 |
commit | 85f0a8484fae7fc4f28b85298253e786645a5b6a (patch) | |
tree | 723472495b0c8155f5eb698d4bbb08cb935ebc69 /gdb/dwarfread.c | |
parent | 7f70a2756406d76578fc4a6af98c42fd85f28b12 (diff) | |
download | gdb-85f0a8484fae7fc4f28b85298253e786645a5b6a.zip gdb-85f0a8484fae7fc4f28b85298253e786645a5b6a.tar.gz gdb-85f0a8484fae7fc4f28b85298253e786645a5b6a.tar.bz2 |
* gdbtypes.c (create_array_type): Complete rewrite. Now requires
a optional type to decorate as an array type, the type of the
index, and the bounds of the array. Records this additional info
in the array type for use with languages with nonzero array
bounds.
* gdbtypes.h (enum type_code): Update comment for TYPE_CODE_ARRAY
to note that arrays may have bounds.
* gdbtypes.h (create_array_type): Update prototype.
* c-exp.y (ptype production): Adjust for new create_array_type
calling conventions.
* coffread.c (decode_type): Call create_array_type rather than
handcrafting array types.
* convex-tdep.c (value_type): Remove, now use create_array_type.
* convex-tdep.c (value_of_trapped_internalvar): Convert calls to
vector_type into calls to create_array_type.
* dwarfread.c (decode_subscr_data): Name changed to
decode_subscript_data_item throughout.
* dwarfread.c (decode_subscript_data_item): Rewrite to use
create_array_type. Now records index type and range as well.
* dwarfread.c (dwarf_read_array_type): Rewrite as part of
change to use create_array_type.
* dwarfread.c (read_subroutine_type): Test existing user defined
types before decorating them, to ensure they are blank, and
complain about it if they are not.
* dwarfread.c (decode_fund_type): For unrecognized types, always
return some valid type (type integer). If the unrecognized type
cannot be an implementation defined type, complain as well.
* m88k-tdep.c (pushed_size): Update comment for TYPE_CODE_ARRAY.
* m88k-tdep.c (store_param): Update comment for TYPE_CODE_ARRAY.
* mipsread.c (upgrade_type): Add FIXME comment that code to
handcraft arrays should be replaced with call to create_array_type.
* stabsread.c (read_array_type): Replace code to handcraft
array types with call to create_array_type.
* valprint.c (type_print_varspec_prefix): Minor formatting
change, join lines that don't need to be split.
Diffstat (limited to 'gdb/dwarfread.c')
-rw-r--r-- | gdb/dwarfread.c | 118 |
1 files changed, 71 insertions, 47 deletions
diff --git a/gdb/dwarfread.c b/gdb/dwarfread.c index df9d72d..6d63543 100644 --- a/gdb/dwarfread.c +++ b/gdb/dwarfread.c @@ -413,7 +413,7 @@ static struct type * decode_array_element_type PARAMS ((char *)); static struct type * -decode_subscr_data PARAMS ((char *, char *)); +decode_subscript_data_item PARAMS ((char *, char *)); static void dwarf_read_array_type PARAMS ((struct dieinfo *)); @@ -1249,11 +1249,12 @@ decode_array_element_type (scan) LOCAL FUNCTION - decode_subscr_data -- decode array subscript and element type data + decode_subscript_data_item -- decode array subscript item SYNOPSIS - static struct type *decode_subscr_data (char *scan, char *end) + static struct type * + decode_subscript_data_item (char *scan, char *end) DESCRIPTION @@ -1265,9 +1266,21 @@ DESCRIPTION source (I.E. leftmost dimension first, next to leftmost second, etc). + The data items describing each array dimension consist of four + parts: (1) a format specifier, (2) type type of the subscript + index, (3) a description of the low bound of the array dimension, + and (4) a description of the high bound of the array dimension. + + The last data item is the description of the type of each of + the array elements. + We are passed a pointer to the start of the block of bytes - containing the data items, and a pointer to the first byte past - the data. This function decodes the data and returns a type. + containing the remaining data items, and a pointer to the first + byte past the data. This function recursively decodes the + remaining data items and returns a type. + + If we somehow fail to decode some data, we complain about it + and return a type "array of int". BUGS FIXME: This code only implements the forms currently used @@ -1278,12 +1291,13 @@ BUGS */ static struct type * -decode_subscr_data (scan, end) +decode_subscript_data_item (scan, end) char *scan; char *end; { - struct type *typep = NULL; - struct type *nexttype; + struct type *typep = NULL; /* Array type we are building */ + struct type *nexttype; /* Type of each element (may be array) */ + struct type *indextype; /* Type of this index */ unsigned int format; unsigned short fundtype; unsigned long lowbound; @@ -1299,26 +1313,24 @@ decode_subscr_data (scan, end) typep = decode_array_element_type (scan); break; case FMT_FT_C_C: - /* Read the type of the index, but don't do anything with it. - FIXME: This is OK for C since only int's are allowed. - It might not be OK for other languages. */ fundtype = target_to_host (scan, SIZEOF_FMT_FT, GET_UNSIGNED, current_objfile); + indextype = decode_fund_type (fundtype); scan += SIZEOF_FMT_FT; nbytes = TARGET_FT_LONG_SIZE (current_objfile); lowbound = target_to_host (scan, nbytes, GET_UNSIGNED, current_objfile); scan += nbytes; highbound = target_to_host (scan, nbytes, GET_UNSIGNED, current_objfile); scan += nbytes; - nexttype = decode_subscr_data (scan, end); - if (nexttype != NULL) + nexttype = decode_subscript_data_item (scan, end); + if (nexttype == NULL) { - typep = alloc_type (current_objfile); - TYPE_CODE (typep) = TYPE_CODE_ARRAY; - TYPE_LENGTH (typep) = TYPE_LENGTH (nexttype); - TYPE_LENGTH (typep) *= (highbound - lowbound) + 1; - TYPE_TARGET_TYPE (typep) = nexttype; - } + /* Munged subscript data or other problem, fake it. */ + SQUAWK (("can't decode subscript data items")); + nexttype = dwarf_fundamental_type (current_objfile, FT_INTEGER); + } + typep = create_array_type ((struct type *) NULL, nexttype, indextype, + lowbound, highbound); break; case FMT_FT_C_X: case FMT_FT_X_C: @@ -1328,9 +1340,13 @@ decode_subscr_data (scan, end) case FMT_UT_X_C: case FMT_UT_X_X: SQUAWK (("array subscript format 0x%x not handled yet", format)); + typep = dwarf_fundamental_type (current_objfile, FT_INTEGER); + typep = create_array_type ((struct type *) NULL, typep, typep, 0, 1); break; default: SQUAWK (("unknown array subscript format %x", format)); + typep = dwarf_fundamental_type (current_objfile, FT_INTEGER); + typep = create_array_type ((struct type *) NULL, typep, typep, 0, 1); break; } return (typep); @@ -1374,30 +1390,29 @@ dwarf_read_array_type (dip) blocksz = target_to_host (sub, nbytes, GET_UNSIGNED, current_objfile); subend = sub + nbytes + blocksz; sub += nbytes; - type = decode_subscr_data (sub, subend); - if (type == NULL) + type = decode_subscript_data_item (sub, subend); + if ((utype = lookup_utype (dip -> die_ref)) == NULL) { - if ((utype = lookup_utype (dip -> die_ref)) == NULL) - { - utype = alloc_utype (dip -> die_ref, NULL); - } - TYPE_CODE (utype) = TYPE_CODE_ARRAY; - TYPE_TARGET_TYPE (utype) = - dwarf_fundamental_type (current_objfile, FT_INTEGER); - TYPE_LENGTH (utype) = 1 * TYPE_LENGTH (TYPE_TARGET_TYPE (utype)); + /* Install user defined type that has not been referenced yet. */ + alloc_utype (dip -> die_ref, type); + } + else if (TYPE_CODE (utype) == TYPE_CODE_UNDEF) + { + /* Ick! A forward ref has already generated a blank type in our + slot, and this type probably already has things pointing to it + (which is what caused it to be created in the first place). + If it's just a place holder we can plop our fully defined type + on top of it. We can't recover the space allocated for our + new type since it might be on an obstack, but we could reuse + it if we kept a list of them, but it might not be worth it + (FIXME). */ + *utype = *type; } else { - if ((utype = lookup_utype (dip -> die_ref)) == NULL) - { - alloc_utype (dip -> die_ref, type); - } - else - { - TYPE_CODE (utype) = TYPE_CODE_ARRAY; - TYPE_LENGTH (utype) = TYPE_LENGTH (type); - TYPE_TARGET_TYPE (utype) = TYPE_TARGET_TYPE (type); - } + /* Double ick! Not only is a type already in our slot, but + someone has decorated it. Complain and leave it alone. */ + SQUAWK (("duplicate user defined array type definition")); } } } @@ -1495,7 +1510,7 @@ read_subroutine_type (dip, thisdie, enddie) ftype = lookup_function_type (type); alloc_utype (dip -> die_ref, ftype); } - else + else if (TYPE_CODE (ftype) == TYPE_CODE_UNDEF) { /* We have an existing partially constructed type, so bash it into the correct type. */ @@ -1504,6 +1519,10 @@ read_subroutine_type (dip, thisdie, enddie) TYPE_LENGTH (ftype) = 1; TYPE_CODE (ftype) = TYPE_CODE_FUNC; } + else + { + SQUAWK (("duplicate user defined function type definition")); + } } /* @@ -3197,10 +3216,12 @@ DESCRIPTION NOTES - If we encounter a fundamental type that we are unprepared to - deal with, and it is not in the range of those types defined - as application specific types, then we issue a warning and - treat the type as an "int". + For robustness, if we are asked to translate a fundamental + type that we are unprepared to deal with, we return int so + callers can always depend upon a valid type being returned, + and so gdb may at least do something reasonable by default. + If the type is not in the range of those types defined as + application specific types, we also issue a warning. */ static struct type * @@ -3311,10 +3332,13 @@ decode_fund_type (fundtype) } - if ((typep == NULL) && !(FT_lo_user <= fundtype && fundtype <= FT_hi_user)) + if (typep == NULL) { - SQUAWK (("unexpected fundamental type 0x%x", fundtype)); - typep = dwarf_fundamental_type (current_objfile, FT_VOID); + typep = dwarf_fundamental_type (current_objfile, FT_INTEGER); + if (!(FT_lo_user <= fundtype && fundtype <= FT_hi_user)) + { + SQUAWK (("unexpected fundamental type 0x%x", fundtype)); + } } return (typep); |