1 /* Evaluate expressions for GDB.
3 Copyright (C) 1986-2021 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. */
31 #include "objc-lang.h"
33 #include "parser-defs.h"
34 #include "cp-support.h"
37 #include "user-regs.h"
39 #include "gdb_obstack.h"
41 #include "typeprint.h"
46 /* Prototypes for local functions. */
48 static struct value
*evaluate_subexp_for_sizeof (struct expression
*, int *,
51 static struct value
*evaluate_subexp_for_address (struct expression
*,
54 static value
*evaluate_subexp_for_cast (expression
*exp
, int *pos
,
58 static struct value
*evaluate_struct_tuple (struct value
*,
59 struct expression
*, int *,
63 evaluate_subexp (struct type
*expect_type
, struct expression
*exp
,
64 int *pos
, enum noside noside
)
66 return ((*exp
->language_defn
->expression_ops ()->evaluate_exp
)
67 (expect_type
, exp
, pos
, noside
));
70 /* Parse the string EXP as a C expression, evaluate it,
71 and return the result as a number. */
74 parse_and_eval_address (const char *exp
)
76 expression_up expr
= parse_expression (exp
);
78 return value_as_address (evaluate_expression (expr
.get ()));
81 /* Like parse_and_eval_address, but treats the value of the expression
82 as an integer, not an address, returns a LONGEST, not a CORE_ADDR. */
84 parse_and_eval_long (const char *exp
)
86 expression_up expr
= parse_expression (exp
);
88 return value_as_long (evaluate_expression (expr
.get ()));
92 parse_and_eval (const char *exp
)
94 expression_up expr
= parse_expression (exp
);
96 return evaluate_expression (expr
.get ());
99 /* Parse up to a comma (or to a closeparen)
100 in the string EXPP as an expression, evaluate it, and return the value.
101 EXPP is advanced to point to the comma. */
104 parse_to_comma_and_eval (const char **expp
)
106 expression_up expr
= parse_exp_1 (expp
, 0, nullptr, 1);
108 return evaluate_expression (expr
.get ());
112 /* See expression.h. */
115 expression::evaluate (struct type
*expect_type
, enum noside noside
)
117 gdb::optional
<enable_thread_stack_temporaries
> stack_temporaries
;
118 if (target_has_execution ()
119 && language_defn
->la_language
== language_cplus
120 && !thread_stack_temporaries_enabled_p (inferior_thread ()))
121 stack_temporaries
.emplace (inferior_thread ());
123 struct value
*retval
;
125 retval
= op
->evaluate (expect_type
, this, noside
);
129 retval
= evaluate_subexp (expect_type
, this, &pos
, noside
);
132 if (stack_temporaries
.has_value ()
133 && value_in_thread_stack_temporaries (retval
, inferior_thread ()))
134 retval
= value_non_lval (retval
);
142 evaluate_expression (struct expression
*exp
, struct type
*expect_type
)
144 return exp
->evaluate (expect_type
, EVAL_NORMAL
);
147 /* Evaluate an expression, avoiding all memory references
148 and getting a value whose type alone is correct. */
151 evaluate_type (struct expression
*exp
)
153 return exp
->evaluate (nullptr, EVAL_AVOID_SIDE_EFFECTS
);
156 /* Evaluate a subexpression, avoiding all memory references and
157 getting a value whose type alone is correct. */
160 evaluate_subexpression_type (struct expression
*exp
, int subexp
)
162 if (exp
->op
!= nullptr)
163 return exp
->op
->evaluate (nullptr, exp
, EVAL_AVOID_SIDE_EFFECTS
);
164 return evaluate_subexp (nullptr, exp
, &subexp
, EVAL_AVOID_SIDE_EFFECTS
);
167 /* Find the current value of a watchpoint on EXP. Return the value in
168 *VALP and *RESULTP and the chain of intermediate and final values
169 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
172 If PRESERVE_ERRORS is true, then exceptions are passed through.
173 Otherwise, if PRESERVE_ERRORS is false, then if a memory error
174 occurs while evaluating the expression, *RESULTP will be set to
175 NULL. *RESULTP may be a lazy value, if the result could not be
176 read from memory. It is used to determine whether a value is
177 user-specified (we should watch the whole value) or intermediate
178 (we should watch only the bit used to locate the final value).
180 If the final value, or any intermediate value, could not be read
181 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
182 set to any referenced values. *VALP will never be a lazy value.
183 This is the value which we store in struct breakpoint.
185 If VAL_CHAIN is non-NULL, the values put into *VAL_CHAIN will be
186 released from the value chain. If VAL_CHAIN is NULL, all generated
187 values will be left on the value chain. */
190 fetch_subexp_value (struct expression
*exp
, int *pc
,
192 struct value
**valp
, struct value
**resultp
,
193 std::vector
<value_ref_ptr
> *val_chain
,
194 bool preserve_errors
)
196 struct value
*mark
, *new_mark
, *result
;
204 /* Evaluate the expression. */
205 mark
= value_mark ();
211 result
= evaluate_subexp (nullptr, exp
, pc
, EVAL_NORMAL
);
213 result
= op
->evaluate (nullptr, exp
, EVAL_NORMAL
);
215 catch (const gdb_exception
&ex
)
217 /* Ignore memory errors if we want watchpoints pointing at
218 inaccessible memory to still be created; otherwise, throw the
219 error to some higher catcher. */
223 if (!preserve_errors
)
232 new_mark
= value_mark ();
233 if (mark
== new_mark
)
238 /* Make sure it's not lazy, so that after the target stops again we
239 have a non-lazy previous value to compare with. */
242 if (!value_lazy (result
))
249 value_fetch_lazy (result
);
252 catch (const gdb_exception_error
&except
)
260 /* Return the chain of intermediate values. We use this to
261 decide which addresses to watch. */
262 *val_chain
= value_release_to_mark (mark
);
266 /* Extract a field operation from an expression. If the subexpression
267 of EXP starting at *SUBEXP is not a structure dereference
268 operation, return NULL. Otherwise, return the name of the
269 dereferenced field, and advance *SUBEXP to point to the
270 subexpression of the left-hand-side of the dereference. This is
271 used when completing field names. */
274 extract_field_op (struct expression
*exp
, int *subexp
)
279 if (exp
->elts
[*subexp
].opcode
!= STRUCTOP_STRUCT
280 && exp
->elts
[*subexp
].opcode
!= STRUCTOP_PTR
)
282 tem
= longest_to_int (exp
->elts
[*subexp
+ 1].longconst
);
283 result
= &exp
->elts
[*subexp
+ 2].string
;
284 (*subexp
) += 1 + 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
288 /* This function evaluates brace-initializers (in C/C++) for
291 static struct value
*
292 evaluate_struct_tuple (struct value
*struct_val
,
293 struct expression
*exp
,
294 int *pos
, enum noside noside
, int nargs
)
296 struct type
*struct_type
= check_typedef (value_type (struct_val
));
297 struct type
*field_type
;
302 struct value
*val
= NULL
;
307 /* Skip static fields. */
308 while (fieldno
< struct_type
->num_fields ()
309 && field_is_static (&struct_type
->field (fieldno
)))
311 if (fieldno
>= struct_type
->num_fields ())
312 error (_("too many initializers"));
313 field_type
= struct_type
->field (fieldno
).type ();
314 if (field_type
->code () == TYPE_CODE_UNION
315 && TYPE_FIELD_NAME (struct_type
, fieldno
)[0] == '0')
316 error (_("don't know which variant you want to set"));
318 /* Here, struct_type is the type of the inner struct,
319 while substruct_type is the type of the inner struct.
320 These are the same for normal structures, but a variant struct
321 contains anonymous union fields that contain substruct fields.
322 The value fieldno is the index of the top-level (normal or
323 anonymous union) field in struct_field, while the value
324 subfieldno is the index of the actual real (named inner) field
325 in substruct_type. */
327 field_type
= struct_type
->field (fieldno
).type ();
329 val
= evaluate_subexp (field_type
, exp
, pos
, noside
);
331 /* Now actually set the field in struct_val. */
333 /* Assign val to field fieldno. */
334 if (value_type (val
) != field_type
)
335 val
= value_cast (field_type
, val
);
337 bitsize
= TYPE_FIELD_BITSIZE (struct_type
, fieldno
);
338 bitpos
= TYPE_FIELD_BITPOS (struct_type
, fieldno
);
339 addr
= value_contents_writeable (struct_val
) + bitpos
/ 8;
341 modify_field (struct_type
, addr
,
342 value_as_long (val
), bitpos
% 8, bitsize
);
344 memcpy (addr
, value_contents (val
),
345 TYPE_LENGTH (value_type (val
)));
351 /* Promote value ARG1 as appropriate before performing a unary operation
353 If the result is not appropriate for any particular language then it
354 needs to patch this function. */
357 unop_promote (const struct language_defn
*language
, struct gdbarch
*gdbarch
,
362 *arg1
= coerce_ref (*arg1
);
363 type1
= check_typedef (value_type (*arg1
));
365 if (is_integral_type (type1
))
367 switch (language
->la_language
)
370 /* Perform integral promotion for ANSI C/C++.
371 If not appropriate for any particular language
372 it needs to modify this function. */
374 struct type
*builtin_int
= builtin_type (gdbarch
)->builtin_int
;
376 if (TYPE_LENGTH (type1
) < TYPE_LENGTH (builtin_int
))
377 *arg1
= value_cast (builtin_int
, *arg1
);
384 /* Promote values ARG1 and ARG2 as appropriate before performing a binary
385 operation on those two operands.
386 If the result is not appropriate for any particular language then it
387 needs to patch this function. */
390 binop_promote (const struct language_defn
*language
, struct gdbarch
*gdbarch
,
391 struct value
**arg1
, struct value
**arg2
)
393 struct type
*promoted_type
= NULL
;
397 *arg1
= coerce_ref (*arg1
);
398 *arg2
= coerce_ref (*arg2
);
400 type1
= check_typedef (value_type (*arg1
));
401 type2
= check_typedef (value_type (*arg2
));
403 if ((type1
->code () != TYPE_CODE_FLT
404 && type1
->code () != TYPE_CODE_DECFLOAT
405 && !is_integral_type (type1
))
406 || (type2
->code () != TYPE_CODE_FLT
407 && type2
->code () != TYPE_CODE_DECFLOAT
408 && !is_integral_type (type2
)))
411 if (is_fixed_point_type (type1
) || is_fixed_point_type (type2
))
414 if (type1
->code () == TYPE_CODE_DECFLOAT
415 || type2
->code () == TYPE_CODE_DECFLOAT
)
417 /* No promotion required. */
419 else if (type1
->code () == TYPE_CODE_FLT
420 || type2
->code () == TYPE_CODE_FLT
)
422 switch (language
->la_language
)
428 case language_opencl
:
429 /* No promotion required. */
433 /* For other languages the result type is unchanged from gdb
434 version 6.7 for backward compatibility.
435 If either arg was long double, make sure that value is also long
436 double. Otherwise use double. */
437 if (TYPE_LENGTH (type1
) * 8 > gdbarch_double_bit (gdbarch
)
438 || TYPE_LENGTH (type2
) * 8 > gdbarch_double_bit (gdbarch
))
439 promoted_type
= builtin_type (gdbarch
)->builtin_long_double
;
441 promoted_type
= builtin_type (gdbarch
)->builtin_double
;
445 else if (type1
->code () == TYPE_CODE_BOOL
446 && type2
->code () == TYPE_CODE_BOOL
)
448 /* No promotion required. */
451 /* Integral operations here. */
452 /* FIXME: Also mixed integral/booleans, with result an integer. */
454 const struct builtin_type
*builtin
= builtin_type (gdbarch
);
455 unsigned int promoted_len1
= TYPE_LENGTH (type1
);
456 unsigned int promoted_len2
= TYPE_LENGTH (type2
);
457 int is_unsigned1
= type1
->is_unsigned ();
458 int is_unsigned2
= type2
->is_unsigned ();
459 unsigned int result_len
;
460 int unsigned_operation
;
462 /* Determine type length and signedness after promotion for
464 if (promoted_len1
< TYPE_LENGTH (builtin
->builtin_int
))
467 promoted_len1
= TYPE_LENGTH (builtin
->builtin_int
);
469 if (promoted_len2
< TYPE_LENGTH (builtin
->builtin_int
))
472 promoted_len2
= TYPE_LENGTH (builtin
->builtin_int
);
475 if (promoted_len1
> promoted_len2
)
477 unsigned_operation
= is_unsigned1
;
478 result_len
= promoted_len1
;
480 else if (promoted_len2
> promoted_len1
)
482 unsigned_operation
= is_unsigned2
;
483 result_len
= promoted_len2
;
487 unsigned_operation
= is_unsigned1
|| is_unsigned2
;
488 result_len
= promoted_len1
;
491 switch (language
->la_language
)
497 if (result_len
<= TYPE_LENGTH (builtin
->builtin_int
))
499 promoted_type
= (unsigned_operation
500 ? builtin
->builtin_unsigned_int
501 : builtin
->builtin_int
);
503 else if (result_len
<= TYPE_LENGTH (builtin
->builtin_long
))
505 promoted_type
= (unsigned_operation
506 ? builtin
->builtin_unsigned_long
507 : builtin
->builtin_long
);
511 promoted_type
= (unsigned_operation
512 ? builtin
->builtin_unsigned_long_long
513 : builtin
->builtin_long_long
);
516 case language_opencl
:
517 if (result_len
<= TYPE_LENGTH (lookup_signed_typename
522 ? lookup_unsigned_typename (language
, "int")
523 : lookup_signed_typename (language
, "int"));
525 else if (result_len
<= TYPE_LENGTH (lookup_signed_typename
530 ? lookup_unsigned_typename (language
, "long")
531 : lookup_signed_typename (language
,"long"));
535 /* For other languages the result type is unchanged from gdb
536 version 6.7 for backward compatibility.
537 If either arg was long long, make sure that value is also long
538 long. Otherwise use long. */
539 if (unsigned_operation
)
541 if (result_len
> gdbarch_long_bit (gdbarch
) / HOST_CHAR_BIT
)
542 promoted_type
= builtin
->builtin_unsigned_long_long
;
544 promoted_type
= builtin
->builtin_unsigned_long
;
548 if (result_len
> gdbarch_long_bit (gdbarch
) / HOST_CHAR_BIT
)
549 promoted_type
= builtin
->builtin_long_long
;
551 promoted_type
= builtin
->builtin_long
;
559 /* Promote both operands to common type. */
560 *arg1
= value_cast (promoted_type
, *arg1
);
561 *arg2
= value_cast (promoted_type
, *arg2
);
566 ptrmath_type_p (const struct language_defn
*lang
, struct type
*type
)
568 type
= check_typedef (type
);
569 if (TYPE_IS_REFERENCE (type
))
570 type
= TYPE_TARGET_TYPE (type
);
572 switch (type
->code ())
578 case TYPE_CODE_ARRAY
:
579 return type
->is_vector () ? 0 : lang
->c_style_arrays_p ();
586 /* Represents a fake method with the given parameter types. This is
587 used by the parser to construct a temporary "expected" type for
588 method overload resolution. FLAGS is used as instance flags of the
589 new type, in order to be able to make the new type represent a
590 const/volatile overload. */
595 fake_method (type_instance_flags flags
,
596 int num_types
, struct type
**param_types
);
599 /* The constructed type. */
600 struct type
*type () { return &m_type
; }
603 struct type m_type
{};
604 main_type m_main_type
{};
607 fake_method::fake_method (type_instance_flags flags
,
608 int num_types
, struct type
**param_types
)
610 struct type
*type
= &m_type
;
612 TYPE_MAIN_TYPE (type
) = &m_main_type
;
613 TYPE_LENGTH (type
) = 1;
614 type
->set_code (TYPE_CODE_METHOD
);
615 TYPE_CHAIN (type
) = type
;
616 type
->set_instance_flags (flags
);
619 if (param_types
[num_types
- 1] == NULL
)
622 type
->set_has_varargs (true);
624 else if (check_typedef (param_types
[num_types
- 1])->code ()
628 /* Caller should have ensured this. */
629 gdb_assert (num_types
== 0);
630 type
->set_is_prototyped (true);
634 /* We don't use TYPE_ZALLOC here to allocate space as TYPE is owned by
635 neither an objfile nor a gdbarch. As a result we must manually
636 allocate memory for auxiliary fields, and free the memory ourselves
637 when we are done with it. */
638 type
->set_num_fields (num_types
);
640 ((struct field
*) xzalloc (sizeof (struct field
) * num_types
));
642 while (num_types
-- > 0)
643 type
->field (num_types
).set_type (param_types
[num_types
]);
646 fake_method::~fake_method ()
648 xfree (m_type
.fields ());
655 type_instance_operation::evaluate (struct type
*expect_type
,
656 struct expression
*exp
,
659 type_instance_flags flags
= std::get
<0> (m_storage
);
660 std::vector
<type
*> &types
= std::get
<1> (m_storage
);
662 fake_method
fake_expect_type (flags
, types
.size (), types
.data ());
663 return std::get
<2> (m_storage
)->evaluate (fake_expect_type
.type (),
669 /* Helper for evaluating an OP_VAR_VALUE. */
672 evaluate_var_value (enum noside noside
, const block
*blk
, symbol
*var
)
674 /* JYG: We used to just return value_zero of the symbol type if
675 we're asked to avoid side effects. Otherwise we return
676 value_of_variable (...). However I'm not sure if
677 value_of_variable () has any side effect. We need a full value
678 object returned here for whatis_exp () to call evaluate_type ()
679 and then pass the full value to value_rtti_target_type () if we
680 are dealing with a pointer or reference to a base class and print
683 struct value
*ret
= NULL
;
687 ret
= value_of_variable (var
, blk
);
690 catch (const gdb_exception_error
&except
)
692 if (noside
!= EVAL_AVOID_SIDE_EFFECTS
)
695 ret
= value_zero (SYMBOL_TYPE (var
), not_lval
);
706 var_value_operation::evaluate (struct type
*expect_type
,
707 struct expression
*exp
,
710 symbol
*var
= std::get
<0> (m_storage
);
711 if (SYMBOL_TYPE (var
)->code () == TYPE_CODE_ERROR
)
712 error_unknown_type (var
->print_name ());
713 return evaluate_var_value (noside
, std::get
<1> (m_storage
), var
);
716 } /* namespace expr */
718 /* Helper for evaluating an OP_VAR_MSYM_VALUE. */
721 evaluate_var_msym_value (enum noside noside
,
722 struct objfile
*objfile
, minimal_symbol
*msymbol
)
725 type
*the_type
= find_minsym_type_and_address (msymbol
, objfile
, &address
);
727 if (noside
== EVAL_AVOID_SIDE_EFFECTS
&& !the_type
->is_gnu_ifunc ())
728 return value_zero (the_type
, not_lval
);
730 return value_at_lazy (the_type
, address
);
733 /* Helper for returning a value when handling EVAL_SKIP. */
736 eval_skip_value (expression
*exp
)
738 return value_from_longest (builtin_type (exp
->gdbarch
)->builtin_int
, 1);
741 /* See expression.h. */
744 evaluate_subexp_do_call (expression
*exp
, enum noside noside
,
746 gdb::array_view
<value
*> argvec
,
747 const char *function_name
,
748 type
*default_return_type
)
751 error (_("Cannot evaluate function -- may be inlined"));
752 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
754 /* If the return type doesn't look like a function type,
755 call an error. This can happen if somebody tries to turn
756 a variable into a function call. */
758 type
*ftype
= value_type (callee
);
760 if (ftype
->code () == TYPE_CODE_INTERNAL_FUNCTION
)
762 /* We don't know anything about what the internal
763 function might return, but we have to return
765 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
,
768 else if (ftype
->code () == TYPE_CODE_XMETHOD
)
770 type
*return_type
= result_type_of_xmethod (callee
, argvec
);
772 if (return_type
== NULL
)
773 error (_("Xmethod is missing return type."));
774 return value_zero (return_type
, not_lval
);
776 else if (ftype
->code () == TYPE_CODE_FUNC
777 || ftype
->code () == TYPE_CODE_METHOD
)
779 if (ftype
->is_gnu_ifunc ())
781 CORE_ADDR address
= value_address (callee
);
782 type
*resolved_type
= find_gnu_ifunc_target_type (address
);
784 if (resolved_type
!= NULL
)
785 ftype
= resolved_type
;
788 type
*return_type
= TYPE_TARGET_TYPE (ftype
);
790 if (return_type
== NULL
)
791 return_type
= default_return_type
;
793 if (return_type
== NULL
)
794 error_call_unknown_return_type (function_name
);
796 return allocate_value (return_type
);
799 error (_("Expression of type other than "
800 "\"Function returning ...\" used as function"));
802 switch (value_type (callee
)->code ())
804 case TYPE_CODE_INTERNAL_FUNCTION
:
805 return call_internal_function (exp
->gdbarch
, exp
->language_defn
,
806 callee
, argvec
.size (), argvec
.data ());
807 case TYPE_CODE_XMETHOD
:
808 return call_xmethod (callee
, argvec
);
810 return call_function_by_hand (callee
, default_return_type
, argvec
);
814 /* Helper for evaluating an OP_FUNCALL. */
817 evaluate_funcall (type
*expect_type
, expression
*exp
, int *pos
,
825 symbol
*function
= NULL
;
826 char *function_name
= NULL
;
827 const char *var_func_name
= NULL
;
832 exp_opcode op
= exp
->elts
[*pos
].opcode
;
833 int nargs
= longest_to_int (exp
->elts
[pc
].longconst
);
834 /* Allocate arg vector, including space for the function to be
835 called in argvec[0], a potential `this', and a terminating
837 value
**argvec
= (value
**) alloca (sizeof (value
*) * (nargs
+ 3));
838 if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
840 /* First, evaluate the structure into arg2. */
843 if (op
== STRUCTOP_MEMBER
)
845 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
849 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
852 /* If the function is a virtual function, then the aggregate
853 value (providing the structure) plays its part by providing
854 the vtable. Otherwise, it is just along for the ride: call
855 the function directly. */
857 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
859 type
*a1_type
= check_typedef (value_type (arg1
));
860 if (noside
== EVAL_SKIP
)
861 tem
= 1; /* Set it to the right arg index so that all
862 arguments can also be skipped. */
863 else if (a1_type
->code () == TYPE_CODE_METHODPTR
)
865 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
866 arg1
= value_zero (TYPE_TARGET_TYPE (a1_type
), not_lval
);
868 arg1
= cplus_method_ptr_to_value (&arg2
, arg1
);
870 /* Now, say which argument to start evaluating from. */
875 else if (a1_type
->code () == TYPE_CODE_MEMBERPTR
)
877 struct type
*type_ptr
878 = lookup_pointer_type (TYPE_SELF_TYPE (a1_type
));
879 struct type
*target_type_ptr
880 = lookup_pointer_type (TYPE_TARGET_TYPE (a1_type
));
882 /* Now, convert these values to an address. */
883 arg2
= value_cast (type_ptr
, arg2
);
885 long mem_offset
= value_as_long (arg1
);
887 arg1
= value_from_pointer (target_type_ptr
,
888 value_as_long (arg2
) + mem_offset
);
889 arg1
= value_ind (arg1
);
893 error (_("Non-pointer-to-member value used in pointer-to-member "
896 else if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
898 /* Hair for method invocations. */
902 /* First, evaluate the structure into arg2. */
904 tem2
= longest_to_int (exp
->elts
[pc2
+ 1].longconst
);
905 *pos
+= 3 + BYTES_TO_EXP_ELEM (tem2
+ 1);
907 if (op
== STRUCTOP_STRUCT
)
909 /* If v is a variable in a register, and the user types
910 v.method (), this will produce an error, because v has no
913 A possible way around this would be to allocate a copy of
914 the variable on the stack, copy in the contents, call the
915 function, and copy out the contents. I.e. convert this
916 from call by reference to call by copy-return (or
917 whatever it's called). However, this does not work
918 because it is not the same: the method being called could
919 stash a copy of the address, and then future uses through
920 that address (after the method returns) would be expected
921 to use the variable itself, not some copy of it. */
922 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
926 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
928 /* Check to see if the operator '->' has been overloaded.
929 If the operator has been overloaded replace arg2 with the
930 value returned by the custom operator and continue
932 while (unop_user_defined_p (op
, arg2
))
934 struct value
*value
= NULL
;
937 value
= value_x_unop (arg2
, op
, noside
);
940 catch (const gdb_exception_error
&except
)
942 if (except
.error
== NOT_FOUND_ERROR
)
951 /* Now, say which argument to start evaluating from. */
954 else if (op
== OP_SCOPE
955 && overload_resolution
956 && (exp
->language_defn
->la_language
== language_cplus
))
958 /* Unpack it locally so we can properly handle overload
964 local_tem
= longest_to_int (exp
->elts
[pc2
+ 2].longconst
);
965 (*pos
) += 4 + BYTES_TO_EXP_ELEM (local_tem
+ 1);
966 struct type
*type
= exp
->elts
[pc2
+ 1].type
;
967 name
= &exp
->elts
[pc2
+ 3].string
;
970 function_name
= NULL
;
971 if (type
->code () == TYPE_CODE_NAMESPACE
)
973 function
= cp_lookup_symbol_namespace (type
->name (),
975 get_selected_block (0),
977 if (function
== NULL
)
978 error (_("No symbol \"%s\" in namespace \"%s\"."),
979 name
, type
->name ());
982 /* arg2 is left as NULL on purpose. */
986 gdb_assert (type
->code () == TYPE_CODE_STRUCT
987 || type
->code () == TYPE_CODE_UNION
);
988 function_name
= name
;
990 /* We need a properly typed value for method lookup. For
991 static methods arg2 is otherwise unused. */
992 arg2
= value_zero (type
, lval_memory
);
997 else if (op
== OP_ADL_FUNC
)
999 /* Save the function position and move pos so that the arguments
1000 can be evaluated. */
1006 func_name_len
= longest_to_int (exp
->elts
[save_pos1
+ 3].longconst
);
1007 (*pos
) += 6 + BYTES_TO_EXP_ELEM (func_name_len
+ 1);
1011 /* Non-method function call. */
1015 /* If this is a C++ function wait until overload resolution. */
1016 if (op
== OP_VAR_VALUE
1017 && overload_resolution
1018 && (exp
->language_defn
->la_language
== language_cplus
))
1020 (*pos
) += 4; /* Skip the evaluation of the symbol. */
1025 if (op
== OP_VAR_MSYM_VALUE
)
1027 minimal_symbol
*msym
= exp
->elts
[*pos
+ 2].msymbol
;
1028 var_func_name
= msym
->print_name ();
1030 else if (op
== OP_VAR_VALUE
)
1032 symbol
*sym
= exp
->elts
[*pos
+ 2].symbol
;
1033 var_func_name
= sym
->print_name ();
1036 argvec
[0] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1037 type
*type
= value_type (argvec
[0]);
1038 if (type
&& type
->code () == TYPE_CODE_PTR
)
1039 type
= TYPE_TARGET_TYPE (type
);
1040 if (type
&& type
->code () == TYPE_CODE_FUNC
)
1042 for (; tem
<= nargs
&& tem
<= type
->num_fields (); tem
++)
1044 argvec
[tem
] = evaluate_subexp (type
->field (tem
- 1).type (),
1051 /* Evaluate arguments (if not already done, e.g., namespace::func()
1052 and overload-resolution is off). */
1053 for (; tem
<= nargs
; tem
++)
1055 /* Ensure that array expressions are coerced into pointer
1057 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1060 /* Signal end of arglist. */
1063 if (noside
== EVAL_SKIP
)
1064 return eval_skip_value (exp
);
1066 if (op
== OP_ADL_FUNC
)
1068 struct symbol
*symp
;
1071 int string_pc
= save_pos1
+ 3;
1073 /* Extract the function name. */
1074 name_len
= longest_to_int (exp
->elts
[string_pc
].longconst
);
1075 func_name
= (char *) alloca (name_len
+ 1);
1076 strcpy (func_name
, &exp
->elts
[string_pc
+ 1].string
);
1078 find_overload_match (gdb::make_array_view (&argvec
[1], nargs
),
1080 NON_METHOD
, /* not method */
1081 NULL
, NULL
, /* pass NULL symbol since
1082 symbol is unknown */
1083 NULL
, &symp
, NULL
, 0, noside
);
1085 /* Now fix the expression being evaluated. */
1086 exp
->elts
[save_pos1
+ 2].symbol
= symp
;
1087 argvec
[0] = evaluate_subexp_with_coercion (exp
, &save_pos1
, noside
);
1090 if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
1091 || (op
== OP_SCOPE
&& function_name
!= NULL
))
1093 int static_memfuncp
;
1096 /* Method invocation: stuff "this" as first parameter. If the
1097 method turns out to be static we undo this below. */
1102 /* Name of method from expression. */
1103 tstr
= &exp
->elts
[pc2
+ 2].string
;
1106 tstr
= function_name
;
1108 if (overload_resolution
&& (exp
->language_defn
->la_language
1111 /* Language is C++, do some overload resolution before
1113 struct value
*valp
= NULL
;
1115 (void) find_overload_match (gdb::make_array_view (&argvec
[1], nargs
),
1117 METHOD
, /* method */
1118 &arg2
, /* the object */
1120 &static_memfuncp
, 0, noside
);
1122 if (op
== OP_SCOPE
&& !static_memfuncp
)
1124 /* For the time being, we don't handle this. */
1125 error (_("Call to overloaded function %s requires "
1129 argvec
[1] = arg2
; /* the ``this'' pointer */
1130 argvec
[0] = valp
; /* Use the method found after overload
1134 /* Non-C++ case -- or no overload resolution. */
1136 struct value
*temp
= arg2
;
1138 argvec
[0] = value_struct_elt (&temp
, argvec
+ 1, tstr
,
1140 op
== STRUCTOP_STRUCT
1141 ? "structure" : "structure pointer");
1142 /* value_struct_elt updates temp with the correct value of
1143 the ``this'' pointer if necessary, so modify argvec[1] to
1144 reflect any ``this'' changes. */
1146 = value_from_longest (lookup_pointer_type(value_type (temp
)),
1147 value_address (temp
)
1148 + value_embedded_offset (temp
));
1149 argvec
[1] = arg2
; /* the ``this'' pointer */
1152 /* Take out `this' if needed. */
1153 if (static_memfuncp
)
1155 argvec
[1] = argvec
[0];
1160 else if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
1162 /* Pointer to member. argvec[1] is already set up. */
1165 else if (op
== OP_VAR_VALUE
|| (op
== OP_SCOPE
&& function
!= NULL
))
1167 /* Non-member function being called. */
1168 /* fn: This can only be done for C++ functions. A C-style
1169 function in a C++ program, for instance, does not have the
1170 fields that are expected here. */
1172 if (overload_resolution
&& (exp
->language_defn
->la_language
1175 /* Language is C++, do some overload resolution before
1177 struct symbol
*symp
;
1180 /* If a scope has been specified disable ADL. */
1184 if (op
== OP_VAR_VALUE
)
1185 function
= exp
->elts
[save_pos1
+2].symbol
;
1187 (void) find_overload_match (gdb::make_array_view (&argvec
[1], nargs
),
1188 NULL
, /* no need for name */
1189 NON_METHOD
, /* not method */
1190 NULL
, function
, /* the function */
1191 NULL
, &symp
, NULL
, no_adl
, noside
);
1193 if (op
== OP_VAR_VALUE
)
1195 /* Now fix the expression being evaluated. */
1196 exp
->elts
[save_pos1
+2].symbol
= symp
;
1197 argvec
[0] = evaluate_subexp_with_coercion (exp
, &save_pos1
,
1201 argvec
[0] = value_of_variable (symp
, get_selected_block (0));
1205 /* Not C++, or no overload resolution allowed. */
1206 /* Nothing to be done; argvec already correctly set up. */
1211 /* It is probably a C-style function. */
1212 /* Nothing to be done; argvec already correctly set up. */
1215 return evaluate_subexp_do_call (exp
, noside
, argvec
[0],
1216 gdb::make_array_view (argvec
+ 1, nargs
),
1217 var_func_name
, expect_type
);
1224 operation::evaluate_funcall (struct type
*expect_type
,
1225 struct expression
*exp
,
1227 const char *function_name
,
1228 const std::vector
<operation_up
> &args
)
1230 std::vector
<value
*> vals (args
.size ());
1232 value
*callee
= evaluate_with_coercion (exp
, noside
);
1233 for (int i
= 0; i
< args
.size (); ++i
)
1234 vals
[i
] = args
[i
]->evaluate_with_coercion (exp
, noside
);
1236 return evaluate_subexp_do_call (exp
, noside
, callee
, vals
,
1237 function_name
, expect_type
);
1241 var_value_operation::evaluate_funcall (struct type
*expect_type
,
1242 struct expression
*exp
,
1244 const std::vector
<operation_up
> &args
)
1246 if (!overload_resolution
1247 || exp
->language_defn
->la_language
!= language_cplus
)
1248 return operation::evaluate_funcall (expect_type
, exp
, noside
, args
);
1250 std::vector
<value
*> argvec (args
.size ());
1251 for (int i
= 0; i
< args
.size (); ++i
)
1252 argvec
[i
] = args
[i
]->evaluate_with_coercion (exp
, noside
);
1254 struct symbol
*symp
;
1255 find_overload_match (argvec
, NULL
, NON_METHOD
,
1256 NULL
, std::get
<0> (m_storage
),
1257 NULL
, &symp
, NULL
, 0, noside
);
1259 if (SYMBOL_TYPE (symp
)->code () == TYPE_CODE_ERROR
)
1260 error_unknown_type (symp
->print_name ());
1261 value
*callee
= evaluate_var_value (noside
, std::get
<1> (m_storage
), symp
);
1263 return evaluate_subexp_do_call (exp
, noside
, callee
, argvec
,
1264 nullptr, expect_type
);
1268 scope_operation::evaluate_funcall (struct type
*expect_type
,
1269 struct expression
*exp
,
1271 const std::vector
<operation_up
> &args
)
1273 if (!overload_resolution
1274 || exp
->language_defn
->la_language
!= language_cplus
)
1275 return operation::evaluate_funcall (expect_type
, exp
, noside
, args
);
1277 /* Unpack it locally so we can properly handle overload
1279 const std::string
&name
= std::get
<1> (m_storage
);
1280 struct type
*type
= std::get
<0> (m_storage
);
1282 symbol
*function
= NULL
;
1283 const char *function_name
= NULL
;
1284 std::vector
<value
*> argvec (1 + args
.size ());
1285 if (type
->code () == TYPE_CODE_NAMESPACE
)
1287 function
= cp_lookup_symbol_namespace (type
->name (),
1289 get_selected_block (0),
1291 if (function
== NULL
)
1292 error (_("No symbol \"%s\" in namespace \"%s\"."),
1293 name
.c_str (), type
->name ());
1297 gdb_assert (type
->code () == TYPE_CODE_STRUCT
1298 || type
->code () == TYPE_CODE_UNION
);
1299 function_name
= name
.c_str ();
1301 /* We need a properly typed value for method lookup. */
1302 argvec
[0] = value_zero (type
, lval_memory
);
1305 for (int i
= 0; i
< args
.size (); ++i
)
1306 argvec
[i
+ 1] = args
[i
]->evaluate_with_coercion (exp
, noside
);
1307 gdb::array_view
<value
*> arg_view
= argvec
;
1309 value
*callee
= nullptr;
1310 if (function_name
!= nullptr)
1312 int static_memfuncp
;
1314 find_overload_match (arg_view
, function_name
, METHOD
,
1315 &argvec
[0], nullptr, &callee
, nullptr,
1316 &static_memfuncp
, 0, noside
);
1317 if (!static_memfuncp
)
1319 /* For the time being, we don't handle this. */
1320 error (_("Call to overloaded function %s requires "
1325 arg_view
= arg_view
.slice (1);
1330 arg_view
= arg_view
.slice (1);
1331 find_overload_match (arg_view
, nullptr,
1332 NON_METHOD
, nullptr, function
,
1333 nullptr, &symp
, nullptr, 1, noside
);
1334 callee
= value_of_variable (symp
, get_selected_block (0));
1337 return evaluate_subexp_do_call (exp
, noside
, callee
, arg_view
,
1338 nullptr, expect_type
);
1342 structop_member_base::evaluate_funcall (struct type
*expect_type
,
1343 struct expression
*exp
,
1345 const std::vector
<operation_up
> &args
)
1347 /* First, evaluate the structure into lhs. */
1349 if (opcode () == STRUCTOP_MEMBER
)
1350 lhs
= std::get
<0> (m_storage
)->evaluate_for_address (exp
, noside
);
1352 lhs
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1354 std::vector
<value
*> vals (args
.size () + 1);
1355 gdb::array_view
<value
*> val_view
= vals
;
1356 /* If the function is a virtual function, then the aggregate
1357 value (providing the structure) plays its part by providing
1358 the vtable. Otherwise, it is just along for the ride: call
1359 the function directly. */
1360 value
*rhs
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
1363 type
*a1_type
= check_typedef (value_type (rhs
));
1364 if (a1_type
->code () == TYPE_CODE_METHODPTR
)
1366 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1367 callee
= value_zero (TYPE_TARGET_TYPE (a1_type
), not_lval
);
1369 callee
= cplus_method_ptr_to_value (&lhs
, rhs
);
1373 else if (a1_type
->code () == TYPE_CODE_MEMBERPTR
)
1375 struct type
*type_ptr
1376 = lookup_pointer_type (TYPE_SELF_TYPE (a1_type
));
1377 struct type
*target_type_ptr
1378 = lookup_pointer_type (TYPE_TARGET_TYPE (a1_type
));
1380 /* Now, convert this value to an address. */
1381 lhs
= value_cast (type_ptr
, lhs
);
1383 long mem_offset
= value_as_long (rhs
);
1385 callee
= value_from_pointer (target_type_ptr
,
1386 value_as_long (lhs
) + mem_offset
);
1387 callee
= value_ind (callee
);
1389 val_view
= val_view
.slice (1);
1392 error (_("Non-pointer-to-member value used in pointer-to-member "
1395 for (int i
= 0; i
< args
.size (); ++i
)
1396 vals
[i
+ 1] = args
[i
]->evaluate_with_coercion (exp
, noside
);
1398 return evaluate_subexp_do_call (exp
, noside
, callee
, val_view
,
1399 nullptr, expect_type
);
1404 structop_base_operation::evaluate_funcall
1405 (struct type
*expect_type
, struct expression
*exp
, enum noside noside
,
1406 const std::vector
<operation_up
> &args
)
1408 std::vector
<value
*> vals (args
.size () + 1);
1409 /* First, evaluate the structure into vals[0]. */
1410 enum exp_opcode op
= opcode ();
1411 if (op
== STRUCTOP_STRUCT
)
1413 /* If v is a variable in a register, and the user types
1414 v.method (), this will produce an error, because v has no
1417 A possible way around this would be to allocate a copy of
1418 the variable on the stack, copy in the contents, call the
1419 function, and copy out the contents. I.e. convert this
1420 from call by reference to call by copy-return (or
1421 whatever it's called). However, this does not work
1422 because it is not the same: the method being called could
1423 stash a copy of the address, and then future uses through
1424 that address (after the method returns) would be expected
1425 to use the variable itself, not some copy of it. */
1426 vals
[0] = std::get
<0> (m_storage
)->evaluate_for_address (exp
, noside
);
1430 vals
[0] = std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
1431 /* Check to see if the operator '->' has been overloaded.
1432 If the operator has been overloaded replace vals[0] with the
1433 value returned by the custom operator and continue
1435 while (unop_user_defined_p (op
, vals
[0]))
1437 struct value
*value
= nullptr;
1440 value
= value_x_unop (vals
[0], op
, noside
);
1442 catch (const gdb_exception_error
&except
)
1444 if (except
.error
== NOT_FOUND_ERROR
)
1454 for (int i
= 0; i
< args
.size (); ++i
)
1455 vals
[i
+ 1] = args
[i
]->evaluate_with_coercion (exp
, noside
);
1456 gdb::array_view
<value
*> arg_view
= vals
;
1458 int static_memfuncp
;
1460 const char *tstr
= std::get
<1> (m_storage
).c_str ();
1461 if (overload_resolution
1462 && exp
->language_defn
->la_language
== language_cplus
)
1464 /* Language is C++, do some overload resolution before
1466 value
*val0
= vals
[0];
1467 find_overload_match (arg_view
, tstr
, METHOD
,
1468 &val0
, nullptr, &callee
, nullptr,
1469 &static_memfuncp
, 0, noside
);
1473 /* Non-C++ case -- or no overload resolution. */
1475 struct value
*temp
= vals
[0];
1477 callee
= value_struct_elt (&temp
, &vals
[1], tstr
,
1479 op
== STRUCTOP_STRUCT
1480 ? "structure" : "structure pointer");
1481 /* value_struct_elt updates temp with the correct value of the
1482 ``this'' pointer if necessary, so modify it to reflect any
1483 ``this'' changes. */
1484 vals
[0] = value_from_longest (lookup_pointer_type (value_type (temp
)),
1485 value_address (temp
)
1486 + value_embedded_offset (temp
));
1489 /* Take out `this' if needed. */
1490 if (static_memfuncp
)
1491 arg_view
= arg_view
.slice (1);
1493 return evaluate_subexp_do_call (exp
, noside
, callee
, arg_view
,
1494 nullptr, expect_type
);
1498 } /* namespace expr */
1500 /* Return true if type is integral or reference to integral */
1503 is_integral_or_integral_reference (struct type
*type
)
1505 if (is_integral_type (type
))
1508 type
= check_typedef (type
);
1509 return (type
!= nullptr
1510 && TYPE_IS_REFERENCE (type
)
1511 && is_integral_type (TYPE_TARGET_TYPE (type
)));
1514 /* Helper function that implements the body of OP_SCOPE. */
1517 eval_op_scope (struct type
*expect_type
, struct expression
*exp
,
1519 struct type
*type
, const char *string
)
1521 if (noside
== EVAL_SKIP
)
1522 return eval_skip_value (exp
);
1523 struct value
*arg1
= value_aggregate_elt (type
, string
, expect_type
,
1526 error (_("There is no field named %s"), string
);
1530 /* Helper function that implements the body of OP_VAR_ENTRY_VALUE. */
1533 eval_op_var_entry_value (struct type
*expect_type
, struct expression
*exp
,
1534 enum noside noside
, symbol
*sym
)
1536 if (noside
== EVAL_SKIP
)
1537 return eval_skip_value (exp
);
1538 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1539 return value_zero (SYMBOL_TYPE (sym
), not_lval
);
1541 if (SYMBOL_COMPUTED_OPS (sym
) == NULL
1542 || SYMBOL_COMPUTED_OPS (sym
)->read_variable_at_entry
== NULL
)
1543 error (_("Symbol \"%s\" does not have any specific entry value"),
1544 sym
->print_name ());
1546 struct frame_info
*frame
= get_selected_frame (NULL
);
1547 return SYMBOL_COMPUTED_OPS (sym
)->read_variable_at_entry (sym
, frame
);
1550 /* Helper function that implements the body of OP_VAR_MSYM_VALUE. */
1553 eval_op_var_msym_value (struct type
*expect_type
, struct expression
*exp
,
1554 enum noside noside
, bool outermost_p
,
1555 minimal_symbol
*msymbol
, struct objfile
*objfile
)
1557 value
*val
= evaluate_var_msym_value (noside
, objfile
, msymbol
);
1559 struct type
*type
= value_type (val
);
1560 if (type
->code () == TYPE_CODE_ERROR
1561 && (noside
!= EVAL_AVOID_SIDE_EFFECTS
|| !outermost_p
))
1562 error_unknown_type (msymbol
->print_name ());
1566 /* Helper function that implements the body of OP_FUNC_STATIC_VAR. */
1569 eval_op_func_static_var (struct type
*expect_type
, struct expression
*exp
,
1571 value
*func
, const char *var
)
1573 if (noside
== EVAL_SKIP
)
1574 return eval_skip_value (exp
);
1575 CORE_ADDR addr
= value_address (func
);
1576 const block
*blk
= block_for_pc (addr
);
1577 struct block_symbol sym
= lookup_symbol (var
, blk
, VAR_DOMAIN
, NULL
);
1578 if (sym
.symbol
== NULL
)
1579 error (_("No symbol \"%s\" in specified context."), var
);
1580 return evaluate_var_value (noside
, sym
.block
, sym
.symbol
);
1583 /* Helper function that implements the body of OP_REGISTER. */
1586 eval_op_register (struct type
*expect_type
, struct expression
*exp
,
1587 enum noside noside
, const char *name
)
1592 regno
= user_reg_map_name_to_regnum (exp
->gdbarch
,
1593 name
, strlen (name
));
1595 error (_("Register $%s not available."), name
);
1597 /* In EVAL_AVOID_SIDE_EFFECTS mode, we only need to return
1598 a value with the appropriate register type. Unfortunately,
1599 we don't have easy access to the type of user registers.
1600 So for these registers, we fetch the register value regardless
1601 of the evaluation mode. */
1602 if (noside
== EVAL_AVOID_SIDE_EFFECTS
1603 && regno
< gdbarch_num_cooked_regs (exp
->gdbarch
))
1604 val
= value_zero (register_type (exp
->gdbarch
, regno
), not_lval
);
1606 val
= value_of_register (regno
, get_selected_frame (NULL
));
1608 error (_("Value of register %s not available."), name
);
1613 /* Helper function that implements the body of OP_STRING. */
1616 eval_op_string (struct type
*expect_type
, struct expression
*exp
,
1617 enum noside noside
, int len
, const char *string
)
1619 if (noside
== EVAL_SKIP
)
1620 return eval_skip_value (exp
);
1621 struct type
*type
= language_string_char_type (exp
->language_defn
,
1623 return value_string (string
, len
, type
);
1626 /* Helper function that implements the body of OP_OBJC_SELECTOR. */
1629 eval_op_objc_selector (struct type
*expect_type
, struct expression
*exp
,
1633 if (noside
== EVAL_SKIP
)
1634 return eval_skip_value (exp
);
1636 struct type
*selector_type
= builtin_type (exp
->gdbarch
)->builtin_data_ptr
;
1637 return value_from_longest (selector_type
,
1638 lookup_child_selector (exp
->gdbarch
, sel
));
1641 /* Helper function that implements the body of BINOP_CONCAT. */
1644 eval_op_concat (struct type
*expect_type
, struct expression
*exp
,
1645 enum noside noside
, struct value
*arg1
, struct value
*arg2
)
1647 if (noside
== EVAL_SKIP
)
1648 return eval_skip_value (exp
);
1649 if (binop_user_defined_p (BINOP_CONCAT
, arg1
, arg2
))
1650 return value_x_binop (arg1
, arg2
, BINOP_CONCAT
, OP_NULL
, noside
);
1652 return value_concat (arg1
, arg2
);
1655 /* A helper function for TERNOP_SLICE. */
1658 eval_op_ternop (struct type
*expect_type
, struct expression
*exp
,
1660 struct value
*array
, struct value
*low
, struct value
*upper
)
1662 if (noside
== EVAL_SKIP
)
1663 return eval_skip_value (exp
);
1664 int lowbound
= value_as_long (low
);
1665 int upperbound
= value_as_long (upper
);
1666 return value_slice (array
, lowbound
, upperbound
- lowbound
+ 1);
1669 /* A helper function for STRUCTOP_STRUCT. */
1672 eval_op_structop_struct (struct type
*expect_type
, struct expression
*exp
,
1674 struct value
*arg1
, const char *string
)
1676 if (noside
== EVAL_SKIP
)
1677 return eval_skip_value (exp
);
1678 struct value
*arg3
= value_struct_elt (&arg1
, NULL
, string
,
1680 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1681 arg3
= value_zero (value_type (arg3
), VALUE_LVAL (arg3
));
1685 /* A helper function for STRUCTOP_PTR. */
1688 eval_op_structop_ptr (struct type
*expect_type
, struct expression
*exp
,
1690 struct value
*arg1
, const char *string
)
1692 if (noside
== EVAL_SKIP
)
1693 return eval_skip_value (exp
);
1695 /* Check to see if operator '->' has been overloaded. If so replace
1696 arg1 with the value returned by evaluating operator->(). */
1697 while (unop_user_defined_p (STRUCTOP_PTR
, arg1
))
1699 struct value
*value
= NULL
;
1702 value
= value_x_unop (arg1
, STRUCTOP_PTR
, noside
);
1705 catch (const gdb_exception_error
&except
)
1707 if (except
.error
== NOT_FOUND_ERROR
)
1716 /* JYG: if print object is on we need to replace the base type
1717 with rtti type in order to continue on with successful
1718 lookup of member / method only available in the rtti type. */
1720 struct type
*arg_type
= value_type (arg1
);
1721 struct type
*real_type
;
1722 int full
, using_enc
;
1724 struct value_print_options opts
;
1726 get_user_print_options (&opts
);
1727 if (opts
.objectprint
&& TYPE_TARGET_TYPE (arg_type
)
1728 && (TYPE_TARGET_TYPE (arg_type
)->code () == TYPE_CODE_STRUCT
))
1730 real_type
= value_rtti_indirect_type (arg1
, &full
, &top
,
1733 arg1
= value_cast (real_type
, arg1
);
1737 struct value
*arg3
= value_struct_elt (&arg1
, NULL
, string
,
1738 NULL
, "structure pointer");
1739 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1740 arg3
= value_zero (value_type (arg3
), VALUE_LVAL (arg3
));
1744 /* A helper function for STRUCTOP_MEMBER. */
1747 eval_op_member (struct type
*expect_type
, struct expression
*exp
,
1749 struct value
*arg1
, struct value
*arg2
)
1753 if (noside
== EVAL_SKIP
)
1754 return eval_skip_value (exp
);
1757 struct type
*type
= check_typedef (value_type (arg2
));
1758 switch (type
->code ())
1760 case TYPE_CODE_METHODPTR
:
1761 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1762 return value_zero (TYPE_TARGET_TYPE (type
), not_lval
);
1765 arg2
= cplus_method_ptr_to_value (&arg1
, arg2
);
1766 gdb_assert (value_type (arg2
)->code () == TYPE_CODE_PTR
);
1767 return value_ind (arg2
);
1770 case TYPE_CODE_MEMBERPTR
:
1771 /* Now, convert these values to an address. */
1772 arg1
= value_cast_pointers (lookup_pointer_type (TYPE_SELF_TYPE (type
)),
1775 mem_offset
= value_as_long (arg2
);
1777 arg3
= value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
1778 value_as_long (arg1
) + mem_offset
);
1779 return value_ind (arg3
);
1782 error (_("non-pointer-to-member value used "
1783 "in pointer-to-member construct"));
1787 /* A helper function for BINOP_ADD. */
1790 eval_op_add (struct type
*expect_type
, struct expression
*exp
,
1792 struct value
*arg1
, struct value
*arg2
)
1794 if (noside
== EVAL_SKIP
)
1795 return eval_skip_value (exp
);
1796 if (binop_user_defined_p (BINOP_ADD
, arg1
, arg2
))
1797 return value_x_binop (arg1
, arg2
, BINOP_ADD
, OP_NULL
, noside
);
1798 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
1799 && is_integral_or_integral_reference (value_type (arg2
)))
1800 return value_ptradd (arg1
, value_as_long (arg2
));
1801 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg2
))
1802 && is_integral_or_integral_reference (value_type (arg1
)))
1803 return value_ptradd (arg2
, value_as_long (arg1
));
1806 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
1807 return value_binop (arg1
, arg2
, BINOP_ADD
);
1811 /* A helper function for BINOP_SUB. */
1814 eval_op_sub (struct type
*expect_type
, struct expression
*exp
,
1816 struct value
*arg1
, struct value
*arg2
)
1818 if (noside
== EVAL_SKIP
)
1819 return eval_skip_value (exp
);
1820 if (binop_user_defined_p (BINOP_SUB
, arg1
, arg2
))
1821 return value_x_binop (arg1
, arg2
, BINOP_SUB
, OP_NULL
, noside
);
1822 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
1823 && ptrmath_type_p (exp
->language_defn
, value_type (arg2
)))
1825 /* FIXME -- should be ptrdiff_t */
1826 struct type
*type
= builtin_type (exp
->gdbarch
)->builtin_long
;
1827 return value_from_longest (type
, value_ptrdiff (arg1
, arg2
));
1829 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
1830 && is_integral_or_integral_reference (value_type (arg2
)))
1831 return value_ptradd (arg1
, - value_as_long (arg2
));
1834 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
1835 return value_binop (arg1
, arg2
, BINOP_SUB
);
1839 /* Helper function for several different binary operations. */
1842 eval_op_binary (struct type
*expect_type
, struct expression
*exp
,
1843 enum noside noside
, enum exp_opcode op
,
1844 struct value
*arg1
, struct value
*arg2
)
1846 if (noside
== EVAL_SKIP
)
1847 return eval_skip_value (exp
);
1848 if (binop_user_defined_p (op
, arg1
, arg2
))
1849 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1852 /* If EVAL_AVOID_SIDE_EFFECTS and we're dividing by zero,
1853 fudge arg2 to avoid division-by-zero, the caller is
1854 (theoretically) only looking for the type of the result. */
1855 if (noside
== EVAL_AVOID_SIDE_EFFECTS
1856 /* ??? Do we really want to test for BINOP_MOD here?
1857 The implementation of value_binop gives it a well-defined
1860 || op
== BINOP_INTDIV
1863 && value_logical_not (arg2
))
1865 struct value
*v_one
;
1867 v_one
= value_one (value_type (arg2
));
1868 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &v_one
);
1869 return value_binop (arg1
, v_one
, op
);
1873 /* For shift and integer exponentiation operations,
1874 only promote the first argument. */
1875 if ((op
== BINOP_LSH
|| op
== BINOP_RSH
|| op
== BINOP_EXP
)
1876 && is_integral_type (value_type (arg2
)))
1877 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
1879 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
1881 return value_binop (arg1
, arg2
, op
);
1886 /* A helper function for BINOP_SUBSCRIPT. */
1889 eval_op_subscript (struct type
*expect_type
, struct expression
*exp
,
1890 enum noside noside
, enum exp_opcode op
,
1891 struct value
*arg1
, struct value
*arg2
)
1893 if (noside
== EVAL_SKIP
)
1894 return eval_skip_value (exp
);
1895 if (binop_user_defined_p (op
, arg1
, arg2
))
1896 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1899 /* If the user attempts to subscript something that is not an
1900 array or pointer type (like a plain int variable for example),
1901 then report this as an error. */
1903 arg1
= coerce_ref (arg1
);
1904 struct type
*type
= check_typedef (value_type (arg1
));
1905 if (type
->code () != TYPE_CODE_ARRAY
1906 && type
->code () != TYPE_CODE_PTR
)
1909 error (_("cannot subscript something of type `%s'"),
1912 error (_("cannot subscript requested type"));
1915 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1916 return value_zero (TYPE_TARGET_TYPE (type
), VALUE_LVAL (arg1
));
1918 return value_subscript (arg1
, value_as_long (arg2
));
1922 /* A helper function for BINOP_EQUAL. */
1925 eval_op_equal (struct type
*expect_type
, struct expression
*exp
,
1926 enum noside noside
, enum exp_opcode op
,
1927 struct value
*arg1
, struct value
*arg2
)
1929 if (noside
== EVAL_SKIP
)
1930 return eval_skip_value (exp
);
1931 if (binop_user_defined_p (op
, arg1
, arg2
))
1933 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1937 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
1938 int tem
= value_equal (arg1
, arg2
);
1939 struct type
*type
= language_bool_type (exp
->language_defn
,
1941 return value_from_longest (type
, (LONGEST
) tem
);
1945 /* A helper function for BINOP_NOTEQUAL. */
1948 eval_op_notequal (struct type
*expect_type
, struct expression
*exp
,
1949 enum noside noside
, enum exp_opcode op
,
1950 struct value
*arg1
, struct value
*arg2
)
1952 if (noside
== EVAL_SKIP
)
1953 return eval_skip_value (exp
);
1954 if (binop_user_defined_p (op
, arg1
, arg2
))
1956 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1960 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
1961 int tem
= value_equal (arg1
, arg2
);
1962 struct type
*type
= language_bool_type (exp
->language_defn
,
1964 return value_from_longest (type
, (LONGEST
) ! tem
);
1968 /* A helper function for BINOP_LESS. */
1971 eval_op_less (struct type
*expect_type
, struct expression
*exp
,
1972 enum noside noside
, enum exp_opcode op
,
1973 struct value
*arg1
, struct value
*arg2
)
1975 if (noside
== EVAL_SKIP
)
1976 return eval_skip_value (exp
);
1977 if (binop_user_defined_p (op
, arg1
, arg2
))
1979 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1983 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
1984 int tem
= value_less (arg1
, arg2
);
1985 struct type
*type
= language_bool_type (exp
->language_defn
,
1987 return value_from_longest (type
, (LONGEST
) tem
);
1991 /* A helper function for BINOP_GTR. */
1994 eval_op_gtr (struct type
*expect_type
, struct expression
*exp
,
1995 enum noside noside
, enum exp_opcode op
,
1996 struct value
*arg1
, struct value
*arg2
)
1998 if (noside
== EVAL_SKIP
)
1999 return eval_skip_value (exp
);
2000 if (binop_user_defined_p (op
, arg1
, arg2
))
2002 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2006 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2007 int tem
= value_less (arg2
, arg1
);
2008 struct type
*type
= language_bool_type (exp
->language_defn
,
2010 return value_from_longest (type
, (LONGEST
) tem
);
2014 /* A helper function for BINOP_GEQ. */
2017 eval_op_geq (struct type
*expect_type
, struct expression
*exp
,
2018 enum noside noside
, enum exp_opcode op
,
2019 struct value
*arg1
, struct value
*arg2
)
2021 if (noside
== EVAL_SKIP
)
2022 return eval_skip_value (exp
);
2023 if (binop_user_defined_p (op
, arg1
, arg2
))
2025 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2029 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2030 int tem
= value_less (arg2
, arg1
) || value_equal (arg1
, arg2
);
2031 struct type
*type
= language_bool_type (exp
->language_defn
,
2033 return value_from_longest (type
, (LONGEST
) tem
);
2037 /* A helper function for BINOP_LEQ. */
2040 eval_op_leq (struct type
*expect_type
, struct expression
*exp
,
2041 enum noside noside
, enum exp_opcode op
,
2042 struct value
*arg1
, struct value
*arg2
)
2044 if (noside
== EVAL_SKIP
)
2045 return eval_skip_value (exp
);
2046 if (binop_user_defined_p (op
, arg1
, arg2
))
2048 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2052 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2053 int tem
= value_less (arg1
, arg2
) || value_equal (arg1
, arg2
);
2054 struct type
*type
= language_bool_type (exp
->language_defn
,
2056 return value_from_longest (type
, (LONGEST
) tem
);
2060 /* A helper function for BINOP_REPEAT. */
2063 eval_op_repeat (struct type
*expect_type
, struct expression
*exp
,
2064 enum noside noside
, enum exp_opcode op
,
2065 struct value
*arg1
, struct value
*arg2
)
2067 if (noside
== EVAL_SKIP
)
2068 return eval_skip_value (exp
);
2069 struct type
*type
= check_typedef (value_type (arg2
));
2070 if (type
->code () != TYPE_CODE_INT
2071 && type
->code () != TYPE_CODE_ENUM
)
2072 error (_("Non-integral right operand for \"@\" operator."));
2073 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2075 return allocate_repeat_value (value_type (arg1
),
2076 longest_to_int (value_as_long (arg2
)));
2079 return value_repeat (arg1
, longest_to_int (value_as_long (arg2
)));
2082 /* A helper function for UNOP_PLUS. */
2085 eval_op_plus (struct type
*expect_type
, struct expression
*exp
,
2086 enum noside noside
, enum exp_opcode op
,
2089 if (noside
== EVAL_SKIP
)
2090 return eval_skip_value (exp
);
2091 if (unop_user_defined_p (op
, arg1
))
2092 return value_x_unop (arg1
, op
, noside
);
2095 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2096 return value_pos (arg1
);
2100 /* A helper function for UNOP_NEG. */
2103 eval_op_neg (struct type
*expect_type
, struct expression
*exp
,
2104 enum noside noside
, enum exp_opcode op
,
2107 if (noside
== EVAL_SKIP
)
2108 return eval_skip_value (exp
);
2109 if (unop_user_defined_p (op
, arg1
))
2110 return value_x_unop (arg1
, op
, noside
);
2113 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2114 return value_neg (arg1
);
2118 /* A helper function for UNOP_COMPLEMENT. */
2121 eval_op_complement (struct type
*expect_type
, struct expression
*exp
,
2122 enum noside noside
, enum exp_opcode op
,
2125 if (noside
== EVAL_SKIP
)
2126 return eval_skip_value (exp
);
2127 if (unop_user_defined_p (UNOP_COMPLEMENT
, arg1
))
2128 return value_x_unop (arg1
, UNOP_COMPLEMENT
, noside
);
2131 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2132 return value_complement (arg1
);
2136 /* A helper function for UNOP_LOGICAL_NOT. */
2139 eval_op_lognot (struct type
*expect_type
, struct expression
*exp
,
2140 enum noside noside
, enum exp_opcode op
,
2143 if (noside
== EVAL_SKIP
)
2144 return eval_skip_value (exp
);
2145 if (unop_user_defined_p (op
, arg1
))
2146 return value_x_unop (arg1
, op
, noside
);
2149 struct type
*type
= language_bool_type (exp
->language_defn
,
2151 return value_from_longest (type
, (LONGEST
) value_logical_not (arg1
));
2155 /* A helper function for UNOP_IND. */
2158 eval_op_ind (struct type
*expect_type
, struct expression
*exp
,
2162 struct type
*type
= check_typedef (value_type (arg1
));
2163 if (type
->code () == TYPE_CODE_METHODPTR
2164 || type
->code () == TYPE_CODE_MEMBERPTR
)
2165 error (_("Attempt to dereference pointer "
2166 "to member without an object"));
2167 if (noside
== EVAL_SKIP
)
2168 return eval_skip_value (exp
);
2169 if (unop_user_defined_p (UNOP_IND
, arg1
))
2170 return value_x_unop (arg1
, UNOP_IND
, noside
);
2171 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2173 type
= check_typedef (value_type (arg1
));
2175 /* If the type pointed to is dynamic then in order to resolve the
2176 dynamic properties we must actually dereference the pointer.
2177 There is a risk that this dereference will have side-effects
2178 in the inferior, but being able to print accurate type
2179 information seems worth the risk. */
2180 if ((type
->code () != TYPE_CODE_PTR
2181 && !TYPE_IS_REFERENCE (type
))
2182 || !is_dynamic_type (TYPE_TARGET_TYPE (type
)))
2184 if (type
->code () == TYPE_CODE_PTR
2185 || TYPE_IS_REFERENCE (type
)
2186 /* In C you can dereference an array to get the 1st elt. */
2187 || type
->code () == TYPE_CODE_ARRAY
)
2188 return value_zero (TYPE_TARGET_TYPE (type
),
2190 else if (type
->code () == TYPE_CODE_INT
)
2191 /* GDB allows dereferencing an int. */
2192 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
,
2195 error (_("Attempt to take contents of a non-pointer value."));
2199 /* Allow * on an integer so we can cast it to whatever we want.
2200 This returns an int, which seems like the most C-like thing to
2201 do. "long long" variables are rare enough that
2202 BUILTIN_TYPE_LONGEST would seem to be a mistake. */
2203 if (type
->code () == TYPE_CODE_INT
)
2204 return value_at_lazy (builtin_type (exp
->gdbarch
)->builtin_int
,
2205 (CORE_ADDR
) value_as_address (arg1
));
2206 return value_ind (arg1
);
2209 /* A helper function for UNOP_ALIGNOF. */
2212 eval_op_alignof (struct type
*expect_type
, struct expression
*exp
,
2216 struct type
*type
= value_type (arg1
);
2217 /* FIXME: This should be size_t. */
2218 struct type
*size_type
= builtin_type (exp
->gdbarch
)->builtin_int
;
2219 ULONGEST align
= type_align (type
);
2221 error (_("could not determine alignment of type"));
2222 return value_from_longest (size_type
, align
);
2225 /* A helper function for UNOP_MEMVAL. */
2228 eval_op_memval (struct type
*expect_type
, struct expression
*exp
,
2230 struct value
*arg1
, struct type
*type
)
2232 if (noside
== EVAL_SKIP
)
2233 return eval_skip_value (exp
);
2234 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2235 return value_zero (type
, lval_memory
);
2237 return value_at_lazy (type
, value_as_address (arg1
));
2240 /* A helper function for UNOP_PREINCREMENT. */
2243 eval_op_preinc (struct type
*expect_type
, struct expression
*exp
,
2244 enum noside noside
, enum exp_opcode op
,
2247 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2249 else if (unop_user_defined_p (op
, arg1
))
2251 return value_x_unop (arg1
, op
, noside
);
2256 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2257 arg2
= value_ptradd (arg1
, 1);
2260 struct value
*tmp
= arg1
;
2262 arg2
= value_one (value_type (arg1
));
2263 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2264 arg2
= value_binop (tmp
, arg2
, BINOP_ADD
);
2267 return value_assign (arg1
, arg2
);
2271 /* A helper function for UNOP_PREDECREMENT. */
2274 eval_op_predec (struct type
*expect_type
, struct expression
*exp
,
2275 enum noside noside
, enum exp_opcode op
,
2278 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2280 else if (unop_user_defined_p (op
, arg1
))
2282 return value_x_unop (arg1
, op
, noside
);
2287 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2288 arg2
= value_ptradd (arg1
, -1);
2291 struct value
*tmp
= arg1
;
2293 arg2
= value_one (value_type (arg1
));
2294 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2295 arg2
= value_binop (tmp
, arg2
, BINOP_SUB
);
2298 return value_assign (arg1
, arg2
);
2302 /* A helper function for UNOP_POSTINCREMENT. */
2305 eval_op_postinc (struct type
*expect_type
, struct expression
*exp
,
2306 enum noside noside
, enum exp_opcode op
,
2309 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2311 else if (unop_user_defined_p (op
, arg1
))
2313 return value_x_unop (arg1
, op
, noside
);
2317 struct value
*arg3
= value_non_lval (arg1
);
2320 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2321 arg2
= value_ptradd (arg1
, 1);
2324 struct value
*tmp
= arg1
;
2326 arg2
= value_one (value_type (arg1
));
2327 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2328 arg2
= value_binop (tmp
, arg2
, BINOP_ADD
);
2331 value_assign (arg1
, arg2
);
2336 /* A helper function for UNOP_POSTDECREMENT. */
2339 eval_op_postdec (struct type
*expect_type
, struct expression
*exp
,
2340 enum noside noside
, enum exp_opcode op
,
2343 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2345 else if (unop_user_defined_p (op
, arg1
))
2347 return value_x_unop (arg1
, op
, noside
);
2351 struct value
*arg3
= value_non_lval (arg1
);
2354 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2355 arg2
= value_ptradd (arg1
, -1);
2358 struct value
*tmp
= arg1
;
2360 arg2
= value_one (value_type (arg1
));
2361 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2362 arg2
= value_binop (tmp
, arg2
, BINOP_SUB
);
2365 value_assign (arg1
, arg2
);
2370 /* A helper function for OP_TYPE. */
2373 eval_op_type (struct type
*expect_type
, struct expression
*exp
,
2374 enum noside noside
, struct type
*type
)
2376 if (noside
== EVAL_SKIP
)
2377 return eval_skip_value (exp
);
2378 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2379 return allocate_value (type
);
2381 error (_("Attempt to use a type name as an expression"));
2384 /* A helper function for BINOP_ASSIGN_MODIFY. */
2387 eval_binop_assign_modify (struct type
*expect_type
, struct expression
*exp
,
2388 enum noside noside
, enum exp_opcode op
,
2389 struct value
*arg1
, struct value
*arg2
)
2391 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2393 if (binop_user_defined_p (op
, arg1
, arg2
))
2394 return value_x_binop (arg1
, arg2
, BINOP_ASSIGN_MODIFY
, op
, noside
);
2395 else if (op
== BINOP_ADD
&& ptrmath_type_p (exp
->language_defn
,
2397 && is_integral_type (value_type (arg2
)))
2398 arg2
= value_ptradd (arg1
, value_as_long (arg2
));
2399 else if (op
== BINOP_SUB
&& ptrmath_type_p (exp
->language_defn
,
2401 && is_integral_type (value_type (arg2
)))
2402 arg2
= value_ptradd (arg1
, - value_as_long (arg2
));
2405 struct value
*tmp
= arg1
;
2407 /* For shift and integer exponentiation operations,
2408 only promote the first argument. */
2409 if ((op
== BINOP_LSH
|| op
== BINOP_RSH
|| op
== BINOP_EXP
)
2410 && is_integral_type (value_type (arg2
)))
2411 unop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
);
2413 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2415 arg2
= value_binop (tmp
, arg2
, op
);
2417 return value_assign (arg1
, arg2
);
2420 /* Note that ARGS needs 2 empty slots up front and must end with a
2422 static struct value
*
2423 eval_op_objc_msgcall (struct type
*expect_type
, struct expression
*exp
,
2424 enum noside noside
, CORE_ADDR selector
,
2425 value
*target
, gdb::array_view
<value
*> args
)
2427 CORE_ADDR responds_selector
= 0;
2428 CORE_ADDR method_selector
= 0;
2430 int struct_return
= 0;
2432 struct value
*msg_send
= NULL
;
2433 struct value
*msg_send_stret
= NULL
;
2434 int gnu_runtime
= 0;
2436 struct value
*method
= NULL
;
2437 struct value
*called_method
= NULL
;
2439 struct type
*selector_type
= NULL
;
2440 struct type
*long_type
;
2443 struct value
*ret
= NULL
;
2448 long_type
= builtin_type (exp
->gdbarch
)->builtin_long
;
2449 selector_type
= builtin_type (exp
->gdbarch
)->builtin_data_ptr
;
2451 if (value_as_long (target
) == 0)
2452 return value_from_longest (long_type
, 0);
2454 if (lookup_minimal_symbol ("objc_msg_lookup", 0, 0).minsym
)
2457 /* Find the method dispatch (Apple runtime) or method lookup
2458 (GNU runtime) function for Objective-C. These will be used
2459 to lookup the symbol information for the method. If we
2460 can't find any symbol information, then we'll use these to
2461 call the method, otherwise we can call the method
2462 directly. The msg_send_stret function is used in the special
2463 case of a method that returns a structure (Apple runtime
2467 type
= selector_type
;
2469 type
= lookup_function_type (type
);
2470 type
= lookup_pointer_type (type
);
2471 type
= lookup_function_type (type
);
2472 type
= lookup_pointer_type (type
);
2474 msg_send
= find_function_in_inferior ("objc_msg_lookup", NULL
);
2476 = find_function_in_inferior ("objc_msg_lookup", NULL
);
2478 msg_send
= value_from_pointer (type
, value_as_address (msg_send
));
2479 msg_send_stret
= value_from_pointer (type
,
2480 value_as_address (msg_send_stret
));
2484 msg_send
= find_function_in_inferior ("objc_msgSend", NULL
);
2485 /* Special dispatcher for methods returning structs. */
2487 = find_function_in_inferior ("objc_msgSend_stret", NULL
);
2490 /* Verify the target object responds to this method. The
2491 standard top-level 'Object' class uses a different name for
2492 the verification method than the non-standard, but more
2493 often used, 'NSObject' class. Make sure we check for both. */
2496 = lookup_child_selector (exp
->gdbarch
, "respondsToSelector:");
2497 if (responds_selector
== 0)
2499 = lookup_child_selector (exp
->gdbarch
, "respondsTo:");
2501 if (responds_selector
== 0)
2502 error (_("no 'respondsTo:' or 'respondsToSelector:' method"));
2505 = lookup_child_selector (exp
->gdbarch
, "methodForSelector:");
2506 if (method_selector
== 0)
2508 = lookup_child_selector (exp
->gdbarch
, "methodFor:");
2510 if (method_selector
== 0)
2511 error (_("no 'methodFor:' or 'methodForSelector:' method"));
2513 /* Call the verification method, to make sure that the target
2514 class implements the desired method. */
2516 argvec
[0] = msg_send
;
2518 argvec
[2] = value_from_longest (long_type
, responds_selector
);
2519 argvec
[3] = value_from_longest (long_type
, selector
);
2522 ret
= call_function_by_hand (argvec
[0], NULL
, {argvec
+ 1, 3});
2525 /* Function objc_msg_lookup returns a pointer. */
2527 ret
= call_function_by_hand (argvec
[0], NULL
, {argvec
+ 1, 3});
2529 if (value_as_long (ret
) == 0)
2530 error (_("Target does not respond to this message selector."));
2532 /* Call "methodForSelector:" method, to get the address of a
2533 function method that implements this selector for this
2534 class. If we can find a symbol at that address, then we
2535 know the return type, parameter types etc. (that's a good
2538 argvec
[0] = msg_send
;
2540 argvec
[2] = value_from_longest (long_type
, method_selector
);
2541 argvec
[3] = value_from_longest (long_type
, selector
);
2544 ret
= call_function_by_hand (argvec
[0], NULL
, {argvec
+ 1, 3});
2548 ret
= call_function_by_hand (argvec
[0], NULL
, {argvec
+ 1, 3});
2551 /* ret should now be the selector. */
2553 addr
= value_as_long (ret
);
2556 struct symbol
*sym
= NULL
;
2558 /* The address might point to a function descriptor;
2559 resolve it to the actual code address instead. */
2560 addr
= gdbarch_convert_from_func_ptr_addr (exp
->gdbarch
, addr
,
2561 current_top_target ());
2563 /* Is it a high_level symbol? */
2564 sym
= find_pc_function (addr
);
2566 method
= value_of_variable (sym
, 0);
2569 /* If we found a method with symbol information, check to see
2570 if it returns a struct. Otherwise assume it doesn't. */
2575 struct type
*val_type
;
2577 funaddr
= find_function_addr (method
, &val_type
);
2579 block_for_pc (funaddr
);
2581 val_type
= check_typedef (val_type
);
2583 if ((val_type
== NULL
)
2584 || (val_type
->code () == TYPE_CODE_ERROR
))
2586 if (expect_type
!= NULL
)
2587 val_type
= expect_type
;
2590 struct_return
= using_struct_return (exp
->gdbarch
, method
,
2593 else if (expect_type
!= NULL
)
2595 struct_return
= using_struct_return (exp
->gdbarch
, NULL
,
2596 check_typedef (expect_type
));
2599 /* Found a function symbol. Now we will substitute its
2600 value in place of the message dispatcher (obj_msgSend),
2601 so that we call the method directly instead of thru
2602 the dispatcher. The main reason for doing this is that
2603 we can now evaluate the return value and parameter values
2604 according to their known data types, in case we need to
2605 do things like promotion, dereferencing, special handling
2606 of structs and doubles, etc.
2608 We want to use the type signature of 'method', but still
2609 jump to objc_msgSend() or objc_msgSend_stret() to better
2610 mimic the behavior of the runtime. */
2614 if (value_type (method
)->code () != TYPE_CODE_FUNC
)
2615 error (_("method address has symbol information "
2616 "with non-function type; skipping"));
2618 /* Create a function pointer of the appropriate type, and
2619 replace its value with the value of msg_send or
2620 msg_send_stret. We must use a pointer here, as
2621 msg_send and msg_send_stret are of pointer type, and
2622 the representation may be different on systems that use
2623 function descriptors. */
2626 = value_from_pointer (lookup_pointer_type (value_type (method
)),
2627 value_as_address (msg_send_stret
));
2630 = value_from_pointer (lookup_pointer_type (value_type (method
)),
2631 value_as_address (msg_send
));
2636 called_method
= msg_send_stret
;
2638 called_method
= msg_send
;
2641 if (noside
== EVAL_SKIP
)
2642 return eval_skip_value (exp
);
2644 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2646 /* If the return type doesn't look like a function type,
2647 call an error. This can happen if somebody tries to
2648 turn a variable into a function call. This is here
2649 because people often want to call, eg, strcmp, which
2650 gdb doesn't know is a function. If gdb isn't asked for
2651 it's opinion (ie. through "whatis"), it won't offer
2654 struct type
*callee_type
= value_type (called_method
);
2656 if (callee_type
&& callee_type
->code () == TYPE_CODE_PTR
)
2657 callee_type
= TYPE_TARGET_TYPE (callee_type
);
2658 callee_type
= TYPE_TARGET_TYPE (callee_type
);
2662 if ((callee_type
->code () == TYPE_CODE_ERROR
) && expect_type
)
2663 return allocate_value (expect_type
);
2665 return allocate_value (callee_type
);
2668 error (_("Expression of type other than "
2669 "\"method returning ...\" used as a method"));
2672 /* Now depending on whether we found a symbol for the method,
2673 we will either call the runtime dispatcher or the method
2677 args
[1] = value_from_longest (long_type
, selector
);
2679 if (gnu_runtime
&& (method
!= NULL
))
2681 /* Function objc_msg_lookup returns a pointer. */
2682 struct type
*tem_type
= value_type (called_method
);
2683 tem_type
= lookup_pointer_type (lookup_function_type (tem_type
));
2684 deprecated_set_value_type (called_method
, tem_type
);
2685 called_method
= call_function_by_hand (called_method
, NULL
, args
);
2688 return call_function_by_hand (called_method
, NULL
, args
);
2691 /* Helper function for MULTI_SUBSCRIPT. */
2693 static struct value
*
2694 eval_multi_subscript (struct type
*expect_type
, struct expression
*exp
,
2695 enum noside noside
, value
*arg1
,
2696 gdb::array_view
<value
*> args
)
2698 if (noside
== EVAL_SKIP
)
2700 for (value
*arg2
: args
)
2702 if (binop_user_defined_p (MULTI_SUBSCRIPT
, arg1
, arg2
))
2704 arg1
= value_x_binop (arg1
, arg2
, MULTI_SUBSCRIPT
, OP_NULL
, noside
);
2708 arg1
= coerce_ref (arg1
);
2709 struct type
*type
= check_typedef (value_type (arg1
));
2711 switch (type
->code ())
2714 case TYPE_CODE_ARRAY
:
2715 case TYPE_CODE_STRING
:
2716 arg1
= value_subscript (arg1
, value_as_long (arg2
));
2721 error (_("cannot subscript something of type `%s'"),
2724 error (_("cannot subscript requested type"));
2735 objc_msgcall_operation::evaluate (struct type
*expect_type
,
2736 struct expression
*exp
,
2739 enum noside sub_no_side
= EVAL_NORMAL
;
2740 struct type
*selector_type
= builtin_type (exp
->gdbarch
)->builtin_data_ptr
;
2742 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2743 sub_no_side
= EVAL_NORMAL
;
2745 sub_no_side
= noside
;
2747 = std::get
<1> (m_storage
)->evaluate (selector_type
, exp
, sub_no_side
);
2749 if (value_as_long (target
) == 0)
2750 sub_no_side
= EVAL_AVOID_SIDE_EFFECTS
;
2752 sub_no_side
= noside
;
2753 std::vector
<operation_up
> &args
= std::get
<2> (m_storage
);
2754 value
**argvec
= XALLOCAVEC (struct value
*, args
.size () + 3);
2755 argvec
[0] = nullptr;
2756 argvec
[1] = nullptr;
2757 for (int i
= 0; i
< args
.size (); ++i
)
2758 argvec
[i
+ 2] = args
[i
]->evaluate_with_coercion (exp
, sub_no_side
);
2759 argvec
[args
.size () + 2] = nullptr;
2761 return eval_op_objc_msgcall (expect_type
, exp
, noside
, std::
2762 get
<0> (m_storage
), target
,
2763 gdb::make_array_view (argvec
,
2768 multi_subscript_operation::evaluate (struct type
*expect_type
,
2769 struct expression
*exp
,
2772 value
*arg1
= std::get
<0> (m_storage
)->evaluate_with_coercion (exp
, noside
);
2773 std::vector
<operation_up
> &values
= std::get
<1> (m_storage
);
2774 value
**argvec
= XALLOCAVEC (struct value
*, values
.size ());
2775 for (int ix
= 0; ix
< values
.size (); ++ix
)
2776 argvec
[ix
] = values
[ix
]->evaluate_with_coercion (exp
, noside
);
2777 return eval_multi_subscript (expect_type
, exp
, noside
, arg1
,
2778 gdb::make_array_view (argvec
, values
.size ()));
2782 logical_and_operation::evaluate (struct type
*expect_type
,
2783 struct expression
*exp
,
2786 value
*arg1
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
2787 if (noside
== EVAL_SKIP
)
2788 return eval_skip_value (exp
);
2790 value
*arg2
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
,
2791 EVAL_AVOID_SIDE_EFFECTS
);
2793 if (binop_user_defined_p (BINOP_LOGICAL_AND
, arg1
, arg2
))
2795 arg2
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
2796 return value_x_binop (arg1
, arg2
, BINOP_LOGICAL_AND
, OP_NULL
, noside
);
2800 int tem
= value_logical_not (arg1
);
2803 arg2
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
2804 tem
= value_logical_not (arg2
);
2806 struct type
*type
= language_bool_type (exp
->language_defn
,
2808 return value_from_longest (type
, !tem
);
2813 logical_or_operation::evaluate (struct type
*expect_type
,
2814 struct expression
*exp
,
2817 value
*arg1
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
2818 if (noside
== EVAL_SKIP
)
2819 return eval_skip_value (exp
);
2821 value
*arg2
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
,
2822 EVAL_AVOID_SIDE_EFFECTS
);
2824 if (binop_user_defined_p (BINOP_LOGICAL_OR
, arg1
, arg2
))
2826 arg2
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
2827 return value_x_binop (arg1
, arg2
, BINOP_LOGICAL_OR
, OP_NULL
, noside
);
2831 int tem
= value_logical_not (arg1
);
2834 arg2
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
2835 tem
= value_logical_not (arg2
);
2838 struct type
*type
= language_bool_type (exp
->language_defn
,
2840 return value_from_longest (type
, !tem
);
2845 adl_func_operation::evaluate (struct type
*expect_type
,
2846 struct expression
*exp
,
2849 std::vector
<operation_up
> &arg_ops
= std::get
<2> (m_storage
);
2850 std::vector
<value
*> args (arg_ops
.size ());
2851 for (int i
= 0; i
< arg_ops
.size (); ++i
)
2852 args
[i
] = arg_ops
[i
]->evaluate_with_coercion (exp
, noside
);
2854 struct symbol
*symp
;
2855 find_overload_match (args
, std::get
<0> (m_storage
).c_str (),
2858 nullptr, &symp
, nullptr, 0, noside
);
2859 if (SYMBOL_TYPE (symp
)->code () == TYPE_CODE_ERROR
)
2860 error_unknown_type (symp
->print_name ());
2861 value
*callee
= evaluate_var_value (noside
, std::get
<1> (m_storage
), symp
);
2862 return evaluate_subexp_do_call (exp
, noside
, callee
, args
,
2863 nullptr, expect_type
);
2867 /* This function evaluates brace-initializers (in C/C++) for
2871 array_operation::evaluate_struct_tuple (struct value
*struct_val
,
2872 struct expression
*exp
,
2873 enum noside noside
, int nargs
)
2875 const std::vector
<operation_up
> &in_args
= std::get
<2> (m_storage
);
2876 struct type
*struct_type
= check_typedef (value_type (struct_val
));
2877 struct type
*field_type
;
2881 while (--nargs
>= 0)
2883 struct value
*val
= NULL
;
2884 int bitpos
, bitsize
;
2888 /* Skip static fields. */
2889 while (fieldno
< struct_type
->num_fields ()
2890 && field_is_static (&struct_type
->field (fieldno
)))
2892 if (fieldno
>= struct_type
->num_fields ())
2893 error (_("too many initializers"));
2894 field_type
= struct_type
->field (fieldno
).type ();
2895 if (field_type
->code () == TYPE_CODE_UNION
2896 && TYPE_FIELD_NAME (struct_type
, fieldno
)[0] == '0')
2897 error (_("don't know which variant you want to set"));
2899 /* Here, struct_type is the type of the inner struct,
2900 while substruct_type is the type of the inner struct.
2901 These are the same for normal structures, but a variant struct
2902 contains anonymous union fields that contain substruct fields.
2903 The value fieldno is the index of the top-level (normal or
2904 anonymous union) field in struct_field, while the value
2905 subfieldno is the index of the actual real (named inner) field
2906 in substruct_type. */
2908 field_type
= struct_type
->field (fieldno
).type ();
2910 val
= in_args
[idx
++]->evaluate (field_type
, exp
, noside
);
2912 /* Now actually set the field in struct_val. */
2914 /* Assign val to field fieldno. */
2915 if (value_type (val
) != field_type
)
2916 val
= value_cast (field_type
, val
);
2918 bitsize
= TYPE_FIELD_BITSIZE (struct_type
, fieldno
);
2919 bitpos
= TYPE_FIELD_BITPOS (struct_type
, fieldno
);
2920 addr
= value_contents_writeable (struct_val
) + bitpos
/ 8;
2922 modify_field (struct_type
, addr
,
2923 value_as_long (val
), bitpos
% 8, bitsize
);
2925 memcpy (addr
, value_contents (val
),
2926 TYPE_LENGTH (value_type (val
)));
2933 array_operation::evaluate (struct type
*expect_type
,
2934 struct expression
*exp
,
2938 int tem2
= std::get
<0> (m_storage
);
2939 int tem3
= std::get
<1> (m_storage
);
2940 const std::vector
<operation_up
> &in_args
= std::get
<2> (m_storage
);
2941 int nargs
= tem3
- tem2
+ 1;
2942 struct type
*type
= expect_type
? check_typedef (expect_type
) : nullptr;
2944 if (expect_type
!= nullptr && noside
!= EVAL_SKIP
2945 && type
->code () == TYPE_CODE_STRUCT
)
2947 struct value
*rec
= allocate_value (expect_type
);
2949 memset (value_contents_raw (rec
), '\0', TYPE_LENGTH (type
));
2950 return evaluate_struct_tuple (rec
, exp
, noside
, nargs
);
2953 if (expect_type
!= nullptr && noside
!= EVAL_SKIP
2954 && type
->code () == TYPE_CODE_ARRAY
)
2956 struct type
*range_type
= type
->index_type ();
2957 struct type
*element_type
= TYPE_TARGET_TYPE (type
);
2958 struct value
*array
= allocate_value (expect_type
);
2959 int element_size
= TYPE_LENGTH (check_typedef (element_type
));
2960 LONGEST low_bound
, high_bound
, index
;
2962 if (!get_discrete_bounds (range_type
, &low_bound
, &high_bound
))
2965 high_bound
= (TYPE_LENGTH (type
) / element_size
) - 1;
2968 memset (value_contents_raw (array
), 0, TYPE_LENGTH (expect_type
));
2969 for (tem
= nargs
; --nargs
>= 0;)
2971 struct value
*element
;
2973 element
= in_args
[index
- low_bound
]->evaluate (element_type
,
2975 if (value_type (element
) != element_type
)
2976 element
= value_cast (element_type
, element
);
2977 if (index
> high_bound
)
2978 /* To avoid memory corruption. */
2979 error (_("Too many array elements"));
2980 memcpy (value_contents_raw (array
)
2981 + (index
- low_bound
) * element_size
,
2982 value_contents (element
),
2989 if (expect_type
!= nullptr && noside
!= EVAL_SKIP
2990 && type
->code () == TYPE_CODE_SET
)
2992 struct value
*set
= allocate_value (expect_type
);
2993 gdb_byte
*valaddr
= value_contents_raw (set
);
2994 struct type
*element_type
= type
->index_type ();
2995 struct type
*check_type
= element_type
;
2996 LONGEST low_bound
, high_bound
;
2998 /* Get targettype of elementtype. */
2999 while (check_type
->code () == TYPE_CODE_RANGE
3000 || check_type
->code () == TYPE_CODE_TYPEDEF
)
3001 check_type
= TYPE_TARGET_TYPE (check_type
);
3003 if (!get_discrete_bounds (element_type
, &low_bound
, &high_bound
))
3004 error (_("(power)set type with unknown size"));
3005 memset (valaddr
, '\0', TYPE_LENGTH (type
));
3007 for (tem
= 0; tem
< nargs
; tem
++)
3009 LONGEST range_low
, range_high
;
3010 struct type
*range_low_type
, *range_high_type
;
3011 struct value
*elem_val
;
3013 elem_val
= in_args
[idx
++]->evaluate (element_type
, exp
, noside
);
3014 range_low_type
= range_high_type
= value_type (elem_val
);
3015 range_low
= range_high
= value_as_long (elem_val
);
3017 /* Check types of elements to avoid mixture of elements from
3018 different types. Also check if type of element is "compatible"
3019 with element type of powerset. */
3020 if (range_low_type
->code () == TYPE_CODE_RANGE
)
3021 range_low_type
= TYPE_TARGET_TYPE (range_low_type
);
3022 if (range_high_type
->code () == TYPE_CODE_RANGE
)
3023 range_high_type
= TYPE_TARGET_TYPE (range_high_type
);
3024 if ((range_low_type
->code () != range_high_type
->code ())
3025 || (range_low_type
->code () == TYPE_CODE_ENUM
3026 && (range_low_type
!= range_high_type
)))
3027 /* different element modes. */
3028 error (_("POWERSET tuple elements of different mode"));
3029 if ((check_type
->code () != range_low_type
->code ())
3030 || (check_type
->code () == TYPE_CODE_ENUM
3031 && range_low_type
!= check_type
))
3032 error (_("incompatible POWERSET tuple elements"));
3033 if (range_low
> range_high
)
3035 warning (_("empty POWERSET tuple range"));
3038 if (range_low
< low_bound
|| range_high
> high_bound
)
3039 error (_("POWERSET tuple element out of range"));
3040 range_low
-= low_bound
;
3041 range_high
-= low_bound
;
3042 for (; range_low
<= range_high
; range_low
++)
3044 int bit_index
= (unsigned) range_low
% TARGET_CHAR_BIT
;
3046 if (gdbarch_byte_order (exp
->gdbarch
) == BFD_ENDIAN_BIG
)
3047 bit_index
= TARGET_CHAR_BIT
- 1 - bit_index
;
3048 valaddr
[(unsigned) range_low
/ TARGET_CHAR_BIT
]
3055 value
**argvec
= XALLOCAVEC (struct value
*, nargs
);
3056 for (tem
= 0; tem
< nargs
; tem
++)
3058 /* Ensure that array expressions are coerced into pointer
3060 argvec
[tem
] = in_args
[tem
]->evaluate_with_coercion (exp
, noside
);
3062 if (noside
== EVAL_SKIP
)
3063 return eval_skip_value (exp
);
3064 return value_array (tem2
, tem3
, argvec
);
3070 evaluate_subexp_standard (struct type
*expect_type
,
3071 struct expression
*exp
, int *pos
,
3075 int tem
, tem2
, tem3
;
3077 struct value
*arg1
= NULL
;
3078 struct value
*arg2
= NULL
;
3081 struct value
**argvec
;
3083 struct type
**arg_types
;
3086 op
= exp
->elts
[pc
].opcode
;
3091 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
3092 (*pos
) += 4 + BYTES_TO_EXP_ELEM (tem
+ 1);
3093 return eval_op_scope (expect_type
, exp
, noside
,
3094 exp
->elts
[pc
+ 1].type
,
3095 &exp
->elts
[pc
+ 3].string
);
3099 return value_from_longest (exp
->elts
[pc
+ 1].type
,
3100 exp
->elts
[pc
+ 2].longconst
);
3104 return value_from_contents (exp
->elts
[pc
+ 1].type
,
3105 exp
->elts
[pc
+ 2].floatconst
);
3111 symbol
*var
= exp
->elts
[pc
+ 2].symbol
;
3112 if (SYMBOL_TYPE (var
)->code () == TYPE_CODE_ERROR
)
3113 error_unknown_type (var
->print_name ());
3114 if (noside
!= EVAL_SKIP
)
3115 return evaluate_var_value (noside
, exp
->elts
[pc
+ 1].block
, var
);
3118 /* Return a dummy value of the correct type when skipping, so
3119 that parent functions know what is to be skipped. */
3120 return allocate_value (SYMBOL_TYPE (var
));
3124 case OP_VAR_MSYM_VALUE
:
3128 minimal_symbol
*msymbol
= exp
->elts
[pc
+ 2].msymbol
;
3129 return eval_op_var_msym_value (expect_type
, exp
, noside
,
3131 exp
->elts
[pc
+ 1].objfile
);
3134 case OP_VAR_ENTRY_VALUE
:
3138 struct symbol
*sym
= exp
->elts
[pc
+ 1].symbol
;
3140 return eval_op_var_entry_value (expect_type
, exp
, noside
, sym
);
3143 case OP_FUNC_STATIC_VAR
:
3144 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
3145 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
3146 if (noside
== EVAL_SKIP
)
3147 return eval_skip_value (exp
);
3150 value
*func
= evaluate_subexp_standard (NULL
, exp
, pos
, noside
);
3152 return eval_op_func_static_var (expect_type
, exp
, noside
, func
,
3153 &exp
->elts
[pc
+ 2].string
);
3159 access_value_history (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
3163 const char *name
= &exp
->elts
[pc
+ 2].string
;
3165 (*pos
) += 3 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
3166 return eval_op_register (expect_type
, exp
, noside
, name
);
3170 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
3171 return value_from_longest (type
, exp
->elts
[pc
+ 1].longconst
);
3173 case OP_INTERNALVAR
:
3175 return value_of_internalvar (exp
->gdbarch
,
3176 exp
->elts
[pc
+ 1].internalvar
);
3179 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
3180 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
3181 return eval_op_string (expect_type
, exp
, noside
, tem
,
3182 &exp
->elts
[pc
+ 2].string
);
3184 case OP_OBJC_NSSTRING
: /* Objective C Foundation Class
3185 NSString constant. */
3186 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
3187 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
3188 if (noside
== EVAL_SKIP
)
3189 return eval_skip_value (exp
);
3190 return value_nsstring (exp
->gdbarch
, &exp
->elts
[pc
+ 2].string
, tem
+ 1);
3194 tem2
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
3195 tem3
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
3196 nargs
= tem3
- tem2
+ 1;
3197 type
= expect_type
? check_typedef (expect_type
) : nullptr;
3199 if (expect_type
!= nullptr && noside
!= EVAL_SKIP
3200 && type
->code () == TYPE_CODE_STRUCT
)
3202 struct value
*rec
= allocate_value (expect_type
);
3204 memset (value_contents_raw (rec
), '\0', TYPE_LENGTH (type
));
3205 return evaluate_struct_tuple (rec
, exp
, pos
, noside
, nargs
);
3208 if (expect_type
!= nullptr && noside
!= EVAL_SKIP
3209 && type
->code () == TYPE_CODE_ARRAY
)
3211 struct type
*range_type
= type
->index_type ();
3212 struct type
*element_type
= TYPE_TARGET_TYPE (type
);
3213 struct value
*array
= allocate_value (expect_type
);
3214 int element_size
= TYPE_LENGTH (check_typedef (element_type
));
3215 LONGEST low_bound
, high_bound
, index
;
3217 if (!get_discrete_bounds (range_type
, &low_bound
, &high_bound
))
3220 high_bound
= (TYPE_LENGTH (type
) / element_size
) - 1;
3223 memset (value_contents_raw (array
), 0, TYPE_LENGTH (expect_type
));
3224 for (tem
= nargs
; --nargs
>= 0;)
3226 struct value
*element
;
3228 element
= evaluate_subexp (element_type
, exp
, pos
, noside
);
3229 if (value_type (element
) != element_type
)
3230 element
= value_cast (element_type
, element
);
3231 if (index
> high_bound
)
3232 /* To avoid memory corruption. */
3233 error (_("Too many array elements"));
3234 memcpy (value_contents_raw (array
)
3235 + (index
- low_bound
) * element_size
,
3236 value_contents (element
),
3243 if (expect_type
!= nullptr && noside
!= EVAL_SKIP
3244 && type
->code () == TYPE_CODE_SET
)
3246 struct value
*set
= allocate_value (expect_type
);
3247 gdb_byte
*valaddr
= value_contents_raw (set
);
3248 struct type
*element_type
= type
->index_type ();
3249 struct type
*check_type
= element_type
;
3250 LONGEST low_bound
, high_bound
;
3252 /* Get targettype of elementtype. */
3253 while (check_type
->code () == TYPE_CODE_RANGE
3254 || check_type
->code () == TYPE_CODE_TYPEDEF
)
3255 check_type
= TYPE_TARGET_TYPE (check_type
);
3257 if (!get_discrete_bounds (element_type
, &low_bound
, &high_bound
))
3258 error (_("(power)set type with unknown size"));
3259 memset (valaddr
, '\0', TYPE_LENGTH (type
));
3260 for (tem
= 0; tem
< nargs
; tem
++)
3262 LONGEST range_low
, range_high
;
3263 struct type
*range_low_type
, *range_high_type
;
3264 struct value
*elem_val
;
3266 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
3267 range_low_type
= range_high_type
= value_type (elem_val
);
3268 range_low
= range_high
= value_as_long (elem_val
);
3270 /* Check types of elements to avoid mixture of elements from
3271 different types. Also check if type of element is "compatible"
3272 with element type of powerset. */
3273 if (range_low_type
->code () == TYPE_CODE_RANGE
)
3274 range_low_type
= TYPE_TARGET_TYPE (range_low_type
);
3275 if (range_high_type
->code () == TYPE_CODE_RANGE
)
3276 range_high_type
= TYPE_TARGET_TYPE (range_high_type
);
3277 if ((range_low_type
->code () != range_high_type
->code ())
3278 || (range_low_type
->code () == TYPE_CODE_ENUM
3279 && (range_low_type
!= range_high_type
)))
3280 /* different element modes. */
3281 error (_("POWERSET tuple elements of different mode"));
3282 if ((check_type
->code () != range_low_type
->code ())
3283 || (check_type
->code () == TYPE_CODE_ENUM
3284 && range_low_type
!= check_type
))
3285 error (_("incompatible POWERSET tuple elements"));
3286 if (range_low
> range_high
)
3288 warning (_("empty POWERSET tuple range"));
3291 if (range_low
< low_bound
|| range_high
> high_bound
)
3292 error (_("POWERSET tuple element out of range"));
3293 range_low
-= low_bound
;
3294 range_high
-= low_bound
;
3295 for (; range_low
<= range_high
; range_low
++)
3297 int bit_index
= (unsigned) range_low
% TARGET_CHAR_BIT
;
3299 if (gdbarch_byte_order (exp
->gdbarch
) == BFD_ENDIAN_BIG
)
3300 bit_index
= TARGET_CHAR_BIT
- 1 - bit_index
;
3301 valaddr
[(unsigned) range_low
/ TARGET_CHAR_BIT
]
3308 argvec
= XALLOCAVEC (struct value
*, nargs
);
3309 for (tem
= 0; tem
< nargs
; tem
++)
3311 /* Ensure that array expressions are coerced into pointer
3313 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
3315 if (noside
== EVAL_SKIP
)
3316 return eval_skip_value (exp
);
3317 return value_array (tem2
, tem3
, argvec
);
3321 struct value
*array
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3322 struct value
*low
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3323 struct value
*upper
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3324 return eval_op_ternop (expect_type
, exp
, noside
, array
, low
, upper
);
3328 /* Skip third and second args to evaluate the first one. */
3329 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3330 if (value_logical_not (arg1
))
3332 evaluate_subexp (nullptr, exp
, pos
, EVAL_SKIP
);
3333 return evaluate_subexp (nullptr, exp
, pos
, noside
);
3337 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3338 evaluate_subexp (nullptr, exp
, pos
, EVAL_SKIP
);
3342 case OP_OBJC_SELECTOR
:
3343 { /* Objective C @selector operator. */
3344 char *sel
= &exp
->elts
[pc
+ 2].string
;
3345 int len
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
3347 (*pos
) += 3 + BYTES_TO_EXP_ELEM (len
+ 1);
3349 sel
[len
] = 0; /* Make sure it's terminated. */
3351 return eval_op_objc_selector (expect_type
, exp
, noside
, sel
);
3354 case OP_OBJC_MSGCALL
:
3355 { /* Objective C message (method) call. */
3356 CORE_ADDR selector
= 0;
3358 enum noside sub_no_side
= EVAL_NORMAL
;
3360 struct value
*target
= NULL
;
3362 struct type
*selector_type
= NULL
;
3364 selector
= exp
->elts
[pc
+ 1].longconst
;
3365 nargs
= exp
->elts
[pc
+ 2].longconst
;
3366 argvec
= XALLOCAVEC (struct value
*, nargs
+ 3);
3370 selector_type
= builtin_type (exp
->gdbarch
)->builtin_data_ptr
;
3372 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
3373 sub_no_side
= EVAL_NORMAL
;
3375 sub_no_side
= noside
;
3377 target
= evaluate_subexp (selector_type
, exp
, pos
, sub_no_side
);
3379 if (value_as_long (target
) == 0)
3380 sub_no_side
= EVAL_SKIP
;
3382 sub_no_side
= noside
;
3384 /* Now depending on whether we found a symbol for the method,
3385 we will either call the runtime dispatcher or the method
3388 argvec
[0] = nullptr;
3389 argvec
[1] = nullptr;
3390 /* User-supplied arguments. */
3391 for (tem
= 0; tem
< nargs
; tem
++)
3392 argvec
[tem
+ 2] = evaluate_subexp_with_coercion (exp
, pos
,
3394 argvec
[tem
+ 3] = 0;
3396 auto call_args
= gdb::make_array_view (argvec
, nargs
+ 3);
3398 return eval_op_objc_msgcall (expect_type
, exp
, noside
, selector
,
3404 return evaluate_funcall (expect_type
, exp
, pos
, noside
);
3407 /* We have a complex number, There should be 2 floating
3408 point numbers that compose it. */
3410 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3411 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3413 return value_literal_complex (arg1
, arg2
, exp
->elts
[pc
+ 1].type
);
3415 case STRUCTOP_STRUCT
:
3416 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
3417 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
3418 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3419 return eval_op_structop_struct (expect_type
, exp
, noside
, arg1
,
3420 &exp
->elts
[pc
+ 2].string
);
3423 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
3424 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
3425 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3426 return eval_op_structop_ptr (expect_type
, exp
, noside
, arg1
,
3427 &exp
->elts
[pc
+ 2].string
);
3429 case STRUCTOP_MEMBER
:
3431 if (op
== STRUCTOP_MEMBER
)
3432 arg1
= evaluate_subexp_for_address (exp
, pos
, noside
);
3434 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3436 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3438 return eval_op_member (expect_type
, exp
, noside
, arg1
, arg2
);
3442 type_instance_flags flags
3443 = (type_instance_flag_value
) longest_to_int (exp
->elts
[pc
+ 1].longconst
);
3444 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
3445 arg_types
= (struct type
**) alloca (nargs
* sizeof (struct type
*));
3446 for (ix
= 0; ix
< nargs
; ++ix
)
3447 arg_types
[ix
] = exp
->elts
[pc
+ 2 + ix
+ 1].type
;
3449 fake_method
fake_expect_type (flags
, nargs
, arg_types
);
3450 *(pos
) += 4 + nargs
;
3451 return evaluate_subexp_standard (fake_expect_type
.type (), exp
, pos
,
3456 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
3457 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
3458 return eval_op_concat (expect_type
, exp
, noside
, arg1
, arg2
);
3461 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3462 /* Special-case assignments where the left-hand-side is a
3463 convenience variable -- in these, don't bother setting an
3464 expected type. This avoids a weird case where re-assigning a
3465 string or array to an internal variable could error with "Too
3466 many array elements". */
3467 arg2
= evaluate_subexp (VALUE_LVAL (arg1
) == lval_internalvar
3469 : value_type (arg1
),
3472 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
3474 if (binop_user_defined_p (op
, arg1
, arg2
))
3475 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
3477 return value_assign (arg1
, arg2
);
3479 case BINOP_ASSIGN_MODIFY
:
3481 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3482 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
3483 op
= exp
->elts
[pc
+ 1].opcode
;
3484 return eval_binop_assign_modify (expect_type
, exp
, noside
, op
,
3488 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
3489 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
3490 return eval_op_add (expect_type
, exp
, noside
, arg1
, arg2
);
3493 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
3494 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
3495 return eval_op_sub (expect_type
, exp
, noside
, arg1
, arg2
);
3505 case BINOP_BITWISE_AND
:
3506 case BINOP_BITWISE_IOR
:
3507 case BINOP_BITWISE_XOR
:
3508 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3509 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3510 return eval_op_binary (expect_type
, exp
, noside
, op
, arg1
, arg2
);
3512 case BINOP_SUBSCRIPT
:
3513 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3514 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3515 return eval_op_subscript (expect_type
, exp
, noside
, op
, arg1
, arg2
);
3517 case MULTI_SUBSCRIPT
:
3519 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
3520 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
3521 argvec
= XALLOCAVEC (struct value
*, nargs
);
3522 for (ix
= 0; ix
< nargs
; ++ix
)
3523 argvec
[ix
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
3524 return eval_multi_subscript (expect_type
, exp
, noside
, arg1
,
3525 gdb::make_array_view (argvec
, nargs
));
3527 case BINOP_LOGICAL_AND
:
3528 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3529 if (noside
== EVAL_SKIP
)
3531 evaluate_subexp (nullptr, exp
, pos
, noside
);
3532 return eval_skip_value (exp
);
3536 arg2
= evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3539 if (binop_user_defined_p (op
, arg1
, arg2
))
3541 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3542 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
3546 tem
= value_logical_not (arg1
);
3548 = evaluate_subexp (nullptr, exp
, pos
, (tem
? EVAL_SKIP
: noside
));
3549 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
3550 return value_from_longest (type
,
3551 (LONGEST
) (!tem
&& !value_logical_not (arg2
)));
3554 case BINOP_LOGICAL_OR
:
3555 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3556 if (noside
== EVAL_SKIP
)
3558 evaluate_subexp (nullptr, exp
, pos
, noside
);
3559 return eval_skip_value (exp
);
3563 arg2
= evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3566 if (binop_user_defined_p (op
, arg1
, arg2
))
3568 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3569 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
3573 tem
= value_logical_not (arg1
);
3575 = evaluate_subexp (nullptr, exp
, pos
, (!tem
? EVAL_SKIP
: noside
));
3576 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
3577 return value_from_longest (type
,
3578 (LONGEST
) (!tem
|| !value_logical_not (arg2
)));
3582 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3583 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
3584 return eval_op_equal (expect_type
, exp
, noside
, op
, arg1
, arg2
);
3586 case BINOP_NOTEQUAL
:
3587 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3588 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
3589 return eval_op_notequal (expect_type
, exp
, noside
, op
, arg1
, arg2
);
3592 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3593 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
3594 return eval_op_less (expect_type
, exp
, noside
, op
, arg1
, arg2
);
3597 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3598 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
3599 return eval_op_gtr (expect_type
, exp
, noside
, op
, arg1
, arg2
);
3602 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3603 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
3604 return eval_op_geq (expect_type
, exp
, noside
, op
, arg1
, arg2
);
3607 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3608 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
3609 return eval_op_leq (expect_type
, exp
, noside
, op
, arg1
, arg2
);
3612 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3613 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3614 return eval_op_repeat (expect_type
, exp
, noside
, op
, arg1
, arg2
);
3617 evaluate_subexp (nullptr, exp
, pos
, noside
);
3618 return evaluate_subexp (nullptr, exp
, pos
, noside
);
3621 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3622 return eval_op_plus (expect_type
, exp
, noside
, op
, arg1
);
3625 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3626 return eval_op_neg (expect_type
, exp
, noside
, op
, arg1
);
3628 case UNOP_COMPLEMENT
:
3629 /* C++: check for and handle destructor names. */
3631 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3632 return eval_op_complement (expect_type
, exp
, noside
, op
, arg1
);
3634 case UNOP_LOGICAL_NOT
:
3635 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3636 return eval_op_lognot (expect_type
, exp
, noside
, op
, arg1
);
3639 if (expect_type
&& expect_type
->code () == TYPE_CODE_PTR
)
3640 expect_type
= TYPE_TARGET_TYPE (check_typedef (expect_type
));
3641 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
3642 return eval_op_ind (expect_type
, exp
, noside
, arg1
);
3645 /* C++: check for and handle pointer to members. */
3647 if (noside
== EVAL_SKIP
)
3649 evaluate_subexp (nullptr, exp
, pos
, EVAL_SKIP
);
3650 return eval_skip_value (exp
);
3653 return evaluate_subexp_for_address (exp
, pos
, noside
);
3656 if (noside
== EVAL_SKIP
)
3658 evaluate_subexp (nullptr, exp
, pos
, EVAL_SKIP
);
3659 return eval_skip_value (exp
);
3661 return evaluate_subexp_for_sizeof (exp
, pos
, noside
);
3664 arg1
= evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3665 return eval_op_alignof (expect_type
, exp
, noside
, arg1
);
3669 type
= exp
->elts
[pc
+ 1].type
;
3670 return evaluate_subexp_for_cast (exp
, pos
, noside
, type
);
3672 case UNOP_CAST_TYPE
:
3673 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3674 type
= value_type (arg1
);
3675 return evaluate_subexp_for_cast (exp
, pos
, noside
, type
);
3677 case UNOP_DYNAMIC_CAST
:
3678 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3679 type
= value_type (arg1
);
3680 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
3681 if (noside
== EVAL_SKIP
)
3682 return eval_skip_value (exp
);
3683 return value_dynamic_cast (type
, arg1
);
3685 case UNOP_REINTERPRET_CAST
:
3686 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3687 type
= value_type (arg1
);
3688 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
3689 if (noside
== EVAL_SKIP
)
3690 return eval_skip_value (exp
);
3691 return value_reinterpret_cast (type
, arg1
);
3695 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
3696 return eval_op_memval (expect_type
, exp
, noside
, arg1
,
3697 exp
->elts
[pc
+ 1].type
);
3699 case UNOP_MEMVAL_TYPE
:
3700 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3701 type
= value_type (arg1
);
3702 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
3703 return eval_op_memval (expect_type
, exp
, noside
, arg1
, type
);
3705 case UNOP_PREINCREMENT
:
3706 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
3707 return eval_op_preinc (expect_type
, exp
, noside
, op
, arg1
);
3709 case UNOP_PREDECREMENT
:
3710 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
3711 return eval_op_predec (expect_type
, exp
, noside
, op
, arg1
);
3713 case UNOP_POSTINCREMENT
:
3714 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
3715 return eval_op_postinc (expect_type
, exp
, noside
, op
, arg1
);
3717 case UNOP_POSTDECREMENT
:
3718 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
3719 return eval_op_postdec (expect_type
, exp
, noside
, op
, arg1
);
3723 return value_of_this (exp
->language_defn
);
3726 /* The value is not supposed to be used. This is here to make it
3727 easier to accommodate expressions that contain types. */
3729 return eval_op_type (expect_type
, exp
, noside
, exp
->elts
[pc
+ 1].type
);
3733 if (noside
== EVAL_SKIP
)
3735 evaluate_subexp (nullptr, exp
, pos
, EVAL_SKIP
);
3736 return eval_skip_value (exp
);
3738 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
3740 enum exp_opcode sub_op
= exp
->elts
[*pos
].opcode
;
3741 struct value
*result
;
3743 result
= evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3745 /* 'decltype' has special semantics for lvalues. */
3746 if (op
== OP_DECLTYPE
3747 && (sub_op
== BINOP_SUBSCRIPT
3748 || sub_op
== STRUCTOP_MEMBER
3749 || sub_op
== STRUCTOP_MPTR
3750 || sub_op
== UNOP_IND
3751 || sub_op
== STRUCTOP_STRUCT
3752 || sub_op
== STRUCTOP_PTR
3753 || sub_op
== OP_SCOPE
))
3755 type
= value_type (result
);
3757 if (!TYPE_IS_REFERENCE (type
))
3759 type
= lookup_lvalue_reference_type (type
);
3760 result
= allocate_value (type
);
3767 error (_("Attempt to use a type as an expression"));
3771 struct value
*result
;
3772 enum exp_opcode sub_op
= exp
->elts
[*pos
].opcode
;
3774 if (sub_op
== OP_TYPE
|| sub_op
== OP_DECLTYPE
|| sub_op
== OP_TYPEOF
)
3775 result
= evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3777 result
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3779 if (noside
!= EVAL_NORMAL
)
3780 return allocate_value (cplus_typeid_type (exp
->gdbarch
));
3782 return cplus_typeid (result
);
3786 /* Removing this case and compiling with gcc -Wall reveals that
3787 a lot of cases are hitting this case. Some of these should
3788 probably be removed from expression.h; others are legitimate
3789 expressions which are (apparently) not fully implemented.
3791 If there are any cases landing here which mean a user error,
3792 then they should be separate cases, with more descriptive
3795 error (_("GDB does not (yet) know how to "
3796 "evaluate that kind of expression"));
3799 gdb_assert_not_reached ("missed return?");
3802 /* Helper for evaluate_subexp_for_address. */
3805 evaluate_subexp_for_address_base (struct expression
*exp
, enum noside noside
,
3808 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
3810 struct type
*type
= check_typedef (value_type (x
));
3812 if (TYPE_IS_REFERENCE (type
))
3813 return value_zero (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
3815 else if (VALUE_LVAL (x
) == lval_memory
|| value_must_coerce_to_target (x
))
3816 return value_zero (lookup_pointer_type (value_type (x
)),
3819 error (_("Attempt to take address of "
3820 "value not located in memory."));
3822 return value_addr (x
);
3825 /* Evaluate a subexpression of EXP, at index *POS,
3826 and return the address of that subexpression.
3827 Advance *POS over the subexpression.
3828 If the subexpression isn't an lvalue, get an error.
3829 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
3830 then only the type of the result need be correct. */
3832 static struct value
*
3833 evaluate_subexp_for_address (struct expression
*exp
, int *pos
,
3843 op
= exp
->elts
[pc
].opcode
;
3849 x
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3851 /* We can't optimize out "&*" if there's a user-defined operator*. */
3852 if (unop_user_defined_p (op
, x
))
3854 x
= value_x_unop (x
, op
, noside
);
3855 goto default_case_after_eval
;
3858 return coerce_array (x
);
3862 return value_cast (lookup_pointer_type (exp
->elts
[pc
+ 1].type
),
3863 evaluate_subexp (nullptr, exp
, pos
, noside
));
3865 case UNOP_MEMVAL_TYPE
:
3870 x
= evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3871 type
= value_type (x
);
3872 return value_cast (lookup_pointer_type (type
),
3873 evaluate_subexp (nullptr, exp
, pos
, noside
));
3877 var
= exp
->elts
[pc
+ 2].symbol
;
3879 /* C++: The "address" of a reference should yield the address
3880 * of the object pointed to. Let value_addr() deal with it. */
3881 if (TYPE_IS_REFERENCE (SYMBOL_TYPE (var
)))
3885 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
3888 lookup_pointer_type (SYMBOL_TYPE (var
));
3889 enum address_class sym_class
= SYMBOL_CLASS (var
);
3891 if (sym_class
== LOC_CONST
3892 || sym_class
== LOC_CONST_BYTES
3893 || sym_class
== LOC_REGISTER
)
3894 error (_("Attempt to take address of register or constant."));
3897 value_zero (type
, not_lval
);
3900 return address_of_variable (var
, exp
->elts
[pc
+ 1].block
);
3902 case OP_VAR_MSYM_VALUE
:
3906 value
*val
= evaluate_var_msym_value (noside
,
3907 exp
->elts
[pc
+ 1].objfile
,
3908 exp
->elts
[pc
+ 2].msymbol
);
3909 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
3911 struct type
*type
= lookup_pointer_type (value_type (val
));
3912 return value_zero (type
, not_lval
);
3915 return value_addr (val
);
3919 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
3920 (*pos
) += 5 + BYTES_TO_EXP_ELEM (tem
+ 1);
3921 x
= value_aggregate_elt (exp
->elts
[pc
+ 1].type
,
3922 &exp
->elts
[pc
+ 3].string
,
3925 error (_("There is no field named %s"), &exp
->elts
[pc
+ 3].string
);
3930 x
= evaluate_subexp (nullptr, exp
, pos
, noside
);
3931 default_case_after_eval
:
3932 return evaluate_subexp_for_address_base (exp
, noside
, x
);
3940 operation::evaluate_for_cast (struct type
*expect_type
,
3941 struct expression
*exp
,
3944 value
*val
= evaluate (expect_type
, exp
, noside
);
3945 if (noside
== EVAL_SKIP
)
3946 return eval_skip_value (exp
);
3947 return value_cast (expect_type
, val
);
3951 operation::evaluate_for_address (struct expression
*exp
, enum noside noside
)
3953 value
*val
= evaluate (nullptr, exp
, noside
);
3954 return evaluate_subexp_for_address_base (exp
, noside
, val
);
3958 scope_operation::evaluate_for_address (struct expression
*exp
,
3961 value
*x
= value_aggregate_elt (std::get
<0> (m_storage
),
3962 std::get
<1> (m_storage
).c_str (),
3965 error (_("There is no field named %s"), std::get
<1> (m_storage
).c_str ());
3970 unop_ind_base_operation::evaluate_for_address (struct expression
*exp
,
3973 value
*x
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
3975 /* We can't optimize out "&*" if there's a user-defined operator*. */
3976 if (unop_user_defined_p (UNOP_IND
, x
))
3978 x
= value_x_unop (x
, UNOP_IND
, noside
);
3979 return evaluate_subexp_for_address_base (exp
, noside
, x
);
3982 return coerce_array (x
);
3986 var_msym_value_operation::evaluate_for_address (struct expression
*exp
,
3989 value
*val
= evaluate_var_msym_value (noside
,
3990 std::get
<1> (m_storage
),
3991 std::get
<0> (m_storage
));
3992 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
3994 struct type
*type
= lookup_pointer_type (value_type (val
));
3995 return value_zero (type
, not_lval
);
3998 return value_addr (val
);
4002 unop_memval_operation::evaluate_for_address (struct expression
*exp
,
4005 return value_cast (lookup_pointer_type (std::get
<1> (m_storage
)),
4006 std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
));
4010 unop_memval_type_operation::evaluate_for_address (struct expression
*exp
,
4013 value
*typeval
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
4014 EVAL_AVOID_SIDE_EFFECTS
);
4015 struct type
*type
= value_type (typeval
);
4016 return value_cast (lookup_pointer_type (type
),
4017 std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
));
4022 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
4023 When used in contexts where arrays will be coerced anyway, this is
4024 equivalent to `evaluate_subexp' but much faster because it avoids
4025 actually fetching array contents (perhaps obsolete now that we have
4028 Note that we currently only do the coercion for C expressions, where
4029 arrays are zero based and the coercion is correct. For other languages,
4030 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
4031 to decide if coercion is appropriate. */
4034 evaluate_subexp_with_coercion (struct expression
*exp
,
4035 int *pos
, enum noside noside
)
4044 op
= exp
->elts
[pc
].opcode
;
4049 var
= exp
->elts
[pc
+ 2].symbol
;
4050 type
= check_typedef (SYMBOL_TYPE (var
));
4051 if (type
->code () == TYPE_CODE_ARRAY
4052 && !type
->is_vector ()
4053 && CAST_IS_CONVERSION (exp
->language_defn
))
4056 val
= address_of_variable (var
, exp
->elts
[pc
+ 1].block
);
4057 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
4063 return evaluate_subexp (nullptr, exp
, pos
, noside
);
4071 var_value_operation::evaluate_for_address (struct expression
*exp
,
4074 symbol
*var
= std::get
<0> (m_storage
);
4076 /* C++: The "address" of a reference should yield the address
4077 * of the object pointed to. Let value_addr() deal with it. */
4078 if (TYPE_IS_REFERENCE (SYMBOL_TYPE (var
)))
4079 return operation::evaluate_for_address (exp
, noside
);
4081 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
4083 struct type
*type
= lookup_pointer_type (SYMBOL_TYPE (var
));
4084 enum address_class sym_class
= SYMBOL_CLASS (var
);
4086 if (sym_class
== LOC_CONST
4087 || sym_class
== LOC_CONST_BYTES
4088 || sym_class
== LOC_REGISTER
)
4089 error (_("Attempt to take address of register or constant."));
4091 return value_zero (type
, not_lval
);
4094 return address_of_variable (var
, std::get
<1> (m_storage
));
4098 var_value_operation::evaluate_with_coercion (struct expression
*exp
,
4101 struct symbol
*var
= std::get
<0> (m_storage
);
4102 struct type
*type
= check_typedef (SYMBOL_TYPE (var
));
4103 if (type
->code () == TYPE_CODE_ARRAY
4104 && !type
->is_vector ()
4105 && CAST_IS_CONVERSION (exp
->language_defn
))
4107 struct value
*val
= address_of_variable (var
, std::get
<1> (m_storage
));
4108 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type
)), val
);
4110 return evaluate (nullptr, exp
, noside
);
4115 /* Helper function for evaluating the size of a type. */
4118 evaluate_subexp_for_sizeof_base (struct expression
*exp
, struct type
*type
)
4120 /* FIXME: This should be size_t. */
4121 struct type
*size_type
= builtin_type (exp
->gdbarch
)->builtin_int
;
4122 /* $5.3.3/2 of the C++ Standard (n3290 draft) says of sizeof:
4123 "When applied to a reference or a reference type, the result is
4124 the size of the referenced type." */
4125 type
= check_typedef (type
);
4126 if (exp
->language_defn
->la_language
== language_cplus
4127 && (TYPE_IS_REFERENCE (type
)))
4128 type
= check_typedef (TYPE_TARGET_TYPE (type
));
4129 return value_from_longest (size_type
, (LONGEST
) TYPE_LENGTH (type
));
4132 /* Evaluate a subexpression of EXP, at index *POS,
4133 and return a value for the size of that subexpression.
4134 Advance *POS over the subexpression. If NOSIDE is EVAL_NORMAL
4135 we allow side-effects on the operand if its type is a variable
4138 static struct value
*
4139 evaluate_subexp_for_sizeof (struct expression
*exp
, int *pos
,
4142 /* FIXME: This should be size_t. */
4143 struct type
*size_type
= builtin_type (exp
->gdbarch
)->builtin_int
;
4150 op
= exp
->elts
[pc
].opcode
;
4154 /* This case is handled specially
4155 so that we avoid creating a value for the result type.
4156 If the result type is very big, it's desirable not to
4157 create a value unnecessarily. */
4160 val
= evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
4161 type
= check_typedef (value_type (val
));
4162 if (type
->code () != TYPE_CODE_PTR
4163 && !TYPE_IS_REFERENCE (type
)
4164 && type
->code () != TYPE_CODE_ARRAY
)
4165 error (_("Attempt to take contents of a non-pointer value."));
4166 type
= TYPE_TARGET_TYPE (type
);
4167 if (is_dynamic_type (type
))
4168 type
= value_type (value_ind (val
));
4169 return value_from_longest (size_type
, (LONGEST
) TYPE_LENGTH (type
));
4173 type
= exp
->elts
[pc
+ 1].type
;
4176 case UNOP_MEMVAL_TYPE
:
4178 val
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
4179 type
= value_type (val
);
4183 type
= SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
);
4184 if (is_dynamic_type (type
))
4186 val
= evaluate_subexp (nullptr, exp
, pos
, EVAL_NORMAL
);
4187 type
= value_type (val
);
4188 if (type
->code () == TYPE_CODE_ARRAY
)
4190 if (type_not_allocated (type
) || type_not_associated (type
))
4191 return value_zero (size_type
, not_lval
);
4192 else if (is_dynamic_type (type
->index_type ())
4193 && type
->bounds ()->high
.kind () == PROP_UNDEFINED
)
4194 return allocate_optimized_out_value (size_type
);
4201 case OP_VAR_MSYM_VALUE
:
4205 minimal_symbol
*msymbol
= exp
->elts
[pc
+ 2].msymbol
;
4206 value
*mval
= evaluate_var_msym_value (noside
,
4207 exp
->elts
[pc
+ 1].objfile
,
4210 type
= value_type (mval
);
4211 if (type
->code () == TYPE_CODE_ERROR
)
4212 error_unknown_type (msymbol
->print_name ());
4214 return value_from_longest (size_type
, TYPE_LENGTH (type
));
4218 /* Deal with the special case if NOSIDE is EVAL_NORMAL and the resulting
4219 type of the subscript is a variable length array type. In this case we
4220 must re-evaluate the right hand side of the subscription to allow
4222 case BINOP_SUBSCRIPT
:
4223 if (noside
== EVAL_NORMAL
)
4225 int npc
= (*pos
) + 1;
4227 val
= evaluate_subexp (nullptr, exp
, &npc
, EVAL_AVOID_SIDE_EFFECTS
);
4228 type
= check_typedef (value_type (val
));
4229 if (type
->code () == TYPE_CODE_ARRAY
)
4231 type
= check_typedef (TYPE_TARGET_TYPE (type
));
4232 if (type
->code () == TYPE_CODE_ARRAY
)
4234 type
= type
->index_type ();
4235 /* Only re-evaluate the right hand side if the resulting type
4236 is a variable length type. */
4237 if (type
->bounds ()->flag_bound_evaluated
)
4239 val
= evaluate_subexp (nullptr, exp
, pos
, EVAL_NORMAL
);
4240 return value_from_longest
4241 (size_type
, (LONGEST
) TYPE_LENGTH (value_type (val
)));
4250 val
= evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
4251 type
= value_type (val
);
4255 return evaluate_subexp_for_sizeof_base (exp
, type
);
4262 operation::evaluate_for_sizeof (struct expression
*exp
, enum noside noside
)
4264 value
*val
= evaluate (nullptr, exp
, EVAL_AVOID_SIDE_EFFECTS
);
4265 return evaluate_subexp_for_sizeof_base (exp
, value_type (val
));
4269 var_msym_value_operation::evaluate_for_sizeof (struct expression
*exp
,
4273 minimal_symbol
*msymbol
= std::get
<0> (m_storage
);
4274 value
*mval
= evaluate_var_msym_value (noside
,
4275 std::get
<1> (m_storage
),
4278 struct type
*type
= value_type (mval
);
4279 if (type
->code () == TYPE_CODE_ERROR
)
4280 error_unknown_type (msymbol
->print_name ());
4282 /* FIXME: This should be size_t. */
4283 struct type
*size_type
= builtin_type (exp
->gdbarch
)->builtin_int
;
4284 return value_from_longest (size_type
, TYPE_LENGTH (type
));
4288 subscript_operation::evaluate_for_sizeof (struct expression
*exp
,
4291 if (noside
== EVAL_NORMAL
)
4293 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
4294 EVAL_AVOID_SIDE_EFFECTS
);
4295 struct type
*type
= check_typedef (value_type (val
));
4296 if (type
->code () == TYPE_CODE_ARRAY
)
4298 type
= check_typedef (TYPE_TARGET_TYPE (type
));
4299 if (type
->code () == TYPE_CODE_ARRAY
)
4301 type
= type
->index_type ();
4302 /* Only re-evaluate the right hand side if the resulting type
4303 is a variable length type. */
4304 if (type
->bounds ()->flag_bound_evaluated
)
4306 val
= evaluate (nullptr, exp
, EVAL_NORMAL
);
4307 /* FIXME: This should be size_t. */
4308 struct type
*size_type
4309 = builtin_type (exp
->gdbarch
)->builtin_int
;
4310 return value_from_longest
4311 (size_type
, (LONGEST
) TYPE_LENGTH (value_type (val
)));
4317 return operation::evaluate_for_sizeof (exp
, noside
);
4321 unop_ind_base_operation::evaluate_for_sizeof (struct expression
*exp
,
4324 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
4325 EVAL_AVOID_SIDE_EFFECTS
);
4326 struct type
*type
= check_typedef (value_type (val
));
4327 if (type
->code () != TYPE_CODE_PTR
4328 && !TYPE_IS_REFERENCE (type
)
4329 && type
->code () != TYPE_CODE_ARRAY
)
4330 error (_("Attempt to take contents of a non-pointer value."));
4331 type
= TYPE_TARGET_TYPE (type
);
4332 if (is_dynamic_type (type
))
4333 type
= value_type (value_ind (val
));
4334 /* FIXME: This should be size_t. */
4335 struct type
*size_type
= builtin_type (exp
->gdbarch
)->builtin_int
;
4336 return value_from_longest (size_type
, (LONGEST
) TYPE_LENGTH (type
));
4340 unop_memval_operation::evaluate_for_sizeof (struct expression
*exp
,
4343 return evaluate_subexp_for_sizeof_base (exp
, std::get
<1> (m_storage
));
4347 unop_memval_type_operation::evaluate_for_sizeof (struct expression
*exp
,
4350 value
*typeval
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
4351 EVAL_AVOID_SIDE_EFFECTS
);
4352 return evaluate_subexp_for_sizeof_base (exp
, value_type (typeval
));
4356 var_value_operation::evaluate_for_sizeof (struct expression
*exp
,
4359 struct type
*type
= SYMBOL_TYPE (std::get
<0> (m_storage
));
4360 if (is_dynamic_type (type
))
4362 value
*val
= evaluate (nullptr, exp
, EVAL_NORMAL
);
4363 type
= value_type (val
);
4364 if (type
->code () == TYPE_CODE_ARRAY
)
4366 /* FIXME: This should be size_t. */
4367 struct type
*size_type
= builtin_type (exp
->gdbarch
)->builtin_int
;
4368 if (type_not_allocated (type
) || type_not_associated (type
))
4369 return value_zero (size_type
, not_lval
);
4370 else if (is_dynamic_type (type
->index_type ())
4371 && type
->bounds ()->high
.kind () == PROP_UNDEFINED
)
4372 return allocate_optimized_out_value (size_type
);
4375 return evaluate_subexp_for_sizeof_base (exp
, type
);
4380 /* Evaluate a subexpression of EXP, at index *POS, and return a value
4381 for that subexpression cast to TO_TYPE. Advance *POS over the
4385 evaluate_subexp_for_cast (expression
*exp
, int *pos
,
4387 struct type
*to_type
)
4391 /* Don't let symbols be evaluated with evaluate_subexp because that
4392 throws an "unknown type" error for no-debug data symbols.
4393 Instead, we want the cast to reinterpret the symbol. */
4394 if (exp
->elts
[pc
].opcode
== OP_VAR_MSYM_VALUE
4395 || exp
->elts
[pc
].opcode
== OP_VAR_VALUE
)
4400 if (exp
->elts
[pc
].opcode
== OP_VAR_MSYM_VALUE
)
4402 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
4403 return value_zero (to_type
, not_lval
);
4405 val
= evaluate_var_msym_value (noside
,
4406 exp
->elts
[pc
+ 1].objfile
,
4407 exp
->elts
[pc
+ 2].msymbol
);
4410 val
= evaluate_var_value (noside
,
4411 exp
->elts
[pc
+ 1].block
,
4412 exp
->elts
[pc
+ 2].symbol
);
4414 if (noside
== EVAL_SKIP
)
4415 return eval_skip_value (exp
);
4417 val
= value_cast (to_type
, val
);
4419 /* Don't allow e.g. '&(int)var_with_no_debug_info'. */
4420 if (VALUE_LVAL (val
) == lval_memory
)
4422 if (value_lazy (val
))
4423 value_fetch_lazy (val
);
4424 VALUE_LVAL (val
) = not_lval
;
4429 value
*val
= evaluate_subexp (to_type
, exp
, pos
, noside
);
4430 if (noside
== EVAL_SKIP
)
4431 return eval_skip_value (exp
);
4432 return value_cast (to_type
, val
);
4439 var_msym_value_operation::evaluate_for_cast (struct type
*to_type
,
4440 struct expression
*exp
,
4443 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
4444 return value_zero (to_type
, not_lval
);
4446 value
*val
= evaluate_var_msym_value (noside
,
4447 std::get
<1> (m_storage
),
4448 std::get
<0> (m_storage
));
4450 if (noside
== EVAL_SKIP
)
4451 return eval_skip_value (exp
);
4453 val
= value_cast (to_type
, val
);
4455 /* Don't allow e.g. '&(int)var_with_no_debug_info'. */
4456 if (VALUE_LVAL (val
) == lval_memory
)
4458 if (value_lazy (val
))
4459 value_fetch_lazy (val
);
4460 VALUE_LVAL (val
) = not_lval
;
4466 var_value_operation::evaluate_for_cast (struct type
*to_type
,
4467 struct expression
*exp
,
4470 value
*val
= evaluate_var_value (noside
,
4471 std::get
<1> (m_storage
),
4472 std::get
<0> (m_storage
));
4474 if (noside
== EVAL_SKIP
)
4475 return eval_skip_value (exp
);
4477 val
= value_cast (to_type
, val
);
4479 /* Don't allow e.g. '&(int)var_with_no_debug_info'. */
4480 if (VALUE_LVAL (val
) == lval_memory
)
4482 if (value_lazy (val
))
4483 value_fetch_lazy (val
);
4484 VALUE_LVAL (val
) = not_lval
;
4491 /* Parse a type expression in the string [P..P+LENGTH). */
4494 parse_and_eval_type (const char *p
, int length
)
4496 char *tmp
= (char *) alloca (length
+ 4);
4499 memcpy (tmp
+ 1, p
, length
);
4500 tmp
[length
+ 1] = ')';
4501 tmp
[length
+ 2] = '0';
4502 tmp
[length
+ 3] = '\0';
4503 expression_up expr
= parse_expression (tmp
);
4504 if (expr
->first_opcode () != UNOP_CAST
)
4505 error (_("Internal error in eval_type."));
4507 if (expr
->op
!= nullptr)
4509 expr::unop_cast_operation
*op
4510 = dynamic_cast<expr::unop_cast_operation
*> (expr
->op
.get ());
4511 return op
->get_type ();
4514 return expr
->elts
[1].type
;