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"
44 /* Prototypes for local functions. */
46 static struct value
*evaluate_subexp_for_sizeof (struct expression
*, int *,
49 static struct value
*evaluate_subexp_for_address (struct expression
*,
52 static value
*evaluate_subexp_for_cast (expression
*exp
, int *pos
,
56 static struct value
*evaluate_struct_tuple (struct value
*,
57 struct expression
*, int *,
61 evaluate_subexp (struct type
*expect_type
, struct expression
*exp
,
62 int *pos
, enum noside noside
)
66 gdb::optional
<enable_thread_stack_temporaries
> stack_temporaries
;
67 if (*pos
== 0 && target_has_execution ()
68 && exp
->language_defn
->la_language
== language_cplus
69 && !thread_stack_temporaries_enabled_p (inferior_thread ()))
70 stack_temporaries
.emplace (inferior_thread ());
72 retval
= (*exp
->language_defn
->expression_ops ()->evaluate_exp
)
73 (expect_type
, exp
, pos
, noside
);
75 if (stack_temporaries
.has_value ()
76 && value_in_thread_stack_temporaries (retval
, inferior_thread ()))
77 retval
= value_non_lval (retval
);
82 /* Parse the string EXP as a C expression, evaluate it,
83 and return the result as a number. */
86 parse_and_eval_address (const char *exp
)
88 expression_up expr
= parse_expression (exp
);
90 return value_as_address (evaluate_expression (expr
.get ()));
93 /* Like parse_and_eval_address, but treats the value of the expression
94 as an integer, not an address, returns a LONGEST, not a CORE_ADDR. */
96 parse_and_eval_long (const char *exp
)
98 expression_up expr
= parse_expression (exp
);
100 return value_as_long (evaluate_expression (expr
.get ()));
104 parse_and_eval (const char *exp
)
106 expression_up expr
= parse_expression (exp
);
108 return evaluate_expression (expr
.get ());
111 /* Parse up to a comma (or to a closeparen)
112 in the string EXPP as an expression, evaluate it, and return the value.
113 EXPP is advanced to point to the comma. */
116 parse_to_comma_and_eval (const char **expp
)
118 expression_up expr
= parse_exp_1 (expp
, 0, nullptr, 1);
120 return evaluate_expression (expr
.get ());
127 evaluate_expression (struct expression
*exp
, struct type
*expect_type
)
131 return evaluate_subexp (expect_type
, exp
, &pc
, EVAL_NORMAL
);
134 /* Evaluate an expression, avoiding all memory references
135 and getting a value whose type alone is correct. */
138 evaluate_type (struct expression
*exp
)
142 return evaluate_subexp (nullptr, exp
, &pc
, EVAL_AVOID_SIDE_EFFECTS
);
145 /* Evaluate a subexpression, avoiding all memory references and
146 getting a value whose type alone is correct. */
149 evaluate_subexpression_type (struct expression
*exp
, int subexp
)
151 return evaluate_subexp (nullptr, exp
, &subexp
, EVAL_AVOID_SIDE_EFFECTS
);
154 /* Find the current value of a watchpoint on EXP. Return the value in
155 *VALP and *RESULTP and the chain of intermediate and final values
156 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
159 If PRESERVE_ERRORS is true, then exceptions are passed through.
160 Otherwise, if PRESERVE_ERRORS is false, then if a memory error
161 occurs while evaluating the expression, *RESULTP will be set to
162 NULL. *RESULTP may be a lazy value, if the result could not be
163 read from memory. It is used to determine whether a value is
164 user-specified (we should watch the whole value) or intermediate
165 (we should watch only the bit used to locate the final value).
167 If the final value, or any intermediate value, could not be read
168 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
169 set to any referenced values. *VALP will never be a lazy value.
170 This is the value which we store in struct breakpoint.
172 If VAL_CHAIN is non-NULL, the values put into *VAL_CHAIN will be
173 released from the value chain. If VAL_CHAIN is NULL, all generated
174 values will be left on the value chain. */
177 fetch_subexp_value (struct expression
*exp
, int *pc
, struct value
**valp
,
178 struct value
**resultp
,
179 std::vector
<value_ref_ptr
> *val_chain
,
180 bool preserve_errors
)
182 struct value
*mark
, *new_mark
, *result
;
190 /* Evaluate the expression. */
191 mark
= value_mark ();
196 result
= evaluate_subexp (nullptr, exp
, pc
, EVAL_NORMAL
);
198 catch (const gdb_exception
&ex
)
200 /* Ignore memory errors if we want watchpoints pointing at
201 inaccessible memory to still be created; otherwise, throw the
202 error to some higher catcher. */
206 if (!preserve_errors
)
215 new_mark
= value_mark ();
216 if (mark
== new_mark
)
221 /* Make sure it's not lazy, so that after the target stops again we
222 have a non-lazy previous value to compare with. */
225 if (!value_lazy (result
))
232 value_fetch_lazy (result
);
235 catch (const gdb_exception_error
&except
)
243 /* Return the chain of intermediate values. We use this to
244 decide which addresses to watch. */
245 *val_chain
= value_release_to_mark (mark
);
249 /* Extract a field operation from an expression. If the subexpression
250 of EXP starting at *SUBEXP is not a structure dereference
251 operation, return NULL. Otherwise, return the name of the
252 dereferenced field, and advance *SUBEXP to point to the
253 subexpression of the left-hand-side of the dereference. This is
254 used when completing field names. */
257 extract_field_op (struct expression
*exp
, int *subexp
)
262 if (exp
->elts
[*subexp
].opcode
!= STRUCTOP_STRUCT
263 && exp
->elts
[*subexp
].opcode
!= STRUCTOP_PTR
)
265 tem
= longest_to_int (exp
->elts
[*subexp
+ 1].longconst
);
266 result
= &exp
->elts
[*subexp
+ 2].string
;
267 (*subexp
) += 1 + 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
271 /* This function evaluates brace-initializers (in C/C++) for
274 static struct value
*
275 evaluate_struct_tuple (struct value
*struct_val
,
276 struct expression
*exp
,
277 int *pos
, enum noside noside
, int nargs
)
279 struct type
*struct_type
= check_typedef (value_type (struct_val
));
280 struct type
*field_type
;
285 struct value
*val
= NULL
;
290 /* Skip static fields. */
291 while (fieldno
< struct_type
->num_fields ()
292 && field_is_static (&struct_type
->field (fieldno
)))
294 if (fieldno
>= struct_type
->num_fields ())
295 error (_("too many initializers"));
296 field_type
= struct_type
->field (fieldno
).type ();
297 if (field_type
->code () == TYPE_CODE_UNION
298 && TYPE_FIELD_NAME (struct_type
, fieldno
)[0] == '0')
299 error (_("don't know which variant you want to set"));
301 /* Here, struct_type is the type of the inner struct,
302 while substruct_type is the type of the inner struct.
303 These are the same for normal structures, but a variant struct
304 contains anonymous union fields that contain substruct fields.
305 The value fieldno is the index of the top-level (normal or
306 anonymous union) field in struct_field, while the value
307 subfieldno is the index of the actual real (named inner) field
308 in substruct_type. */
310 field_type
= struct_type
->field (fieldno
).type ();
312 val
= evaluate_subexp (field_type
, exp
, pos
, noside
);
314 /* Now actually set the field in struct_val. */
316 /* Assign val to field fieldno. */
317 if (value_type (val
) != field_type
)
318 val
= value_cast (field_type
, val
);
320 bitsize
= TYPE_FIELD_BITSIZE (struct_type
, fieldno
);
321 bitpos
= TYPE_FIELD_BITPOS (struct_type
, fieldno
);
322 addr
= value_contents_writeable (struct_val
) + bitpos
/ 8;
324 modify_field (struct_type
, addr
,
325 value_as_long (val
), bitpos
% 8, bitsize
);
327 memcpy (addr
, value_contents (val
),
328 TYPE_LENGTH (value_type (val
)));
334 /* Promote value ARG1 as appropriate before performing a unary operation
336 If the result is not appropriate for any particular language then it
337 needs to patch this function. */
340 unop_promote (const struct language_defn
*language
, struct gdbarch
*gdbarch
,
345 *arg1
= coerce_ref (*arg1
);
346 type1
= check_typedef (value_type (*arg1
));
348 if (is_integral_type (type1
))
350 switch (language
->la_language
)
353 /* Perform integral promotion for ANSI C/C++.
354 If not appropriate for any particular language
355 it needs to modify this function. */
357 struct type
*builtin_int
= builtin_type (gdbarch
)->builtin_int
;
359 if (TYPE_LENGTH (type1
) < TYPE_LENGTH (builtin_int
))
360 *arg1
= value_cast (builtin_int
, *arg1
);
367 /* Promote values ARG1 and ARG2 as appropriate before performing a binary
368 operation on those two operands.
369 If the result is not appropriate for any particular language then it
370 needs to patch this function. */
373 binop_promote (const struct language_defn
*language
, struct gdbarch
*gdbarch
,
374 struct value
**arg1
, struct value
**arg2
)
376 struct type
*promoted_type
= NULL
;
380 *arg1
= coerce_ref (*arg1
);
381 *arg2
= coerce_ref (*arg2
);
383 type1
= check_typedef (value_type (*arg1
));
384 type2
= check_typedef (value_type (*arg2
));
386 if ((type1
->code () != TYPE_CODE_FLT
387 && type1
->code () != TYPE_CODE_DECFLOAT
388 && !is_integral_type (type1
))
389 || (type2
->code () != TYPE_CODE_FLT
390 && type2
->code () != TYPE_CODE_DECFLOAT
391 && !is_integral_type (type2
)))
394 if (is_fixed_point_type (type1
) || is_fixed_point_type (type2
))
397 if (type1
->code () == TYPE_CODE_DECFLOAT
398 || type2
->code () == TYPE_CODE_DECFLOAT
)
400 /* No promotion required. */
402 else if (type1
->code () == TYPE_CODE_FLT
403 || type2
->code () == TYPE_CODE_FLT
)
405 switch (language
->la_language
)
411 case language_opencl
:
412 /* No promotion required. */
416 /* For other languages the result type is unchanged from gdb
417 version 6.7 for backward compatibility.
418 If either arg was long double, make sure that value is also long
419 double. Otherwise use double. */
420 if (TYPE_LENGTH (type1
) * 8 > gdbarch_double_bit (gdbarch
)
421 || TYPE_LENGTH (type2
) * 8 > gdbarch_double_bit (gdbarch
))
422 promoted_type
= builtin_type (gdbarch
)->builtin_long_double
;
424 promoted_type
= builtin_type (gdbarch
)->builtin_double
;
428 else if (type1
->code () == TYPE_CODE_BOOL
429 && type2
->code () == TYPE_CODE_BOOL
)
431 /* No promotion required. */
434 /* Integral operations here. */
435 /* FIXME: Also mixed integral/booleans, with result an integer. */
437 const struct builtin_type
*builtin
= builtin_type (gdbarch
);
438 unsigned int promoted_len1
= TYPE_LENGTH (type1
);
439 unsigned int promoted_len2
= TYPE_LENGTH (type2
);
440 int is_unsigned1
= type1
->is_unsigned ();
441 int is_unsigned2
= type2
->is_unsigned ();
442 unsigned int result_len
;
443 int unsigned_operation
;
445 /* Determine type length and signedness after promotion for
447 if (promoted_len1
< TYPE_LENGTH (builtin
->builtin_int
))
450 promoted_len1
= TYPE_LENGTH (builtin
->builtin_int
);
452 if (promoted_len2
< TYPE_LENGTH (builtin
->builtin_int
))
455 promoted_len2
= TYPE_LENGTH (builtin
->builtin_int
);
458 if (promoted_len1
> promoted_len2
)
460 unsigned_operation
= is_unsigned1
;
461 result_len
= promoted_len1
;
463 else if (promoted_len2
> promoted_len1
)
465 unsigned_operation
= is_unsigned2
;
466 result_len
= promoted_len2
;
470 unsigned_operation
= is_unsigned1
|| is_unsigned2
;
471 result_len
= promoted_len1
;
474 switch (language
->la_language
)
480 if (result_len
<= TYPE_LENGTH (builtin
->builtin_int
))
482 promoted_type
= (unsigned_operation
483 ? builtin
->builtin_unsigned_int
484 : builtin
->builtin_int
);
486 else if (result_len
<= TYPE_LENGTH (builtin
->builtin_long
))
488 promoted_type
= (unsigned_operation
489 ? builtin
->builtin_unsigned_long
490 : builtin
->builtin_long
);
494 promoted_type
= (unsigned_operation
495 ? builtin
->builtin_unsigned_long_long
496 : builtin
->builtin_long_long
);
499 case language_opencl
:
500 if (result_len
<= TYPE_LENGTH (lookup_signed_typename
505 ? lookup_unsigned_typename (language
, "int")
506 : lookup_signed_typename (language
, "int"));
508 else if (result_len
<= TYPE_LENGTH (lookup_signed_typename
513 ? lookup_unsigned_typename (language
, "long")
514 : lookup_signed_typename (language
,"long"));
518 /* For other languages the result type is unchanged from gdb
519 version 6.7 for backward compatibility.
520 If either arg was long long, make sure that value is also long
521 long. Otherwise use long. */
522 if (unsigned_operation
)
524 if (result_len
> gdbarch_long_bit (gdbarch
) / HOST_CHAR_BIT
)
525 promoted_type
= builtin
->builtin_unsigned_long_long
;
527 promoted_type
= builtin
->builtin_unsigned_long
;
531 if (result_len
> gdbarch_long_bit (gdbarch
) / HOST_CHAR_BIT
)
532 promoted_type
= builtin
->builtin_long_long
;
534 promoted_type
= builtin
->builtin_long
;
542 /* Promote both operands to common type. */
543 *arg1
= value_cast (promoted_type
, *arg1
);
544 *arg2
= value_cast (promoted_type
, *arg2
);
549 ptrmath_type_p (const struct language_defn
*lang
, struct type
*type
)
551 type
= check_typedef (type
);
552 if (TYPE_IS_REFERENCE (type
))
553 type
= TYPE_TARGET_TYPE (type
);
555 switch (type
->code ())
561 case TYPE_CODE_ARRAY
:
562 return type
->is_vector () ? 0 : lang
->c_style_arrays_p ();
569 /* Represents a fake method with the given parameter types. This is
570 used by the parser to construct a temporary "expected" type for
571 method overload resolution. FLAGS is used as instance flags of the
572 new type, in order to be able to make the new type represent a
573 const/volatile overload. */
578 fake_method (type_instance_flags flags
,
579 int num_types
, struct type
**param_types
);
582 /* The constructed type. */
583 struct type
*type () { return &m_type
; }
586 struct type m_type
{};
587 main_type m_main_type
{};
590 fake_method::fake_method (type_instance_flags flags
,
591 int num_types
, struct type
**param_types
)
593 struct type
*type
= &m_type
;
595 TYPE_MAIN_TYPE (type
) = &m_main_type
;
596 TYPE_LENGTH (type
) = 1;
597 type
->set_code (TYPE_CODE_METHOD
);
598 TYPE_CHAIN (type
) = type
;
599 type
->set_instance_flags (flags
);
602 if (param_types
[num_types
- 1] == NULL
)
605 type
->set_has_varargs (true);
607 else if (check_typedef (param_types
[num_types
- 1])->code ()
611 /* Caller should have ensured this. */
612 gdb_assert (num_types
== 0);
613 type
->set_is_prototyped (true);
617 /* We don't use TYPE_ZALLOC here to allocate space as TYPE is owned by
618 neither an objfile nor a gdbarch. As a result we must manually
619 allocate memory for auxiliary fields, and free the memory ourselves
620 when we are done with it. */
621 type
->set_num_fields (num_types
);
623 ((struct field
*) xzalloc (sizeof (struct field
) * num_types
));
625 while (num_types
-- > 0)
626 type
->field (num_types
).set_type (param_types
[num_types
]);
629 fake_method::~fake_method ()
631 xfree (m_type
.fields ());
634 /* Helper for evaluating an OP_VAR_VALUE. */
637 evaluate_var_value (enum noside noside
, const block
*blk
, symbol
*var
)
639 /* JYG: We used to just return value_zero of the symbol type if
640 we're asked to avoid side effects. Otherwise we return
641 value_of_variable (...). However I'm not sure if
642 value_of_variable () has any side effect. We need a full value
643 object returned here for whatis_exp () to call evaluate_type ()
644 and then pass the full value to value_rtti_target_type () if we
645 are dealing with a pointer or reference to a base class and print
648 struct value
*ret
= NULL
;
652 ret
= value_of_variable (var
, blk
);
655 catch (const gdb_exception_error
&except
)
657 if (noside
!= EVAL_AVOID_SIDE_EFFECTS
)
660 ret
= value_zero (SYMBOL_TYPE (var
), not_lval
);
666 /* Helper for evaluating an OP_VAR_MSYM_VALUE. */
669 evaluate_var_msym_value (enum noside noside
,
670 struct objfile
*objfile
, minimal_symbol
*msymbol
)
673 type
*the_type
= find_minsym_type_and_address (msymbol
, objfile
, &address
);
675 if (noside
== EVAL_AVOID_SIDE_EFFECTS
&& !the_type
->is_gnu_ifunc ())
676 return value_zero (the_type
, not_lval
);
678 return value_at_lazy (the_type
, address
);
681 /* Helper for returning a value when handling EVAL_SKIP. */
684 eval_skip_value (expression
*exp
)
686 return value_from_longest (builtin_type (exp
->gdbarch
)->builtin_int
, 1);
689 /* See expression.h. */
692 evaluate_subexp_do_call (expression
*exp
, enum noside noside
,
694 gdb::array_view
<value
*> argvec
,
695 const char *function_name
,
696 type
*default_return_type
)
699 error (_("Cannot evaluate function -- may be inlined"));
700 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
702 /* If the return type doesn't look like a function type,
703 call an error. This can happen if somebody tries to turn
704 a variable into a function call. */
706 type
*ftype
= value_type (callee
);
708 if (ftype
->code () == TYPE_CODE_INTERNAL_FUNCTION
)
710 /* We don't know anything about what the internal
711 function might return, but we have to return
713 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
,
716 else if (ftype
->code () == TYPE_CODE_XMETHOD
)
718 type
*return_type
= result_type_of_xmethod (callee
, argvec
);
720 if (return_type
== NULL
)
721 error (_("Xmethod is missing return type."));
722 return value_zero (return_type
, not_lval
);
724 else if (ftype
->code () == TYPE_CODE_FUNC
725 || ftype
->code () == TYPE_CODE_METHOD
)
727 if (ftype
->is_gnu_ifunc ())
729 CORE_ADDR address
= value_address (callee
);
730 type
*resolved_type
= find_gnu_ifunc_target_type (address
);
732 if (resolved_type
!= NULL
)
733 ftype
= resolved_type
;
736 type
*return_type
= TYPE_TARGET_TYPE (ftype
);
738 if (return_type
== NULL
)
739 return_type
= default_return_type
;
741 if (return_type
== NULL
)
742 error_call_unknown_return_type (function_name
);
744 return allocate_value (return_type
);
747 error (_("Expression of type other than "
748 "\"Function returning ...\" used as function"));
750 switch (value_type (callee
)->code ())
752 case TYPE_CODE_INTERNAL_FUNCTION
:
753 return call_internal_function (exp
->gdbarch
, exp
->language_defn
,
754 callee
, argvec
.size (), argvec
.data ());
755 case TYPE_CODE_XMETHOD
:
756 return call_xmethod (callee
, argvec
);
758 return call_function_by_hand (callee
, default_return_type
, argvec
);
762 /* Helper for evaluating an OP_FUNCALL. */
765 evaluate_funcall (type
*expect_type
, expression
*exp
, int *pos
,
773 symbol
*function
= NULL
;
774 char *function_name
= NULL
;
775 const char *var_func_name
= NULL
;
780 exp_opcode op
= exp
->elts
[*pos
].opcode
;
781 int nargs
= longest_to_int (exp
->elts
[pc
].longconst
);
782 /* Allocate arg vector, including space for the function to be
783 called in argvec[0], a potential `this', and a terminating
785 value
**argvec
= (value
**) alloca (sizeof (value
*) * (nargs
+ 3));
786 if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
788 /* First, evaluate the structure into arg2. */
791 if (op
== STRUCTOP_MEMBER
)
793 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
797 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
800 /* If the function is a virtual function, then the aggregate
801 value (providing the structure) plays its part by providing
802 the vtable. Otherwise, it is just along for the ride: call
803 the function directly. */
805 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
807 type
*a1_type
= check_typedef (value_type (arg1
));
808 if (noside
== EVAL_SKIP
)
809 tem
= 1; /* Set it to the right arg index so that all
810 arguments can also be skipped. */
811 else if (a1_type
->code () == TYPE_CODE_METHODPTR
)
813 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
814 arg1
= value_zero (TYPE_TARGET_TYPE (a1_type
), not_lval
);
816 arg1
= cplus_method_ptr_to_value (&arg2
, arg1
);
818 /* Now, say which argument to start evaluating from. */
823 else if (a1_type
->code () == TYPE_CODE_MEMBERPTR
)
825 struct type
*type_ptr
826 = lookup_pointer_type (TYPE_SELF_TYPE (a1_type
));
827 struct type
*target_type_ptr
828 = lookup_pointer_type (TYPE_TARGET_TYPE (a1_type
));
830 /* Now, convert these values to an address. */
831 arg2
= value_cast (type_ptr
, arg2
);
833 long mem_offset
= value_as_long (arg1
);
835 arg1
= value_from_pointer (target_type_ptr
,
836 value_as_long (arg2
) + mem_offset
);
837 arg1
= value_ind (arg1
);
841 error (_("Non-pointer-to-member value used in pointer-to-member "
844 else if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
846 /* Hair for method invocations. */
850 /* First, evaluate the structure into arg2. */
852 tem2
= longest_to_int (exp
->elts
[pc2
+ 1].longconst
);
853 *pos
+= 3 + BYTES_TO_EXP_ELEM (tem2
+ 1);
855 if (op
== STRUCTOP_STRUCT
)
857 /* If v is a variable in a register, and the user types
858 v.method (), this will produce an error, because v has no
861 A possible way around this would be to allocate a copy of
862 the variable on the stack, copy in the contents, call the
863 function, and copy out the contents. I.e. convert this
864 from call by reference to call by copy-return (or
865 whatever it's called). However, this does not work
866 because it is not the same: the method being called could
867 stash a copy of the address, and then future uses through
868 that address (after the method returns) would be expected
869 to use the variable itself, not some copy of it. */
870 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
874 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
876 /* Check to see if the operator '->' has been overloaded.
877 If the operator has been overloaded replace arg2 with the
878 value returned by the custom operator and continue
880 while (unop_user_defined_p (op
, arg2
))
882 struct value
*value
= NULL
;
885 value
= value_x_unop (arg2
, op
, noside
);
888 catch (const gdb_exception_error
&except
)
890 if (except
.error
== NOT_FOUND_ERROR
)
899 /* Now, say which argument to start evaluating from. */
902 else if (op
== OP_SCOPE
903 && overload_resolution
904 && (exp
->language_defn
->la_language
== language_cplus
))
906 /* Unpack it locally so we can properly handle overload
912 local_tem
= longest_to_int (exp
->elts
[pc2
+ 2].longconst
);
913 (*pos
) += 4 + BYTES_TO_EXP_ELEM (local_tem
+ 1);
914 struct type
*type
= exp
->elts
[pc2
+ 1].type
;
915 name
= &exp
->elts
[pc2
+ 3].string
;
918 function_name
= NULL
;
919 if (type
->code () == TYPE_CODE_NAMESPACE
)
921 function
= cp_lookup_symbol_namespace (type
->name (),
923 get_selected_block (0),
925 if (function
== NULL
)
926 error (_("No symbol \"%s\" in namespace \"%s\"."),
927 name
, type
->name ());
930 /* arg2 is left as NULL on purpose. */
934 gdb_assert (type
->code () == TYPE_CODE_STRUCT
935 || type
->code () == TYPE_CODE_UNION
);
936 function_name
= name
;
938 /* We need a properly typed value for method lookup. For
939 static methods arg2 is otherwise unused. */
940 arg2
= value_zero (type
, lval_memory
);
945 else if (op
== OP_ADL_FUNC
)
947 /* Save the function position and move pos so that the arguments
954 func_name_len
= longest_to_int (exp
->elts
[save_pos1
+ 3].longconst
);
955 (*pos
) += 6 + BYTES_TO_EXP_ELEM (func_name_len
+ 1);
959 /* Non-method function call. */
963 /* If this is a C++ function wait until overload resolution. */
964 if (op
== OP_VAR_VALUE
965 && overload_resolution
966 && (exp
->language_defn
->la_language
== language_cplus
))
968 (*pos
) += 4; /* Skip the evaluation of the symbol. */
973 if (op
== OP_VAR_MSYM_VALUE
)
975 minimal_symbol
*msym
= exp
->elts
[*pos
+ 2].msymbol
;
976 var_func_name
= msym
->print_name ();
978 else if (op
== OP_VAR_VALUE
)
980 symbol
*sym
= exp
->elts
[*pos
+ 2].symbol
;
981 var_func_name
= sym
->print_name ();
984 argvec
[0] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
985 type
*type
= value_type (argvec
[0]);
986 if (type
&& type
->code () == TYPE_CODE_PTR
)
987 type
= TYPE_TARGET_TYPE (type
);
988 if (type
&& type
->code () == TYPE_CODE_FUNC
)
990 for (; tem
<= nargs
&& tem
<= type
->num_fields (); tem
++)
992 argvec
[tem
] = evaluate_subexp (type
->field (tem
- 1).type (),
999 /* Evaluate arguments (if not already done, e.g., namespace::func()
1000 and overload-resolution is off). */
1001 for (; tem
<= nargs
; tem
++)
1003 /* Ensure that array expressions are coerced into pointer
1005 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1008 /* Signal end of arglist. */
1011 if (noside
== EVAL_SKIP
)
1012 return eval_skip_value (exp
);
1014 if (op
== OP_ADL_FUNC
)
1016 struct symbol
*symp
;
1019 int string_pc
= save_pos1
+ 3;
1021 /* Extract the function name. */
1022 name_len
= longest_to_int (exp
->elts
[string_pc
].longconst
);
1023 func_name
= (char *) alloca (name_len
+ 1);
1024 strcpy (func_name
, &exp
->elts
[string_pc
+ 1].string
);
1026 find_overload_match (gdb::make_array_view (&argvec
[1], nargs
),
1028 NON_METHOD
, /* not method */
1029 NULL
, NULL
, /* pass NULL symbol since
1030 symbol is unknown */
1031 NULL
, &symp
, NULL
, 0, noside
);
1033 /* Now fix the expression being evaluated. */
1034 exp
->elts
[save_pos1
+ 2].symbol
= symp
;
1035 argvec
[0] = evaluate_subexp_with_coercion (exp
, &save_pos1
, noside
);
1038 if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
1039 || (op
== OP_SCOPE
&& function_name
!= NULL
))
1041 int static_memfuncp
;
1044 /* Method invocation: stuff "this" as first parameter. If the
1045 method turns out to be static we undo this below. */
1050 /* Name of method from expression. */
1051 tstr
= &exp
->elts
[pc2
+ 2].string
;
1054 tstr
= function_name
;
1056 if (overload_resolution
&& (exp
->language_defn
->la_language
1059 /* Language is C++, do some overload resolution before
1061 struct value
*valp
= NULL
;
1063 (void) find_overload_match (gdb::make_array_view (&argvec
[1], nargs
),
1065 METHOD
, /* method */
1066 &arg2
, /* the object */
1068 &static_memfuncp
, 0, noside
);
1070 if (op
== OP_SCOPE
&& !static_memfuncp
)
1072 /* For the time being, we don't handle this. */
1073 error (_("Call to overloaded function %s requires "
1077 argvec
[1] = arg2
; /* the ``this'' pointer */
1078 argvec
[0] = valp
; /* Use the method found after overload
1082 /* Non-C++ case -- or no overload resolution. */
1084 struct value
*temp
= arg2
;
1086 argvec
[0] = value_struct_elt (&temp
, argvec
+ 1, tstr
,
1088 op
== STRUCTOP_STRUCT
1089 ? "structure" : "structure pointer");
1090 /* value_struct_elt updates temp with the correct value of
1091 the ``this'' pointer if necessary, so modify argvec[1] to
1092 reflect any ``this'' changes. */
1094 = value_from_longest (lookup_pointer_type(value_type (temp
)),
1095 value_address (temp
)
1096 + value_embedded_offset (temp
));
1097 argvec
[1] = arg2
; /* the ``this'' pointer */
1100 /* Take out `this' if needed. */
1101 if (static_memfuncp
)
1103 argvec
[1] = argvec
[0];
1108 else if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
1110 /* Pointer to member. argvec[1] is already set up. */
1113 else if (op
== OP_VAR_VALUE
|| (op
== OP_SCOPE
&& function
!= NULL
))
1115 /* Non-member function being called. */
1116 /* fn: This can only be done for C++ functions. A C-style
1117 function in a C++ program, for instance, does not have the
1118 fields that are expected here. */
1120 if (overload_resolution
&& (exp
->language_defn
->la_language
1123 /* Language is C++, do some overload resolution before
1125 struct symbol
*symp
;
1128 /* If a scope has been specified disable ADL. */
1132 if (op
== OP_VAR_VALUE
)
1133 function
= exp
->elts
[save_pos1
+2].symbol
;
1135 (void) find_overload_match (gdb::make_array_view (&argvec
[1], nargs
),
1136 NULL
, /* no need for name */
1137 NON_METHOD
, /* not method */
1138 NULL
, function
, /* the function */
1139 NULL
, &symp
, NULL
, no_adl
, noside
);
1141 if (op
== OP_VAR_VALUE
)
1143 /* Now fix the expression being evaluated. */
1144 exp
->elts
[save_pos1
+2].symbol
= symp
;
1145 argvec
[0] = evaluate_subexp_with_coercion (exp
, &save_pos1
,
1149 argvec
[0] = value_of_variable (symp
, get_selected_block (0));
1153 /* Not C++, or no overload resolution allowed. */
1154 /* Nothing to be done; argvec already correctly set up. */
1159 /* It is probably a C-style function. */
1160 /* Nothing to be done; argvec already correctly set up. */
1163 return evaluate_subexp_do_call (exp
, noside
, argvec
[0],
1164 gdb::make_array_view (argvec
+ 1, nargs
),
1165 var_func_name
, expect_type
);
1168 /* Return true if type is integral or reference to integral */
1171 is_integral_or_integral_reference (struct type
*type
)
1173 if (is_integral_type (type
))
1176 type
= check_typedef (type
);
1177 return (type
!= nullptr
1178 && TYPE_IS_REFERENCE (type
)
1179 && is_integral_type (TYPE_TARGET_TYPE (type
)));
1183 evaluate_subexp_standard (struct type
*expect_type
,
1184 struct expression
*exp
, int *pos
,
1188 int tem
, tem2
, tem3
;
1190 struct value
*arg1
= NULL
;
1191 struct value
*arg2
= NULL
;
1195 struct value
**argvec
;
1198 struct type
**arg_types
;
1201 op
= exp
->elts
[pc
].opcode
;
1206 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
1207 (*pos
) += 4 + BYTES_TO_EXP_ELEM (tem
+ 1);
1208 if (noside
== EVAL_SKIP
)
1209 return eval_skip_value (exp
);
1210 arg1
= value_aggregate_elt (exp
->elts
[pc
+ 1].type
,
1211 &exp
->elts
[pc
+ 3].string
,
1212 expect_type
, 0, noside
);
1214 error (_("There is no field named %s"), &exp
->elts
[pc
+ 3].string
);
1219 return value_from_longest (exp
->elts
[pc
+ 1].type
,
1220 exp
->elts
[pc
+ 2].longconst
);
1224 return value_from_contents (exp
->elts
[pc
+ 1].type
,
1225 exp
->elts
[pc
+ 2].floatconst
);
1231 symbol
*var
= exp
->elts
[pc
+ 2].symbol
;
1232 if (SYMBOL_TYPE (var
)->code () == TYPE_CODE_ERROR
)
1233 error_unknown_type (var
->print_name ());
1234 if (noside
!= EVAL_SKIP
)
1235 return evaluate_var_value (noside
, exp
->elts
[pc
+ 1].block
, var
);
1238 /* Return a dummy value of the correct type when skipping, so
1239 that parent functions know what is to be skipped. */
1240 return allocate_value (SYMBOL_TYPE (var
));
1244 case OP_VAR_MSYM_VALUE
:
1248 minimal_symbol
*msymbol
= exp
->elts
[pc
+ 2].msymbol
;
1249 value
*val
= evaluate_var_msym_value (noside
,
1250 exp
->elts
[pc
+ 1].objfile
,
1253 type
= value_type (val
);
1254 if (type
->code () == TYPE_CODE_ERROR
1255 && (noside
!= EVAL_AVOID_SIDE_EFFECTS
|| pc
!= 0))
1256 error_unknown_type (msymbol
->print_name ());
1260 case OP_VAR_ENTRY_VALUE
:
1262 if (noside
== EVAL_SKIP
)
1263 return eval_skip_value (exp
);
1266 struct symbol
*sym
= exp
->elts
[pc
+ 1].symbol
;
1267 struct frame_info
*frame
;
1269 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1270 return value_zero (SYMBOL_TYPE (sym
), not_lval
);
1272 if (SYMBOL_COMPUTED_OPS (sym
) == NULL
1273 || SYMBOL_COMPUTED_OPS (sym
)->read_variable_at_entry
== NULL
)
1274 error (_("Symbol \"%s\" does not have any specific entry value"),
1275 sym
->print_name ());
1277 frame
= get_selected_frame (NULL
);
1278 return SYMBOL_COMPUTED_OPS (sym
)->read_variable_at_entry (sym
, frame
);
1281 case OP_FUNC_STATIC_VAR
:
1282 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1283 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1284 if (noside
== EVAL_SKIP
)
1285 return eval_skip_value (exp
);
1288 value
*func
= evaluate_subexp_standard (NULL
, exp
, pos
, noside
);
1289 CORE_ADDR addr
= value_address (func
);
1291 const block
*blk
= block_for_pc (addr
);
1292 const char *var
= &exp
->elts
[pc
+ 2].string
;
1294 struct block_symbol sym
= lookup_symbol (var
, blk
, VAR_DOMAIN
, NULL
);
1296 if (sym
.symbol
== NULL
)
1297 error (_("No symbol \"%s\" in specified context."), var
);
1299 return evaluate_var_value (noside
, sym
.block
, sym
.symbol
);
1305 access_value_history (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
1309 const char *name
= &exp
->elts
[pc
+ 2].string
;
1313 (*pos
) += 3 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
1314 regno
= user_reg_map_name_to_regnum (exp
->gdbarch
,
1315 name
, strlen (name
));
1317 error (_("Register $%s not available."), name
);
1319 /* In EVAL_AVOID_SIDE_EFFECTS mode, we only need to return
1320 a value with the appropriate register type. Unfortunately,
1321 we don't have easy access to the type of user registers.
1322 So for these registers, we fetch the register value regardless
1323 of the evaluation mode. */
1324 if (noside
== EVAL_AVOID_SIDE_EFFECTS
1325 && regno
< gdbarch_num_cooked_regs (exp
->gdbarch
))
1326 val
= value_zero (register_type (exp
->gdbarch
, regno
), not_lval
);
1328 val
= value_of_register (regno
, get_selected_frame (NULL
));
1330 error (_("Value of register %s not available."), name
);
1336 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
1337 return value_from_longest (type
, exp
->elts
[pc
+ 1].longconst
);
1339 case OP_INTERNALVAR
:
1341 return value_of_internalvar (exp
->gdbarch
,
1342 exp
->elts
[pc
+ 1].internalvar
);
1345 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1346 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1347 if (noside
== EVAL_SKIP
)
1348 return eval_skip_value (exp
);
1349 type
= language_string_char_type (exp
->language_defn
, exp
->gdbarch
);
1350 return value_string (&exp
->elts
[pc
+ 2].string
, tem
, type
);
1352 case OP_OBJC_NSSTRING
: /* Objective C Foundation Class
1353 NSString constant. */
1354 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1355 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1356 if (noside
== EVAL_SKIP
)
1357 return eval_skip_value (exp
);
1358 return value_nsstring (exp
->gdbarch
, &exp
->elts
[pc
+ 2].string
, tem
+ 1);
1362 tem2
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1363 tem3
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
1364 nargs
= tem3
- tem2
+ 1;
1365 type
= expect_type
? check_typedef (expect_type
) : nullptr;
1367 if (expect_type
!= nullptr && noside
!= EVAL_SKIP
1368 && type
->code () == TYPE_CODE_STRUCT
)
1370 struct value
*rec
= allocate_value (expect_type
);
1372 memset (value_contents_raw (rec
), '\0', TYPE_LENGTH (type
));
1373 return evaluate_struct_tuple (rec
, exp
, pos
, noside
, nargs
);
1376 if (expect_type
!= nullptr && noside
!= EVAL_SKIP
1377 && type
->code () == TYPE_CODE_ARRAY
)
1379 struct type
*range_type
= type
->index_type ();
1380 struct type
*element_type
= TYPE_TARGET_TYPE (type
);
1381 struct value
*array
= allocate_value (expect_type
);
1382 int element_size
= TYPE_LENGTH (check_typedef (element_type
));
1383 LONGEST low_bound
, high_bound
, index
;
1385 if (!get_discrete_bounds (range_type
, &low_bound
, &high_bound
))
1388 high_bound
= (TYPE_LENGTH (type
) / element_size
) - 1;
1391 memset (value_contents_raw (array
), 0, TYPE_LENGTH (expect_type
));
1392 for (tem
= nargs
; --nargs
>= 0;)
1394 struct value
*element
;
1396 element
= evaluate_subexp (element_type
, exp
, pos
, noside
);
1397 if (value_type (element
) != element_type
)
1398 element
= value_cast (element_type
, element
);
1399 if (index
> high_bound
)
1400 /* To avoid memory corruption. */
1401 error (_("Too many array elements"));
1402 memcpy (value_contents_raw (array
)
1403 + (index
- low_bound
) * element_size
,
1404 value_contents (element
),
1411 if (expect_type
!= nullptr && noside
!= EVAL_SKIP
1412 && type
->code () == TYPE_CODE_SET
)
1414 struct value
*set
= allocate_value (expect_type
);
1415 gdb_byte
*valaddr
= value_contents_raw (set
);
1416 struct type
*element_type
= type
->index_type ();
1417 struct type
*check_type
= element_type
;
1418 LONGEST low_bound
, high_bound
;
1420 /* Get targettype of elementtype. */
1421 while (check_type
->code () == TYPE_CODE_RANGE
1422 || check_type
->code () == TYPE_CODE_TYPEDEF
)
1423 check_type
= TYPE_TARGET_TYPE (check_type
);
1425 if (!get_discrete_bounds (element_type
, &low_bound
, &high_bound
))
1426 error (_("(power)set type with unknown size"));
1427 memset (valaddr
, '\0', TYPE_LENGTH (type
));
1428 for (tem
= 0; tem
< nargs
; tem
++)
1430 LONGEST range_low
, range_high
;
1431 struct type
*range_low_type
, *range_high_type
;
1432 struct value
*elem_val
;
1434 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
1435 range_low_type
= range_high_type
= value_type (elem_val
);
1436 range_low
= range_high
= value_as_long (elem_val
);
1438 /* Check types of elements to avoid mixture of elements from
1439 different types. Also check if type of element is "compatible"
1440 with element type of powerset. */
1441 if (range_low_type
->code () == TYPE_CODE_RANGE
)
1442 range_low_type
= TYPE_TARGET_TYPE (range_low_type
);
1443 if (range_high_type
->code () == TYPE_CODE_RANGE
)
1444 range_high_type
= TYPE_TARGET_TYPE (range_high_type
);
1445 if ((range_low_type
->code () != range_high_type
->code ())
1446 || (range_low_type
->code () == TYPE_CODE_ENUM
1447 && (range_low_type
!= range_high_type
)))
1448 /* different element modes. */
1449 error (_("POWERSET tuple elements of different mode"));
1450 if ((check_type
->code () != range_low_type
->code ())
1451 || (check_type
->code () == TYPE_CODE_ENUM
1452 && range_low_type
!= check_type
))
1453 error (_("incompatible POWERSET tuple elements"));
1454 if (range_low
> range_high
)
1456 warning (_("empty POWERSET tuple range"));
1459 if (range_low
< low_bound
|| range_high
> high_bound
)
1460 error (_("POWERSET tuple element out of range"));
1461 range_low
-= low_bound
;
1462 range_high
-= low_bound
;
1463 for (; range_low
<= range_high
; range_low
++)
1465 int bit_index
= (unsigned) range_low
% TARGET_CHAR_BIT
;
1467 if (gdbarch_byte_order (exp
->gdbarch
) == BFD_ENDIAN_BIG
)
1468 bit_index
= TARGET_CHAR_BIT
- 1 - bit_index
;
1469 valaddr
[(unsigned) range_low
/ TARGET_CHAR_BIT
]
1476 argvec
= XALLOCAVEC (struct value
*, nargs
);
1477 for (tem
= 0; tem
< nargs
; tem
++)
1479 /* Ensure that array expressions are coerced into pointer
1481 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1483 if (noside
== EVAL_SKIP
)
1484 return eval_skip_value (exp
);
1485 return value_array (tem2
, tem3
, argvec
);
1489 struct value
*array
= evaluate_subexp (nullptr, exp
, pos
, noside
);
1491 = value_as_long (evaluate_subexp (nullptr, exp
, pos
, noside
));
1492 int upper
= value_as_long (evaluate_subexp (nullptr, exp
, pos
, noside
));
1494 if (noside
== EVAL_SKIP
)
1495 return eval_skip_value (exp
);
1496 return value_slice (array
, lowbound
, upper
- lowbound
+ 1);
1500 /* Skip third and second args to evaluate the first one. */
1501 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
1502 if (value_logical_not (arg1
))
1504 evaluate_subexp (nullptr, exp
, pos
, EVAL_SKIP
);
1505 return evaluate_subexp (nullptr, exp
, pos
, noside
);
1509 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
1510 evaluate_subexp (nullptr, exp
, pos
, EVAL_SKIP
);
1514 case OP_OBJC_SELECTOR
:
1515 { /* Objective C @selector operator. */
1516 char *sel
= &exp
->elts
[pc
+ 2].string
;
1517 int len
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1518 struct type
*selector_type
;
1520 (*pos
) += 3 + BYTES_TO_EXP_ELEM (len
+ 1);
1521 if (noside
== EVAL_SKIP
)
1522 return eval_skip_value (exp
);
1525 sel
[len
] = 0; /* Make sure it's terminated. */
1527 selector_type
= builtin_type (exp
->gdbarch
)->builtin_data_ptr
;
1528 return value_from_longest (selector_type
,
1529 lookup_child_selector (exp
->gdbarch
, sel
));
1532 case OP_OBJC_MSGCALL
:
1533 { /* Objective C message (method) call. */
1535 CORE_ADDR responds_selector
= 0;
1536 CORE_ADDR method_selector
= 0;
1538 CORE_ADDR selector
= 0;
1540 int struct_return
= 0;
1541 enum noside sub_no_side
= EVAL_NORMAL
;
1543 struct value
*msg_send
= NULL
;
1544 struct value
*msg_send_stret
= NULL
;
1545 int gnu_runtime
= 0;
1547 struct value
*target
= NULL
;
1548 struct value
*method
= NULL
;
1549 struct value
*called_method
= NULL
;
1551 struct type
*selector_type
= NULL
;
1552 struct type
*long_type
;
1554 struct value
*ret
= NULL
;
1557 selector
= exp
->elts
[pc
+ 1].longconst
;
1558 nargs
= exp
->elts
[pc
+ 2].longconst
;
1559 argvec
= XALLOCAVEC (struct value
*, nargs
+ 5);
1563 long_type
= builtin_type (exp
->gdbarch
)->builtin_long
;
1564 selector_type
= builtin_type (exp
->gdbarch
)->builtin_data_ptr
;
1566 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1567 sub_no_side
= EVAL_NORMAL
;
1569 sub_no_side
= noside
;
1571 target
= evaluate_subexp (selector_type
, exp
, pos
, sub_no_side
);
1573 if (value_as_long (target
) == 0)
1574 return value_from_longest (long_type
, 0);
1576 if (lookup_minimal_symbol ("objc_msg_lookup", 0, 0).minsym
)
1579 /* Find the method dispatch (Apple runtime) or method lookup
1580 (GNU runtime) function for Objective-C. These will be used
1581 to lookup the symbol information for the method. If we
1582 can't find any symbol information, then we'll use these to
1583 call the method, otherwise we can call the method
1584 directly. The msg_send_stret function is used in the special
1585 case of a method that returns a structure (Apple runtime
1589 type
= selector_type
;
1591 type
= lookup_function_type (type
);
1592 type
= lookup_pointer_type (type
);
1593 type
= lookup_function_type (type
);
1594 type
= lookup_pointer_type (type
);
1596 msg_send
= find_function_in_inferior ("objc_msg_lookup", NULL
);
1598 = find_function_in_inferior ("objc_msg_lookup", NULL
);
1600 msg_send
= value_from_pointer (type
, value_as_address (msg_send
));
1601 msg_send_stret
= value_from_pointer (type
,
1602 value_as_address (msg_send_stret
));
1606 msg_send
= find_function_in_inferior ("objc_msgSend", NULL
);
1607 /* Special dispatcher for methods returning structs. */
1609 = find_function_in_inferior ("objc_msgSend_stret", NULL
);
1612 /* Verify the target object responds to this method. The
1613 standard top-level 'Object' class uses a different name for
1614 the verification method than the non-standard, but more
1615 often used, 'NSObject' class. Make sure we check for both. */
1618 = lookup_child_selector (exp
->gdbarch
, "respondsToSelector:");
1619 if (responds_selector
== 0)
1621 = lookup_child_selector (exp
->gdbarch
, "respondsTo:");
1623 if (responds_selector
== 0)
1624 error (_("no 'respondsTo:' or 'respondsToSelector:' method"));
1627 = lookup_child_selector (exp
->gdbarch
, "methodForSelector:");
1628 if (method_selector
== 0)
1630 = lookup_child_selector (exp
->gdbarch
, "methodFor:");
1632 if (method_selector
== 0)
1633 error (_("no 'methodFor:' or 'methodForSelector:' method"));
1635 /* Call the verification method, to make sure that the target
1636 class implements the desired method. */
1638 argvec
[0] = msg_send
;
1640 argvec
[2] = value_from_longest (long_type
, responds_selector
);
1641 argvec
[3] = value_from_longest (long_type
, selector
);
1644 ret
= call_function_by_hand (argvec
[0], NULL
, {argvec
+ 1, 3});
1647 /* Function objc_msg_lookup returns a pointer. */
1649 ret
= call_function_by_hand (argvec
[0], NULL
, {argvec
+ 1, 3});
1651 if (value_as_long (ret
) == 0)
1652 error (_("Target does not respond to this message selector."));
1654 /* Call "methodForSelector:" method, to get the address of a
1655 function method that implements this selector for this
1656 class. If we can find a symbol at that address, then we
1657 know the return type, parameter types etc. (that's a good
1660 argvec
[0] = msg_send
;
1662 argvec
[2] = value_from_longest (long_type
, method_selector
);
1663 argvec
[3] = value_from_longest (long_type
, selector
);
1666 ret
= call_function_by_hand (argvec
[0], NULL
, {argvec
+ 1, 3});
1670 ret
= call_function_by_hand (argvec
[0], NULL
, {argvec
+ 1, 3});
1673 /* ret should now be the selector. */
1675 addr
= value_as_long (ret
);
1678 struct symbol
*sym
= NULL
;
1680 /* The address might point to a function descriptor;
1681 resolve it to the actual code address instead. */
1682 addr
= gdbarch_convert_from_func_ptr_addr (exp
->gdbarch
, addr
,
1683 current_top_target ());
1685 /* Is it a high_level symbol? */
1686 sym
= find_pc_function (addr
);
1688 method
= value_of_variable (sym
, 0);
1691 /* If we found a method with symbol information, check to see
1692 if it returns a struct. Otherwise assume it doesn't. */
1697 struct type
*val_type
;
1699 funaddr
= find_function_addr (method
, &val_type
);
1701 block_for_pc (funaddr
);
1703 val_type
= check_typedef (val_type
);
1705 if ((val_type
== NULL
)
1706 || (val_type
->code () == TYPE_CODE_ERROR
))
1708 if (expect_type
!= NULL
)
1709 val_type
= expect_type
;
1712 struct_return
= using_struct_return (exp
->gdbarch
, method
,
1715 else if (expect_type
!= NULL
)
1717 struct_return
= using_struct_return (exp
->gdbarch
, NULL
,
1718 check_typedef (expect_type
));
1721 /* Found a function symbol. Now we will substitute its
1722 value in place of the message dispatcher (obj_msgSend),
1723 so that we call the method directly instead of thru
1724 the dispatcher. The main reason for doing this is that
1725 we can now evaluate the return value and parameter values
1726 according to their known data types, in case we need to
1727 do things like promotion, dereferencing, special handling
1728 of structs and doubles, etc.
1730 We want to use the type signature of 'method', but still
1731 jump to objc_msgSend() or objc_msgSend_stret() to better
1732 mimic the behavior of the runtime. */
1736 if (value_type (method
)->code () != TYPE_CODE_FUNC
)
1737 error (_("method address has symbol information "
1738 "with non-function type; skipping"));
1740 /* Create a function pointer of the appropriate type, and
1741 replace its value with the value of msg_send or
1742 msg_send_stret. We must use a pointer here, as
1743 msg_send and msg_send_stret are of pointer type, and
1744 the representation may be different on systems that use
1745 function descriptors. */
1748 = value_from_pointer (lookup_pointer_type (value_type (method
)),
1749 value_as_address (msg_send_stret
));
1752 = value_from_pointer (lookup_pointer_type (value_type (method
)),
1753 value_as_address (msg_send
));
1758 called_method
= msg_send_stret
;
1760 called_method
= msg_send
;
1763 if (noside
== EVAL_SKIP
)
1764 return eval_skip_value (exp
);
1766 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1768 /* If the return type doesn't look like a function type,
1769 call an error. This can happen if somebody tries to
1770 turn a variable into a function call. This is here
1771 because people often want to call, eg, strcmp, which
1772 gdb doesn't know is a function. If gdb isn't asked for
1773 it's opinion (ie. through "whatis"), it won't offer
1776 struct type
*callee_type
= value_type (called_method
);
1778 if (callee_type
&& callee_type
->code () == TYPE_CODE_PTR
)
1779 callee_type
= TYPE_TARGET_TYPE (callee_type
);
1780 callee_type
= TYPE_TARGET_TYPE (callee_type
);
1784 if ((callee_type
->code () == TYPE_CODE_ERROR
) && expect_type
)
1785 return allocate_value (expect_type
);
1787 return allocate_value (callee_type
);
1790 error (_("Expression of type other than "
1791 "\"method returning ...\" used as a method"));
1794 /* Now depending on whether we found a symbol for the method,
1795 we will either call the runtime dispatcher or the method
1798 argvec
[0] = called_method
;
1800 argvec
[2] = value_from_longest (long_type
, selector
);
1801 /* User-supplied arguments. */
1802 for (tem
= 0; tem
< nargs
; tem
++)
1803 argvec
[tem
+ 3] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1804 argvec
[tem
+ 3] = 0;
1806 auto call_args
= gdb::make_array_view (argvec
+ 1, nargs
+ 2);
1808 if (gnu_runtime
&& (method
!= NULL
))
1810 /* Function objc_msg_lookup returns a pointer. */
1811 deprecated_set_value_type (argvec
[0],
1812 lookup_pointer_type (lookup_function_type (value_type (argvec
[0]))));
1813 argvec
[0] = call_function_by_hand (argvec
[0], NULL
, call_args
);
1816 return call_function_by_hand (argvec
[0], NULL
, call_args
);
1821 return evaluate_funcall (expect_type
, exp
, pos
, noside
);
1824 /* We have a complex number, There should be 2 floating
1825 point numbers that compose it. */
1827 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
1828 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
1830 return value_literal_complex (arg1
, arg2
, exp
->elts
[pc
+ 1].type
);
1832 case STRUCTOP_STRUCT
:
1833 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1834 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1835 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
1836 if (noside
== EVAL_SKIP
)
1837 return eval_skip_value (exp
);
1838 arg3
= value_struct_elt (&arg1
, NULL
, &exp
->elts
[pc
+ 2].string
,
1840 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1841 arg3
= value_zero (value_type (arg3
), VALUE_LVAL (arg3
));
1845 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1846 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1847 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
1848 if (noside
== EVAL_SKIP
)
1849 return eval_skip_value (exp
);
1851 /* Check to see if operator '->' has been overloaded. If so replace
1852 arg1 with the value returned by evaluating operator->(). */
1853 while (unop_user_defined_p (op
, arg1
))
1855 struct value
*value
= NULL
;
1858 value
= value_x_unop (arg1
, op
, noside
);
1861 catch (const gdb_exception_error
&except
)
1863 if (except
.error
== NOT_FOUND_ERROR
)
1872 /* JYG: if print object is on we need to replace the base type
1873 with rtti type in order to continue on with successful
1874 lookup of member / method only available in the rtti type. */
1876 struct type
*arg_type
= value_type (arg1
);
1877 struct type
*real_type
;
1878 int full
, using_enc
;
1880 struct value_print_options opts
;
1882 get_user_print_options (&opts
);
1883 if (opts
.objectprint
&& TYPE_TARGET_TYPE (arg_type
)
1884 && (TYPE_TARGET_TYPE (arg_type
)->code () == TYPE_CODE_STRUCT
))
1886 real_type
= value_rtti_indirect_type (arg1
, &full
, &top
,
1889 arg1
= value_cast (real_type
, arg1
);
1893 arg3
= value_struct_elt (&arg1
, NULL
, &exp
->elts
[pc
+ 2].string
,
1894 NULL
, "structure pointer");
1895 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1896 arg3
= value_zero (value_type (arg3
), VALUE_LVAL (arg3
));
1899 case STRUCTOP_MEMBER
:
1901 if (op
== STRUCTOP_MEMBER
)
1902 arg1
= evaluate_subexp_for_address (exp
, pos
, noside
);
1904 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
1906 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
1908 if (noside
== EVAL_SKIP
)
1909 return eval_skip_value (exp
);
1911 type
= check_typedef (value_type (arg2
));
1912 switch (type
->code ())
1914 case TYPE_CODE_METHODPTR
:
1915 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1916 return value_zero (TYPE_TARGET_TYPE (type
), not_lval
);
1919 arg2
= cplus_method_ptr_to_value (&arg1
, arg2
);
1920 gdb_assert (value_type (arg2
)->code () == TYPE_CODE_PTR
);
1921 return value_ind (arg2
);
1924 case TYPE_CODE_MEMBERPTR
:
1925 /* Now, convert these values to an address. */
1926 arg1
= value_cast_pointers (lookup_pointer_type (TYPE_SELF_TYPE (type
)),
1929 mem_offset
= value_as_long (arg2
);
1931 arg3
= value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
1932 value_as_long (arg1
) + mem_offset
);
1933 return value_ind (arg3
);
1936 error (_("non-pointer-to-member value used "
1937 "in pointer-to-member construct"));
1942 type_instance_flags flags
1943 = (type_instance_flag_value
) longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1944 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
1945 arg_types
= (struct type
**) alloca (nargs
* sizeof (struct type
*));
1946 for (ix
= 0; ix
< nargs
; ++ix
)
1947 arg_types
[ix
] = exp
->elts
[pc
+ 2 + ix
+ 1].type
;
1949 fake_method
fake_expect_type (flags
, nargs
, arg_types
);
1950 *(pos
) += 4 + nargs
;
1951 return evaluate_subexp_standard (fake_expect_type
.type (), exp
, pos
,
1956 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1957 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1958 if (noside
== EVAL_SKIP
)
1959 return eval_skip_value (exp
);
1960 if (binop_user_defined_p (op
, arg1
, arg2
))
1961 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1963 return value_concat (arg1
, arg2
);
1966 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
1967 /* Special-case assignments where the left-hand-side is a
1968 convenience variable -- in these, don't bother setting an
1969 expected type. This avoids a weird case where re-assigning a
1970 string or array to an internal variable could error with "Too
1971 many array elements". */
1972 arg2
= evaluate_subexp (VALUE_LVAL (arg1
) == lval_internalvar
1974 : value_type (arg1
),
1977 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1979 if (binop_user_defined_p (op
, arg1
, arg2
))
1980 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1982 return value_assign (arg1
, arg2
);
1984 case BINOP_ASSIGN_MODIFY
:
1986 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
1987 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
1988 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1990 op
= exp
->elts
[pc
+ 1].opcode
;
1991 if (binop_user_defined_p (op
, arg1
, arg2
))
1992 return value_x_binop (arg1
, arg2
, BINOP_ASSIGN_MODIFY
, op
, noside
);
1993 else if (op
== BINOP_ADD
&& ptrmath_type_p (exp
->language_defn
,
1995 && is_integral_type (value_type (arg2
)))
1996 arg2
= value_ptradd (arg1
, value_as_long (arg2
));
1997 else if (op
== BINOP_SUB
&& ptrmath_type_p (exp
->language_defn
,
1999 && is_integral_type (value_type (arg2
)))
2000 arg2
= value_ptradd (arg1
, - value_as_long (arg2
));
2003 struct value
*tmp
= arg1
;
2005 /* For shift and integer exponentiation operations,
2006 only promote the first argument. */
2007 if ((op
== BINOP_LSH
|| op
== BINOP_RSH
|| op
== BINOP_EXP
)
2008 && is_integral_type (value_type (arg2
)))
2009 unop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
);
2011 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2013 arg2
= value_binop (tmp
, arg2
, op
);
2015 return value_assign (arg1
, arg2
);
2018 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2019 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2020 if (noside
== EVAL_SKIP
)
2021 return eval_skip_value (exp
);
2022 if (binop_user_defined_p (op
, arg1
, arg2
))
2023 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2024 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
2025 && is_integral_or_integral_reference (value_type (arg2
)))
2026 return value_ptradd (arg1
, value_as_long (arg2
));
2027 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg2
))
2028 && is_integral_or_integral_reference (value_type (arg1
)))
2029 return value_ptradd (arg2
, value_as_long (arg1
));
2032 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2033 return value_binop (arg1
, arg2
, BINOP_ADD
);
2037 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2038 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2039 if (noside
== EVAL_SKIP
)
2040 return eval_skip_value (exp
);
2041 if (binop_user_defined_p (op
, arg1
, arg2
))
2042 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2043 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
2044 && ptrmath_type_p (exp
->language_defn
, value_type (arg2
)))
2046 /* FIXME -- should be ptrdiff_t */
2047 type
= builtin_type (exp
->gdbarch
)->builtin_long
;
2048 return value_from_longest (type
, value_ptrdiff (arg1
, arg2
));
2050 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
2051 && is_integral_or_integral_reference (value_type (arg2
)))
2052 return value_ptradd (arg1
, - value_as_long (arg2
));
2055 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2056 return value_binop (arg1
, arg2
, BINOP_SUB
);
2067 case BINOP_BITWISE_AND
:
2068 case BINOP_BITWISE_IOR
:
2069 case BINOP_BITWISE_XOR
:
2070 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2071 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2072 if (noside
== EVAL_SKIP
)
2073 return eval_skip_value (exp
);
2074 if (binop_user_defined_p (op
, arg1
, arg2
))
2075 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2078 /* If EVAL_AVOID_SIDE_EFFECTS and we're dividing by zero,
2079 fudge arg2 to avoid division-by-zero, the caller is
2080 (theoretically) only looking for the type of the result. */
2081 if (noside
== EVAL_AVOID_SIDE_EFFECTS
2082 /* ??? Do we really want to test for BINOP_MOD here?
2083 The implementation of value_binop gives it a well-defined
2086 || op
== BINOP_INTDIV
2089 && value_logical_not (arg2
))
2091 struct value
*v_one
;
2093 v_one
= value_one (value_type (arg2
));
2094 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &v_one
);
2095 return value_binop (arg1
, v_one
, op
);
2099 /* For shift and integer exponentiation operations,
2100 only promote the first argument. */
2101 if ((op
== BINOP_LSH
|| op
== BINOP_RSH
|| op
== BINOP_EXP
)
2102 && is_integral_type (value_type (arg2
)))
2103 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2105 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2107 return value_binop (arg1
, arg2
, op
);
2111 case BINOP_SUBSCRIPT
:
2112 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2113 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2114 if (noside
== EVAL_SKIP
)
2115 return eval_skip_value (exp
);
2116 if (binop_user_defined_p (op
, arg1
, arg2
))
2117 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2120 /* If the user attempts to subscript something that is not an
2121 array or pointer type (like a plain int variable for example),
2122 then report this as an error. */
2124 arg1
= coerce_ref (arg1
);
2125 type
= check_typedef (value_type (arg1
));
2126 if (type
->code () != TYPE_CODE_ARRAY
2127 && type
->code () != TYPE_CODE_PTR
)
2130 error (_("cannot subscript something of type `%s'"),
2133 error (_("cannot subscript requested type"));
2136 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2137 return value_zero (TYPE_TARGET_TYPE (type
), VALUE_LVAL (arg1
));
2139 return value_subscript (arg1
, value_as_long (arg2
));
2141 case MULTI_SUBSCRIPT
:
2143 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
2144 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2145 argvec
= XALLOCAVEC (struct value
*, nargs
);
2146 for (ix
= 0; ix
< nargs
; ++ix
)
2147 argvec
[ix
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
2148 if (noside
== EVAL_SKIP
)
2150 for (ix
= 0; ix
< nargs
; ++ix
)
2154 if (binop_user_defined_p (op
, arg1
, arg2
))
2156 arg1
= value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2160 arg1
= coerce_ref (arg1
);
2161 type
= check_typedef (value_type (arg1
));
2163 switch (type
->code ())
2166 case TYPE_CODE_ARRAY
:
2167 case TYPE_CODE_STRING
:
2168 arg1
= value_subscript (arg1
, value_as_long (arg2
));
2173 error (_("cannot subscript something of type `%s'"),
2176 error (_("cannot subscript requested type"));
2182 case BINOP_LOGICAL_AND
:
2183 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2184 if (noside
== EVAL_SKIP
)
2186 evaluate_subexp (nullptr, exp
, pos
, noside
);
2187 return eval_skip_value (exp
);
2191 arg2
= evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2194 if (binop_user_defined_p (op
, arg1
, arg2
))
2196 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2197 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2201 tem
= value_logical_not (arg1
);
2203 = evaluate_subexp (nullptr, exp
, pos
, (tem
? EVAL_SKIP
: noside
));
2204 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2205 return value_from_longest (type
,
2206 (LONGEST
) (!tem
&& !value_logical_not (arg2
)));
2209 case BINOP_LOGICAL_OR
:
2210 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2211 if (noside
== EVAL_SKIP
)
2213 evaluate_subexp (nullptr, exp
, pos
, noside
);
2214 return eval_skip_value (exp
);
2218 arg2
= evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2221 if (binop_user_defined_p (op
, arg1
, arg2
))
2223 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2224 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2228 tem
= value_logical_not (arg1
);
2230 = evaluate_subexp (nullptr, exp
, pos
, (!tem
? EVAL_SKIP
: noside
));
2231 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2232 return value_from_longest (type
,
2233 (LONGEST
) (!tem
|| !value_logical_not (arg2
)));
2237 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2238 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2239 if (noside
== EVAL_SKIP
)
2240 return eval_skip_value (exp
);
2241 if (binop_user_defined_p (op
, arg1
, arg2
))
2243 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2247 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2248 tem
= value_equal (arg1
, arg2
);
2249 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2250 return value_from_longest (type
, (LONGEST
) tem
);
2253 case BINOP_NOTEQUAL
:
2254 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2255 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2256 if (noside
== EVAL_SKIP
)
2257 return eval_skip_value (exp
);
2258 if (binop_user_defined_p (op
, arg1
, arg2
))
2260 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2264 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2265 tem
= value_equal (arg1
, arg2
);
2266 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2267 return value_from_longest (type
, (LONGEST
) ! tem
);
2271 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2272 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2273 if (noside
== EVAL_SKIP
)
2274 return eval_skip_value (exp
);
2275 if (binop_user_defined_p (op
, arg1
, arg2
))
2277 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2281 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2282 tem
= value_less (arg1
, arg2
);
2283 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2284 return value_from_longest (type
, (LONGEST
) tem
);
2288 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2289 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2290 if (noside
== EVAL_SKIP
)
2291 return eval_skip_value (exp
);
2292 if (binop_user_defined_p (op
, arg1
, arg2
))
2294 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2298 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2299 tem
= value_less (arg2
, arg1
);
2300 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2301 return value_from_longest (type
, (LONGEST
) tem
);
2305 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2306 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2307 if (noside
== EVAL_SKIP
)
2308 return eval_skip_value (exp
);
2309 if (binop_user_defined_p (op
, arg1
, arg2
))
2311 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2315 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2316 tem
= value_less (arg2
, arg1
) || value_equal (arg1
, arg2
);
2317 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2318 return value_from_longest (type
, (LONGEST
) tem
);
2322 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2323 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2324 if (noside
== EVAL_SKIP
)
2325 return eval_skip_value (exp
);
2326 if (binop_user_defined_p (op
, arg1
, arg2
))
2328 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2332 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2333 tem
= value_less (arg1
, arg2
) || value_equal (arg1
, arg2
);
2334 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2335 return value_from_longest (type
, (LONGEST
) tem
);
2339 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2340 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2341 if (noside
== EVAL_SKIP
)
2342 return eval_skip_value (exp
);
2343 type
= check_typedef (value_type (arg2
));
2344 if (type
->code () != TYPE_CODE_INT
2345 && type
->code () != TYPE_CODE_ENUM
)
2346 error (_("Non-integral right operand for \"@\" operator."));
2347 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2349 return allocate_repeat_value (value_type (arg1
),
2350 longest_to_int (value_as_long (arg2
)));
2353 return value_repeat (arg1
, longest_to_int (value_as_long (arg2
)));
2356 evaluate_subexp (nullptr, exp
, pos
, noside
);
2357 return evaluate_subexp (nullptr, exp
, pos
, noside
);
2360 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2361 if (noside
== EVAL_SKIP
)
2362 return eval_skip_value (exp
);
2363 if (unop_user_defined_p (op
, arg1
))
2364 return value_x_unop (arg1
, op
, noside
);
2367 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2368 return value_pos (arg1
);
2372 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2373 if (noside
== EVAL_SKIP
)
2374 return eval_skip_value (exp
);
2375 if (unop_user_defined_p (op
, arg1
))
2376 return value_x_unop (arg1
, op
, noside
);
2379 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2380 return value_neg (arg1
);
2383 case UNOP_COMPLEMENT
:
2384 /* C++: check for and handle destructor names. */
2386 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2387 if (noside
== EVAL_SKIP
)
2388 return eval_skip_value (exp
);
2389 if (unop_user_defined_p (UNOP_COMPLEMENT
, arg1
))
2390 return value_x_unop (arg1
, UNOP_COMPLEMENT
, noside
);
2393 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2394 return value_complement (arg1
);
2397 case UNOP_LOGICAL_NOT
:
2398 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2399 if (noside
== EVAL_SKIP
)
2400 return eval_skip_value (exp
);
2401 if (unop_user_defined_p (op
, arg1
))
2402 return value_x_unop (arg1
, op
, noside
);
2405 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2406 return value_from_longest (type
, (LONGEST
) value_logical_not (arg1
));
2410 if (expect_type
&& expect_type
->code () == TYPE_CODE_PTR
)
2411 expect_type
= TYPE_TARGET_TYPE (check_typedef (expect_type
));
2412 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2413 type
= check_typedef (value_type (arg1
));
2414 if (type
->code () == TYPE_CODE_METHODPTR
2415 || type
->code () == TYPE_CODE_MEMBERPTR
)
2416 error (_("Attempt to dereference pointer "
2417 "to member without an object"));
2418 if (noside
== EVAL_SKIP
)
2419 return eval_skip_value (exp
);
2420 if (unop_user_defined_p (op
, arg1
))
2421 return value_x_unop (arg1
, op
, noside
);
2422 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2424 type
= check_typedef (value_type (arg1
));
2425 if (type
->code () == TYPE_CODE_PTR
2426 || TYPE_IS_REFERENCE (type
)
2427 /* In C you can dereference an array to get the 1st elt. */
2428 || type
->code () == TYPE_CODE_ARRAY
2430 return value_zero (TYPE_TARGET_TYPE (type
),
2432 else if (type
->code () == TYPE_CODE_INT
)
2433 /* GDB allows dereferencing an int. */
2434 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
,
2437 error (_("Attempt to take contents of a non-pointer value."));
2440 /* Allow * on an integer so we can cast it to whatever we want.
2441 This returns an int, which seems like the most C-like thing to
2442 do. "long long" variables are rare enough that
2443 BUILTIN_TYPE_LONGEST would seem to be a mistake. */
2444 if (type
->code () == TYPE_CODE_INT
)
2445 return value_at_lazy (builtin_type (exp
->gdbarch
)->builtin_int
,
2446 (CORE_ADDR
) value_as_address (arg1
));
2447 return value_ind (arg1
);
2450 /* C++: check for and handle pointer to members. */
2452 if (noside
== EVAL_SKIP
)
2454 evaluate_subexp (nullptr, exp
, pos
, EVAL_SKIP
);
2455 return eval_skip_value (exp
);
2458 return evaluate_subexp_for_address (exp
, pos
, noside
);
2461 if (noside
== EVAL_SKIP
)
2463 evaluate_subexp (nullptr, exp
, pos
, EVAL_SKIP
);
2464 return eval_skip_value (exp
);
2466 return evaluate_subexp_for_sizeof (exp
, pos
, noside
);
2471 evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
));
2472 /* FIXME: This should be size_t. */
2473 struct type
*size_type
= builtin_type (exp
->gdbarch
)->builtin_int
;
2474 ULONGEST align
= type_align (type
);
2476 error (_("could not determine alignment of type"));
2477 return value_from_longest (size_type
, align
);
2482 type
= exp
->elts
[pc
+ 1].type
;
2483 return evaluate_subexp_for_cast (exp
, pos
, noside
, type
);
2485 case UNOP_CAST_TYPE
:
2486 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2487 type
= value_type (arg1
);
2488 return evaluate_subexp_for_cast (exp
, pos
, noside
, type
);
2490 case UNOP_DYNAMIC_CAST
:
2491 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2492 type
= value_type (arg1
);
2493 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
2494 if (noside
== EVAL_SKIP
)
2495 return eval_skip_value (exp
);
2496 return value_dynamic_cast (type
, arg1
);
2498 case UNOP_REINTERPRET_CAST
:
2499 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2500 type
= value_type (arg1
);
2501 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
2502 if (noside
== EVAL_SKIP
)
2503 return eval_skip_value (exp
);
2504 return value_reinterpret_cast (type
, arg1
);
2508 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2509 if (noside
== EVAL_SKIP
)
2510 return eval_skip_value (exp
);
2511 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2512 return value_zero (exp
->elts
[pc
+ 1].type
, lval_memory
);
2514 return value_at_lazy (exp
->elts
[pc
+ 1].type
,
2515 value_as_address (arg1
));
2517 case UNOP_MEMVAL_TYPE
:
2518 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2519 type
= value_type (arg1
);
2520 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2521 if (noside
== EVAL_SKIP
)
2522 return eval_skip_value (exp
);
2523 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2524 return value_zero (type
, lval_memory
);
2526 return value_at_lazy (type
, value_as_address (arg1
));
2528 case UNOP_PREINCREMENT
:
2529 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2530 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2532 else if (unop_user_defined_p (op
, arg1
))
2534 return value_x_unop (arg1
, op
, noside
);
2538 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2539 arg2
= value_ptradd (arg1
, 1);
2542 struct value
*tmp
= arg1
;
2544 arg2
= value_one (value_type (arg1
));
2545 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2546 arg2
= value_binop (tmp
, arg2
, BINOP_ADD
);
2549 return value_assign (arg1
, arg2
);
2552 case UNOP_PREDECREMENT
:
2553 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2554 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2556 else if (unop_user_defined_p (op
, arg1
))
2558 return value_x_unop (arg1
, op
, noside
);
2562 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2563 arg2
= value_ptradd (arg1
, -1);
2566 struct value
*tmp
= arg1
;
2568 arg2
= value_one (value_type (arg1
));
2569 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2570 arg2
= value_binop (tmp
, arg2
, BINOP_SUB
);
2573 return value_assign (arg1
, arg2
);
2576 case UNOP_POSTINCREMENT
:
2577 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2578 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2580 else if (unop_user_defined_p (op
, arg1
))
2582 return value_x_unop (arg1
, op
, noside
);
2586 arg3
= value_non_lval (arg1
);
2588 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2589 arg2
= value_ptradd (arg1
, 1);
2592 struct value
*tmp
= arg1
;
2594 arg2
= value_one (value_type (arg1
));
2595 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2596 arg2
= value_binop (tmp
, arg2
, BINOP_ADD
);
2599 value_assign (arg1
, arg2
);
2603 case UNOP_POSTDECREMENT
:
2604 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2605 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2607 else if (unop_user_defined_p (op
, arg1
))
2609 return value_x_unop (arg1
, op
, noside
);
2613 arg3
= value_non_lval (arg1
);
2615 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2616 arg2
= value_ptradd (arg1
, -1);
2619 struct value
*tmp
= arg1
;
2621 arg2
= value_one (value_type (arg1
));
2622 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2623 arg2
= value_binop (tmp
, arg2
, BINOP_SUB
);
2626 value_assign (arg1
, arg2
);
2632 return value_of_this (exp
->language_defn
);
2635 /* The value is not supposed to be used. This is here to make it
2636 easier to accommodate expressions that contain types. */
2638 if (noside
== EVAL_SKIP
)
2639 return eval_skip_value (exp
);
2640 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2641 return allocate_value (exp
->elts
[pc
+ 1].type
);
2643 error (_("Attempt to use a type name as an expression"));
2647 if (noside
== EVAL_SKIP
)
2649 evaluate_subexp (nullptr, exp
, pos
, EVAL_SKIP
);
2650 return eval_skip_value (exp
);
2652 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2654 enum exp_opcode sub_op
= exp
->elts
[*pos
].opcode
;
2655 struct value
*result
;
2657 result
= evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2659 /* 'decltype' has special semantics for lvalues. */
2660 if (op
== OP_DECLTYPE
2661 && (sub_op
== BINOP_SUBSCRIPT
2662 || sub_op
== STRUCTOP_MEMBER
2663 || sub_op
== STRUCTOP_MPTR
2664 || sub_op
== UNOP_IND
2665 || sub_op
== STRUCTOP_STRUCT
2666 || sub_op
== STRUCTOP_PTR
2667 || sub_op
== OP_SCOPE
))
2669 type
= value_type (result
);
2671 if (!TYPE_IS_REFERENCE (type
))
2673 type
= lookup_lvalue_reference_type (type
);
2674 result
= allocate_value (type
);
2681 error (_("Attempt to use a type as an expression"));
2685 struct value
*result
;
2686 enum exp_opcode sub_op
= exp
->elts
[*pos
].opcode
;
2688 if (sub_op
== OP_TYPE
|| sub_op
== OP_DECLTYPE
|| sub_op
== OP_TYPEOF
)
2689 result
= evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2691 result
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2693 if (noside
!= EVAL_NORMAL
)
2694 return allocate_value (cplus_typeid_type (exp
->gdbarch
));
2696 return cplus_typeid (result
);
2700 /* Removing this case and compiling with gcc -Wall reveals that
2701 a lot of cases are hitting this case. Some of these should
2702 probably be removed from expression.h; others are legitimate
2703 expressions which are (apparently) not fully implemented.
2705 If there are any cases landing here which mean a user error,
2706 then they should be separate cases, with more descriptive
2709 error (_("GDB does not (yet) know how to "
2710 "evaluate that kind of expression"));
2713 gdb_assert_not_reached ("missed return?");
2716 /* Evaluate a subexpression of EXP, at index *POS,
2717 and return the address of that subexpression.
2718 Advance *POS over the subexpression.
2719 If the subexpression isn't an lvalue, get an error.
2720 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
2721 then only the type of the result need be correct. */
2723 static struct value
*
2724 evaluate_subexp_for_address (struct expression
*exp
, int *pos
,
2734 op
= exp
->elts
[pc
].opcode
;
2740 x
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2742 /* We can't optimize out "&*" if there's a user-defined operator*. */
2743 if (unop_user_defined_p (op
, x
))
2745 x
= value_x_unop (x
, op
, noside
);
2746 goto default_case_after_eval
;
2749 return coerce_array (x
);
2753 return value_cast (lookup_pointer_type (exp
->elts
[pc
+ 1].type
),
2754 evaluate_subexp (nullptr, exp
, pos
, noside
));
2756 case UNOP_MEMVAL_TYPE
:
2761 x
= evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2762 type
= value_type (x
);
2763 return value_cast (lookup_pointer_type (type
),
2764 evaluate_subexp (nullptr, exp
, pos
, noside
));
2768 var
= exp
->elts
[pc
+ 2].symbol
;
2770 /* C++: The "address" of a reference should yield the address
2771 * of the object pointed to. Let value_addr() deal with it. */
2772 if (TYPE_IS_REFERENCE (SYMBOL_TYPE (var
)))
2776 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2779 lookup_pointer_type (SYMBOL_TYPE (var
));
2780 enum address_class sym_class
= SYMBOL_CLASS (var
);
2782 if (sym_class
== LOC_CONST
2783 || sym_class
== LOC_CONST_BYTES
2784 || sym_class
== LOC_REGISTER
)
2785 error (_("Attempt to take address of register or constant."));
2788 value_zero (type
, not_lval
);
2791 return address_of_variable (var
, exp
->elts
[pc
+ 1].block
);
2793 case OP_VAR_MSYM_VALUE
:
2797 value
*val
= evaluate_var_msym_value (noside
,
2798 exp
->elts
[pc
+ 1].objfile
,
2799 exp
->elts
[pc
+ 2].msymbol
);
2800 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2802 struct type
*type
= lookup_pointer_type (value_type (val
));
2803 return value_zero (type
, not_lval
);
2806 return value_addr (val
);
2810 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
2811 (*pos
) += 5 + BYTES_TO_EXP_ELEM (tem
+ 1);
2812 x
= value_aggregate_elt (exp
->elts
[pc
+ 1].type
,
2813 &exp
->elts
[pc
+ 3].string
,
2816 error (_("There is no field named %s"), &exp
->elts
[pc
+ 3].string
);
2821 x
= evaluate_subexp (nullptr, exp
, pos
, noside
);
2822 default_case_after_eval
:
2823 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2825 struct type
*type
= check_typedef (value_type (x
));
2827 if (TYPE_IS_REFERENCE (type
))
2828 return value_zero (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
2830 else if (VALUE_LVAL (x
) == lval_memory
|| value_must_coerce_to_target (x
))
2831 return value_zero (lookup_pointer_type (value_type (x
)),
2834 error (_("Attempt to take address of "
2835 "value not located in memory."));
2837 return value_addr (x
);
2841 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
2842 When used in contexts where arrays will be coerced anyway, this is
2843 equivalent to `evaluate_subexp' but much faster because it avoids
2844 actually fetching array contents (perhaps obsolete now that we have
2847 Note that we currently only do the coercion for C expressions, where
2848 arrays are zero based and the coercion is correct. For other languages,
2849 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
2850 to decide if coercion is appropriate. */
2853 evaluate_subexp_with_coercion (struct expression
*exp
,
2854 int *pos
, enum noside noside
)
2863 op
= exp
->elts
[pc
].opcode
;
2868 var
= exp
->elts
[pc
+ 2].symbol
;
2869 type
= check_typedef (SYMBOL_TYPE (var
));
2870 if (type
->code () == TYPE_CODE_ARRAY
2871 && !type
->is_vector ()
2872 && CAST_IS_CONVERSION (exp
->language_defn
))
2875 val
= address_of_variable (var
, exp
->elts
[pc
+ 1].block
);
2876 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
2882 return evaluate_subexp (nullptr, exp
, pos
, noside
);
2886 /* Evaluate a subexpression of EXP, at index *POS,
2887 and return a value for the size of that subexpression.
2888 Advance *POS over the subexpression. If NOSIDE is EVAL_NORMAL
2889 we allow side-effects on the operand if its type is a variable
2892 static struct value
*
2893 evaluate_subexp_for_sizeof (struct expression
*exp
, int *pos
,
2896 /* FIXME: This should be size_t. */
2897 struct type
*size_type
= builtin_type (exp
->gdbarch
)->builtin_int
;
2904 op
= exp
->elts
[pc
].opcode
;
2908 /* This case is handled specially
2909 so that we avoid creating a value for the result type.
2910 If the result type is very big, it's desirable not to
2911 create a value unnecessarily. */
2914 val
= evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2915 type
= check_typedef (value_type (val
));
2916 if (type
->code () != TYPE_CODE_PTR
2917 && !TYPE_IS_REFERENCE (type
)
2918 && type
->code () != TYPE_CODE_ARRAY
)
2919 error (_("Attempt to take contents of a non-pointer value."));
2920 type
= TYPE_TARGET_TYPE (type
);
2921 if (is_dynamic_type (type
))
2922 type
= value_type (value_ind (val
));
2923 return value_from_longest (size_type
, (LONGEST
) TYPE_LENGTH (type
));
2927 type
= exp
->elts
[pc
+ 1].type
;
2930 case UNOP_MEMVAL_TYPE
:
2932 val
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2933 type
= value_type (val
);
2937 type
= SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
);
2938 if (is_dynamic_type (type
))
2940 val
= evaluate_subexp (nullptr, exp
, pos
, EVAL_NORMAL
);
2941 type
= value_type (val
);
2942 if (type
->code () == TYPE_CODE_ARRAY
)
2944 if (type_not_allocated (type
) || type_not_associated (type
))
2945 return value_zero (size_type
, not_lval
);
2946 else if (is_dynamic_type (type
->index_type ())
2947 && type
->bounds ()->high
.kind () == PROP_UNDEFINED
)
2948 return allocate_optimized_out_value (size_type
);
2955 case OP_VAR_MSYM_VALUE
:
2959 minimal_symbol
*msymbol
= exp
->elts
[pc
+ 2].msymbol
;
2960 value
*mval
= evaluate_var_msym_value (noside
,
2961 exp
->elts
[pc
+ 1].objfile
,
2964 type
= value_type (mval
);
2965 if (type
->code () == TYPE_CODE_ERROR
)
2966 error_unknown_type (msymbol
->print_name ());
2968 return value_from_longest (size_type
, TYPE_LENGTH (type
));
2972 /* Deal with the special case if NOSIDE is EVAL_NORMAL and the resulting
2973 type of the subscript is a variable length array type. In this case we
2974 must re-evaluate the right hand side of the subscription to allow
2976 case BINOP_SUBSCRIPT
:
2977 if (noside
== EVAL_NORMAL
)
2979 int npc
= (*pos
) + 1;
2981 val
= evaluate_subexp (nullptr, exp
, &npc
, EVAL_AVOID_SIDE_EFFECTS
);
2982 type
= check_typedef (value_type (val
));
2983 if (type
->code () == TYPE_CODE_ARRAY
)
2985 type
= check_typedef (TYPE_TARGET_TYPE (type
));
2986 if (type
->code () == TYPE_CODE_ARRAY
)
2988 type
= type
->index_type ();
2989 /* Only re-evaluate the right hand side if the resulting type
2990 is a variable length type. */
2991 if (type
->bounds ()->flag_bound_evaluated
)
2993 val
= evaluate_subexp (nullptr, exp
, pos
, EVAL_NORMAL
);
2994 return value_from_longest
2995 (size_type
, (LONGEST
) TYPE_LENGTH (value_type (val
)));
3004 val
= evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3005 type
= value_type (val
);
3009 /* $5.3.3/2 of the C++ Standard (n3290 draft) says of sizeof:
3010 "When applied to a reference or a reference type, the result is
3011 the size of the referenced type." */
3012 type
= check_typedef (type
);
3013 if (exp
->language_defn
->la_language
== language_cplus
3014 && (TYPE_IS_REFERENCE (type
)))
3015 type
= check_typedef (TYPE_TARGET_TYPE (type
));
3016 return value_from_longest (size_type
, (LONGEST
) TYPE_LENGTH (type
));
3019 /* Evaluate a subexpression of EXP, at index *POS, and return a value
3020 for that subexpression cast to TO_TYPE. Advance *POS over the
3024 evaluate_subexp_for_cast (expression
*exp
, int *pos
,
3026 struct type
*to_type
)
3030 /* Don't let symbols be evaluated with evaluate_subexp because that
3031 throws an "unknown type" error for no-debug data symbols.
3032 Instead, we want the cast to reinterpret the symbol. */
3033 if (exp
->elts
[pc
].opcode
== OP_VAR_MSYM_VALUE
3034 || exp
->elts
[pc
].opcode
== OP_VAR_VALUE
)
3039 if (exp
->elts
[pc
].opcode
== OP_VAR_MSYM_VALUE
)
3041 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
3042 return value_zero (to_type
, not_lval
);
3044 val
= evaluate_var_msym_value (noside
,
3045 exp
->elts
[pc
+ 1].objfile
,
3046 exp
->elts
[pc
+ 2].msymbol
);
3049 val
= evaluate_var_value (noside
,
3050 exp
->elts
[pc
+ 1].block
,
3051 exp
->elts
[pc
+ 2].symbol
);
3053 if (noside
== EVAL_SKIP
)
3054 return eval_skip_value (exp
);
3056 val
= value_cast (to_type
, val
);
3058 /* Don't allow e.g. '&(int)var_with_no_debug_info'. */
3059 if (VALUE_LVAL (val
) == lval_memory
)
3061 if (value_lazy (val
))
3062 value_fetch_lazy (val
);
3063 VALUE_LVAL (val
) = not_lval
;
3068 value
*val
= evaluate_subexp (to_type
, exp
, pos
, noside
);
3069 if (noside
== EVAL_SKIP
)
3070 return eval_skip_value (exp
);
3071 return value_cast (to_type
, val
);
3074 /* Parse a type expression in the string [P..P+LENGTH). */
3077 parse_and_eval_type (const char *p
, int length
)
3079 char *tmp
= (char *) alloca (length
+ 4);
3082 memcpy (tmp
+ 1, p
, length
);
3083 tmp
[length
+ 1] = ')';
3084 tmp
[length
+ 2] = '0';
3085 tmp
[length
+ 3] = '\0';
3086 expression_up expr
= parse_expression (tmp
);
3087 if (expr
->first_opcode () != UNOP_CAST
)
3088 error (_("Internal error in eval_type."));
3089 return expr
->elts
[1].type
;