This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[rfc][15/37] Eliminate builtin_type_ macros: Dereferencing of integer types
- From: uweigand at de dot ibm dot com
- To: gdb-patches at sourceware dot org
- Date: Sun, 31 Aug 2008 19:51:00 +0200
- Subject: [rfc][15/37] Eliminate builtin_type_ macros: Dereferencing of integer types
- References: <20080831175045.128504000@de.ibm.com>
Hello,
GDB allows to dereference an integer type, treating it as if it were
an "int *". This patch pulls support for this special extension out
of common value_ind code (which doesn't know which architecture to
use for that "int" type) and into the expression evaluators -- which
already handle it for the EVAL_AVOID_SIDE_EFFECTS case.
It might make sense to check for which languages this extension
is actually useful, and remove it from the rest.
Bye,
Ulrich
ChangeLog:
* valops.c (value_ind): No longer allow dereferencing an
integer type.
* eval.c (evaluate_subexp_standard): Handle deferencing an
integer type here.
* ada-lang.c (ada_evaluate_subexp): Likewise.
* jv-lang.c (evaluate_subexp_java): Likewise.
Index: gdb-head/gdb/ada-lang.c
===================================================================
--- gdb-head.orig/gdb/ada-lang.c
+++ gdb-head/gdb/ada-lang.c
@@ -9194,7 +9194,8 @@ ada_evaluate_subexp (struct type *expect
}
else if (TYPE_CODE (type) == TYPE_CODE_INT)
/* GDB allows dereferencing an int. */
- return value_zero (builtin_type_int, lval_memory);
+ return value_zero (builtin_type (exp->gdbarch)->builtin_int,
+ lval_memory);
else
error (_("Attempt to take contents of a non-pointer value."));
}
@@ -9204,6 +9205,10 @@ ada_evaluate_subexp (struct type *expect
if (ada_is_array_descriptor_type (type))
/* GDB allows dereferencing GNAT array descriptors. */
return ada_coerce_to_simple_array (arg1);
+ else if (TYPE_CODE (type) == TYPE_CODE_INT)
+ /* GDB allows dereferencing an int. */
+ return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int,
+ (CORE_ADDR) value_as_address (arg1));
else
return ada_value_ind (arg1);
Index: gdb-head/gdb/eval.c
===================================================================
--- gdb-head.orig/gdb/eval.c
+++ gdb-head/gdb/eval.c
@@ -2288,10 +2288,19 @@ evaluate_subexp_standard (struct type *e
lval_memory);
else if (TYPE_CODE (type) == TYPE_CODE_INT)
/* GDB allows dereferencing an int. */
- return value_zero (builtin_type_int, lval_memory);
+ return value_zero (builtin_type (exp->gdbarch)->builtin_int,
+ lval_memory);
else
error (_("Attempt to take contents of a non-pointer value."));
}
+
+ /* Allow * on an integer so we can cast it to whatever we want.
+ This returns an int, which seems like the most C-like thing to
+ do. "long long" variables are rare enough that
+ BUILTIN_TYPE_LONGEST would seem to be a mistake. */
+ if (TYPE_CODE (type) == TYPE_CODE_INT)
+ return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int,
+ (CORE_ADDR) value_as_address (arg1));
return value_ind (arg1);
case UNOP_ADDR:
Index: gdb-head/gdb/jv-lang.c
===================================================================
--- gdb-head.orig/gdb/jv-lang.c
+++ gdb-head/gdb/jv-lang.c
@@ -855,6 +855,10 @@ evaluate_subexp_java (struct type *expec
}
if (noside == EVAL_SKIP)
goto nosideret;
+ if (TYPE_CODE (value_type (arg1)) == TYPE_CODE_INT)
+ /* GDB allows dereferencing an int. */
+ return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int,
+ (CORE_ADDR) value_as_address (arg1));
return value_ind (arg1);
case BINOP_SUBSCRIPT:
Index: gdb-head/gdb/valops.c
===================================================================
--- gdb-head.orig/gdb/valops.c
+++ gdb-head/gdb/valops.c
@@ -1166,14 +1166,7 @@ value_ind (struct value *arg1)
base_type = check_typedef (value_type (arg1));
- /* Allow * on an integer so we can cast it to whatever we want.
- This returns an int, which seems like the most C-like thing to
- do. "long long" variables are rare enough that
- BUILTIN_TYPE_LONGEST would seem to be a mistake. */
- if (TYPE_CODE (base_type) == TYPE_CODE_INT)
- return value_at_lazy (builtin_type_int,
- (CORE_ADDR) value_as_address (arg1));
- else if (TYPE_CODE (base_type) == TYPE_CODE_PTR)
+ if (TYPE_CODE (base_type) == TYPE_CODE_PTR)
{
struct type *enc_type;
/* We may be pointing to something embedded in a larger object.
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com