diff options
author | Fred Fish <fnf@specifix.com> | 1993-01-16 05:15:58 +0000 |
---|---|---|
committer | Fred Fish <fnf@specifix.com> | 1993-01-16 05:15:58 +0000 |
commit | c4413e2c9b9e257a93b4370c5e4e976c768b9e9a (patch) | |
tree | 2a5d96fdb815d54e5d8d800918fe16e06471d816 /gdb | |
parent | 7d9f0c54d614f654124963d8e1b48fd884b92f24 (diff) | |
download | gdb-c4413e2c9b9e257a93b4370c5e4e976c768b9e9a.zip gdb-c4413e2c9b9e257a93b4370c5e4e976c768b9e9a.tar.gz gdb-c4413e2c9b9e257a93b4370c5e4e976c768b9e9a.tar.bz2 |
* c-exp.y (exp:STRING): Convert C strings into array-of-char
constants with an explicit null byte terminator. OP_STRING is
now used for real string types.
* c-lang.c (builtin_type_*): Move declarations to lang.c since
they are used by all languages.
* c-lang.c (_initialize_c_language): Move initializations of
builtin_type_* to lang.c.
* c-typeprint.c (c_type_print_varspec_prefix,
c_type_print_varspec_suffix): TYPE_CODE_PASCAL_ARRAY renamed
to TYPE_CODE_STRING.
* c-valprint.c (c_val_print): Change the way character arrays
are printed as strings to be consistent with the way strings
are printed when pointer-to-char types are dereferenced.
Remove test of print_max before calling val_print_string, which
now does it's own test.
* eval.c (evaluate_subexp): Add case for OP_ARRAY.
* expprint.c (print_subexp, dump_expression): Add case for OP_ARRAY.
* expression.h (enum exp_opcode): Add OP_ARRAY and document.
* gdbtypes.c (builtin_type_*): Add declarations moved from
c-lang.c.
* gdbtypes.c (create_string_type): New function to create real
string types.
* gdbtypes.c (recursive_dump_type): TYPE_CODE_PASCAL_ARRAY
renamed to TYPE_CODE_STRING.
* gdbtypes.c (_initialize_gdbtypes): Add initializations of
builtin_type_* types moved from c-lang.c.
* gdbtypes.h (enum type_code): TYPE_CODE_PASCAL_ARRAY renamed
to TYPE_CODE_STRING.
* gdbtypes.h (builtin_type_string): Add extern declaration.
* gdbtypes.h (create_string_type): Add prototype.
* m2-lang.c (m2_create_fundamental_type): TYPE_CODE_PASCAL_ARRAY
renamed to TYPE_CODE_STRING.
* m88k-tdep.c (pushed_size): TYPE_CODE_PASCAL_ARRAY renamed to
TYPE_CODE_STRING.
* mipsread.c (_initialize_mipsread): TYPE_CODE_PASCAL_ARRAY
renamed to TYPE_CODE_STRING.
* parse.c (length_of_subexp, prefixify_subexp): Add case for
OP_ARRAY.
* printcmd.c (print_formatted): Recognize TYPE_CODE_STRING.
* typeprint.c (print_type_scalar): TYPE_CODE_PASCAL_ARRAY renamed
to TYPE_CODE_STRING.
* valops.c (allocate_space_in_inferior): New function and
prototype, using code ripped out of value_string.
* valops.c (value_string): Rewritten to use new function
allocate_space_in_inferior, but temporarily disabled until some
other support is in place.
* valops.c (value_array): New function to create array constants.
* valprint.c (val_print_string): Add comment to document use,
complete rewrite to fix several small buglets.
* value.h (value_array): Add prototype.
* value.h (val_print_string): Change prototype to match rewrite.
**** start-sanitize-chill ****
* ch-valprint.c (chill_val_print): Add case for TYPE_CODE_STRING.
* ch-exp.y (match_character_literal): Disable recognition of
control sequence form of character literals and document why.
**** end-sanitize-chill ****
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 59 | ||||
-rw-r--r-- | gdb/c-exp.y | 24 | ||||
-rw-r--r-- | gdb/c-lang.c | 90 | ||||
-rw-r--r-- | gdb/c-typeprint.c | 4 | ||||
-rw-r--r-- | gdb/c-valprint.c | 30 | ||||
-rw-r--r-- | gdb/ch-exp.y | 7 | ||||
-rw-r--r-- | gdb/ch-valprint.c | 20 | ||||
-rw-r--r-- | gdb/expprint.c | 20 | ||||
-rw-r--r-- | gdb/gdbtypes.c | 123 | ||||
-rw-r--r-- | gdb/gdbtypes.h | 6 | ||||
-rw-r--r-- | gdb/m2-lang.c | 2 | ||||
-rw-r--r-- | gdb/m88k-tdep.c | 2 | ||||
-rw-r--r-- | gdb/mipsread.c | 34 | ||||
-rw-r--r-- | gdb/parse.c | 14 | ||||
-rw-r--r-- | gdb/typeprint.c | 2 | ||||
-rw-r--r-- | gdb/values.c | 3 |
16 files changed, 303 insertions, 137 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 40540d6..e68647a 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,62 @@ +Fri Jan 15 20:26:50 1993 Fred Fish (fnf@cygnus.com) + + * c-exp.y (exp:STRING): Convert C strings into array-of-char + constants with an explicit null byte terminator. OP_STRING is + now used for real string types. + * c-lang.c (builtin_type_*): Move declarations to lang.c since + they are used by all languages. + * c-lang.c (_initialize_c_language): Move initializations of + builtin_type_* to lang.c. + * c-typeprint.c (c_type_print_varspec_prefix, + c_type_print_varspec_suffix): TYPE_CODE_PASCAL_ARRAY renamed + to TYPE_CODE_STRING. + * c-valprint.c (c_val_print): Change the way character arrays + are printed as strings to be consistent with the way strings + are printed when pointer-to-char types are dereferenced. + Remove test of print_max before calling val_print_string, which + now does it's own test. + * eval.c (evaluate_subexp): Add case for OP_ARRAY. + * expprint.c (print_subexp, dump_expression): Add case for OP_ARRAY. + * expression.h (enum exp_opcode): Add OP_ARRAY and document. + * gdbtypes.c (builtin_type_*): Add declarations moved from + c-lang.c. + * gdbtypes.c (create_string_type): New function to create real + string types. + * gdbtypes.c (recursive_dump_type): TYPE_CODE_PASCAL_ARRAY + renamed to TYPE_CODE_STRING. + * gdbtypes.c (_initialize_gdbtypes): Add initializations of + builtin_type_* types moved from c-lang.c. + * gdbtypes.h (enum type_code): TYPE_CODE_PASCAL_ARRAY renamed + to TYPE_CODE_STRING. + * gdbtypes.h (builtin_type_string): Add extern declaration. + * gdbtypes.h (create_string_type): Add prototype. + * m2-lang.c (m2_create_fundamental_type): TYPE_CODE_PASCAL_ARRAY + renamed to TYPE_CODE_STRING. + * m88k-tdep.c (pushed_size): TYPE_CODE_PASCAL_ARRAY renamed to + TYPE_CODE_STRING. + * mipsread.c (_initialize_mipsread): TYPE_CODE_PASCAL_ARRAY + renamed to TYPE_CODE_STRING. + * parse.c (length_of_subexp, prefixify_subexp): Add case for + OP_ARRAY. + * printcmd.c (print_formatted): Recognize TYPE_CODE_STRING. + * typeprint.c (print_type_scalar): TYPE_CODE_PASCAL_ARRAY renamed + to TYPE_CODE_STRING. + * valops.c (allocate_space_in_inferior): New function and + prototype, using code ripped out of value_string. + * valops.c (value_string): Rewritten to use new function + allocate_space_in_inferior, but temporarily disabled until some + other support is in place. + * valops.c (value_array): New function to create array constants. + * valprint.c (val_print_string): Add comment to document use, + complete rewrite to fix several small buglets. + * value.h (value_array): Add prototype. + * value.h (val_print_string): Change prototype to match rewrite. + **** start-sanitize-chill **** + * ch-valprint.c (chill_val_print): Add case for TYPE_CODE_STRING. + * ch-exp.y (match_character_literal): Disable recognition of + control sequence form of character literals and document why. + **** end-sanitize-chill **** + Thu Jan 14 15:48:12 1993 Stu Grossman (grossman at cygnus.com) * nindy-share/nindy.c: Add comments to #endif's to clarify diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 21df46d..bca3d6d 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -480,9 +480,27 @@ exp : SIZEOF '(' type ')' %prec UNARY ; exp : STRING - { write_exp_elt_opcode (OP_STRING); - write_exp_string ($1); - write_exp_elt_opcode (OP_STRING); } + { /* C strings are converted into array constants with + an explicit null byte added at the end. Thus + the array upper bound is the string length. + There is no such thing in C as a completely empty + string. */ + char *sp = $1.ptr; int count = $1.length; + while (count-- > 0) + { + write_exp_elt_opcode (OP_LONG); + write_exp_elt_type (builtin_type_char); + write_exp_elt_longcst ((LONGEST)(*sp++)); + write_exp_elt_opcode (OP_LONG); + } + write_exp_elt_opcode (OP_LONG); + write_exp_elt_type (builtin_type_char); + write_exp_elt_longcst ((LONGEST)'\0'); + write_exp_elt_opcode (OP_LONG); + write_exp_elt_opcode (OP_ARRAY); + write_exp_elt_longcst ((LONGEST) 0); + write_exp_elt_longcst ((LONGEST) ($1.length)); + write_exp_elt_opcode (OP_ARRAY); } ; /* C++. */ diff --git a/gdb/c-lang.c b/gdb/c-lang.c index 5aa48a2..df88210 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -363,27 +363,6 @@ static const struct op_print c_op_print_tab[] = {NULL, 0, 0, 0} }; -/* These variables point to the objects - representing the predefined C data types. */ - -struct type *builtin_type_void; -struct type *builtin_type_char; -struct type *builtin_type_short; -struct type *builtin_type_int; -struct type *builtin_type_long; -struct type *builtin_type_long_long; -struct type *builtin_type_signed_char; -struct type *builtin_type_unsigned_char; -struct type *builtin_type_unsigned_short; -struct type *builtin_type_unsigned_int; -struct type *builtin_type_unsigned_long; -struct type *builtin_type_unsigned_long_long; -struct type *builtin_type_float; -struct type *builtin_type_double; -struct type *builtin_type_long_double; -struct type *builtin_type_complex; -struct type *builtin_type_double_complex; - struct type ** const (c_builtin_types[]) = { &builtin_type_int, @@ -457,75 +436,6 @@ const struct language_defn cplus_language_defn = { void _initialize_c_language () { - builtin_type_void = - init_type (TYPE_CODE_VOID, 1, - 0, - "void", (struct objfile *) NULL); - builtin_type_char = - init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, - 0, - "char", (struct objfile *) NULL); - builtin_type_signed_char = - init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, - TYPE_FLAG_SIGNED, - "signed char", (struct objfile *) NULL); - builtin_type_unsigned_char = - init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, - TYPE_FLAG_UNSIGNED, - "unsigned char", (struct objfile *) NULL); - builtin_type_short = - init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT, - 0, - "short", (struct objfile *) NULL); - builtin_type_unsigned_short = - init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT, - TYPE_FLAG_UNSIGNED, - "unsigned short", (struct objfile *) NULL); - builtin_type_int = - init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, - 0, - "int", (struct objfile *) NULL); - builtin_type_unsigned_int = - init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, - TYPE_FLAG_UNSIGNED, - "unsigned int", (struct objfile *) NULL); - builtin_type_long = - init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, - 0, - "long", (struct objfile *) NULL); - builtin_type_unsigned_long = - init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, - TYPE_FLAG_UNSIGNED, - "unsigned long", (struct objfile *) NULL); - builtin_type_long_long = - init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, - 0, - "long long", (struct objfile *) NULL); - builtin_type_unsigned_long_long = - init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, - TYPE_FLAG_UNSIGNED, - "unsigned long long", (struct objfile *) NULL); - builtin_type_float = - init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT, - 0, - "float", (struct objfile *) NULL); - builtin_type_double = - init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, - 0, - "double", (struct objfile *) NULL); - builtin_type_long_double = - init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, - 0, - "long double", (struct objfile *) NULL); - builtin_type_complex = - init_type (TYPE_CODE_FLT, TARGET_COMPLEX_BIT / TARGET_CHAR_BIT, - 0, - "complex", (struct objfile *) NULL); - builtin_type_double_complex = - init_type (TYPE_CODE_FLT, TARGET_DOUBLE_COMPLEX_BIT / TARGET_CHAR_BIT, - 0, - "double complex", (struct objfile *) NULL); - add_language (&c_language_defn); add_language (&cplus_language_defn); } diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c index 40e3f52..1740a06 100644 --- a/gdb/c-typeprint.c +++ b/gdb/c-typeprint.c @@ -307,7 +307,7 @@ c_type_print_varspec_prefix (type, stream, show, passed_a_ptr) case TYPE_CODE_BOOL: case TYPE_CODE_SET: case TYPE_CODE_RANGE: - case TYPE_CODE_PASCAL_ARRAY: + case TYPE_CODE_STRING: /* These types need no prefix. They are listed here so that gcc -Wall will reveal any types that haven't been handled. */ break; @@ -430,7 +430,7 @@ c_type_print_varspec_suffix (type, stream, show, passed_a_ptr, demangled_args) case TYPE_CODE_BOOL: case TYPE_CODE_SET: case TYPE_CODE_RANGE: - case TYPE_CODE_PASCAL_ARRAY: + case TYPE_CODE_STRING: /* These types do not need a suffix. They are listed so that gcc -Wall will report types that may not have been considered. */ break; diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c index 4b7da62..2d13db2 100644 --- a/gdb/c-valprint.c +++ b/gdb/c-valprint.c @@ -89,12 +89,13 @@ c_val_print (type, valaddr, address, stream, format, deref_ref, recurse, int recurse; enum val_prettyprint pretty; { - register unsigned int i; + register unsigned int i = 0; /* Number of characters printed */ unsigned len; struct type *elttype; unsigned eltlen; LONGEST val; unsigned char c; + CORE_ADDR addr; switch (TYPE_CODE (type)) { @@ -108,15 +109,19 @@ c_val_print (type, valaddr, address, stream, format, deref_ref, recurse, { print_spaces_filtered (2 + 2 * recurse, stream); } - fprintf_filtered (stream, "{"); /* For an array of chars, print with string syntax. */ if (eltlen == 1 && TYPE_CODE (elttype) == TYPE_CODE_INT - && (format == 0 || format == 's') ) + && (format == 0 || format == 's')) { + if (addressprint && format != 's') + { + fprintf_filtered (stream, "0x%x ", address); + } LA_PRINT_STRING (stream, valaddr, len, 0); } else { + fprintf_filtered (stream, "{"); /* If this is a virtual function table, print the 0th entry specially, and the rest of the members normally. */ if (cp_is_vtbl_ptr_type (elttype)) @@ -130,12 +135,13 @@ c_val_print (type, valaddr, address, stream, format, deref_ref, recurse, } val_print_array_elements (type, valaddr, address, stream, format, deref_ref, recurse, pretty, i); + fprintf_filtered (stream, "}"); } - fprintf_filtered (stream, "}"); break; } /* Array of unspecified length: treat like pointer to first elt. */ valaddr = (char *) &address; + /* FALL THROUGH */ case TYPE_CODE_PTR: if (format && format != 's') @@ -155,7 +161,7 @@ c_val_print (type, valaddr, address, stream, format, deref_ref, recurse, } else { - CORE_ADDR addr = unpack_pointer (type, valaddr); + addr = unpack_pointer (type, valaddr); elttype = TYPE_TARGET_TYPE (type); if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) @@ -173,16 +179,12 @@ c_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_INT && - (format == 0 || format == 's') && - addr != 0 && - /* If print_max is UINT_MAX, the alloca below will fail. - In that case don't try to print the string. */ - print_max < UINT_MAX) + if (TYPE_LENGTH (elttype) == 1 + && TYPE_CODE (elttype) == TYPE_CODE_INT + && (format == 0 || format == 's') + && addr != 0) { - i = val_print_string (addr, stream); + i = val_print_string (addr, 0, stream); } else if (cp_is_vtbl_member(type)) { diff --git a/gdb/ch-exp.y b/gdb/ch-exp.y index 279a0cd..35fb2fe 100644 --- a/gdb/ch-exp.y +++ b/gdb/ch-exp.y @@ -1367,6 +1367,12 @@ match_string_literal () Note that more than a single character, enclosed in single quotes, is a string literal. + Also note that the control sequence form is not in GNU Chill since it + is ambiguous with the string literal form using single quotes. I.E. + is '^(7)' a character literal or a string literal. In theory it it + possible to tell by context, but GNU Chill doesn't accept the control + sequence form, so neither do we (for now the code is disabled). + Returns CHARACTER_LITERAL if a match is found. */ @@ -1397,6 +1403,7 @@ match_character_literal () if ((*tokptr == '^') && (*(tokptr + 1) == '(')) { + return (0); /* Disable, see note above. */ /* Match and decode a control sequence. Return zero if we don't find a valid integer literal, or if the next unconsumed character after the integer literal is not the trailing ')'. diff --git a/gdb/ch-valprint.c b/gdb/ch-valprint.c index b53326a..c465fc3 100644 --- a/gdb/ch-valprint.c +++ b/gdb/ch-valprint.c @@ -172,6 +172,26 @@ chill_val_print (type, valaddr, address, stream, format, deref_ref, recurse, return (i + (print_max && i != print_max)); break; + case TYPE_CODE_STRING: + if (format && format != 's') + { + 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); + } + /* Return number of characters printed, plus one for the terminating + null if we have "reached the end". */ + return (i + (print_max && i != print_max)); + break; + case TYPE_CODE_MEMBER: case TYPE_CODE_REF: case TYPE_CODE_UNION: diff --git a/gdb/expprint.c b/gdb/expprint.c index 44b31e7..b50086a 100644 --- a/gdb/expprint.c +++ b/gdb/expprint.c @@ -81,8 +81,7 @@ print_subexp (exp, pos, stream, prec) (enum precedence) ((int) myprec + assoc)); fputs_filtered (" :: ", stream); nargs = longest_to_int (exp->elts[pc + 2].longconst); - (*pos) += 2 + (nargs + sizeof (union exp_element)) / sizeof (union exp_element); - + (*pos) += 2 + BYTES_TO_EXP_ELEM (nargs + 1); fputs_filtered (&exp->elts[pc + 3].string, stream); return; @@ -146,14 +145,21 @@ print_subexp (exp, pos, stream, prec) case OP_STRING: nargs = longest_to_int (exp -> elts[pc + 1].longconst); - (*pos) += 3 + (nargs + sizeof (union exp_element)) - / sizeof (union exp_element); + (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1); /* LA_PRINT_STRING will print using the current repeat count threshold. If necessary, we can temporarily set it to zero, or pass it as an additional parameter to LA_PRINT_STRING. -fnf */ LA_PRINT_STRING (stream, &exp->elts[pc + 2].string, nargs, 0); return; + case OP_BITSTRING: + error ("support for OP_BITSTRING unimplemented"); + break; + + case OP_ARRAY: + error ("support for OP_ARRAY unimplemented"); + break; + case TERNOP_COND: if ((int) prec > (int) PREC_COMMA) fputs_filtered ("(", stream); @@ -172,7 +178,7 @@ print_subexp (exp, pos, stream, prec) case STRUCTOP_STRUCT: tem = longest_to_int (exp->elts[pc + 1].longconst); - (*pos) += 3 + (tem + sizeof (union exp_element)) / sizeof (union exp_element); + (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); print_subexp (exp, pos, stream, PREC_SUFFIX); fputs_filtered (".", stream); fputs_filtered (&exp->elts[pc + 2].string, stream); @@ -181,7 +187,7 @@ print_subexp (exp, pos, stream, prec) /* Will not occur for Modula-2 */ case STRUCTOP_PTR: tem = longest_to_int (exp->elts[pc + 1].longconst); - (*pos) += 3 + (tem + sizeof (union exp_element)) / sizeof (union exp_element); + (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); print_subexp (exp, pos, stream, PREC_SUFFIX); fputs_filtered ("->", stream); fputs_filtered (&exp->elts[pc + 2].string, stream); @@ -487,6 +493,8 @@ dump_expression (exp, stream, note) case OP_INTERNALVAR: opcode_name = "OP_INTERNALVAR"; break; case OP_FUNCALL: opcode_name = "OP_FUNCALL"; break; case OP_STRING: opcode_name = "OP_STRING"; break; + case OP_BITSTRING: opcode_name = "OP_BITSTRING"; break; + case OP_ARRAY: opcode_name = "OP_ARRAY"; break; case UNOP_CAST: opcode_name = "UNOP_CAST"; break; case UNOP_MEMVAL: opcode_name = "UNOP_MEMVAL"; break; case UNOP_NEG: opcode_name = "UNOP_NEG"; break; diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index c0115da..525c515 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -32,6 +32,28 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "demangle.h" #include "complaints.h" +/* These variables point to the objects + representing the predefined C data types. */ + +struct type *builtin_type_void; +struct type *builtin_type_char; +struct type *builtin_type_short; +struct type *builtin_type_int; +struct type *builtin_type_long; +struct type *builtin_type_long_long; +struct type *builtin_type_signed_char; +struct type *builtin_type_unsigned_char; +struct type *builtin_type_unsigned_short; +struct type *builtin_type_unsigned_int; +struct type *builtin_type_unsigned_long; +struct type *builtin_type_unsigned_long_long; +struct type *builtin_type_float; +struct type *builtin_type_double; +struct type *builtin_type_long_double; +struct type *builtin_type_complex; +struct type *builtin_type_double_complex; +struct type *builtin_type_string; + /* Alloc a new type structure and fill it with some defaults. If OBJFILE is non-NULL, then allocate the space for the type structure in that objfile's type_obstack. */ @@ -370,6 +392,26 @@ create_array_type (result_type, element_type, range_type) return (result_type); } +/* Create a string type using either a blank type supplied in RESULT_TYPE, + or creating a new type. String types are similar enough to array of + char types that we can use create_array_type to build the basic type + and then bash it into a string type. + + For fixed length strings, the range type contains 0 as the lower + bound and the length of the string minus one as the upper bound. + + 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 string type? */ + +struct type * +create_string_type (result_type, range_type) + struct type *result_type; + struct type *range_type; +{ + result_type = create_array_type (result_type, builtin_type_char, range_type); + TYPE_CODE (result_type) = TYPE_CODE_STRING; + return (result_type); +} /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE. A MEMBER is a wierd thing -- it amounts to a typed offset into @@ -1188,8 +1230,8 @@ recursive_dump_type (type, spaces) case TYPE_CODE_RANGE: printf_filtered ("(TYPE_CODE_RANGE)"); break; - case TYPE_CODE_PASCAL_ARRAY: - printf_filtered ("(TYPE_CODE_PASCAL_ARRAY)"); + case TYPE_CODE_STRING: + printf_filtered ("(TYPE_CODE_STRING)"); break; case TYPE_CODE_ERROR: printf_filtered ("(TYPE_CODE_ERROR)"); @@ -1297,3 +1339,80 @@ recursive_dump_type (type, spaces) } #endif /* MAINTENANCE_CMDS */ + +void +_initialize_gdbtypes () +{ + builtin_type_void = + init_type (TYPE_CODE_VOID, 1, + 0, + "void", (struct objfile *) NULL); + builtin_type_char = + init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, + 0, + "char", (struct objfile *) NULL); + builtin_type_signed_char = + init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, + TYPE_FLAG_SIGNED, + "signed char", (struct objfile *) NULL); + builtin_type_unsigned_char = + init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, + TYPE_FLAG_UNSIGNED, + "unsigned char", (struct objfile *) NULL); + builtin_type_short = + init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT, + 0, + "short", (struct objfile *) NULL); + builtin_type_unsigned_short = + init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT, + TYPE_FLAG_UNSIGNED, + "unsigned short", (struct objfile *) NULL); + builtin_type_int = + init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, + 0, + "int", (struct objfile *) NULL); + builtin_type_unsigned_int = + init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, + TYPE_FLAG_UNSIGNED, + "unsigned int", (struct objfile *) NULL); + builtin_type_long = + init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, + 0, + "long", (struct objfile *) NULL); + builtin_type_unsigned_long = + init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, + TYPE_FLAG_UNSIGNED, + "unsigned long", (struct objfile *) NULL); + builtin_type_long_long = + init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, + 0, + "long long", (struct objfile *) NULL); + builtin_type_unsigned_long_long = + init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, + TYPE_FLAG_UNSIGNED, + "unsigned long long", (struct objfile *) NULL); + builtin_type_float = + init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT, + 0, + "float", (struct objfile *) NULL); + builtin_type_double = + init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, + 0, + "double", (struct objfile *) NULL); + builtin_type_long_double = + init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, + 0, + "long double", (struct objfile *) NULL); + builtin_type_complex = + init_type (TYPE_CODE_FLT, TARGET_COMPLEX_BIT / TARGET_CHAR_BIT, + 0, + "complex", (struct objfile *) NULL); + builtin_type_double_complex = + init_type (TYPE_CODE_FLT, TARGET_DOUBLE_COMPLEX_BIT / TARGET_CHAR_BIT, + 0, + "double complex", (struct objfile *) NULL); + builtin_type_string = + init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT, + 0, + "string", (struct objfile *) NULL); +} diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index e93cf65..6da24ce 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -81,7 +81,7 @@ enum type_code TYPE_CODE_VOID, /* Void type (values zero length) */ TYPE_CODE_SET, /* Pascal sets */ TYPE_CODE_RANGE, /* Range (integers within spec'd bounds) */ - TYPE_CODE_PASCAL_ARRAY, /* Array with explicit type of index */ + TYPE_CODE_STRING, /* String types, distinct from array of char */ TYPE_CODE_ERROR, /* Unknown type */ /* C++ */ @@ -484,6 +484,7 @@ extern struct type *builtin_type_double; extern struct type *builtin_type_long_double; extern struct type *builtin_type_complex; extern struct type *builtin_type_double_complex; +extern struct type *builtin_type_string; /* This type represents a type that was unrecognized in symbol read-in. */ @@ -599,6 +600,9 @@ extern struct type * create_array_type PARAMS ((struct type *, struct type *, struct type *)); extern struct type * +create_string_type PARAMS ((struct type *, struct type *)); + +extern struct type * lookup_unsigned_typename PARAMS ((char *)); extern struct type * diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c index e059ca2..fdc3386 100644 --- a/gdb/m2-lang.c +++ b/gdb/m2-lang.c @@ -224,7 +224,7 @@ m2_create_fundamental_type (objfile, typeid) TYPE_FLAG_UNSIGNED, "boolean", objfile); break; case FT_STRING: - type = init_type (TYPE_CODE_PASCAL_ARRAY, + type = init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT, 0, "string", objfile); break; diff --git a/gdb/m88k-tdep.c b/gdb/m88k-tdep.c index 43501d7..0648412 100644 --- a/gdb/m88k-tdep.c +++ b/gdb/m88k-tdep.c @@ -626,7 +626,7 @@ pushed_size (prev_words, v) case TYPE_CODE_FUNC: /* Function type */ case TYPE_CODE_SET: /* Pascal sets */ case TYPE_CODE_RANGE: /* Range (integers within bounds) */ - case TYPE_CODE_PASCAL_ARRAY: /* Array with explicit type of index */ + case TYPE_CODE_STRING: /* String type */ case TYPE_CODE_MEMBER: /* Member type */ case TYPE_CODE_METHOD: /* Method type */ /* Don't know how to pass these yet. */ diff --git a/gdb/mipsread.c b/gdb/mipsread.c index 3225b1d..edc0d0f 100644 --- a/gdb/mipsread.c +++ b/gdb/mipsread.c @@ -195,6 +195,10 @@ struct complaint pdr_static_symbol_complaint = /* Things that really are local to this module */ +/* Remember what we deduced to be the source language of this psymtab. */ + +static enum language psymtab_language = language_unknown; + /* MIPS symtab header for the current file */ static HDRR *cur_hdr; @@ -1477,7 +1481,7 @@ parse_type(ax, bs, bigend) complain (&bad_tag_guess_complaint, name); TYPE_CODE(tp) = type_code; } - if (TYPE_NAME(tp) == NULL || strcmp(TYPE_NAME(tp), name) != 0) + if (TYPE_NAME(tp) == NULL || !STREQ (TYPE_NAME(tp), name)) TYPE_NAME(tp) = obsavestring(name, strlen(name), ¤t_objfile -> type_obstack); } @@ -1862,6 +1866,7 @@ parse_partial_symbols (end_of_text_seg, objfile, section_offsets) struct partial_symtab **dependency_list; int dependencies_used, dependencies_allocated; struct cleanup *old_chain; + char *name; extern_tab = (EXTR**)obstack_alloc (&objfile->psymbol_obstack, sizeof(EXTR *) * hdr->iextMax); @@ -1941,9 +1946,8 @@ parse_partial_symbols (end_of_text_seg, objfile, section_offsets) ms_type = mst_unknown; complain (&unknown_ext_complaint, esh->asym.iss); } - prim_record_minimal_symbol ((char *)esh->asym.iss, - esh->asym.value, - ms_type); + name = (char *)esh->asym.iss; + prim_record_minimal_symbol (name, esh->asym.value, ms_type); } /* Pass 3 over files, over local syms: fill in static symbols */ @@ -1984,8 +1988,7 @@ parse_partial_symbols (end_of_text_seg, objfile, section_offsets) (It is the second symbol because the first symbol is the stFile used to signal the start of a file). */ if (fh->csym >= 2 - && strcmp((char *)(((SYMR *)fh->isymBase)[1].iss), - stabs_symbol) == 0) { + && STREQ((char *)(((SYMR *)fh->isymBase)[1].iss), stabs_symbol)) { processing_gcc_compilation = 2; for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++) { int type_code; @@ -2047,7 +2050,8 @@ parse_partial_symbols (end_of_text_seg, objfile, section_offsets) case stStaticProc: /* Function */ ADD_PSYMBOL_TO_LIST(name, strlen(name), VAR_NAMESPACE, LOC_BLOCK, - objfile->static_psymbols, sh->value); + objfile->static_psymbols, sh->value, + psymtab_language, objfile); /* Skip over procedure to next one. */ if (sh->index >= hdr->iauxMax) { @@ -2096,7 +2100,9 @@ parse_partial_symbols (end_of_text_seg, objfile, section_offsets) if (sh->sc == scInfo) { ADD_PSYMBOL_TO_LIST(name, strlen(name), STRUCT_NAMESPACE, LOC_TYPEDEF, - objfile->static_psymbols, sh->value); + objfile->static_psymbols, + sh->value, + psymtab_language, objfile); } /* Skip over the block */ cur_sdx = sh->index; @@ -2124,7 +2130,8 @@ parse_partial_symbols (end_of_text_seg, objfile, section_offsets) /* Use this gdb symbol */ ADD_PSYMBOL_TO_LIST(name, strlen(name), VAR_NAMESPACE, class, - objfile->static_psymbols, sh->value); + objfile->static_psymbols, sh->value, + psymtab_language, objfile); skip: cur_sdx++; /* Go to next file symbol */ } @@ -2357,8 +2364,7 @@ psymtab_to_symtab_1(pst, filename) /* See comment in parse_partial_symbols about the @stabs sentinel. */ if (fh && fh->csym >= 2 - && strcmp((char *)(((SYMR *)fh->isymBase)[1].iss), stabs_symbol) - == 0) { + && STREQ((char *)(((SYMR *)fh->isymBase)[1].iss), stabs_symbol)) { /* * This symbol table contains stabs-in-ecoff entries. @@ -2633,7 +2639,7 @@ mylookup_symbol (name, block, namespace, class) if (SYMBOL_NAME(sym)[0] == inc && SYMBOL_NAMESPACE(sym) == namespace && SYMBOL_CLASS(sym) == class - && !strcmp(SYMBOL_NAME(sym), name)) + && STREQ(SYMBOL_NAME(sym), name)) return sym; bot++; } @@ -2660,7 +2666,7 @@ add_symbol(s,b) if (b == top_stack->cur_block && nsyms >= top_stack->maxsyms) { - complain (&block_overflow_complaint, s->name); + complain (&block_overflow_complaint, SYMBOL_NAME (s)); /* In this case shrink_block is actually grow_block, since BLOCK_NSYMS(b) is larger than its current size. */ origb = b; @@ -3106,7 +3112,7 @@ _initialize_mipsread () /* Missing basic types */ builtin_type_string = - init_type(TYPE_CODE_PASCAL_ARRAY, + init_type(TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT, 0, "string", (struct objfile *) NULL); diff --git a/gdb/parse.c b/gdb/parse.c index 81f79e7..48c8b75 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -423,6 +423,13 @@ length_of_subexp (expr, endpos) oplen = 4 + BYTES_TO_EXP_ELEM (oplen); break; + case OP_ARRAY: + oplen = 4; + args = longest_to_int (expr->elts[endpos - 2].longconst); + args -= longest_to_int (expr->elts[endpos - 3].longconst); + args += 1; + break; + case TERNOP_COND: args = 3; break; @@ -544,6 +551,13 @@ prefixify_subexp (inexpr, outexpr, inend, outbeg) oplen = 4 + BYTES_TO_EXP_ELEM (oplen); break; + case OP_ARRAY: + oplen = 4; + args = longest_to_int (inexpr->elts[inend - 2].longconst); + args -= longest_to_int (inexpr->elts[inend - 3].longconst); + args += 1; + break; + case TERNOP_COND: args = 3; break; diff --git a/gdb/typeprint.c b/gdb/typeprint.c index d82265b..fdd954b 100644 --- a/gdb/typeprint.c +++ b/gdb/typeprint.c @@ -232,7 +232,7 @@ print_type_scalar (type, val, stream) case TYPE_CODE_VOID: case TYPE_CODE_SET: case TYPE_CODE_RANGE: - case TYPE_CODE_PASCAL_ARRAY: + case TYPE_CODE_STRING: case TYPE_CODE_ERROR: case TYPE_CODE_MEMBER: case TYPE_CODE_METHOD: diff --git a/gdb/values.c b/gdb/values.c index fbffe20..c399f8b 100644 --- a/gdb/values.c +++ b/gdb/values.c @@ -701,8 +701,7 @@ unpack_long (type, valaddr) } /* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure whether we want this to be true eventually. */ - else if (code == TYPE_CODE_PTR - || code == TYPE_CODE_REF) + else if (code == TYPE_CODE_PTR || code == TYPE_CODE_REF) { if (len == sizeof(long)) { |