aboutsummaryrefslogtreecommitdiff
path: root/gdb/eval.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-03-08 07:27:57 -0700
committerTom Tromey <tom@tromey.com>2021-03-08 07:28:21 -0700
commit876469ffa1f52b15dfbc8336b31b908edf95fba6 (patch)
tree529d3b4adac4c544c72ca41c199415aa543bb943 /gdb/eval.c
parent6d89e2962a8cc245b8364e1968396873bd0bb9b1 (diff)
downloadgdb-876469ffa1f52b15dfbc8336b31b908edf95fba6.zip
gdb-876469ffa1f52b15dfbc8336b31b908edf95fba6.tar.gz
gdb-876469ffa1f52b15dfbc8336b31b908edf95fba6.tar.bz2
Introduce unop_ind_operation
This adds class unop_ind_operation, which implements UNOP_IND. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * expop.h (class unop_ind_base_operation) (class unop_ind_operation): New. * eval.c (eval_op_ind): No longer static. Remove "op" parameter. (unop_ind_base_operation::evaluate_for_address) (unop_ind_base_operation::evaluate_for_sizeof): New method. * ax-gdb.c (gen_expr_unop) <case UNOP_IND>: New.
Diffstat (limited to 'gdb/eval.c')
-rw-r--r--gdb/eval.c45
1 files changed, 40 insertions, 5 deletions
diff --git a/gdb/eval.c b/gdb/eval.c
index 4f12c7b..1995d39 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1827,9 +1827,9 @@ eval_op_lognot (struct type *expect_type, struct expression *exp,
/* A helper function for UNOP_IND. */
-static struct value *
+struct value *
eval_op_ind (struct type *expect_type, struct expression *exp,
- enum noside noside, enum exp_opcode op,
+ enum noside noside,
struct value *arg1)
{
struct type *type = check_typedef (value_type (arg1));
@@ -1839,8 +1839,8 @@ eval_op_ind (struct type *expect_type, struct expression *exp,
"to member without an object"));
if (noside == EVAL_SKIP)
return eval_skip_value (exp);
- if (unop_user_defined_p (op, arg1))
- return value_x_unop (arg1, op, noside);
+ if (unop_user_defined_p (UNOP_IND, arg1))
+ return value_x_unop (arg1, UNOP_IND, noside);
else if (noside == EVAL_AVOID_SIDE_EFFECTS)
{
type = check_typedef (value_type (arg1));
@@ -2974,7 +2974,7 @@ evaluate_subexp_standard (struct type *expect_type,
if (expect_type && expect_type->code () == TYPE_CODE_PTR)
expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type));
arg1 = evaluate_subexp (expect_type, exp, pos, noside);
- return eval_op_ind (expect_type, exp, noside, op, arg1);
+ return eval_op_ind (expect_type, exp, noside, arg1);
case UNOP_ADDR:
/* C++: check for and handle pointer to members. */
@@ -3302,6 +3302,22 @@ scope_operation::evaluate_for_address (struct expression *exp,
}
value *
+unop_ind_base_operation::evaluate_for_address (struct expression *exp,
+ enum noside noside)
+{
+ value *x = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
+
+ /* We can't optimize out "&*" if there's a user-defined operator*. */
+ if (unop_user_defined_p (UNOP_IND, x))
+ {
+ x = value_x_unop (x, UNOP_IND, noside);
+ return evaluate_subexp_for_address_base (exp, noside, x);
+ }
+
+ return coerce_array (x);
+}
+
+value *
var_msym_value_operation::evaluate_for_address (struct expression *exp,
enum noside noside)
{
@@ -3569,6 +3585,25 @@ subscript_operation::evaluate_for_sizeof (struct expression *exp,
return operation::evaluate_for_sizeof (exp, noside);
}
+value *
+unop_ind_base_operation::evaluate_for_sizeof (struct expression *exp,
+ enum noside noside)
+{
+ value *val = std::get<0> (m_storage)->evaluate (nullptr, exp,
+ EVAL_AVOID_SIDE_EFFECTS);
+ struct type *type = check_typedef (value_type (val));
+ if (type->code () != TYPE_CODE_PTR
+ && !TYPE_IS_REFERENCE (type)
+ && type->code () != TYPE_CODE_ARRAY)
+ error (_("Attempt to take contents of a non-pointer value."));
+ type = TYPE_TARGET_TYPE (type);
+ if (is_dynamic_type (type))
+ type = value_type (value_ind (val));
+ /* FIXME: This should be size_t. */
+ struct type *size_type = builtin_type (exp->gdbarch)->builtin_int;
+ return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
+}
+
}
/* Evaluate a subexpression of EXP, at index *POS, and return a value