aboutsummaryrefslogtreecommitdiff
path: root/gdb/eval.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/eval.c')
-rw-r--r--gdb/eval.c85
1 files changed, 37 insertions, 48 deletions
diff --git a/gdb/eval.c b/gdb/eval.c
index 40640ae..539b700 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1,6 +1,6 @@
/* Evaluate expressions for GDB.
- Copyright (C) 1986-2024 Free Software Foundation, Inc.
+ Copyright (C) 1986-2025 Free Software Foundation, Inc.
This file is part of GDB.
@@ -622,11 +622,7 @@ evaluate_subexp_do_call (expression *exp, enum noside noside,
if (ftype->code () == TYPE_CODE_INTERNAL_FUNCTION)
{
- /* We don't know anything about what the internal
- function might return, but we have to return
- something. */
- return value::zero (builtin_type (exp->gdbarch)->builtin_int,
- not_lval);
+ /* The call to call_internal_function below handles noside. */
}
else if (ftype->code () == TYPE_CODE_XMETHOD)
{
@@ -666,7 +662,8 @@ evaluate_subexp_do_call (expression *exp, enum noside noside,
{
case TYPE_CODE_INTERNAL_FUNCTION:
return call_internal_function (exp->gdbarch, exp->language_defn,
- callee, argvec.size (), argvec.data ());
+ callee, argvec.size (), argvec.data (),
+ noside);
case TYPE_CODE_XMETHOD:
return callee->call_xmethod (argvec);
default:
@@ -997,9 +994,10 @@ add_struct_fields (struct type *type, completion_list &output,
output.emplace_back (concat (prefix, type->field (i).name (),
nullptr));
}
- else if (type->field (i).type ()->code () == TYPE_CODE_UNION)
+ else if (type->field (i).type ()->code () == TYPE_CODE_UNION
+ || type->field (i).type ()->code () == TYPE_CODE_STRUCT)
{
- /* Recurse into anonymous unions. */
+ /* Recurse into anonymous unions and structures. */
add_struct_fields (type->field (i).type (),
output, fieldname, namelen, prefix);
}
@@ -1074,20 +1072,6 @@ is_integral_or_integral_reference (struct type *type)
&& is_integral_type (type->target_type ()));
}
-/* Helper function that implements the body of OP_SCOPE. */
-
-struct value *
-eval_op_scope (struct type *expect_type, struct expression *exp,
- enum noside noside,
- struct type *type, const char *string)
-{
- struct value *arg1 = value_aggregate_elt (type, string, expect_type,
- 0, noside);
- if (arg1 == NULL)
- error (_("There is no field named %s"), string);
- return arg1;
-}
-
/* Helper function that implements the body of OP_VAR_ENTRY_VALUE. */
struct value *
@@ -1875,18 +1859,21 @@ eval_op_postdec (struct type *expect_type, struct expression *exp,
}
}
-/* A helper function for OP_TYPE. */
+namespace expr
+{
struct value *
-eval_op_type (struct type *expect_type, struct expression *exp,
- enum noside noside, struct type *type)
+type_operation::evaluate (struct type *expect_type, struct expression *exp,
+ enum noside noside)
{
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value::allocate (type);
+ return value::allocate (std::get<0> (m_storage));
else
error (_("Attempt to use a type name as an expression"));
}
+}
+
/* A helper function for BINOP_ASSIGN_MODIFY. */
struct value *
@@ -1957,7 +1944,8 @@ eval_op_objc_msgcall (struct type *expect_type, struct expression *exp,
if (value_as_long (target) == 0)
return value_from_longest (long_type, 0);
- if (lookup_minimal_symbol ("objc_msg_lookup", 0, 0).minsym)
+ if (lookup_minimal_symbol (current_program_space, "objc_msg_lookup").minsym
+ != nullptr)
gnu_runtime = 1;
/* Find the method dispatch (Apple runtime) or method lookup
@@ -2104,7 +2092,7 @@ eval_op_objc_msgcall (struct type *expect_type, struct expression *exp,
/* Found a function symbol. Now we will substitute its
value in place of the message dispatcher (obj_msgSend),
- so that we call the method directly instead of thru
+ so that we call the method directly instead of through
the dispatcher. The main reason for doing this is that
we can now evaluate the return value and parameter values
according to their known data types, in case we need to
@@ -2570,27 +2558,26 @@ unop_extract_operation::evaluate (struct type *expect_type,
}
-
/* Helper for evaluate_subexp_for_address. */
static value *
-evaluate_subexp_for_address_base (struct expression *exp, enum noside noside,
- value *x)
+evaluate_subexp_for_address_base (enum noside noside, value *x)
{
if (noside == EVAL_AVOID_SIDE_EFFECTS)
{
struct type *type = check_typedef (x->type ());
+ enum type_code typecode = type->code ();
if (TYPE_IS_REFERENCE (type))
return value::zero (lookup_pointer_type (type->target_type ()),
- not_lval);
- else if (x->lval () == lval_memory || value_must_coerce_to_target (x))
- return value::zero (lookup_pointer_type (x->type ()),
- not_lval);
+ not_lval);
+ else if (x->lval () == lval_memory || value_must_coerce_to_target (x)
+ || typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
+ return value::zero (lookup_pointer_type (x->type ()), not_lval);
else
- error (_("Attempt to take address of "
- "value not located in memory."));
+ error (_("Attempt to take address of value not located in memory."));
}
+
return value_addr (x);
}
@@ -2610,18 +2597,20 @@ value *
operation::evaluate_for_address (struct expression *exp, enum noside noside)
{
value *val = evaluate (nullptr, exp, noside);
- return evaluate_subexp_for_address_base (exp, noside, val);
+ return evaluate_subexp_for_address_base (noside, val);
}
value *
-scope_operation::evaluate_for_address (struct expression *exp,
- enum noside noside)
-{
- value *x = value_aggregate_elt (std::get<0> (m_storage),
- std::get<1> (m_storage).c_str (),
- NULL, 1, noside);
- if (x == NULL)
- error (_("There is no field named %s"), std::get<1> (m_storage).c_str ());
+scope_operation::evaluate_internal (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside,
+ bool want_address)
+{
+ const char *string = std::get<1> (m_storage).c_str ();
+ value *x = value_aggregate_elt (std::get<0> (m_storage), string,
+ expect_type, want_address, noside);
+ if (x == nullptr)
+ error (_("There is no field named %s"), string);
return x;
}
@@ -2635,7 +2624,7 @@ unop_ind_base_operation::evaluate_for_address (struct expression *exp,
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 evaluate_subexp_for_address_base (noside, x);
}
return coerce_array (x);