From ec16f7015b91a7324011b41f6a13dfab0fd5d21a Mon Sep 17 00:00:00 2001 From: Fred Fish Date: Tue, 19 Jan 1993 23:00:19 +0000 Subject: [PATCH] * c-exp.y (exp): Add production to support direct creation of array constants using the obvious syntax. * c-valprint.c (c_val_print): Set printed string length. * dwarfread.c (read_tag_string_type): New prototype and function that handles TAG_string_type DIEs. * dwarfread.c (process_dies): Add case for TAG_string_type that calls new read_tag_string_type function. * expprint.c (print_subexp): Add support for OP_ARRAY. * gdbtypes.c (create_range_type, create_array_type): Inherit objfile from the index type. **** start-sanitize-chill **** * ch-typeprint.c (chill_print_type): Add case for TYPE_CODE_STRING. * ch-valprint.c (chill_val_print): Fix case for TYPE_CODE_STRING. **** end-sanitize-chill **** --- gdb/c-exp.y | 11 ++++++++++ gdb/c-valprint.c | 1 + gdb/ch-typeprint.c | 10 +++++++++ gdb/ch-valprint.c | 12 ++++------- gdb/dwarfread.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ gdb/gdbtypes.c | 14 ++++++++----- 6 files changed, 95 insertions(+), 13 deletions(-) diff --git a/gdb/c-exp.y b/gdb/c-exp.y index bca3d6d..a7f7320 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -318,6 +318,17 @@ arglist : arglist ',' exp %prec ABOVE_COMMA { arglist_len++; } ; +exp : '{' + /* This is to save the value of arglist_len + being accumulated by an outer function call. */ + { start_arglist (); } + arglist '}' %prec ARROW + { write_exp_elt_opcode (OP_ARRAY); + write_exp_elt_longcst ((LONGEST) 0); + write_exp_elt_longcst ((LONGEST) end_arglist () - 1); + write_exp_elt_opcode (OP_ARRAY); } + ; + exp : '{' type '}' exp %prec UNARY { write_exp_elt_opcode (UNOP_MEMVAL); write_exp_elt_type ($2); diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c index 2d13db2..1df8228 100644 --- a/gdb/c-valprint.c +++ b/gdb/c-valprint.c @@ -118,6 +118,7 @@ c_val_print (type, valaddr, address, stream, format, deref_ref, recurse, fprintf_filtered (stream, "0x%x ", address); } LA_PRINT_STRING (stream, valaddr, len, 0); + i = len; } else { diff --git a/gdb/ch-typeprint.c b/gdb/ch-typeprint.c index cd3dd36..f4119ca 100644 --- a/gdb/ch-typeprint.c +++ b/gdb/ch-typeprint.c @@ -70,6 +70,16 @@ chill_print_type (type, varstring, stream, show, level) fputs_filtered (") ", stream); chill_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level); break; + + case TYPE_CODE_STRING: + range_type = TYPE_FIELD_TYPE (type, 0); + index_type = TYPE_TARGET_TYPE (range_type); + high_bound = TYPE_FIELD_BITPOS (range_type, 1); + fputs_filtered ("char (", stream); + print_type_scalar (index_type, high_bound + 1, stream); + fputs_filtered (") ", stream); + break; + default: chill_print_type_base (type, stream, show, level); break; diff --git a/gdb/ch-valprint.c b/gdb/ch-valprint.c index c465fc3..37730b4 100644 --- a/gdb/ch-valprint.c +++ b/gdb/ch-valprint.c @@ -52,7 +52,7 @@ chill_val_print (type, valaddr, address, stream, format, deref_ref, recurse, enum val_prettyprint pretty; { LONGEST val; - unsigned int i; + unsigned int i = 0; /* Number of characters printed. */ struct type *elttype; unsigned eltlen; CORE_ADDR addr; @@ -156,7 +156,6 @@ chill_val_print (type, valaddr, address, stream, format, deref_ref, recurse, /* For a pointer to char or unsigned char, also print the string pointed to, unless pointer is null. */ - i = 0; /* Number of characters printed. */ if (TYPE_LENGTH (elttype) == 1 && TYPE_CODE (elttype) == TYPE_CODE_CHAR && (format == 0 || format == 's') @@ -178,15 +177,12 @@ chill_val_print (type, valaddr, address, stream, format, deref_ref, recurse, print_scalar_formatted (valaddr, type, format, 0, stream); break; } - addr = unpack_pointer (lookup_pointer_type (builtin_type_char), valaddr); if (addressprint && format != 's') { - fprintf_filtered (stream, "0x%x", addr); - } - if (addr != 0) - { - i = val_print_string (addr, TYPE_LENGTH (type), stream); + fprintf_filtered (stream, "0x%x ", addr); } + i = TYPE_LENGTH (type); + LA_PRINT_STRING (stream, valaddr, i, 0); /* Return number of characters printed, plus one for the terminating null if we have "reached the end". */ return (i + (print_max && i != print_max)); diff --git a/gdb/dwarfread.c b/gdb/dwarfread.c index 3da9e76..688976a 100644 --- a/gdb/dwarfread.c +++ b/gdb/dwarfread.c @@ -523,6 +523,9 @@ static void read_tag_pointer_type PARAMS ((struct dieinfo *dip)); static void +read_tag_string_type PARAMS ((struct dieinfo *dip)); + +static void read_subroutine_type PARAMS ((struct dieinfo *, char *, char *)); static void @@ -1526,6 +1529,60 @@ read_tag_pointer_type (dip) LOCAL FUNCTION + read_tag_string_type -- read TAG_string_type DIE + +SYNOPSIS + + static void read_tag_string_type (struct dieinfo *dip) + +DESCRIPTION + + Extract all information from a TAG_string_type DIE and add to + the user defined type vector. It isn't really a user defined + type, but it behaves like one, with other DIE's using an + AT_user_def_type attribute to reference it. + */ + +static void +read_tag_string_type (dip) + struct dieinfo *dip; +{ + struct type *utype; + struct type *indextype; + struct type *rangetype; + unsigned long lowbound = 0; + unsigned long highbound; + + if ((utype = lookup_utype (dip -> die_ref)) != NULL) + { + /* Ack, someone has stuck a type in the slot we want. Complain + about it. */ + complain (&dup_user_type_definition, DIE_ID, DIE_NAME); + } + else + { + if (dip -> has_at_byte_size) + { + /* A fixed bounds string */ + highbound = dip -> at_byte_size - 1; + } + else + { + /* A varying length string. Stub for now. (FIXME) */ + highbound = 1; + } + indextype = dwarf_fundamental_type (current_objfile, FT_INTEGER); + rangetype = create_range_type ((struct type *) NULL, indextype, + lowbound, highbound); + utype = create_string_type ((struct type *) NULL, rangetype); + alloc_utype (dip -> die_ref, utype); + } +} + +/* + +LOCAL FUNCTION + read_subroutine_type -- process TAG_subroutine_type dies SYNOPSIS @@ -2011,6 +2068,9 @@ process_dies (thisdie, enddie, objfile) case TAG_pointer_type: read_tag_pointer_type (&di); break; + case TAG_string_type: + read_tag_string_type (&di); + break; default: new_symbol (&di, objfile); break; diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 525c515..b5caccf 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -314,8 +314,10 @@ allocate_stub_method (type) } /* Create a range type using either a blank type supplied in RESULT_TYPE, - or creating a new type. Indices will be of type INDEX_TYPE, and will - range from LOW_BOUND to HIGH_BOUND, inclusive. + or creating a new type, inheriting the objfile from INDEX_TYPE. + + Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to + HIGH_BOUND, inclusive. FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make sure it is TYPE_CODE_UNDEF before we bash it into a range type? */ @@ -348,8 +350,10 @@ create_range_type (result_type, index_type, low_bound, high_bound) /* Create an array type using either a blank type supplied in RESULT_TYPE, - or creating a new type. Elements will be of type ELEMENT_TYPE, the - indices will be of type RANGE_TYPE. + or creating a new type, inheriting the objfile from RANGE_TYPE. + + Elements will be of type ELEMENT_TYPE, the indices will be of type + RANGE_TYPE. FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make sure it is TYPE_CODE_UNDEF before we bash it into an array type? */ @@ -374,7 +378,7 @@ create_array_type (result_type, element_type, range_type) } if (result_type == NULL) { - result_type = alloc_type (TYPE_OBJFILE (element_type)); + result_type = alloc_type (TYPE_OBJFILE (range_type)); } TYPE_CODE (result_type) = TYPE_CODE_ARRAY; TYPE_TARGET_TYPE (result_type) = element_type; -- 2.7.4