#include "target.h"
#include "frame.h"
#include "gdbthread.h"
-#include "language.h" /* For CAST_IS_CONVERSION. */
+#include "language.h"
#include "cp-abi.h"
#include "infcall.h"
#include "objc-lang.h"
{
expression_up expr = parse_expression (exp);
- return value_as_address (evaluate_expression (expr.get ()));
+ return value_as_address (expr->evaluate ());
}
/* Like parse_and_eval_address, but treats the value of the expression
{
expression_up expr = parse_expression (exp);
- return value_as_long (evaluate_expression (expr.get ()));
+ return value_as_long (expr->evaluate ());
}
struct value *
-parse_and_eval (const char *exp)
+parse_and_eval (const char *exp, parser_flags flags)
{
- expression_up expr = parse_expression (exp);
+ expression_up expr = parse_expression (exp, nullptr, flags);
- return evaluate_expression (expr.get ());
+ return expr->evaluate ();
}
/* Parse up to a comma (or to a closeparen)
struct value *
parse_to_comma_and_eval (const char **expp)
{
- expression_up expr = parse_exp_1 (expp, 0, nullptr, 1);
+ expression_up expr = parse_exp_1 (expp, 0, nullptr,
+ PARSER_COMMA_TERMINATES);
- return evaluate_expression (expr.get ());
+ return expr->evaluate ();
}
\f
if (stack_temporaries.has_value ()
&& value_in_thread_stack_temporaries (retval, inferior_thread ()))
- retval = value_non_lval (retval);
+ retval = retval->non_lval ();
return retval;
}
-/* See value.h. */
-
-struct value *
-evaluate_expression (struct expression *exp, struct type *expect_type)
-{
- return exp->evaluate (expect_type, EVAL_NORMAL);
-}
-
-/* Evaluate an expression, avoiding all memory references
- and getting a value whose type alone is correct. */
-
-struct value *
-evaluate_type (struct expression *exp)
-{
- return exp->evaluate (nullptr, EVAL_AVOID_SIDE_EFFECTS);
-}
-
/* Find the current value of a watchpoint on EXP. Return the value in
*VALP and *RESULTP and the chain of intermediate and final values
in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
try
{
- value_fetch_lazy (result);
+ result->fetch_lazy ();
*valp = result;
}
catch (const gdb_exception_error &except)
switch (language->la_language)
{
- case language_c:
- case language_cplus:
- case language_asm:
- case language_objc:
- if (result_len <= builtin->builtin_int->length ())
- {
- promoted_type = (unsigned_operation
- ? builtin->builtin_unsigned_int
- : builtin->builtin_int);
- }
- else if (result_len <= builtin->builtin_long->length ())
- {
- promoted_type = (unsigned_operation
- ? builtin->builtin_unsigned_long
- : builtin->builtin_long);
- }
- else
- {
- promoted_type = (unsigned_operation
- ? builtin->builtin_unsigned_long_long
- : builtin->builtin_long_long);
- }
- break;
case language_opencl:
if (result_len
<= lookup_signed_typename (language, "int")->length())
}
break;
default:
- /* For other languages the result type is unchanged from gdb
- version 6.7 for backward compatibility.
- If either arg was long long, make sure that value is also long
- long. Otherwise use long. */
- if (unsigned_operation)
+ if (result_len <= builtin->builtin_int->length ())
{
- if (result_len > gdbarch_long_bit (gdbarch) / HOST_CHAR_BIT)
- promoted_type = builtin->builtin_unsigned_long_long;
- else
- promoted_type = builtin->builtin_unsigned_long;
+ promoted_type = (unsigned_operation
+ ? builtin->builtin_unsigned_int
+ : builtin->builtin_int);
+ }
+ else if (result_len <= builtin->builtin_long->length ())
+ {
+ promoted_type = (unsigned_operation
+ ? builtin->builtin_unsigned_long
+ : builtin->builtin_long);
+ }
+ else if (result_len <= builtin->builtin_long_long->length ())
+ {
+ promoted_type = (unsigned_operation
+ ? builtin->builtin_unsigned_long_long
+ : builtin->builtin_long_long);
}
else
{
- if (result_len > gdbarch_long_bit (gdbarch) / HOST_CHAR_BIT)
- promoted_type = builtin->builtin_long_long;
- else
- promoted_type = builtin->builtin_long;
+ promoted_type = (unsigned_operation
+ ? builtin->builtin_uint128
+ : builtin->builtin_int128);
}
break;
}
value *
evaluate_var_value (enum noside noside, const block *blk, symbol *var)
{
- /* JYG: We used to just return value_zero of the symbol type if
+ /* JYG: We used to just return value::zero of the symbol type if
we're asked to avoid side effects. Otherwise we return
value_of_variable (...). However I'm not sure if
value_of_variable () has any side effect. We need a full value
if (noside != EVAL_AVOID_SIDE_EFFECTS)
throw;
- ret = value_zero (var->type (), not_lval);
+ ret = value::zero (var->type (), not_lval);
}
return ret;
type *the_type = find_minsym_type_and_address (msymbol, objfile, &address);
if (noside == EVAL_AVOID_SIDE_EFFECTS && !the_type->is_gnu_ifunc ())
- return value_zero (the_type, not_lval);
+ return value::zero (the_type, not_lval);
else
return value_at_lazy (the_type, address);
}
/* 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,
+ return value::zero (builtin_type (exp->gdbarch)->builtin_int,
not_lval);
}
else if (ftype->code () == TYPE_CODE_XMETHOD)
{
- type *return_type = result_type_of_xmethod (callee, argvec);
+ type *return_type = callee->result_type_of_xmethod (argvec);
if (return_type == NULL)
error (_("Xmethod is missing return type."));
- return value_zero (return_type, not_lval);
+ return value::zero (return_type, not_lval);
}
else if (ftype->code () == TYPE_CODE_FUNC
|| ftype->code () == TYPE_CODE_METHOD)
if (return_type == NULL)
error_call_unknown_return_type (function_name);
- return allocate_value (return_type);
+ return value::allocate (return_type);
}
else
error (_("Expression of type other than "
return call_internal_function (exp->gdbarch, exp->language_defn,
callee, argvec.size (), argvec.data ());
case TYPE_CODE_XMETHOD:
- return call_xmethod (callee, argvec);
+ return callee->call_xmethod (argvec);
default:
return call_function_by_hand (callee, default_return_type, argvec);
}
function_name = name.c_str ();
/* We need a properly typed value for method lookup. */
- argvec[0] = value_zero (type, lval_memory);
+ argvec[0] = value::zero (type, lval_memory);
}
for (int i = 0; i < args.size (); ++i)
if (a1_type->code () == TYPE_CODE_METHODPTR)
{
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- callee = value_zero (a1_type->target_type (), not_lval);
+ callee = value::zero (a1_type->target_type (), not_lval);
else
callee = cplus_method_ptr_to_value (&lhs, rhs);
enum noside noside, symbol *sym)
{
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (sym->type (), not_lval);
+ return value::zero (sym->type (), not_lval);
if (SYMBOL_COMPUTED_OPS (sym) == NULL
|| SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry == NULL)
of the evaluation mode. */
if (noside == EVAL_AVOID_SIDE_EFFECTS
&& regno < gdbarch_num_cooked_regs (exp->gdbarch))
- val = value_zero (register_type (exp->gdbarch, regno), not_lval);
+ val = value::zero (register_type (exp->gdbarch, regno), not_lval);
else
val = value_of_register (regno, get_selected_frame (NULL));
if (val == NULL)
return value_string (str.c_str (), str.size (), type);
}
+struct value *
+ternop_slice_operation::evaluate (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside)
+{
+ struct value *array
+ = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
+ struct value *low
+ = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
+ struct value *upper
+ = std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
+
+ int lowbound = value_as_long (low);
+ int upperbound = value_as_long (upper);
+ return value_slice (array, lowbound, upperbound - lowbound + 1);
+}
+
} /* namespace expr */
/* Helper function that implements the body of OP_OBJC_SELECTOR. */
lookup_child_selector (exp->gdbarch, sel));
}
-/* A helper function for TERNOP_SLICE. */
-
-struct value *
-eval_op_ternop (struct type *expect_type, struct expression *exp,
- enum noside noside,
- struct value *array, struct value *low, struct value *upper)
-{
- int lowbound = value_as_long (low);
- int upperbound = value_as_long (upper);
- return value_slice (array, lowbound, upperbound - lowbound + 1);
-}
-
/* A helper function for STRUCTOP_STRUCT. */
struct value *
struct value *arg3 = value_struct_elt (&arg1, {}, string,
NULL, "structure");
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- arg3 = value_zero (arg3->type (), VALUE_LVAL (arg3));
+ arg3 = value::zero (arg3->type (), arg3->lval ());
return arg3;
}
struct value *arg3 = value_struct_elt (&arg1, {}, string,
NULL, "structure pointer");
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- arg3 = value_zero (arg3->type (), VALUE_LVAL (arg3));
+ arg3 = value::zero (arg3->type (), arg3->lval ());
return arg3;
}
{
case TYPE_CODE_METHODPTR:
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (type->target_type (), not_lval);
+ return value::zero (type->target_type (), not_lval);
else
{
arg2 = cplus_method_ptr_to_value (&arg1, arg2);
}
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (type->target_type (), VALUE_LVAL (arg1));
+ return value::zero (type->target_type (), arg1->lval ());
else
return value_subscript (arg1, value_as_long (arg2));
}
if (type->is_pointer_or_reference ()
/* In C you can dereference an array to get the 1st elt. */
|| type->code () == TYPE_CODE_ARRAY)
- return value_zero (type->target_type (),
+ return value::zero (type->target_type (),
lval_memory);
else if (type->code () == TYPE_CODE_INT)
/* GDB allows dereferencing an int. */
- return value_zero (builtin_type (exp->gdbarch)->builtin_int,
+ return value::zero (builtin_type (exp->gdbarch)->builtin_int,
lval_memory);
else
error (_("Attempt to take contents of a non-pointer value."));
struct value *arg1, struct type *type)
{
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (type, lval_memory);
+ return value::zero (type, lval_memory);
else
return value_at_lazy (type, value_as_address (arg1));
}
}
else
{
- struct value *arg3 = value_non_lval (arg1);
+ struct value *arg3 = arg1->non_lval ();
struct value *arg2;
if (ptrmath_type_p (exp->language_defn, arg1->type ()))
}
else
{
- struct value *arg3 = value_non_lval (arg1);
+ struct value *arg3 = arg1->non_lval ();
struct value *arg2;
if (ptrmath_type_p (exp->language_defn, arg1->type ()))
enum noside noside, struct type *type)
{
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return allocate_value (type);
+ return value::allocate (type);
else
error (_("Attempt to use a type name as an expression"));
}
if (callee_type)
{
if ((callee_type->code () == TYPE_CODE_ERROR) && expect_type)
- return allocate_value (expect_type);
+ return value::allocate (expect_type);
else
- return allocate_value (callee_type);
+ return value::allocate (callee_type);
}
else
error (_("Expression of type other than "
fieldno++;
/* Skip static fields. */
while (fieldno < struct_type->num_fields ()
- && field_is_static (&struct_type->field (fieldno)))
+ && struct_type->field (fieldno).is_static ())
fieldno++;
if (fieldno >= struct_type->num_fields ())
error (_("too many initializers"));
if (val->type () != field_type)
val = value_cast (field_type, val);
- bitsize = TYPE_FIELD_BITSIZE (struct_type, fieldno);
+ bitsize = struct_type->field (fieldno).bitsize ();
bitpos = struct_type->field (fieldno).loc_bitpos ();
- addr = value_contents_writeable (struct_val).data () + bitpos / 8;
+ addr = struct_val->contents_writeable ().data () + bitpos / 8;
if (bitsize)
modify_field (struct_type, addr,
value_as_long (val), bitpos % 8, bitsize);
else
- memcpy (addr, value_contents (val).data (),
+ memcpy (addr, val->contents ().data (),
val->type ()->length ());
}
struct expression *exp,
enum noside noside)
{
- int tem;
- int tem2 = std::get<0> (m_storage);
- int tem3 = std::get<1> (m_storage);
+ const int provided_low_bound = std::get<0> (m_storage);
const std::vector<operation_up> &in_args = std::get<2> (m_storage);
- int nargs = tem3 - tem2 + 1;
+ const int nargs = std::get<1> (m_storage) - provided_low_bound + 1;
struct type *type = expect_type ? check_typedef (expect_type) : nullptr;
if (expect_type != nullptr
&& type->code () == TYPE_CODE_STRUCT)
{
- struct value *rec = allocate_value (expect_type);
+ struct value *rec = value::allocate (expect_type);
- memset (value_contents_raw (rec).data (), '\0', type->length ());
+ memset (rec->contents_raw ().data (), '\0', type->length ());
return evaluate_struct_tuple (rec, exp, noside, nargs);
}
{
struct type *range_type = type->index_type ();
struct type *element_type = type->target_type ();
- struct value *array = allocate_value (expect_type);
+ struct value *array = value::allocate (expect_type);
int element_size = check_typedef (element_type)->length ();
- LONGEST low_bound, high_bound, index;
+ LONGEST low_bound, high_bound;
if (!get_discrete_bounds (range_type, &low_bound, &high_bound))
{
low_bound = 0;
high_bound = (type->length () / element_size) - 1;
}
- index = low_bound;
- memset (value_contents_raw (array).data (), 0, expect_type->length ());
- for (tem = nargs; --nargs >= 0;)
+ if (low_bound + nargs - 1 > high_bound)
+ error (_("Too many array elements"));
+ memset (array->contents_raw ().data (), 0, expect_type->length ());
+ for (int idx = 0; idx < nargs; ++idx)
{
struct value *element;
- element = in_args[index - low_bound]->evaluate (element_type,
- exp, noside);
+ element = in_args[idx]->evaluate (element_type, exp, noside);
if (element->type () != element_type)
element = value_cast (element_type, element);
- if (index > high_bound)
- /* To avoid memory corruption. */
- error (_("Too many array elements"));
- memcpy (value_contents_raw (array).data ()
- + (index - low_bound) * element_size,
- value_contents (element).data (),
+ memcpy (array->contents_raw ().data () + idx * element_size,
+ element->contents ().data (),
element_size);
- index++;
}
return array;
}
if (expect_type != nullptr
&& type->code () == TYPE_CODE_SET)
{
- struct value *set = allocate_value (expect_type);
- gdb_byte *valaddr = value_contents_raw (set).data ();
+ struct value *set = value::allocate (expect_type);
+ gdb_byte *valaddr = set->contents_raw ().data ();
struct type *element_type = type->index_type ();
struct type *check_type = element_type;
LONGEST low_bound, high_bound;
if (!get_discrete_bounds (element_type, &low_bound, &high_bound))
error (_("(power)set type with unknown size"));
memset (valaddr, '\0', type->length ());
- int idx = 0;
- for (tem = 0; tem < nargs; tem++)
+ for (int idx = 0; idx < nargs; idx++)
{
LONGEST range_low, range_high;
struct type *range_low_type, *range_high_type;
struct value *elem_val;
- elem_val = in_args[idx++]->evaluate (element_type, exp, noside);
+ elem_val = in_args[idx]->evaluate (element_type, exp, noside);
range_low_type = range_high_type = elem_val->type ();
range_low = range_high = value_as_long (elem_val);
return set;
}
- value **argvec = XALLOCAVEC (struct value *, nargs);
- for (tem = 0; tem < nargs; tem++)
+ std::vector<value *> argvec (nargs);
+ for (int tem = 0; tem < nargs; tem++)
{
/* Ensure that array expressions are coerced into pointer
objects. */
argvec[tem] = in_args[tem]->evaluate_with_coercion (exp, noside);
}
- return value_array (tem2, tem3, argvec);
+ return value_array (provided_low_bound, argvec);
}
value *
if (type->length () > old_value->type ()->length ())
error (_("length type is larger than the value type"));
- struct value *result = allocate_value (type);
- value_contents_copy (result, 0, old_value, 0, type->length ());
+ struct value *result = value::allocate (type);
+ old_value->contents_copy (result, 0, 0, type->length ());
return result;
}
struct type *type = check_typedef (x->type ());
if (TYPE_IS_REFERENCE (type))
- return value_zero (lookup_pointer_type (type->target_type ()),
+ return value::zero (lookup_pointer_type (type->target_type ()),
not_lval);
- else if (VALUE_LVAL (x) == lval_memory || value_must_coerce_to_target (x))
- return value_zero (lookup_pointer_type (x->type ()),
+ else if (x->lval () == lval_memory || value_must_coerce_to_target (x))
+ return value::zero (lookup_pointer_type (x->type ()),
not_lval);
else
error (_("Attempt to take address of "
if (noside == EVAL_AVOID_SIDE_EFFECTS)
{
struct type *type = lookup_pointer_type (val->type ());
- return value_zero (type, not_lval);
+ return value::zero (type, not_lval);
}
else
return value_addr (val);
|| sym_class == LOC_REGISTER)
error (_("Attempt to take address of register or constant."));
- return value_zero (type, not_lval);
+ return value::zero (type, not_lval);
}
else
return address_of_variable (var, std::get<0> (m_storage).block);
/* FIXME: This should be size_t. */
struct type *size_type = builtin_type (exp->gdbarch)->builtin_int;
if (type_not_allocated (type) || type_not_associated (type))
- return value_zero (size_type, not_lval);
+ return value::zero (size_type, not_lval);
else if (is_dynamic_type (type->index_type ())
&& type->bounds ()->high.kind () == PROP_UNDEFINED)
- return allocate_optimized_out_value (size_type);
+ return value::allocate_optimized_out (size_type);
}
}
return evaluate_subexp_for_sizeof_base (exp, type);
enum noside noside)
{
if (noside == EVAL_AVOID_SIDE_EFFECTS)
- return value_zero (to_type, not_lval);
+ return value::zero (to_type, not_lval);
const bound_minimal_symbol &b = std::get<0> (m_storage);
value *val = evaluate_var_msym_value (noside, b.objfile, b.minsym);
val = value_cast (to_type, val);
/* Don't allow e.g. '&(int)var_with_no_debug_info'. */
- if (VALUE_LVAL (val) == lval_memory)
+ if (val->lval () == lval_memory)
{
if (val->lazy ())
- value_fetch_lazy (val);
- VALUE_LVAL (val) = not_lval;
+ val->fetch_lazy ();
+ val->set_lval (not_lval);
}
return val;
}
val = value_cast (to_type, val);
/* Don't allow e.g. '&(int)var_with_no_debug_info'. */
- if (VALUE_LVAL (val) == lval_memory)
+ if (val->lval () == lval_memory)
{
if (val->lazy ())
- value_fetch_lazy (val);
- VALUE_LVAL (val) = not_lval;
+ val->fetch_lazy ();
+ val->set_lval (not_lval);
}
return val;
}