diff options
author | Fred Fish <fnf@specifix.com> | 1993-01-03 22:24:21 +0000 |
---|---|---|
committer | Fred Fish <fnf@specifix.com> | 1993-01-03 22:24:21 +0000 |
commit | fb6e675f95e39ecf9f8664861b64243001fc0a11 (patch) | |
tree | 67fb6eb6769b56a53cc4c8fbb9f37436a35d8791 | |
parent | 191395156c25bce7915660307c78708269ff6c0f (diff) | |
download | gdb-fb6e675f95e39ecf9f8664861b64243001fc0a11.zip gdb-fb6e675f95e39ecf9f8664861b64243001fc0a11.tar.gz gdb-fb6e675f95e39ecf9f8664861b64243001fc0a11.tar.bz2 |
* eval.c (language.h): Include.
* eval.c (evaluate_subexp_with_coercion): Only coerce arrays
to pointer types when the current language is C. It loses for
other languages when the lower index bound is nonzero.
* valarith.c (value_subscript): Take array lower bounds into
account when performing subscripting operations.
* valops.c (value_coerce_array): Add comment describing why
arrays with nonzero lower bounds are dealt with in value_subscript,
rather than in value_coerce_array.
-rw-r--r-- | gdb/ChangeLog | 12 | ||||
-rw-r--r-- | gdb/eval.c | 17 | ||||
-rw-r--r-- | gdb/valarith.c | 32 |
3 files changed, 51 insertions, 10 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e65547a..dabe64b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,15 @@ +Sun Jan 3 14:16:10 1993 Fred Fish (fnf@cygnus.com) + + * eval.c (language.h): Include. + * eval.c (evaluate_subexp_with_coercion): Only coerce arrays + to pointer types when the current language is C. It loses for + other languages when the lower index bound is nonzero. + * valarith.c (value_subscript): Take array lower bounds into + account when performing subscripting operations. + * valops.c (value_coerce_array): Add comment describing why + arrays with nonzero lower bounds are dealt with in value_subscript, + rather than in value_coerce_array. + Sat Jan 2 12:16:41 1993 Fred Fish (fnf@cygnus.com) **** start-sanitize-chill **** @@ -24,6 +24,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "expression.h" #include "target.h" #include "frame.h" +#include "language.h" /* For CAST_IS_CONVERSION */ /* Values of NOSIDE argument to eval_subexp. */ enum noside @@ -1041,9 +1042,16 @@ evaluate_subexp_for_address (exp, pos, noside) } /* Evaluate like `evaluate_subexp' except coercing arrays to pointers. - When used in contexts where arrays will be coerced anyway, - this is equivalent to `evaluate_subexp' - but much faster because it avoids actually fetching array contents. */ + When used in contexts where arrays will be coerced anyway, this is + equivalent to `evaluate_subexp' but much faster because it avoids + actually fetching array contents. + + Note that we currently only do the coercion for C expressions, where + arrays are zero based and the coercion is correct. For other languages, + with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION + to decide if coercion is appropriate. + + */ static value evaluate_subexp_with_coercion (exp, pos, noside) @@ -1063,7 +1071,8 @@ evaluate_subexp_with_coercion (exp, pos, noside) { case OP_VAR_VALUE: var = exp->elts[pc + 1].symbol; - if (TYPE_CODE (SYMBOL_TYPE (var)) == TYPE_CODE_ARRAY) + if (TYPE_CODE (SYMBOL_TYPE (var)) == TYPE_CODE_ARRAY + && CAST_IS_CONVERSION) { (*pos) += 3; val = locate_var_value (var, (FRAME) 0); diff --git a/gdb/valarith.c b/gdb/valarith.c index 7db4681..5ce8c79 100644 --- a/gdb/valarith.c +++ b/gdb/valarith.c @@ -104,17 +104,35 @@ an integer nor a pointer of the same type."); return value_binop (arg1, arg2, BINOP_SUB); } -/* Return the value of ARRAY[IDX]. */ +/* Return the value of ARRAY[IDX]. + See comments in value_coerce_array() for rationale for reason for + doing lower bounds adjustment here rather than there. + FIXME: Perhaps we should validate that the index is valid and if + verbosity is set, warn about invalid indices (but still use them). */ value value_subscript (array, idx) value array, idx; { - if (TYPE_CODE (VALUE_TYPE (array)) == TYPE_CODE_ARRAY - && VALUE_LVAL (array) != lval_memory) - return value_subscripted_rvalue (array, idx); - else - return value_ind (value_add (array, idx)); + int lowerbound; + value bound; + struct type *range_type; + + if (TYPE_CODE (VALUE_TYPE (array)) == TYPE_CODE_ARRAY) + { + range_type = TYPE_FIELD_TYPE (VALUE_TYPE (array), 0); + lowerbound = TYPE_FIELD_BITPOS (range_type, 0); + if (lowerbound != 0) + { + bound = value_from_longest (builtin_type_int, (LONGEST) lowerbound); + idx = value_sub (idx, bound); + } + if (VALUE_LVAL (array) != lval_memory) + { + return value_subscripted_rvalue (array, idx); + } + } + return value_ind (value_add (array, idx)); } /* Return the value of EXPR[IDX], expr an aggregate rvalue @@ -423,7 +441,9 @@ value_binop (arg1, arg2, op) error ("Invalid operation on booleans."); } + /* start-sanitize-chill (FIXME!) */ val = allocate_value (builtin_type_chill_bool); + /* end-sanitize-chill */ SWAP_TARGET_AND_HOST (&v, sizeof (v)); *(LONGEST *) VALUE_CONTENTS_RAW (val) = v; } |