1 /* Evaluate expressions for GDB.
3 Copyright (C) 1986-2020 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "expression.h"
27 #include "gdbthread.h"
28 #include "language.h" /* For CAST_IS_CONVERSION. */
29 #include "f-lang.h" /* For array bound stuff. */
32 #include "objc-lang.h"
34 #include "parser-defs.h"
35 #include "cp-support.h"
38 #include "user-regs.h"
40 #include "gdb_obstack.h"
42 #include "typeprint.h"
45 /* Prototypes for local functions. */
47 static struct value
*evaluate_subexp_for_sizeof (struct expression
*, int *,
50 static struct value
*evaluate_subexp_for_address (struct expression
*,
53 static value
*evaluate_subexp_for_cast (expression
*exp
, int *pos
,
57 static struct value
*evaluate_struct_tuple (struct value
*,
58 struct expression
*, int *,
61 static LONGEST
init_array_element (struct value
*, struct value
*,
62 struct expression
*, int *, enum noside
,
66 evaluate_subexp (struct type
*expect_type
, struct expression
*exp
,
67 int *pos
, enum noside noside
)
71 gdb::optional
<enable_thread_stack_temporaries
> stack_temporaries
;
72 if (*pos
== 0 && target_has_execution
73 && exp
->language_defn
->la_language
== language_cplus
74 && !thread_stack_temporaries_enabled_p (inferior_thread ()))
75 stack_temporaries
.emplace (inferior_thread ());
77 retval
= (*exp
->language_defn
->expression_ops ()->evaluate_exp
)
78 (expect_type
, exp
, pos
, noside
);
80 if (stack_temporaries
.has_value ()
81 && value_in_thread_stack_temporaries (retval
, inferior_thread ()))
82 retval
= value_non_lval (retval
);
87 /* Parse the string EXP as a C expression, evaluate it,
88 and return the result as a number. */
91 parse_and_eval_address (const char *exp
)
93 expression_up expr
= parse_expression (exp
);
95 return value_as_address (evaluate_expression (expr
.get ()));
98 /* Like parse_and_eval_address, but treats the value of the expression
99 as an integer, not an address, returns a LONGEST, not a CORE_ADDR. */
101 parse_and_eval_long (const char *exp
)
103 expression_up expr
= parse_expression (exp
);
105 return value_as_long (evaluate_expression (expr
.get ()));
109 parse_and_eval (const char *exp
)
111 expression_up expr
= parse_expression (exp
);
113 return evaluate_expression (expr
.get ());
116 /* Parse up to a comma (or to a closeparen)
117 in the string EXPP as an expression, evaluate it, and return the value.
118 EXPP is advanced to point to the comma. */
121 parse_to_comma_and_eval (const char **expp
)
123 expression_up expr
= parse_exp_1 (expp
, 0, nullptr, 1);
125 return evaluate_expression (expr
.get ());
128 /* Evaluate an expression in internal prefix form
129 such as is constructed by parse.y.
131 See expression.h for info on the format of an expression. */
134 evaluate_expression (struct expression
*exp
)
138 return evaluate_subexp (nullptr, exp
, &pc
, EVAL_NORMAL
);
141 /* Evaluate an expression, avoiding all memory references
142 and getting a value whose type alone is correct. */
145 evaluate_type (struct expression
*exp
)
149 return evaluate_subexp (nullptr, exp
, &pc
, EVAL_AVOID_SIDE_EFFECTS
);
152 /* Evaluate a subexpression, avoiding all memory references and
153 getting a value whose type alone is correct. */
156 evaluate_subexpression_type (struct expression
*exp
, int subexp
)
158 return evaluate_subexp (nullptr, exp
, &subexp
, EVAL_AVOID_SIDE_EFFECTS
);
161 /* Find the current value of a watchpoint on EXP. Return the value in
162 *VALP and *RESULTP and the chain of intermediate and final values
163 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
166 If PRESERVE_ERRORS is true, then exceptions are passed through.
167 Otherwise, if PRESERVE_ERRORS is false, then if a memory error
168 occurs while evaluating the expression, *RESULTP will be set to
169 NULL. *RESULTP may be a lazy value, if the result could not be
170 read from memory. It is used to determine whether a value is
171 user-specified (we should watch the whole value) or intermediate
172 (we should watch only the bit used to locate the final value).
174 If the final value, or any intermediate value, could not be read
175 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
176 set to any referenced values. *VALP will never be a lazy value.
177 This is the value which we store in struct breakpoint.
179 If VAL_CHAIN is non-NULL, the values put into *VAL_CHAIN will be
180 released from the value chain. If VAL_CHAIN is NULL, all generated
181 values will be left on the value chain. */
184 fetch_subexp_value (struct expression
*exp
, int *pc
, struct value
**valp
,
185 struct value
**resultp
,
186 std::vector
<value_ref_ptr
> *val_chain
,
189 struct value
*mark
, *new_mark
, *result
;
197 /* Evaluate the expression. */
198 mark
= value_mark ();
203 result
= evaluate_subexp (nullptr, exp
, pc
, EVAL_NORMAL
);
205 catch (const gdb_exception
&ex
)
207 /* Ignore memory errors if we want watchpoints pointing at
208 inaccessible memory to still be created; otherwise, throw the
209 error to some higher catcher. */
213 if (!preserve_errors
)
222 new_mark
= value_mark ();
223 if (mark
== new_mark
)
228 /* Make sure it's not lazy, so that after the target stops again we
229 have a non-lazy previous value to compare with. */
232 if (!value_lazy (result
))
239 value_fetch_lazy (result
);
242 catch (const gdb_exception_error
&except
)
250 /* Return the chain of intermediate values. We use this to
251 decide which addresses to watch. */
252 *val_chain
= value_release_to_mark (mark
);
256 /* Extract a field operation from an expression. If the subexpression
257 of EXP starting at *SUBEXP is not a structure dereference
258 operation, return NULL. Otherwise, return the name of the
259 dereferenced field, and advance *SUBEXP to point to the
260 subexpression of the left-hand-side of the dereference. This is
261 used when completing field names. */
264 extract_field_op (struct expression
*exp
, int *subexp
)
269 if (exp
->elts
[*subexp
].opcode
!= STRUCTOP_STRUCT
270 && exp
->elts
[*subexp
].opcode
!= STRUCTOP_PTR
)
272 tem
= longest_to_int (exp
->elts
[*subexp
+ 1].longconst
);
273 result
= &exp
->elts
[*subexp
+ 2].string
;
274 (*subexp
) += 1 + 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
278 /* This function evaluates brace-initializers (in C/C++) for
281 static struct value
*
282 evaluate_struct_tuple (struct value
*struct_val
,
283 struct expression
*exp
,
284 int *pos
, enum noside noside
, int nargs
)
286 struct type
*struct_type
= check_typedef (value_type (struct_val
));
287 struct type
*field_type
;
292 struct value
*val
= NULL
;
297 /* Skip static fields. */
298 while (fieldno
< struct_type
->num_fields ()
299 && field_is_static (&struct_type
->field (fieldno
)))
301 if (fieldno
>= struct_type
->num_fields ())
302 error (_("too many initializers"));
303 field_type
= struct_type
->field (fieldno
).type ();
304 if (field_type
->code () == TYPE_CODE_UNION
305 && TYPE_FIELD_NAME (struct_type
, fieldno
)[0] == '0')
306 error (_("don't know which variant you want to set"));
308 /* Here, struct_type is the type of the inner struct,
309 while substruct_type is the type of the inner struct.
310 These are the same for normal structures, but a variant struct
311 contains anonymous union fields that contain substruct fields.
312 The value fieldno is the index of the top-level (normal or
313 anonymous union) field in struct_field, while the value
314 subfieldno is the index of the actual real (named inner) field
315 in substruct_type. */
317 field_type
= struct_type
->field (fieldno
).type ();
319 val
= evaluate_subexp (field_type
, exp
, pos
, noside
);
321 /* Now actually set the field in struct_val. */
323 /* Assign val to field fieldno. */
324 if (value_type (val
) != field_type
)
325 val
= value_cast (field_type
, val
);
327 bitsize
= TYPE_FIELD_BITSIZE (struct_type
, fieldno
);
328 bitpos
= TYPE_FIELD_BITPOS (struct_type
, fieldno
);
329 addr
= value_contents_writeable (struct_val
) + bitpos
/ 8;
331 modify_field (struct_type
, addr
,
332 value_as_long (val
), bitpos
% 8, bitsize
);
334 memcpy (addr
, value_contents (val
),
335 TYPE_LENGTH (value_type (val
)));
341 /* Recursive helper function for setting elements of array tuples.
342 The target is ARRAY (which has bounds LOW_BOUND to HIGH_BOUND); the
343 element value is ELEMENT; EXP, POS and NOSIDE are as usual.
344 Evaluates index expressions and sets the specified element(s) of
345 ARRAY to ELEMENT. Returns last index value. */
348 init_array_element (struct value
*array
, struct value
*element
,
349 struct expression
*exp
, int *pos
,
350 enum noside noside
, LONGEST low_bound
, LONGEST high_bound
)
353 int element_size
= TYPE_LENGTH (value_type (element
));
355 if (exp
->elts
[*pos
].opcode
== BINOP_COMMA
)
358 init_array_element (array
, element
, exp
, pos
, noside
,
359 low_bound
, high_bound
);
360 return init_array_element (array
, element
,
361 exp
, pos
, noside
, low_bound
, high_bound
);
365 index
= value_as_long (evaluate_subexp (nullptr, exp
, pos
, noside
));
366 if (index
< low_bound
|| index
> high_bound
)
367 error (_("tuple index out of range"));
368 memcpy (value_contents_raw (array
) + (index
- low_bound
) * element_size
,
369 value_contents (element
), element_size
);
374 static struct value
*
375 value_f90_subarray (struct value
*array
,
376 struct expression
*exp
, int *pos
, enum noside noside
)
379 LONGEST low_bound
, high_bound
;
380 struct type
*range
= check_typedef (value_type (array
)->index_type ());
381 enum range_type range_type
382 = (enum range_type
) longest_to_int (exp
->elts
[pc
].longconst
);
386 if (range_type
== LOW_BOUND_DEFAULT
|| range_type
== BOTH_BOUND_DEFAULT
)
387 low_bound
= range
->bounds ()->low
.const_val ();
389 low_bound
= value_as_long (evaluate_subexp (nullptr, exp
, pos
, noside
));
391 if (range_type
== HIGH_BOUND_DEFAULT
|| range_type
== BOTH_BOUND_DEFAULT
)
392 high_bound
= range
->bounds ()->high
.const_val ();
394 high_bound
= value_as_long (evaluate_subexp (nullptr, exp
, pos
, noside
));
396 return value_slice (array
, low_bound
, high_bound
- low_bound
+ 1);
400 /* Promote value ARG1 as appropriate before performing a unary operation
402 If the result is not appropriate for any particular language then it
403 needs to patch this function. */
406 unop_promote (const struct language_defn
*language
, struct gdbarch
*gdbarch
,
411 *arg1
= coerce_ref (*arg1
);
412 type1
= check_typedef (value_type (*arg1
));
414 if (is_integral_type (type1
))
416 switch (language
->la_language
)
419 /* Perform integral promotion for ANSI C/C++.
420 If not appropriate for any particular language
421 it needs to modify this function. */
423 struct type
*builtin_int
= builtin_type (gdbarch
)->builtin_int
;
425 if (TYPE_LENGTH (type1
) < TYPE_LENGTH (builtin_int
))
426 *arg1
= value_cast (builtin_int
, *arg1
);
433 /* Promote values ARG1 and ARG2 as appropriate before performing a binary
434 operation on those two operands.
435 If the result is not appropriate for any particular language then it
436 needs to patch this function. */
439 binop_promote (const struct language_defn
*language
, struct gdbarch
*gdbarch
,
440 struct value
**arg1
, struct value
**arg2
)
442 struct type
*promoted_type
= NULL
;
446 *arg1
= coerce_ref (*arg1
);
447 *arg2
= coerce_ref (*arg2
);
449 type1
= check_typedef (value_type (*arg1
));
450 type2
= check_typedef (value_type (*arg2
));
452 if ((type1
->code () != TYPE_CODE_FLT
453 && type1
->code () != TYPE_CODE_DECFLOAT
454 && !is_integral_type (type1
))
455 || (type2
->code () != TYPE_CODE_FLT
456 && type2
->code () != TYPE_CODE_DECFLOAT
457 && !is_integral_type (type2
)))
460 if (type1
->code () == TYPE_CODE_DECFLOAT
461 || type2
->code () == TYPE_CODE_DECFLOAT
)
463 /* No promotion required. */
465 else if (type1
->code () == TYPE_CODE_FLT
466 || type2
->code () == TYPE_CODE_FLT
)
468 switch (language
->la_language
)
474 case language_opencl
:
475 /* No promotion required. */
479 /* For other languages the result type is unchanged from gdb
480 version 6.7 for backward compatibility.
481 If either arg was long double, make sure that value is also long
482 double. Otherwise use double. */
483 if (TYPE_LENGTH (type1
) * 8 > gdbarch_double_bit (gdbarch
)
484 || TYPE_LENGTH (type2
) * 8 > gdbarch_double_bit (gdbarch
))
485 promoted_type
= builtin_type (gdbarch
)->builtin_long_double
;
487 promoted_type
= builtin_type (gdbarch
)->builtin_double
;
491 else if (type1
->code () == TYPE_CODE_BOOL
492 && type2
->code () == TYPE_CODE_BOOL
)
494 /* No promotion required. */
497 /* Integral operations here. */
498 /* FIXME: Also mixed integral/booleans, with result an integer. */
500 const struct builtin_type
*builtin
= builtin_type (gdbarch
);
501 unsigned int promoted_len1
= TYPE_LENGTH (type1
);
502 unsigned int promoted_len2
= TYPE_LENGTH (type2
);
503 int is_unsigned1
= type1
->is_unsigned ();
504 int is_unsigned2
= type2
->is_unsigned ();
505 unsigned int result_len
;
506 int unsigned_operation
;
508 /* Determine type length and signedness after promotion for
510 if (promoted_len1
< TYPE_LENGTH (builtin
->builtin_int
))
513 promoted_len1
= TYPE_LENGTH (builtin
->builtin_int
);
515 if (promoted_len2
< TYPE_LENGTH (builtin
->builtin_int
))
518 promoted_len2
= TYPE_LENGTH (builtin
->builtin_int
);
521 if (promoted_len1
> promoted_len2
)
523 unsigned_operation
= is_unsigned1
;
524 result_len
= promoted_len1
;
526 else if (promoted_len2
> promoted_len1
)
528 unsigned_operation
= is_unsigned2
;
529 result_len
= promoted_len2
;
533 unsigned_operation
= is_unsigned1
|| is_unsigned2
;
534 result_len
= promoted_len1
;
537 switch (language
->la_language
)
543 if (result_len
<= TYPE_LENGTH (builtin
->builtin_int
))
545 promoted_type
= (unsigned_operation
546 ? builtin
->builtin_unsigned_int
547 : builtin
->builtin_int
);
549 else if (result_len
<= TYPE_LENGTH (builtin
->builtin_long
))
551 promoted_type
= (unsigned_operation
552 ? builtin
->builtin_unsigned_long
553 : builtin
->builtin_long
);
557 promoted_type
= (unsigned_operation
558 ? builtin
->builtin_unsigned_long_long
559 : builtin
->builtin_long_long
);
562 case language_opencl
:
563 if (result_len
<= TYPE_LENGTH (lookup_signed_typename
568 ? lookup_unsigned_typename (language
, "int")
569 : lookup_signed_typename (language
, "int"));
571 else if (result_len
<= TYPE_LENGTH (lookup_signed_typename
576 ? lookup_unsigned_typename (language
, "long")
577 : lookup_signed_typename (language
,"long"));
581 /* For other languages the result type is unchanged from gdb
582 version 6.7 for backward compatibility.
583 If either arg was long long, make sure that value is also long
584 long. Otherwise use long. */
585 if (unsigned_operation
)
587 if (result_len
> gdbarch_long_bit (gdbarch
) / HOST_CHAR_BIT
)
588 promoted_type
= builtin
->builtin_unsigned_long_long
;
590 promoted_type
= builtin
->builtin_unsigned_long
;
594 if (result_len
> gdbarch_long_bit (gdbarch
) / HOST_CHAR_BIT
)
595 promoted_type
= builtin
->builtin_long_long
;
597 promoted_type
= builtin
->builtin_long
;
605 /* Promote both operands to common type. */
606 *arg1
= value_cast (promoted_type
, *arg1
);
607 *arg2
= value_cast (promoted_type
, *arg2
);
612 ptrmath_type_p (const struct language_defn
*lang
, struct type
*type
)
614 type
= check_typedef (type
);
615 if (TYPE_IS_REFERENCE (type
))
616 type
= TYPE_TARGET_TYPE (type
);
618 switch (type
->code ())
624 case TYPE_CODE_ARRAY
:
625 return type
->is_vector () ? 0 : lang
->c_style_arrays_p ();
632 /* Represents a fake method with the given parameter types. This is
633 used by the parser to construct a temporary "expected" type for
634 method overload resolution. FLAGS is used as instance flags of the
635 new type, in order to be able to make the new type represent a
636 const/volatile overload. */
641 fake_method (type_instance_flags flags
,
642 int num_types
, struct type
**param_types
);
645 /* The constructed type. */
646 struct type
*type () { return &m_type
; }
649 struct type m_type
{};
650 main_type m_main_type
{};
653 fake_method::fake_method (type_instance_flags flags
,
654 int num_types
, struct type
**param_types
)
656 struct type
*type
= &m_type
;
658 TYPE_MAIN_TYPE (type
) = &m_main_type
;
659 TYPE_LENGTH (type
) = 1;
660 type
->set_code (TYPE_CODE_METHOD
);
661 TYPE_CHAIN (type
) = type
;
662 type
->set_instance_flags (flags
);
665 if (param_types
[num_types
- 1] == NULL
)
668 type
->set_has_varargs (true);
670 else if (check_typedef (param_types
[num_types
- 1])->code ()
674 /* Caller should have ensured this. */
675 gdb_assert (num_types
== 0);
676 type
->set_is_prototyped (true);
680 /* We don't use TYPE_ZALLOC here to allocate space as TYPE is owned by
681 neither an objfile nor a gdbarch. As a result we must manually
682 allocate memory for auxiliary fields, and free the memory ourselves
683 when we are done with it. */
684 type
->set_num_fields (num_types
);
686 ((struct field
*) xzalloc (sizeof (struct field
) * num_types
));
688 while (num_types
-- > 0)
689 type
->field (num_types
).set_type (param_types
[num_types
]);
692 fake_method::~fake_method ()
694 xfree (m_type
.fields ());
697 /* Helper for evaluating an OP_VAR_VALUE. */
700 evaluate_var_value (enum noside noside
, const block
*blk
, symbol
*var
)
702 /* JYG: We used to just return value_zero of the symbol type if
703 we're asked to avoid side effects. Otherwise we return
704 value_of_variable (...). However I'm not sure if
705 value_of_variable () has any side effect. We need a full value
706 object returned here for whatis_exp () to call evaluate_type ()
707 and then pass the full value to value_rtti_target_type () if we
708 are dealing with a pointer or reference to a base class and print
711 struct value
*ret
= NULL
;
715 ret
= value_of_variable (var
, blk
);
718 catch (const gdb_exception_error
&except
)
720 if (noside
!= EVAL_AVOID_SIDE_EFFECTS
)
723 ret
= value_zero (SYMBOL_TYPE (var
), not_lval
);
729 /* Helper for evaluating an OP_VAR_MSYM_VALUE. */
732 evaluate_var_msym_value (enum noside noside
,
733 struct objfile
*objfile
, minimal_symbol
*msymbol
)
736 type
*the_type
= find_minsym_type_and_address (msymbol
, objfile
, &address
);
738 if (noside
== EVAL_AVOID_SIDE_EFFECTS
&& !the_type
->is_gnu_ifunc ())
739 return value_zero (the_type
, not_lval
);
741 return value_at_lazy (the_type
, address
);
744 /* Helper for returning a value when handling EVAL_SKIP. */
747 eval_skip_value (expression
*exp
)
749 return value_from_longest (builtin_type (exp
->gdbarch
)->builtin_int
, 1);
752 /* Evaluate a function call. The function to be called is in
753 ARGVEC[0] and the arguments passed to the function are in
754 ARGVEC[1..NARGS]. FUNCTION_NAME is the name of the function, if
755 known. DEFAULT_RETURN_TYPE is used as the function's return type
756 if the return type is unknown. */
759 eval_call (expression
*exp
, enum noside noside
,
760 int nargs
, value
**argvec
,
761 const char *function_name
,
762 type
*default_return_type
)
764 if (argvec
[0] == NULL
)
765 error (_("Cannot evaluate function -- may be inlined"));
766 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
768 /* If the return type doesn't look like a function type,
769 call an error. This can happen if somebody tries to turn
770 a variable into a function call. */
772 type
*ftype
= value_type (argvec
[0]);
774 if (ftype
->code () == TYPE_CODE_INTERNAL_FUNCTION
)
776 /* We don't know anything about what the internal
777 function might return, but we have to return
779 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
,
782 else if (ftype
->code () == TYPE_CODE_XMETHOD
)
785 = result_type_of_xmethod (argvec
[0],
786 gdb::make_array_view (argvec
+ 1,
789 if (return_type
== NULL
)
790 error (_("Xmethod is missing return type."));
791 return value_zero (return_type
, not_lval
);
793 else if (ftype
->code () == TYPE_CODE_FUNC
794 || ftype
->code () == TYPE_CODE_METHOD
)
796 if (ftype
->is_gnu_ifunc ())
798 CORE_ADDR address
= value_address (argvec
[0]);
799 type
*resolved_type
= find_gnu_ifunc_target_type (address
);
801 if (resolved_type
!= NULL
)
802 ftype
= resolved_type
;
805 type
*return_type
= TYPE_TARGET_TYPE (ftype
);
807 if (return_type
== NULL
)
808 return_type
= default_return_type
;
810 if (return_type
== NULL
)
811 error_call_unknown_return_type (function_name
);
813 return allocate_value (return_type
);
816 error (_("Expression of type other than "
817 "\"Function returning ...\" used as function"));
819 switch (value_type (argvec
[0])->code ())
821 case TYPE_CODE_INTERNAL_FUNCTION
:
822 return call_internal_function (exp
->gdbarch
, exp
->language_defn
,
823 argvec
[0], nargs
, argvec
+ 1);
824 case TYPE_CODE_XMETHOD
:
825 return call_xmethod (argvec
[0], gdb::make_array_view (argvec
+ 1, nargs
));
827 return call_function_by_hand (argvec
[0], default_return_type
,
828 gdb::make_array_view (argvec
+ 1, nargs
));
832 /* Helper for evaluating an OP_FUNCALL. */
835 evaluate_funcall (type
*expect_type
, expression
*exp
, int *pos
,
843 symbol
*function
= NULL
;
844 char *function_name
= NULL
;
845 const char *var_func_name
= NULL
;
850 exp_opcode op
= exp
->elts
[*pos
].opcode
;
851 int nargs
= longest_to_int (exp
->elts
[pc
].longconst
);
852 /* Allocate arg vector, including space for the function to be
853 called in argvec[0], a potential `this', and a terminating
855 value
**argvec
= (value
**) alloca (sizeof (value
*) * (nargs
+ 3));
856 if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
858 /* First, evaluate the structure into arg2. */
861 if (op
== STRUCTOP_MEMBER
)
863 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
867 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
870 /* If the function is a virtual function, then the aggregate
871 value (providing the structure) plays its part by providing
872 the vtable. Otherwise, it is just along for the ride: call
873 the function directly. */
875 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
877 type
*a1_type
= check_typedef (value_type (arg1
));
878 if (noside
== EVAL_SKIP
)
879 tem
= 1; /* Set it to the right arg index so that all
880 arguments can also be skipped. */
881 else if (a1_type
->code () == TYPE_CODE_METHODPTR
)
883 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
884 arg1
= value_zero (TYPE_TARGET_TYPE (a1_type
), not_lval
);
886 arg1
= cplus_method_ptr_to_value (&arg2
, arg1
);
888 /* Now, say which argument to start evaluating from. */
893 else if (a1_type
->code () == TYPE_CODE_MEMBERPTR
)
895 struct type
*type_ptr
896 = lookup_pointer_type (TYPE_SELF_TYPE (a1_type
));
897 struct type
*target_type_ptr
898 = lookup_pointer_type (TYPE_TARGET_TYPE (a1_type
));
900 /* Now, convert these values to an address. */
901 arg2
= value_cast (type_ptr
, arg2
);
903 long mem_offset
= value_as_long (arg1
);
905 arg1
= value_from_pointer (target_type_ptr
,
906 value_as_long (arg2
) + mem_offset
);
907 arg1
= value_ind (arg1
);
911 error (_("Non-pointer-to-member value used in pointer-to-member "
914 else if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
916 /* Hair for method invocations. */
920 /* First, evaluate the structure into arg2. */
922 tem2
= longest_to_int (exp
->elts
[pc2
+ 1].longconst
);
923 *pos
+= 3 + BYTES_TO_EXP_ELEM (tem2
+ 1);
925 if (op
== STRUCTOP_STRUCT
)
927 /* If v is a variable in a register, and the user types
928 v.method (), this will produce an error, because v has no
931 A possible way around this would be to allocate a copy of
932 the variable on the stack, copy in the contents, call the
933 function, and copy out the contents. I.e. convert this
934 from call by reference to call by copy-return (or
935 whatever it's called). However, this does not work
936 because it is not the same: the method being called could
937 stash a copy of the address, and then future uses through
938 that address (after the method returns) would be expected
939 to use the variable itself, not some copy of it. */
940 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
944 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
946 /* Check to see if the operator '->' has been overloaded.
947 If the operator has been overloaded replace arg2 with the
948 value returned by the custom operator and continue
950 while (unop_user_defined_p (op
, arg2
))
952 struct value
*value
= NULL
;
955 value
= value_x_unop (arg2
, op
, noside
);
958 catch (const gdb_exception_error
&except
)
960 if (except
.error
== NOT_FOUND_ERROR
)
969 /* Now, say which argument to start evaluating from. */
972 else if (op
== OP_SCOPE
973 && overload_resolution
974 && (exp
->language_defn
->la_language
== language_cplus
))
976 /* Unpack it locally so we can properly handle overload
982 local_tem
= longest_to_int (exp
->elts
[pc2
+ 2].longconst
);
983 (*pos
) += 4 + BYTES_TO_EXP_ELEM (local_tem
+ 1);
984 struct type
*type
= exp
->elts
[pc2
+ 1].type
;
985 name
= &exp
->elts
[pc2
+ 3].string
;
988 function_name
= NULL
;
989 if (type
->code () == TYPE_CODE_NAMESPACE
)
991 function
= cp_lookup_symbol_namespace (type
->name (),
993 get_selected_block (0),
995 if (function
== NULL
)
996 error (_("No symbol \"%s\" in namespace \"%s\"."),
997 name
, type
->name ());
1000 /* arg2 is left as NULL on purpose. */
1004 gdb_assert (type
->code () == TYPE_CODE_STRUCT
1005 || type
->code () == TYPE_CODE_UNION
);
1006 function_name
= name
;
1008 /* We need a properly typed value for method lookup. For
1009 static methods arg2 is otherwise unused. */
1010 arg2
= value_zero (type
, lval_memory
);
1015 else if (op
== OP_ADL_FUNC
)
1017 /* Save the function position and move pos so that the arguments
1018 can be evaluated. */
1024 func_name_len
= longest_to_int (exp
->elts
[save_pos1
+ 3].longconst
);
1025 (*pos
) += 6 + BYTES_TO_EXP_ELEM (func_name_len
+ 1);
1029 /* Non-method function call. */
1033 /* If this is a C++ function wait until overload resolution. */
1034 if (op
== OP_VAR_VALUE
1035 && overload_resolution
1036 && (exp
->language_defn
->la_language
== language_cplus
))
1038 (*pos
) += 4; /* Skip the evaluation of the symbol. */
1043 if (op
== OP_VAR_MSYM_VALUE
)
1045 minimal_symbol
*msym
= exp
->elts
[*pos
+ 2].msymbol
;
1046 var_func_name
= msym
->print_name ();
1048 else if (op
== OP_VAR_VALUE
)
1050 symbol
*sym
= exp
->elts
[*pos
+ 2].symbol
;
1051 var_func_name
= sym
->print_name ();
1054 argvec
[0] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1055 type
*type
= value_type (argvec
[0]);
1056 if (type
&& type
->code () == TYPE_CODE_PTR
)
1057 type
= TYPE_TARGET_TYPE (type
);
1058 if (type
&& type
->code () == TYPE_CODE_FUNC
)
1060 for (; tem
<= nargs
&& tem
<= type
->num_fields (); tem
++)
1062 argvec
[tem
] = evaluate_subexp (type
->field (tem
- 1).type (),
1069 /* Evaluate arguments (if not already done, e.g., namespace::func()
1070 and overload-resolution is off). */
1071 for (; tem
<= nargs
; tem
++)
1073 /* Ensure that array expressions are coerced into pointer
1075 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1078 /* Signal end of arglist. */
1081 if (noside
== EVAL_SKIP
)
1082 return eval_skip_value (exp
);
1084 if (op
== OP_ADL_FUNC
)
1086 struct symbol
*symp
;
1089 int string_pc
= save_pos1
+ 3;
1091 /* Extract the function name. */
1092 name_len
= longest_to_int (exp
->elts
[string_pc
].longconst
);
1093 func_name
= (char *) alloca (name_len
+ 1);
1094 strcpy (func_name
, &exp
->elts
[string_pc
+ 1].string
);
1096 find_overload_match (gdb::make_array_view (&argvec
[1], nargs
),
1098 NON_METHOD
, /* not method */
1099 NULL
, NULL
, /* pass NULL symbol since
1100 symbol is unknown */
1101 NULL
, &symp
, NULL
, 0, noside
);
1103 /* Now fix the expression being evaluated. */
1104 exp
->elts
[save_pos1
+ 2].symbol
= symp
;
1105 argvec
[0] = evaluate_subexp_with_coercion (exp
, &save_pos1
, noside
);
1108 if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
1109 || (op
== OP_SCOPE
&& function_name
!= NULL
))
1111 int static_memfuncp
;
1114 /* Method invocation: stuff "this" as first parameter. If the
1115 method turns out to be static we undo this below. */
1120 /* Name of method from expression. */
1121 tstr
= &exp
->elts
[pc2
+ 2].string
;
1124 tstr
= function_name
;
1126 if (overload_resolution
&& (exp
->language_defn
->la_language
1129 /* Language is C++, do some overload resolution before
1131 struct value
*valp
= NULL
;
1133 (void) find_overload_match (gdb::make_array_view (&argvec
[1], nargs
),
1135 METHOD
, /* method */
1136 &arg2
, /* the object */
1138 &static_memfuncp
, 0, noside
);
1140 if (op
== OP_SCOPE
&& !static_memfuncp
)
1142 /* For the time being, we don't handle this. */
1143 error (_("Call to overloaded function %s requires "
1147 argvec
[1] = arg2
; /* the ``this'' pointer */
1148 argvec
[0] = valp
; /* Use the method found after overload
1152 /* Non-C++ case -- or no overload resolution. */
1154 struct value
*temp
= arg2
;
1156 argvec
[0] = value_struct_elt (&temp
, argvec
+ 1, tstr
,
1158 op
== STRUCTOP_STRUCT
1159 ? "structure" : "structure pointer");
1160 /* value_struct_elt updates temp with the correct value of
1161 the ``this'' pointer if necessary, so modify argvec[1] to
1162 reflect any ``this'' changes. */
1164 = value_from_longest (lookup_pointer_type(value_type (temp
)),
1165 value_address (temp
)
1166 + value_embedded_offset (temp
));
1167 argvec
[1] = arg2
; /* the ``this'' pointer */
1170 /* Take out `this' if needed. */
1171 if (static_memfuncp
)
1173 argvec
[1] = argvec
[0];
1178 else if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
1180 /* Pointer to member. argvec[1] is already set up. */
1183 else if (op
== OP_VAR_VALUE
|| (op
== OP_SCOPE
&& function
!= NULL
))
1185 /* Non-member function being called. */
1186 /* fn: This can only be done for C++ functions. A C-style
1187 function in a C++ program, for instance, does not have the
1188 fields that are expected here. */
1190 if (overload_resolution
&& (exp
->language_defn
->la_language
1193 /* Language is C++, do some overload resolution before
1195 struct symbol
*symp
;
1198 /* If a scope has been specified disable ADL. */
1202 if (op
== OP_VAR_VALUE
)
1203 function
= exp
->elts
[save_pos1
+2].symbol
;
1205 (void) find_overload_match (gdb::make_array_view (&argvec
[1], nargs
),
1206 NULL
, /* no need for name */
1207 NON_METHOD
, /* not method */
1208 NULL
, function
, /* the function */
1209 NULL
, &symp
, NULL
, no_adl
, noside
);
1211 if (op
== OP_VAR_VALUE
)
1213 /* Now fix the expression being evaluated. */
1214 exp
->elts
[save_pos1
+2].symbol
= symp
;
1215 argvec
[0] = evaluate_subexp_with_coercion (exp
, &save_pos1
,
1219 argvec
[0] = value_of_variable (symp
, get_selected_block (0));
1223 /* Not C++, or no overload resolution allowed. */
1224 /* Nothing to be done; argvec already correctly set up. */
1229 /* It is probably a C-style function. */
1230 /* Nothing to be done; argvec already correctly set up. */
1233 return eval_call (exp
, noside
, nargs
, argvec
, var_func_name
, expect_type
);
1236 /* Helper for skipping all the arguments in an undetermined argument list.
1237 This function was designed for use in the OP_F77_UNDETERMINED_ARGLIST
1238 case of evaluate_subexp_standard as multiple, but not all, code paths
1239 require a generic skip. */
1242 skip_undetermined_arglist (int nargs
, struct expression
*exp
, int *pos
,
1245 for (int i
= 0; i
< nargs
; ++i
)
1246 evaluate_subexp (nullptr, exp
, pos
, noside
);
1249 /* Return true if type is integral or reference to integral */
1252 is_integral_or_integral_reference (struct type
*type
)
1254 if (is_integral_type (type
))
1257 type
= check_typedef (type
);
1258 return (type
!= nullptr
1259 && TYPE_IS_REFERENCE (type
)
1260 && is_integral_type (TYPE_TARGET_TYPE (type
)));
1263 /* Called from evaluate_subexp_standard to perform array indexing, and
1264 sub-range extraction, for Fortran. As well as arrays this function
1265 also handles strings as they can be treated like arrays of characters.
1266 ARRAY is the array or string being accessed. EXP, POS, and NOSIDE are
1267 as for evaluate_subexp_standard, and NARGS is the number of arguments
1268 in this access (e.g. 'array (1,2,3)' would be NARGS 3). */
1270 static struct value
*
1271 fortran_value_subarray (struct value
*array
, struct expression
*exp
,
1272 int *pos
, int nargs
, enum noside noside
)
1274 if (exp
->elts
[*pos
].opcode
== OP_RANGE
)
1275 return value_f90_subarray (array
, exp
, pos
, noside
);
1277 if (noside
== EVAL_SKIP
)
1279 skip_undetermined_arglist (nargs
, exp
, pos
, noside
);
1280 /* Return the dummy value with the correct type. */
1284 LONGEST subscript_array
[MAX_FORTRAN_DIMS
];
1285 int ndimensions
= 1;
1286 struct type
*type
= check_typedef (value_type (array
));
1288 if (nargs
> MAX_FORTRAN_DIMS
)
1289 error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS
);
1291 ndimensions
= calc_f77_array_dims (type
);
1293 if (nargs
!= ndimensions
)
1294 error (_("Wrong number of subscripts"));
1296 gdb_assert (nargs
> 0);
1298 /* Now that we know we have a legal array subscript expression let us
1299 actually find out where this element exists in the array. */
1301 /* Take array indices left to right. */
1302 for (int i
= 0; i
< nargs
; i
++)
1304 /* Evaluate each subscript; it must be a legal integer in F77. */
1305 value
*arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1307 /* Fill in the subscript array. */
1308 subscript_array
[i
] = value_as_long (arg2
);
1311 /* Internal type of array is arranged right to left. */
1312 for (int i
= nargs
; i
> 0; i
--)
1314 struct type
*array_type
= check_typedef (value_type (array
));
1315 LONGEST index
= subscript_array
[i
- 1];
1317 array
= value_subscripted_rvalue (array
, index
,
1318 f77_get_lowerbound (array_type
));
1325 evaluate_subexp_standard (struct type
*expect_type
,
1326 struct expression
*exp
, int *pos
,
1330 int tem
, tem2
, tem3
;
1332 struct value
*arg1
= NULL
;
1333 struct value
*arg2
= NULL
;
1337 struct value
**argvec
;
1341 struct type
**arg_types
;
1344 op
= exp
->elts
[pc
].opcode
;
1349 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
1350 (*pos
) += 4 + BYTES_TO_EXP_ELEM (tem
+ 1);
1351 if (noside
== EVAL_SKIP
)
1352 return eval_skip_value (exp
);
1353 arg1
= value_aggregate_elt (exp
->elts
[pc
+ 1].type
,
1354 &exp
->elts
[pc
+ 3].string
,
1355 expect_type
, 0, noside
);
1357 error (_("There is no field named %s"), &exp
->elts
[pc
+ 3].string
);
1362 return value_from_longest (exp
->elts
[pc
+ 1].type
,
1363 exp
->elts
[pc
+ 2].longconst
);
1367 return value_from_contents (exp
->elts
[pc
+ 1].type
,
1368 exp
->elts
[pc
+ 2].floatconst
);
1374 symbol
*var
= exp
->elts
[pc
+ 2].symbol
;
1375 if (SYMBOL_TYPE (var
)->code () == TYPE_CODE_ERROR
)
1376 error_unknown_type (var
->print_name ());
1377 if (noside
!= EVAL_SKIP
)
1378 return evaluate_var_value (noside
, exp
->elts
[pc
+ 1].block
, var
);
1381 /* Return a dummy value of the correct type when skipping, so
1382 that parent functions know what is to be skipped. */
1383 return allocate_value (SYMBOL_TYPE (var
));
1387 case OP_VAR_MSYM_VALUE
:
1391 minimal_symbol
*msymbol
= exp
->elts
[pc
+ 2].msymbol
;
1392 value
*val
= evaluate_var_msym_value (noside
,
1393 exp
->elts
[pc
+ 1].objfile
,
1396 type
= value_type (val
);
1397 if (type
->code () == TYPE_CODE_ERROR
1398 && (noside
!= EVAL_AVOID_SIDE_EFFECTS
|| pc
!= 0))
1399 error_unknown_type (msymbol
->print_name ());
1403 case OP_VAR_ENTRY_VALUE
:
1405 if (noside
== EVAL_SKIP
)
1406 return eval_skip_value (exp
);
1409 struct symbol
*sym
= exp
->elts
[pc
+ 1].symbol
;
1410 struct frame_info
*frame
;
1412 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1413 return value_zero (SYMBOL_TYPE (sym
), not_lval
);
1415 if (SYMBOL_COMPUTED_OPS (sym
) == NULL
1416 || SYMBOL_COMPUTED_OPS (sym
)->read_variable_at_entry
== NULL
)
1417 error (_("Symbol \"%s\" does not have any specific entry value"),
1418 sym
->print_name ());
1420 frame
= get_selected_frame (NULL
);
1421 return SYMBOL_COMPUTED_OPS (sym
)->read_variable_at_entry (sym
, frame
);
1424 case OP_FUNC_STATIC_VAR
:
1425 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1426 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1427 if (noside
== EVAL_SKIP
)
1428 return eval_skip_value (exp
);
1431 value
*func
= evaluate_subexp_standard (NULL
, exp
, pos
, noside
);
1432 CORE_ADDR addr
= value_address (func
);
1434 const block
*blk
= block_for_pc (addr
);
1435 const char *var
= &exp
->elts
[pc
+ 2].string
;
1437 struct block_symbol sym
= lookup_symbol (var
, blk
, VAR_DOMAIN
, NULL
);
1439 if (sym
.symbol
== NULL
)
1440 error (_("No symbol \"%s\" in specified context."), var
);
1442 return evaluate_var_value (noside
, sym
.block
, sym
.symbol
);
1448 access_value_history (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
1452 const char *name
= &exp
->elts
[pc
+ 2].string
;
1456 (*pos
) += 3 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
1457 regno
= user_reg_map_name_to_regnum (exp
->gdbarch
,
1458 name
, strlen (name
));
1460 error (_("Register $%s not available."), name
);
1462 /* In EVAL_AVOID_SIDE_EFFECTS mode, we only need to return
1463 a value with the appropriate register type. Unfortunately,
1464 we don't have easy access to the type of user registers.
1465 So for these registers, we fetch the register value regardless
1466 of the evaluation mode. */
1467 if (noside
== EVAL_AVOID_SIDE_EFFECTS
1468 && regno
< gdbarch_num_cooked_regs (exp
->gdbarch
))
1469 val
= value_zero (register_type (exp
->gdbarch
, regno
), not_lval
);
1471 val
= value_of_register (regno
, get_selected_frame (NULL
));
1473 error (_("Value of register %s not available."), name
);
1479 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
1480 return value_from_longest (type
, exp
->elts
[pc
+ 1].longconst
);
1482 case OP_INTERNALVAR
:
1484 return value_of_internalvar (exp
->gdbarch
,
1485 exp
->elts
[pc
+ 1].internalvar
);
1488 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1489 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1490 if (noside
== EVAL_SKIP
)
1491 return eval_skip_value (exp
);
1492 type
= language_string_char_type (exp
->language_defn
, exp
->gdbarch
);
1493 return value_string (&exp
->elts
[pc
+ 2].string
, tem
, type
);
1495 case OP_OBJC_NSSTRING
: /* Objective C Foundation Class
1496 NSString constant. */
1497 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1498 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1499 if (noside
== EVAL_SKIP
)
1500 return eval_skip_value (exp
);
1501 return value_nsstring (exp
->gdbarch
, &exp
->elts
[pc
+ 2].string
, tem
+ 1);
1505 tem2
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1506 tem3
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
1507 nargs
= tem3
- tem2
+ 1;
1508 type
= expect_type
? check_typedef (expect_type
) : nullptr;
1510 if (expect_type
!= nullptr && noside
!= EVAL_SKIP
1511 && type
->code () == TYPE_CODE_STRUCT
)
1513 struct value
*rec
= allocate_value (expect_type
);
1515 memset (value_contents_raw (rec
), '\0', TYPE_LENGTH (type
));
1516 return evaluate_struct_tuple (rec
, exp
, pos
, noside
, nargs
);
1519 if (expect_type
!= nullptr && noside
!= EVAL_SKIP
1520 && type
->code () == TYPE_CODE_ARRAY
)
1522 struct type
*range_type
= type
->index_type ();
1523 struct type
*element_type
= TYPE_TARGET_TYPE (type
);
1524 struct value
*array
= allocate_value (expect_type
);
1525 int element_size
= TYPE_LENGTH (check_typedef (element_type
));
1526 LONGEST low_bound
, high_bound
, index
;
1528 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
1531 high_bound
= (TYPE_LENGTH (type
) / element_size
) - 1;
1534 memset (value_contents_raw (array
), 0, TYPE_LENGTH (expect_type
));
1535 for (tem
= nargs
; --nargs
>= 0;)
1537 struct value
*element
;
1540 element
= evaluate_subexp (element_type
, exp
, pos
, noside
);
1541 if (value_type (element
) != element_type
)
1542 element
= value_cast (element_type
, element
);
1545 int continue_pc
= *pos
;
1548 index
= init_array_element (array
, element
, exp
, pos
, noside
,
1549 low_bound
, high_bound
);
1554 if (index
> high_bound
)
1555 /* To avoid memory corruption. */
1556 error (_("Too many array elements"));
1557 memcpy (value_contents_raw (array
)
1558 + (index
- low_bound
) * element_size
,
1559 value_contents (element
),
1567 if (expect_type
!= nullptr && noside
!= EVAL_SKIP
1568 && type
->code () == TYPE_CODE_SET
)
1570 struct value
*set
= allocate_value (expect_type
);
1571 gdb_byte
*valaddr
= value_contents_raw (set
);
1572 struct type
*element_type
= type
->index_type ();
1573 struct type
*check_type
= element_type
;
1574 LONGEST low_bound
, high_bound
;
1576 /* Get targettype of elementtype. */
1577 while (check_type
->code () == TYPE_CODE_RANGE
1578 || check_type
->code () == TYPE_CODE_TYPEDEF
)
1579 check_type
= TYPE_TARGET_TYPE (check_type
);
1581 if (get_discrete_bounds (element_type
, &low_bound
, &high_bound
) < 0)
1582 error (_("(power)set type with unknown size"));
1583 memset (valaddr
, '\0', TYPE_LENGTH (type
));
1584 for (tem
= 0; tem
< nargs
; tem
++)
1586 LONGEST range_low
, range_high
;
1587 struct type
*range_low_type
, *range_high_type
;
1588 struct value
*elem_val
;
1590 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
1591 range_low_type
= range_high_type
= value_type (elem_val
);
1592 range_low
= range_high
= value_as_long (elem_val
);
1594 /* Check types of elements to avoid mixture of elements from
1595 different types. Also check if type of element is "compatible"
1596 with element type of powerset. */
1597 if (range_low_type
->code () == TYPE_CODE_RANGE
)
1598 range_low_type
= TYPE_TARGET_TYPE (range_low_type
);
1599 if (range_high_type
->code () == TYPE_CODE_RANGE
)
1600 range_high_type
= TYPE_TARGET_TYPE (range_high_type
);
1601 if ((range_low_type
->code () != range_high_type
->code ())
1602 || (range_low_type
->code () == TYPE_CODE_ENUM
1603 && (range_low_type
!= range_high_type
)))
1604 /* different element modes. */
1605 error (_("POWERSET tuple elements of different mode"));
1606 if ((check_type
->code () != range_low_type
->code ())
1607 || (check_type
->code () == TYPE_CODE_ENUM
1608 && range_low_type
!= check_type
))
1609 error (_("incompatible POWERSET tuple elements"));
1610 if (range_low
> range_high
)
1612 warning (_("empty POWERSET tuple range"));
1615 if (range_low
< low_bound
|| range_high
> high_bound
)
1616 error (_("POWERSET tuple element out of range"));
1617 range_low
-= low_bound
;
1618 range_high
-= low_bound
;
1619 for (; range_low
<= range_high
; range_low
++)
1621 int bit_index
= (unsigned) range_low
% TARGET_CHAR_BIT
;
1623 if (gdbarch_byte_order (exp
->gdbarch
) == BFD_ENDIAN_BIG
)
1624 bit_index
= TARGET_CHAR_BIT
- 1 - bit_index
;
1625 valaddr
[(unsigned) range_low
/ TARGET_CHAR_BIT
]
1632 argvec
= XALLOCAVEC (struct value
*, nargs
);
1633 for (tem
= 0; tem
< nargs
; tem
++)
1635 /* Ensure that array expressions are coerced into pointer
1637 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1639 if (noside
== EVAL_SKIP
)
1640 return eval_skip_value (exp
);
1641 return value_array (tem2
, tem3
, argvec
);
1645 struct value
*array
= evaluate_subexp (nullptr, exp
, pos
, noside
);
1647 = value_as_long (evaluate_subexp (nullptr, exp
, pos
, noside
));
1648 int upper
= value_as_long (evaluate_subexp (nullptr, exp
, pos
, noside
));
1650 if (noside
== EVAL_SKIP
)
1651 return eval_skip_value (exp
);
1652 return value_slice (array
, lowbound
, upper
- lowbound
+ 1);
1656 /* Skip third and second args to evaluate the first one. */
1657 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
1658 if (value_logical_not (arg1
))
1660 evaluate_subexp (nullptr, exp
, pos
, EVAL_SKIP
);
1661 return evaluate_subexp (nullptr, exp
, pos
, noside
);
1665 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
1666 evaluate_subexp (nullptr, exp
, pos
, EVAL_SKIP
);
1670 case OP_OBJC_SELECTOR
:
1671 { /* Objective C @selector operator. */
1672 char *sel
= &exp
->elts
[pc
+ 2].string
;
1673 int len
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1674 struct type
*selector_type
;
1676 (*pos
) += 3 + BYTES_TO_EXP_ELEM (len
+ 1);
1677 if (noside
== EVAL_SKIP
)
1678 return eval_skip_value (exp
);
1681 sel
[len
] = 0; /* Make sure it's terminated. */
1683 selector_type
= builtin_type (exp
->gdbarch
)->builtin_data_ptr
;
1684 return value_from_longest (selector_type
,
1685 lookup_child_selector (exp
->gdbarch
, sel
));
1688 case OP_OBJC_MSGCALL
:
1689 { /* Objective C message (method) call. */
1691 CORE_ADDR responds_selector
= 0;
1692 CORE_ADDR method_selector
= 0;
1694 CORE_ADDR selector
= 0;
1696 int struct_return
= 0;
1697 enum noside sub_no_side
= EVAL_NORMAL
;
1699 struct value
*msg_send
= NULL
;
1700 struct value
*msg_send_stret
= NULL
;
1701 int gnu_runtime
= 0;
1703 struct value
*target
= NULL
;
1704 struct value
*method
= NULL
;
1705 struct value
*called_method
= NULL
;
1707 struct type
*selector_type
= NULL
;
1708 struct type
*long_type
;
1710 struct value
*ret
= NULL
;
1713 selector
= exp
->elts
[pc
+ 1].longconst
;
1714 nargs
= exp
->elts
[pc
+ 2].longconst
;
1715 argvec
= XALLOCAVEC (struct value
*, nargs
+ 5);
1719 long_type
= builtin_type (exp
->gdbarch
)->builtin_long
;
1720 selector_type
= builtin_type (exp
->gdbarch
)->builtin_data_ptr
;
1722 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1723 sub_no_side
= EVAL_NORMAL
;
1725 sub_no_side
= noside
;
1727 target
= evaluate_subexp (selector_type
, exp
, pos
, sub_no_side
);
1729 if (value_as_long (target
) == 0)
1730 return value_from_longest (long_type
, 0);
1732 if (lookup_minimal_symbol ("objc_msg_lookup", 0, 0).minsym
)
1735 /* Find the method dispatch (Apple runtime) or method lookup
1736 (GNU runtime) function for Objective-C. These will be used
1737 to lookup the symbol information for the method. If we
1738 can't find any symbol information, then we'll use these to
1739 call the method, otherwise we can call the method
1740 directly. The msg_send_stret function is used in the special
1741 case of a method that returns a structure (Apple runtime
1745 type
= selector_type
;
1747 type
= lookup_function_type (type
);
1748 type
= lookup_pointer_type (type
);
1749 type
= lookup_function_type (type
);
1750 type
= lookup_pointer_type (type
);
1752 msg_send
= find_function_in_inferior ("objc_msg_lookup", NULL
);
1754 = find_function_in_inferior ("objc_msg_lookup", NULL
);
1756 msg_send
= value_from_pointer (type
, value_as_address (msg_send
));
1757 msg_send_stret
= value_from_pointer (type
,
1758 value_as_address (msg_send_stret
));
1762 msg_send
= find_function_in_inferior ("objc_msgSend", NULL
);
1763 /* Special dispatcher for methods returning structs. */
1765 = find_function_in_inferior ("objc_msgSend_stret", NULL
);
1768 /* Verify the target object responds to this method. The
1769 standard top-level 'Object' class uses a different name for
1770 the verification method than the non-standard, but more
1771 often used, 'NSObject' class. Make sure we check for both. */
1774 = lookup_child_selector (exp
->gdbarch
, "respondsToSelector:");
1775 if (responds_selector
== 0)
1777 = lookup_child_selector (exp
->gdbarch
, "respondsTo:");
1779 if (responds_selector
== 0)
1780 error (_("no 'respondsTo:' or 'respondsToSelector:' method"));
1783 = lookup_child_selector (exp
->gdbarch
, "methodForSelector:");
1784 if (method_selector
== 0)
1786 = lookup_child_selector (exp
->gdbarch
, "methodFor:");
1788 if (method_selector
== 0)
1789 error (_("no 'methodFor:' or 'methodForSelector:' method"));
1791 /* Call the verification method, to make sure that the target
1792 class implements the desired method. */
1794 argvec
[0] = msg_send
;
1796 argvec
[2] = value_from_longest (long_type
, responds_selector
);
1797 argvec
[3] = value_from_longest (long_type
, selector
);
1800 ret
= call_function_by_hand (argvec
[0], NULL
, {argvec
+ 1, 3});
1803 /* Function objc_msg_lookup returns a pointer. */
1805 ret
= call_function_by_hand (argvec
[0], NULL
, {argvec
+ 1, 3});
1807 if (value_as_long (ret
) == 0)
1808 error (_("Target does not respond to this message selector."));
1810 /* Call "methodForSelector:" method, to get the address of a
1811 function method that implements this selector for this
1812 class. If we can find a symbol at that address, then we
1813 know the return type, parameter types etc. (that's a good
1816 argvec
[0] = msg_send
;
1818 argvec
[2] = value_from_longest (long_type
, method_selector
);
1819 argvec
[3] = value_from_longest (long_type
, selector
);
1822 ret
= call_function_by_hand (argvec
[0], NULL
, {argvec
+ 1, 3});
1826 ret
= call_function_by_hand (argvec
[0], NULL
, {argvec
+ 1, 3});
1829 /* ret should now be the selector. */
1831 addr
= value_as_long (ret
);
1834 struct symbol
*sym
= NULL
;
1836 /* The address might point to a function descriptor;
1837 resolve it to the actual code address instead. */
1838 addr
= gdbarch_convert_from_func_ptr_addr (exp
->gdbarch
, addr
,
1839 current_top_target ());
1841 /* Is it a high_level symbol? */
1842 sym
= find_pc_function (addr
);
1844 method
= value_of_variable (sym
, 0);
1847 /* If we found a method with symbol information, check to see
1848 if it returns a struct. Otherwise assume it doesn't. */
1853 struct type
*val_type
;
1855 funaddr
= find_function_addr (method
, &val_type
);
1857 block_for_pc (funaddr
);
1859 val_type
= check_typedef (val_type
);
1861 if ((val_type
== NULL
)
1862 || (val_type
->code () == TYPE_CODE_ERROR
))
1864 if (expect_type
!= NULL
)
1865 val_type
= expect_type
;
1868 struct_return
= using_struct_return (exp
->gdbarch
, method
,
1871 else if (expect_type
!= NULL
)
1873 struct_return
= using_struct_return (exp
->gdbarch
, NULL
,
1874 check_typedef (expect_type
));
1877 /* Found a function symbol. Now we will substitute its
1878 value in place of the message dispatcher (obj_msgSend),
1879 so that we call the method directly instead of thru
1880 the dispatcher. The main reason for doing this is that
1881 we can now evaluate the return value and parameter values
1882 according to their known data types, in case we need to
1883 do things like promotion, dereferencing, special handling
1884 of structs and doubles, etc.
1886 We want to use the type signature of 'method', but still
1887 jump to objc_msgSend() or objc_msgSend_stret() to better
1888 mimic the behavior of the runtime. */
1892 if (value_type (method
)->code () != TYPE_CODE_FUNC
)
1893 error (_("method address has symbol information "
1894 "with non-function type; skipping"));
1896 /* Create a function pointer of the appropriate type, and
1897 replace its value with the value of msg_send or
1898 msg_send_stret. We must use a pointer here, as
1899 msg_send and msg_send_stret are of pointer type, and
1900 the representation may be different on systems that use
1901 function descriptors. */
1904 = value_from_pointer (lookup_pointer_type (value_type (method
)),
1905 value_as_address (msg_send_stret
));
1908 = value_from_pointer (lookup_pointer_type (value_type (method
)),
1909 value_as_address (msg_send
));
1914 called_method
= msg_send_stret
;
1916 called_method
= msg_send
;
1919 if (noside
== EVAL_SKIP
)
1920 return eval_skip_value (exp
);
1922 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1924 /* If the return type doesn't look like a function type,
1925 call an error. This can happen if somebody tries to
1926 turn a variable into a function call. This is here
1927 because people often want to call, eg, strcmp, which
1928 gdb doesn't know is a function. If gdb isn't asked for
1929 it's opinion (ie. through "whatis"), it won't offer
1932 struct type
*callee_type
= value_type (called_method
);
1934 if (callee_type
&& callee_type
->code () == TYPE_CODE_PTR
)
1935 callee_type
= TYPE_TARGET_TYPE (callee_type
);
1936 callee_type
= TYPE_TARGET_TYPE (callee_type
);
1940 if ((callee_type
->code () == TYPE_CODE_ERROR
) && expect_type
)
1941 return allocate_value (expect_type
);
1943 return allocate_value (callee_type
);
1946 error (_("Expression of type other than "
1947 "\"method returning ...\" used as a method"));
1950 /* Now depending on whether we found a symbol for the method,
1951 we will either call the runtime dispatcher or the method
1954 argvec
[0] = called_method
;
1956 argvec
[2] = value_from_longest (long_type
, selector
);
1957 /* User-supplied arguments. */
1958 for (tem
= 0; tem
< nargs
; tem
++)
1959 argvec
[tem
+ 3] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1960 argvec
[tem
+ 3] = 0;
1962 auto call_args
= gdb::make_array_view (argvec
+ 1, nargs
+ 2);
1964 if (gnu_runtime
&& (method
!= NULL
))
1966 /* Function objc_msg_lookup returns a pointer. */
1967 deprecated_set_value_type (argvec
[0],
1968 lookup_pointer_type (lookup_function_type (value_type (argvec
[0]))));
1969 argvec
[0] = call_function_by_hand (argvec
[0], NULL
, call_args
);
1972 return call_function_by_hand (argvec
[0], NULL
, call_args
);
1977 return evaluate_funcall (expect_type
, exp
, pos
, noside
);
1979 case OP_F77_UNDETERMINED_ARGLIST
:
1981 /* Remember that in F77, functions, substring ops and
1982 array subscript operations cannot be disambiguated
1983 at parse time. We have made all array subscript operations,
1984 substring operations as well as function calls come here
1985 and we now have to discover what the heck this thing actually was.
1986 If it is a function, we process just as if we got an OP_FUNCALL. */
1988 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1991 /* First determine the type code we are dealing with. */
1992 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
1993 type
= check_typedef (value_type (arg1
));
1994 code
= type
->code ();
1996 if (code
== TYPE_CODE_PTR
)
1998 /* Fortran always passes variable to subroutines as pointer.
1999 So we need to look into its target type to see if it is
2000 array, string or function. If it is, we need to switch
2001 to the target value the original one points to. */
2002 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
2004 if (target_type
->code () == TYPE_CODE_ARRAY
2005 || target_type
->code () == TYPE_CODE_STRING
2006 || target_type
->code () == TYPE_CODE_FUNC
)
2008 arg1
= value_ind (arg1
);
2009 type
= check_typedef (value_type (arg1
));
2010 code
= type
->code ();
2016 case TYPE_CODE_ARRAY
:
2017 case TYPE_CODE_STRING
:
2018 return fortran_value_subarray (arg1
, exp
, pos
, nargs
, noside
);
2021 case TYPE_CODE_FUNC
:
2022 case TYPE_CODE_INTERNAL_FUNCTION
:
2023 /* It's a function call. */
2024 /* Allocate arg vector, including space for the function to be
2025 called in argvec[0] and a terminating NULL. */
2026 argvec
= (struct value
**)
2027 alloca (sizeof (struct value
*) * (nargs
+ 2));
2030 for (; tem
<= nargs
; tem
++)
2032 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
2033 /* Arguments in Fortran are passed by address. Coerce the
2034 arguments here rather than in value_arg_coerce as otherwise
2035 the call to malloc to place the non-lvalue parameters in
2036 target memory is hit by this Fortran specific logic. This
2037 results in malloc being called with a pointer to an integer
2038 followed by an attempt to malloc the arguments to malloc in
2039 target memory. Infinite recursion ensues. */
2040 if (code
== TYPE_CODE_PTR
|| code
== TYPE_CODE_FUNC
)
2043 = TYPE_FIELD_ARTIFICIAL (value_type (arg1
), tem
- 1);
2044 argvec
[tem
] = fortran_argument_convert (argvec
[tem
],
2048 argvec
[tem
] = 0; /* signal end of arglist */
2049 if (noside
== EVAL_SKIP
)
2050 return eval_skip_value (exp
);
2051 return eval_call (exp
, noside
, nargs
, argvec
, NULL
, expect_type
);
2054 error (_("Cannot perform substring on this type"));
2058 /* We have a complex number, There should be 2 floating
2059 point numbers that compose it. */
2061 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2062 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2064 return value_literal_complex (arg1
, arg2
, exp
->elts
[pc
+ 1].type
);
2066 case STRUCTOP_STRUCT
:
2067 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
2068 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
2069 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2070 if (noside
== EVAL_SKIP
)
2071 return eval_skip_value (exp
);
2072 arg3
= value_struct_elt (&arg1
, NULL
, &exp
->elts
[pc
+ 2].string
,
2074 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2075 arg3
= value_zero (value_type (arg3
), VALUE_LVAL (arg3
));
2079 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
2080 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
2081 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2082 if (noside
== EVAL_SKIP
)
2083 return eval_skip_value (exp
);
2085 /* Check to see if operator '->' has been overloaded. If so replace
2086 arg1 with the value returned by evaluating operator->(). */
2087 while (unop_user_defined_p (op
, arg1
))
2089 struct value
*value
= NULL
;
2092 value
= value_x_unop (arg1
, op
, noside
);
2095 catch (const gdb_exception_error
&except
)
2097 if (except
.error
== NOT_FOUND_ERROR
)
2106 /* JYG: if print object is on we need to replace the base type
2107 with rtti type in order to continue on with successful
2108 lookup of member / method only available in the rtti type. */
2110 struct type
*arg_type
= value_type (arg1
);
2111 struct type
*real_type
;
2112 int full
, using_enc
;
2114 struct value_print_options opts
;
2116 get_user_print_options (&opts
);
2117 if (opts
.objectprint
&& TYPE_TARGET_TYPE (arg_type
)
2118 && (TYPE_TARGET_TYPE (arg_type
)->code () == TYPE_CODE_STRUCT
))
2120 real_type
= value_rtti_indirect_type (arg1
, &full
, &top
,
2123 arg1
= value_cast (real_type
, arg1
);
2127 arg3
= value_struct_elt (&arg1
, NULL
, &exp
->elts
[pc
+ 2].string
,
2128 NULL
, "structure pointer");
2129 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2130 arg3
= value_zero (value_type (arg3
), VALUE_LVAL (arg3
));
2133 case STRUCTOP_MEMBER
:
2135 if (op
== STRUCTOP_MEMBER
)
2136 arg1
= evaluate_subexp_for_address (exp
, pos
, noside
);
2138 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2140 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2142 if (noside
== EVAL_SKIP
)
2143 return eval_skip_value (exp
);
2145 type
= check_typedef (value_type (arg2
));
2146 switch (type
->code ())
2148 case TYPE_CODE_METHODPTR
:
2149 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2150 return value_zero (TYPE_TARGET_TYPE (type
), not_lval
);
2153 arg2
= cplus_method_ptr_to_value (&arg1
, arg2
);
2154 gdb_assert (value_type (arg2
)->code () == TYPE_CODE_PTR
);
2155 return value_ind (arg2
);
2158 case TYPE_CODE_MEMBERPTR
:
2159 /* Now, convert these values to an address. */
2160 arg1
= value_cast_pointers (lookup_pointer_type (TYPE_SELF_TYPE (type
)),
2163 mem_offset
= value_as_long (arg2
);
2165 arg3
= value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
2166 value_as_long (arg1
) + mem_offset
);
2167 return value_ind (arg3
);
2170 error (_("non-pointer-to-member value used "
2171 "in pointer-to-member construct"));
2176 type_instance_flags flags
2177 = (type_instance_flag_value
) longest_to_int (exp
->elts
[pc
+ 1].longconst
);
2178 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
2179 arg_types
= (struct type
**) alloca (nargs
* sizeof (struct type
*));
2180 for (ix
= 0; ix
< nargs
; ++ix
)
2181 arg_types
[ix
] = exp
->elts
[pc
+ 2 + ix
+ 1].type
;
2183 fake_method
fake_expect_type (flags
, nargs
, arg_types
);
2184 *(pos
) += 4 + nargs
;
2185 return evaluate_subexp_standard (fake_expect_type
.type (), exp
, pos
,
2190 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2191 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2192 if (noside
== EVAL_SKIP
)
2193 return eval_skip_value (exp
);
2194 if (binop_user_defined_p (op
, arg1
, arg2
))
2195 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2197 return value_concat (arg1
, arg2
);
2200 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2201 /* Special-case assignments where the left-hand-side is a
2202 convenience variable -- in these, don't bother setting an
2203 expected type. This avoids a weird case where re-assigning a
2204 string or array to an internal variable could error with "Too
2205 many array elements". */
2206 arg2
= evaluate_subexp (VALUE_LVAL (arg1
) == lval_internalvar
2208 : value_type (arg1
),
2211 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2213 if (binop_user_defined_p (op
, arg1
, arg2
))
2214 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2216 return value_assign (arg1
, arg2
);
2218 case BINOP_ASSIGN_MODIFY
:
2220 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2221 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2222 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2224 op
= exp
->elts
[pc
+ 1].opcode
;
2225 if (binop_user_defined_p (op
, arg1
, arg2
))
2226 return value_x_binop (arg1
, arg2
, BINOP_ASSIGN_MODIFY
, op
, noside
);
2227 else if (op
== BINOP_ADD
&& ptrmath_type_p (exp
->language_defn
,
2229 && is_integral_type (value_type (arg2
)))
2230 arg2
= value_ptradd (arg1
, value_as_long (arg2
));
2231 else if (op
== BINOP_SUB
&& ptrmath_type_p (exp
->language_defn
,
2233 && is_integral_type (value_type (arg2
)))
2234 arg2
= value_ptradd (arg1
, - value_as_long (arg2
));
2237 struct value
*tmp
= arg1
;
2239 /* For shift and integer exponentiation operations,
2240 only promote the first argument. */
2241 if ((op
== BINOP_LSH
|| op
== BINOP_RSH
|| op
== BINOP_EXP
)
2242 && is_integral_type (value_type (arg2
)))
2243 unop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
);
2245 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2247 arg2
= value_binop (tmp
, arg2
, op
);
2249 return value_assign (arg1
, arg2
);
2252 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2253 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2254 if (noside
== EVAL_SKIP
)
2255 return eval_skip_value (exp
);
2256 if (binop_user_defined_p (op
, arg1
, arg2
))
2257 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2258 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
2259 && is_integral_or_integral_reference (value_type (arg2
)))
2260 return value_ptradd (arg1
, value_as_long (arg2
));
2261 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg2
))
2262 && is_integral_or_integral_reference (value_type (arg1
)))
2263 return value_ptradd (arg2
, value_as_long (arg1
));
2266 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2267 return value_binop (arg1
, arg2
, BINOP_ADD
);
2271 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2272 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2273 if (noside
== EVAL_SKIP
)
2274 return eval_skip_value (exp
);
2275 if (binop_user_defined_p (op
, arg1
, arg2
))
2276 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2277 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
2278 && ptrmath_type_p (exp
->language_defn
, value_type (arg2
)))
2280 /* FIXME -- should be ptrdiff_t */
2281 type
= builtin_type (exp
->gdbarch
)->builtin_long
;
2282 return value_from_longest (type
, value_ptrdiff (arg1
, arg2
));
2284 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
2285 && is_integral_or_integral_reference (value_type (arg2
)))
2286 return value_ptradd (arg1
, - value_as_long (arg2
));
2289 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2290 return value_binop (arg1
, arg2
, BINOP_SUB
);
2301 case BINOP_BITWISE_AND
:
2302 case BINOP_BITWISE_IOR
:
2303 case BINOP_BITWISE_XOR
:
2304 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2305 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2306 if (noside
== EVAL_SKIP
)
2307 return eval_skip_value (exp
);
2308 if (binop_user_defined_p (op
, arg1
, arg2
))
2309 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2312 /* If EVAL_AVOID_SIDE_EFFECTS and we're dividing by zero,
2313 fudge arg2 to avoid division-by-zero, the caller is
2314 (theoretically) only looking for the type of the result. */
2315 if (noside
== EVAL_AVOID_SIDE_EFFECTS
2316 /* ??? Do we really want to test for BINOP_MOD here?
2317 The implementation of value_binop gives it a well-defined
2320 || op
== BINOP_INTDIV
2323 && value_logical_not (arg2
))
2325 struct value
*v_one
, *retval
;
2327 v_one
= value_one (value_type (arg2
));
2328 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &v_one
);
2329 retval
= value_binop (arg1
, v_one
, op
);
2334 /* For shift and integer exponentiation operations,
2335 only promote the first argument. */
2336 if ((op
== BINOP_LSH
|| op
== BINOP_RSH
|| op
== BINOP_EXP
)
2337 && is_integral_type (value_type (arg2
)))
2338 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2340 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2342 return value_binop (arg1
, arg2
, op
);
2346 case BINOP_SUBSCRIPT
:
2347 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2348 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2349 if (noside
== EVAL_SKIP
)
2350 return eval_skip_value (exp
);
2351 if (binop_user_defined_p (op
, arg1
, arg2
))
2352 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2355 /* If the user attempts to subscript something that is not an
2356 array or pointer type (like a plain int variable for example),
2357 then report this as an error. */
2359 arg1
= coerce_ref (arg1
);
2360 type
= check_typedef (value_type (arg1
));
2361 if (type
->code () != TYPE_CODE_ARRAY
2362 && type
->code () != TYPE_CODE_PTR
)
2365 error (_("cannot subscript something of type `%s'"),
2368 error (_("cannot subscript requested type"));
2371 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2372 return value_zero (TYPE_TARGET_TYPE (type
), VALUE_LVAL (arg1
));
2374 return value_subscript (arg1
, value_as_long (arg2
));
2376 case MULTI_SUBSCRIPT
:
2378 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
2379 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2382 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2383 /* FIXME: EVAL_SKIP handling may not be correct. */
2384 if (noside
== EVAL_SKIP
)
2388 return eval_skip_value (exp
);
2390 /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
2391 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2393 /* If the user attempts to subscript something that has no target
2394 type (like a plain int variable for example), then report this
2397 type
= TYPE_TARGET_TYPE (check_typedef (value_type (arg1
)));
2400 arg1
= value_zero (type
, VALUE_LVAL (arg1
));
2406 error (_("cannot subscript something of type `%s'"),
2407 value_type (arg1
)->name ());
2411 if (binop_user_defined_p (op
, arg1
, arg2
))
2413 arg1
= value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2417 arg1
= coerce_ref (arg1
);
2418 type
= check_typedef (value_type (arg1
));
2420 switch (type
->code ())
2423 case TYPE_CODE_ARRAY
:
2424 case TYPE_CODE_STRING
:
2425 arg1
= value_subscript (arg1
, value_as_long (arg2
));
2430 error (_("cannot subscript something of type `%s'"),
2433 error (_("cannot subscript requested type"));
2439 case BINOP_LOGICAL_AND
:
2440 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2441 if (noside
== EVAL_SKIP
)
2443 evaluate_subexp (nullptr, exp
, pos
, noside
);
2444 return eval_skip_value (exp
);
2448 arg2
= evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2451 if (binop_user_defined_p (op
, arg1
, arg2
))
2453 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2454 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2458 tem
= value_logical_not (arg1
);
2460 = evaluate_subexp (nullptr, exp
, pos
, (tem
? EVAL_SKIP
: noside
));
2461 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2462 return value_from_longest (type
,
2463 (LONGEST
) (!tem
&& !value_logical_not (arg2
)));
2466 case BINOP_LOGICAL_OR
:
2467 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2468 if (noside
== EVAL_SKIP
)
2470 evaluate_subexp (nullptr, exp
, pos
, noside
);
2471 return eval_skip_value (exp
);
2475 arg2
= evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2478 if (binop_user_defined_p (op
, arg1
, arg2
))
2480 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2481 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2485 tem
= value_logical_not (arg1
);
2487 = evaluate_subexp (nullptr, exp
, pos
, (!tem
? EVAL_SKIP
: noside
));
2488 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2489 return value_from_longest (type
,
2490 (LONGEST
) (!tem
|| !value_logical_not (arg2
)));
2494 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2495 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2496 if (noside
== EVAL_SKIP
)
2497 return eval_skip_value (exp
);
2498 if (binop_user_defined_p (op
, arg1
, arg2
))
2500 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2504 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2505 tem
= value_equal (arg1
, arg2
);
2506 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2507 return value_from_longest (type
, (LONGEST
) tem
);
2510 case BINOP_NOTEQUAL
:
2511 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2512 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2513 if (noside
== EVAL_SKIP
)
2514 return eval_skip_value (exp
);
2515 if (binop_user_defined_p (op
, arg1
, arg2
))
2517 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2521 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2522 tem
= value_equal (arg1
, arg2
);
2523 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2524 return value_from_longest (type
, (LONGEST
) ! tem
);
2528 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2529 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2530 if (noside
== EVAL_SKIP
)
2531 return eval_skip_value (exp
);
2532 if (binop_user_defined_p (op
, arg1
, arg2
))
2534 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2538 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2539 tem
= value_less (arg1
, arg2
);
2540 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2541 return value_from_longest (type
, (LONGEST
) tem
);
2545 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2546 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2547 if (noside
== EVAL_SKIP
)
2548 return eval_skip_value (exp
);
2549 if (binop_user_defined_p (op
, arg1
, arg2
))
2551 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2555 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2556 tem
= value_less (arg2
, arg1
);
2557 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2558 return value_from_longest (type
, (LONGEST
) tem
);
2562 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2563 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2564 if (noside
== EVAL_SKIP
)
2565 return eval_skip_value (exp
);
2566 if (binop_user_defined_p (op
, arg1
, arg2
))
2568 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2572 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2573 tem
= value_less (arg2
, arg1
) || value_equal (arg1
, arg2
);
2574 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2575 return value_from_longest (type
, (LONGEST
) tem
);
2579 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2580 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2581 if (noside
== EVAL_SKIP
)
2582 return eval_skip_value (exp
);
2583 if (binop_user_defined_p (op
, arg1
, arg2
))
2585 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2589 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2590 tem
= value_less (arg1
, arg2
) || value_equal (arg1
, arg2
);
2591 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2592 return value_from_longest (type
, (LONGEST
) tem
);
2596 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2597 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2598 if (noside
== EVAL_SKIP
)
2599 return eval_skip_value (exp
);
2600 type
= check_typedef (value_type (arg2
));
2601 if (type
->code () != TYPE_CODE_INT
2602 && type
->code () != TYPE_CODE_ENUM
)
2603 error (_("Non-integral right operand for \"@\" operator."));
2604 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2606 return allocate_repeat_value (value_type (arg1
),
2607 longest_to_int (value_as_long (arg2
)));
2610 return value_repeat (arg1
, longest_to_int (value_as_long (arg2
)));
2613 evaluate_subexp (nullptr, exp
, pos
, noside
);
2614 return evaluate_subexp (nullptr, exp
, pos
, noside
);
2617 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2618 if (noside
== EVAL_SKIP
)
2619 return eval_skip_value (exp
);
2620 if (unop_user_defined_p (op
, arg1
))
2621 return value_x_unop (arg1
, op
, noside
);
2624 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2625 return value_pos (arg1
);
2629 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2630 if (noside
== EVAL_SKIP
)
2631 return eval_skip_value (exp
);
2632 if (unop_user_defined_p (op
, arg1
))
2633 return value_x_unop (arg1
, op
, noside
);
2636 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2637 return value_neg (arg1
);
2640 case UNOP_COMPLEMENT
:
2641 /* C++: check for and handle destructor names. */
2643 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2644 if (noside
== EVAL_SKIP
)
2645 return eval_skip_value (exp
);
2646 if (unop_user_defined_p (UNOP_COMPLEMENT
, arg1
))
2647 return value_x_unop (arg1
, UNOP_COMPLEMENT
, noside
);
2650 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2651 return value_complement (arg1
);
2654 case UNOP_LOGICAL_NOT
:
2655 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2656 if (noside
== EVAL_SKIP
)
2657 return eval_skip_value (exp
);
2658 if (unop_user_defined_p (op
, arg1
))
2659 return value_x_unop (arg1
, op
, noside
);
2662 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2663 return value_from_longest (type
, (LONGEST
) value_logical_not (arg1
));
2667 if (expect_type
&& expect_type
->code () == TYPE_CODE_PTR
)
2668 expect_type
= TYPE_TARGET_TYPE (check_typedef (expect_type
));
2669 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2670 type
= check_typedef (value_type (arg1
));
2671 if (type
->code () == TYPE_CODE_METHODPTR
2672 || type
->code () == TYPE_CODE_MEMBERPTR
)
2673 error (_("Attempt to dereference pointer "
2674 "to member without an object"));
2675 if (noside
== EVAL_SKIP
)
2676 return eval_skip_value (exp
);
2677 if (unop_user_defined_p (op
, arg1
))
2678 return value_x_unop (arg1
, op
, noside
);
2679 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2681 type
= check_typedef (value_type (arg1
));
2682 if (type
->code () == TYPE_CODE_PTR
2683 || TYPE_IS_REFERENCE (type
)
2684 /* In C you can dereference an array to get the 1st elt. */
2685 || type
->code () == TYPE_CODE_ARRAY
2687 return value_zero (TYPE_TARGET_TYPE (type
),
2689 else if (type
->code () == TYPE_CODE_INT
)
2690 /* GDB allows dereferencing an int. */
2691 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
,
2694 error (_("Attempt to take contents of a non-pointer value."));
2697 /* Allow * on an integer so we can cast it to whatever we want.
2698 This returns an int, which seems like the most C-like thing to
2699 do. "long long" variables are rare enough that
2700 BUILTIN_TYPE_LONGEST would seem to be a mistake. */
2701 if (type
->code () == TYPE_CODE_INT
)
2702 return value_at_lazy (builtin_type (exp
->gdbarch
)->builtin_int
,
2703 (CORE_ADDR
) value_as_address (arg1
));
2704 return value_ind (arg1
);
2707 /* C++: check for and handle pointer to members. */
2709 if (noside
== EVAL_SKIP
)
2711 evaluate_subexp (nullptr, exp
, pos
, EVAL_SKIP
);
2712 return eval_skip_value (exp
);
2716 struct value
*retvalp
= evaluate_subexp_for_address (exp
, pos
,
2723 if (noside
== EVAL_SKIP
)
2725 evaluate_subexp (nullptr, exp
, pos
, EVAL_SKIP
);
2726 return eval_skip_value (exp
);
2728 return evaluate_subexp_for_sizeof (exp
, pos
, noside
);
2733 evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
));
2734 /* FIXME: This should be size_t. */
2735 struct type
*size_type
= builtin_type (exp
->gdbarch
)->builtin_int
;
2736 ULONGEST align
= type_align (type
);
2738 error (_("could not determine alignment of type"));
2739 return value_from_longest (size_type
, align
);
2744 type
= exp
->elts
[pc
+ 1].type
;
2745 return evaluate_subexp_for_cast (exp
, pos
, noside
, type
);
2747 case UNOP_CAST_TYPE
:
2748 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2749 type
= value_type (arg1
);
2750 return evaluate_subexp_for_cast (exp
, pos
, noside
, type
);
2752 case UNOP_DYNAMIC_CAST
:
2753 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2754 type
= value_type (arg1
);
2755 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
2756 if (noside
== EVAL_SKIP
)
2757 return eval_skip_value (exp
);
2758 return value_dynamic_cast (type
, arg1
);
2760 case UNOP_REINTERPRET_CAST
:
2761 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2762 type
= value_type (arg1
);
2763 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
2764 if (noside
== EVAL_SKIP
)
2765 return eval_skip_value (exp
);
2766 return value_reinterpret_cast (type
, arg1
);
2770 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2771 if (noside
== EVAL_SKIP
)
2772 return eval_skip_value (exp
);
2773 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2774 return value_zero (exp
->elts
[pc
+ 1].type
, lval_memory
);
2776 return value_at_lazy (exp
->elts
[pc
+ 1].type
,
2777 value_as_address (arg1
));
2779 case UNOP_MEMVAL_TYPE
:
2780 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2781 type
= value_type (arg1
);
2782 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2783 if (noside
== EVAL_SKIP
)
2784 return eval_skip_value (exp
);
2785 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2786 return value_zero (type
, lval_memory
);
2788 return value_at_lazy (type
, value_as_address (arg1
));
2790 case UNOP_PREINCREMENT
:
2791 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2792 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2794 else if (unop_user_defined_p (op
, arg1
))
2796 return value_x_unop (arg1
, op
, noside
);
2800 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2801 arg2
= value_ptradd (arg1
, 1);
2804 struct value
*tmp
= arg1
;
2806 arg2
= value_one (value_type (arg1
));
2807 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2808 arg2
= value_binop (tmp
, arg2
, BINOP_ADD
);
2811 return value_assign (arg1
, arg2
);
2814 case UNOP_PREDECREMENT
:
2815 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2816 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2818 else if (unop_user_defined_p (op
, arg1
))
2820 return value_x_unop (arg1
, op
, noside
);
2824 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2825 arg2
= value_ptradd (arg1
, -1);
2828 struct value
*tmp
= arg1
;
2830 arg2
= value_one (value_type (arg1
));
2831 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2832 arg2
= value_binop (tmp
, arg2
, BINOP_SUB
);
2835 return value_assign (arg1
, arg2
);
2838 case UNOP_POSTINCREMENT
:
2839 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2840 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2842 else if (unop_user_defined_p (op
, arg1
))
2844 return value_x_unop (arg1
, op
, noside
);
2848 arg3
= value_non_lval (arg1
);
2850 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2851 arg2
= value_ptradd (arg1
, 1);
2854 struct value
*tmp
= arg1
;
2856 arg2
= value_one (value_type (arg1
));
2857 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2858 arg2
= value_binop (tmp
, arg2
, BINOP_ADD
);
2861 value_assign (arg1
, arg2
);
2865 case UNOP_POSTDECREMENT
:
2866 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2867 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2869 else if (unop_user_defined_p (op
, arg1
))
2871 return value_x_unop (arg1
, op
, noside
);
2875 arg3
= value_non_lval (arg1
);
2877 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2878 arg2
= value_ptradd (arg1
, -1);
2881 struct value
*tmp
= arg1
;
2883 arg2
= value_one (value_type (arg1
));
2884 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2885 arg2
= value_binop (tmp
, arg2
, BINOP_SUB
);
2888 value_assign (arg1
, arg2
);
2894 return value_of_this (exp
->language_defn
);
2897 /* The value is not supposed to be used. This is here to make it
2898 easier to accommodate expressions that contain types. */
2900 if (noside
== EVAL_SKIP
)
2901 return eval_skip_value (exp
);
2902 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2903 return allocate_value (exp
->elts
[pc
+ 1].type
);
2905 error (_("Attempt to use a type name as an expression"));
2909 if (noside
== EVAL_SKIP
)
2911 evaluate_subexp (nullptr, exp
, pos
, EVAL_SKIP
);
2912 return eval_skip_value (exp
);
2914 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2916 enum exp_opcode sub_op
= exp
->elts
[*pos
].opcode
;
2917 struct value
*result
;
2919 result
= evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2921 /* 'decltype' has special semantics for lvalues. */
2922 if (op
== OP_DECLTYPE
2923 && (sub_op
== BINOP_SUBSCRIPT
2924 || sub_op
== STRUCTOP_MEMBER
2925 || sub_op
== STRUCTOP_MPTR
2926 || sub_op
== UNOP_IND
2927 || sub_op
== STRUCTOP_STRUCT
2928 || sub_op
== STRUCTOP_PTR
2929 || sub_op
== OP_SCOPE
))
2931 type
= value_type (result
);
2933 if (!TYPE_IS_REFERENCE (type
))
2935 type
= lookup_lvalue_reference_type (type
);
2936 result
= allocate_value (type
);
2943 error (_("Attempt to use a type as an expression"));
2947 struct value
*result
;
2948 enum exp_opcode sub_op
= exp
->elts
[*pos
].opcode
;
2950 if (sub_op
== OP_TYPE
|| sub_op
== OP_DECLTYPE
|| sub_op
== OP_TYPEOF
)
2951 result
= evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2953 result
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2955 if (noside
!= EVAL_NORMAL
)
2956 return allocate_value (cplus_typeid_type (exp
->gdbarch
));
2958 return cplus_typeid (result
);
2962 /* Removing this case and compiling with gcc -Wall reveals that
2963 a lot of cases are hitting this case. Some of these should
2964 probably be removed from expression.h; others are legitimate
2965 expressions which are (apparently) not fully implemented.
2967 If there are any cases landing here which mean a user error,
2968 then they should be separate cases, with more descriptive
2971 error (_("GDB does not (yet) know how to "
2972 "evaluate that kind of expression"));
2975 gdb_assert_not_reached ("missed return?");
2978 /* Evaluate a subexpression of EXP, at index *POS,
2979 and return the address of that subexpression.
2980 Advance *POS over the subexpression.
2981 If the subexpression isn't an lvalue, get an error.
2982 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
2983 then only the type of the result need be correct. */
2985 static struct value
*
2986 evaluate_subexp_for_address (struct expression
*exp
, int *pos
,
2996 op
= exp
->elts
[pc
].opcode
;
3002 x
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3004 /* We can't optimize out "&*" if there's a user-defined operator*. */
3005 if (unop_user_defined_p (op
, x
))
3007 x
= value_x_unop (x
, op
, noside
);
3008 goto default_case_after_eval
;
3011 return coerce_array (x
);
3015 return value_cast (lookup_pointer_type (exp
->elts
[pc
+ 1].type
),
3016 evaluate_subexp (nullptr, exp
, pos
, noside
));
3018 case UNOP_MEMVAL_TYPE
:
3023 x
= evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3024 type
= value_type (x
);
3025 return value_cast (lookup_pointer_type (type
),
3026 evaluate_subexp (nullptr, exp
, pos
, noside
));
3030 var
= exp
->elts
[pc
+ 2].symbol
;
3032 /* C++: The "address" of a reference should yield the address
3033 * of the object pointed to. Let value_addr() deal with it. */
3034 if (TYPE_IS_REFERENCE (SYMBOL_TYPE (var
)))
3038 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
3041 lookup_pointer_type (SYMBOL_TYPE (var
));
3042 enum address_class sym_class
= SYMBOL_CLASS (var
);
3044 if (sym_class
== LOC_CONST
3045 || sym_class
== LOC_CONST_BYTES
3046 || sym_class
== LOC_REGISTER
)
3047 error (_("Attempt to take address of register or constant."));
3050 value_zero (type
, not_lval
);
3053 return address_of_variable (var
, exp
->elts
[pc
+ 1].block
);
3055 case OP_VAR_MSYM_VALUE
:
3059 value
*val
= evaluate_var_msym_value (noside
,
3060 exp
->elts
[pc
+ 1].objfile
,
3061 exp
->elts
[pc
+ 2].msymbol
);
3062 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
3064 struct type
*type
= lookup_pointer_type (value_type (val
));
3065 return value_zero (type
, not_lval
);
3068 return value_addr (val
);
3072 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
3073 (*pos
) += 5 + BYTES_TO_EXP_ELEM (tem
+ 1);
3074 x
= value_aggregate_elt (exp
->elts
[pc
+ 1].type
,
3075 &exp
->elts
[pc
+ 3].string
,
3078 error (_("There is no field named %s"), &exp
->elts
[pc
+ 3].string
);
3083 x
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3084 default_case_after_eval
:
3085 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
3087 struct type
*type
= check_typedef (value_type (x
));
3089 if (TYPE_IS_REFERENCE (type
))
3090 return value_zero (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
3092 else if (VALUE_LVAL (x
) == lval_memory
|| value_must_coerce_to_target (x
))
3093 return value_zero (lookup_pointer_type (value_type (x
)),
3096 error (_("Attempt to take address of "
3097 "value not located in memory."));
3099 return value_addr (x
);
3103 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
3104 When used in contexts where arrays will be coerced anyway, this is
3105 equivalent to `evaluate_subexp' but much faster because it avoids
3106 actually fetching array contents (perhaps obsolete now that we have
3109 Note that we currently only do the coercion for C expressions, where
3110 arrays are zero based and the coercion is correct. For other languages,
3111 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
3112 to decide if coercion is appropriate. */
3115 evaluate_subexp_with_coercion (struct expression
*exp
,
3116 int *pos
, enum noside noside
)
3125 op
= exp
->elts
[pc
].opcode
;
3130 var
= exp
->elts
[pc
+ 2].symbol
;
3131 type
= check_typedef (SYMBOL_TYPE (var
));
3132 if (type
->code () == TYPE_CODE_ARRAY
3133 && !type
->is_vector ()
3134 && CAST_IS_CONVERSION (exp
->language_defn
))
3137 val
= address_of_variable (var
, exp
->elts
[pc
+ 1].block
);
3138 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
3144 return evaluate_subexp (nullptr, exp
, pos
, noside
);
3148 /* Evaluate a subexpression of EXP, at index *POS,
3149 and return a value for the size of that subexpression.
3150 Advance *POS over the subexpression. If NOSIDE is EVAL_NORMAL
3151 we allow side-effects on the operand if its type is a variable
3154 static struct value
*
3155 evaluate_subexp_for_sizeof (struct expression
*exp
, int *pos
,
3158 /* FIXME: This should be size_t. */
3159 struct type
*size_type
= builtin_type (exp
->gdbarch
)->builtin_int
;
3166 op
= exp
->elts
[pc
].opcode
;
3170 /* This case is handled specially
3171 so that we avoid creating a value for the result type.
3172 If the result type is very big, it's desirable not to
3173 create a value unnecessarily. */
3176 val
= evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3177 type
= check_typedef (value_type (val
));
3178 if (type
->code () != TYPE_CODE_PTR
3179 && !TYPE_IS_REFERENCE (type
)
3180 && type
->code () != TYPE_CODE_ARRAY
)
3181 error (_("Attempt to take contents of a non-pointer value."));
3182 type
= TYPE_TARGET_TYPE (type
);
3183 if (is_dynamic_type (type
))
3184 type
= value_type (value_ind (val
));
3185 return value_from_longest (size_type
, (LONGEST
) TYPE_LENGTH (type
));
3189 type
= exp
->elts
[pc
+ 1].type
;
3192 case UNOP_MEMVAL_TYPE
:
3194 val
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3195 type
= value_type (val
);
3199 type
= SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
);
3200 if (is_dynamic_type (type
))
3202 val
= evaluate_subexp (nullptr, exp
, pos
, EVAL_NORMAL
);
3203 type
= value_type (val
);
3204 if (type
->code () == TYPE_CODE_ARRAY
3205 && is_dynamic_type (type
->index_type ())
3206 && type
->bounds ()->high
.kind () == PROP_UNDEFINED
)
3207 return allocate_optimized_out_value (size_type
);
3213 case OP_VAR_MSYM_VALUE
:
3217 minimal_symbol
*msymbol
= exp
->elts
[pc
+ 2].msymbol
;
3218 value
*mval
= evaluate_var_msym_value (noside
,
3219 exp
->elts
[pc
+ 1].objfile
,
3222 type
= value_type (mval
);
3223 if (type
->code () == TYPE_CODE_ERROR
)
3224 error_unknown_type (msymbol
->print_name ());
3226 return value_from_longest (size_type
, TYPE_LENGTH (type
));
3230 /* Deal with the special case if NOSIDE is EVAL_NORMAL and the resulting
3231 type of the subscript is a variable length array type. In this case we
3232 must re-evaluate the right hand side of the subscription to allow
3234 case BINOP_SUBSCRIPT
:
3235 if (noside
== EVAL_NORMAL
)
3237 int npc
= (*pos
) + 1;
3239 val
= evaluate_subexp (nullptr, exp
, &npc
, EVAL_AVOID_SIDE_EFFECTS
);
3240 type
= check_typedef (value_type (val
));
3241 if (type
->code () == TYPE_CODE_ARRAY
)
3243 type
= check_typedef (TYPE_TARGET_TYPE (type
));
3244 if (type
->code () == TYPE_CODE_ARRAY
)
3246 type
= type
->index_type ();
3247 /* Only re-evaluate the right hand side if the resulting type
3248 is a variable length type. */
3249 if (type
->bounds ()->flag_bound_evaluated
)
3251 val
= evaluate_subexp (nullptr, exp
, pos
, EVAL_NORMAL
);
3252 return value_from_longest
3253 (size_type
, (LONGEST
) TYPE_LENGTH (value_type (val
)));
3262 val
= evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3263 type
= value_type (val
);
3267 /* $5.3.3/2 of the C++ Standard (n3290 draft) says of sizeof:
3268 "When applied to a reference or a reference type, the result is
3269 the size of the referenced type." */
3270 type
= check_typedef (type
);
3271 if (exp
->language_defn
->la_language
== language_cplus
3272 && (TYPE_IS_REFERENCE (type
)))
3273 type
= check_typedef (TYPE_TARGET_TYPE (type
));
3274 return value_from_longest (size_type
, (LONGEST
) TYPE_LENGTH (type
));
3277 /* Evaluate a subexpression of EXP, at index *POS, and return a value
3278 for that subexpression cast to TO_TYPE. Advance *POS over the
3282 evaluate_subexp_for_cast (expression
*exp
, int *pos
,
3284 struct type
*to_type
)
3288 /* Don't let symbols be evaluated with evaluate_subexp because that
3289 throws an "unknown type" error for no-debug data symbols.
3290 Instead, we want the cast to reinterpret the symbol. */
3291 if (exp
->elts
[pc
].opcode
== OP_VAR_MSYM_VALUE
3292 || exp
->elts
[pc
].opcode
== OP_VAR_VALUE
)
3297 if (exp
->elts
[pc
].opcode
== OP_VAR_MSYM_VALUE
)
3299 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
3300 return value_zero (to_type
, not_lval
);
3302 val
= evaluate_var_msym_value (noside
,
3303 exp
->elts
[pc
+ 1].objfile
,
3304 exp
->elts
[pc
+ 2].msymbol
);
3307 val
= evaluate_var_value (noside
,
3308 exp
->elts
[pc
+ 1].block
,
3309 exp
->elts
[pc
+ 2].symbol
);
3311 if (noside
== EVAL_SKIP
)
3312 return eval_skip_value (exp
);
3314 val
= value_cast (to_type
, val
);
3316 /* Don't allow e.g. '&(int)var_with_no_debug_info'. */
3317 if (VALUE_LVAL (val
) == lval_memory
)
3319 if (value_lazy (val
))
3320 value_fetch_lazy (val
);
3321 VALUE_LVAL (val
) = not_lval
;
3326 value
*val
= evaluate_subexp (to_type
, exp
, pos
, noside
);
3327 if (noside
== EVAL_SKIP
)
3328 return eval_skip_value (exp
);
3329 return value_cast (to_type
, val
);
3332 /* Parse a type expression in the string [P..P+LENGTH). */
3335 parse_and_eval_type (char *p
, int length
)
3337 char *tmp
= (char *) alloca (length
+ 4);
3340 memcpy (tmp
+ 1, p
, length
);
3341 tmp
[length
+ 1] = ')';
3342 tmp
[length
+ 2] = '0';
3343 tmp
[length
+ 3] = '\0';
3344 expression_up expr
= parse_expression (tmp
);
3345 if (expr
->elts
[0].opcode
!= UNOP_CAST
)
3346 error (_("Internal error in eval_type."));
3347 return expr
->elts
[1].type
;
3350 /* Return the number of dimensions for a Fortran array or string. */
3353 calc_f77_array_dims (struct type
*array_type
)
3356 struct type
*tmp_type
;
3358 if ((array_type
->code () == TYPE_CODE_STRING
))
3361 if ((array_type
->code () != TYPE_CODE_ARRAY
))
3362 error (_("Can't get dimensions for a non-array type"));
3364 tmp_type
= array_type
;
3366 while ((tmp_type
= TYPE_TARGET_TYPE (tmp_type
)))
3368 if (tmp_type
->code () == TYPE_CODE_ARRAY
)