aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2010-02-11 21:45:25 +0000
committerPedro Alves <palves@redhat.com>2010-02-11 21:45:25 +0000
commitbe636754b785aa5b042991267c851af18ed5b6a9 (patch)
tree47af6d7426102b5b75f722530ba4b0d5deb96839
parent10ef8d6a8dfca5731b2f4eb4dec945a299050e3c (diff)
downloadfsf-binutils-gdb-be636754b785aa5b042991267c851af18ed5b6a9.zip
fsf-binutils-gdb-be636754b785aa5b042991267c851af18ed5b6a9.tar.gz
fsf-binutils-gdb-be636754b785aa5b042991267c851af18ed5b6a9.tar.bz2
* ax-gdb.c (gen_exp_binop_rest) [BINOP_SUBSCRIPT]: Error out on
non-subscriptable types. * valarith.c (binop_types_user_defined_p): New, abstracted out from ... (binop_user_defined_p): ... this. * value.h (binop_types_user_defined_p): Declare.
-rw-r--r--gdb/ChangeLog9
-rw-r--r--gdb/ax-gdb.c34
-rw-r--r--gdb/valarith.c21
-rw-r--r--gdb/value.h4
4 files changed, 59 insertions, 9 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index a679110..d9b7c60 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,14 @@
2010-02-11 Pedro Alves <pedro@codesourcery.com>
+ * ax-gdb.c (gen_exp_binop_rest) [BINOP_SUBSCRIPT]: Error out on
+ non-subscriptable types.
+ * valarith.c (binop_types_user_defined_p): New, abstracted out
+ from ...
+ (binop_user_defined_p): ... this.
+ * value.h (binop_types_user_defined_p): Declare.
+
+2010-02-11 Pedro Alves <pedro@codesourcery.com>
+
* tracepoint.c (tfile_open): Remove spurious discard_cleanups.
Merge uploaded TSVs before merging uploaded tracepoints.
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index eb53238..75aa7ca6 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -1885,11 +1885,35 @@ gen_expr_binop_rest (struct expression *exp,
aop_rem_signed, aop_rem_unsigned, 1, "remainder");
break;
case BINOP_SUBSCRIPT:
- gen_ptradd (ax, value, value1, value2);
- if (!pointer_type (value->type))
- error (_("Invalid combination of types in array subscripting."));
- gen_deref (ax, value);
- break;
+ {
+ struct type *type;
+
+ if (binop_types_user_defined_p (op, value1->type, value2->type))
+ {
+ error (_("\
+cannot subscript requested type: cannot call user defined functions"));
+ }
+ else
+ {
+ /* If the user attempts to subscript something that is not
+ an array or pointer type (like a plain int variable for
+ example), then report this as an error. */
+ type = check_typedef (value1->type);
+ if (TYPE_CODE (type) != TYPE_CODE_ARRAY
+ && TYPE_CODE (type) != TYPE_CODE_PTR)
+ {
+ if (TYPE_NAME (type))
+ error (_("cannot subscript something of type `%s'"),
+ TYPE_NAME (type));
+ else
+ error (_("cannot subscript requested type"));
+ }
+ }
+
+ gen_ptradd (ax, value, value1, value2);
+ gen_deref (ax, value);
+ break;
+ }
case BINOP_BITWISE_AND:
gen_binop (ax, value, value1, value2,
aop_bit_and, aop_bit_and, 0, "bitwise and");
diff --git a/gdb/valarith.c b/gdb/valarith.c
index c87bc6f..9f91f4e 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -263,17 +263,17 @@ value_bitstring_subscript (struct type *type,
For now, we do not overload the `=' operator. */
int
-binop_user_defined_p (enum exp_opcode op, struct value *arg1, struct value *arg2)
+binop_types_user_defined_p (enum exp_opcode op,
+ struct type *type1, struct type *type2)
{
- struct type *type1, *type2;
if (op == BINOP_ASSIGN || op == BINOP_CONCAT)
return 0;
- type1 = check_typedef (value_type (arg1));
+ type1 = check_typedef (type1);
if (TYPE_CODE (type1) == TYPE_CODE_REF)
type1 = check_typedef (TYPE_TARGET_TYPE (type1));
- type2 = check_typedef (value_type (arg2));
+ type2 = check_typedef (type1);
if (TYPE_CODE (type2) == TYPE_CODE_REF)
type2 = check_typedef (TYPE_TARGET_TYPE (type2));
@@ -281,6 +281,19 @@ binop_user_defined_p (enum exp_opcode op, struct value *arg1, struct value *arg2
|| TYPE_CODE (type2) == TYPE_CODE_STRUCT);
}
+/* Check to see if either argument is a structure, or a reference to
+ one. This is called so we know whether to go ahead with the normal
+ binop or look for a user defined function instead.
+
+ For now, we do not overload the `=' operator. */
+
+int
+binop_user_defined_p (enum exp_opcode op,
+ struct value *arg1, struct value *arg2)
+{
+ return binop_types_user_defined_p (op, value_type (arg1), value_type (arg2));
+}
+
/* Check to see if argument is a structure. This is called so
we know whether to go ahead with the normal unop or look for a
user defined function instead.
diff --git a/gdb/value.h b/gdb/value.h
index 43b8c3b..1f2086e 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -590,6 +590,10 @@ extern struct value *value_x_unop (struct value *arg1, enum exp_opcode op,
extern struct value *value_fn_field (struct value **arg1p, struct fn_field *f,
int j, struct type *type, int offset);
+extern int binop_types_user_defined_p (enum exp_opcode op,
+ struct type *type1,
+ struct type *type2);
+
extern int binop_user_defined_p (enum exp_opcode op, struct value *arg1,
struct value *arg2);