1 /* Evaluate expressions for GDB.
3 Copyright (C) 1986-2020 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "expression.h"
27 #include "gdbthread.h"
28 #include "language.h" /* For CAST_IS_CONVERSION. */
29 #include "f-lang.h" /* For array bound stuff. */
32 #include "objc-lang.h"
34 #include "parser-defs.h"
35 #include "cp-support.h"
38 #include "user-regs.h"
40 #include "gdb_obstack.h"
42 #include "typeprint.h"
45 /* Prototypes for local functions. */
47 static struct value
*evaluate_subexp_for_sizeof (struct expression
*, int *,
50 static struct value
*evaluate_subexp_for_address (struct expression
*,
53 static value
*evaluate_subexp_for_cast (expression
*exp
, int *pos
,
57 static struct value
*evaluate_struct_tuple (struct value
*,
58 struct expression
*, int *,
61 static LONGEST
init_array_element (struct value
*, struct value
*,
62 struct expression
*, int *, enum noside
,
66 evaluate_subexp (struct type
*expect_type
, struct expression
*exp
,
67 int *pos
, enum noside noside
)
71 gdb::optional
<enable_thread_stack_temporaries
> stack_temporaries
;
72 if (*pos
== 0 && target_has_execution
73 && exp
->language_defn
->la_language
== language_cplus
74 && !thread_stack_temporaries_enabled_p (inferior_thread ()))
75 stack_temporaries
.emplace (inferior_thread ());
77 retval
= (*exp
->language_defn
->la_exp_desc
->evaluate_exp
)
78 (expect_type
, exp
, pos
, noside
);
80 if (stack_temporaries
.has_value ()
81 && value_in_thread_stack_temporaries (retval
, inferior_thread ()))
82 retval
= value_non_lval (retval
);
87 /* Parse the string EXP as a C expression, evaluate it,
88 and return the result as a number. */
91 parse_and_eval_address (const char *exp
)
93 expression_up expr
= parse_expression (exp
);
95 return value_as_address (evaluate_expression (expr
.get ()));
98 /* Like parse_and_eval_address, but treats the value of the expression
99 as an integer, not an address, returns a LONGEST, not a CORE_ADDR. */
101 parse_and_eval_long (const char *exp
)
103 expression_up expr
= parse_expression (exp
);
105 return value_as_long (evaluate_expression (expr
.get ()));
109 parse_and_eval (const char *exp
)
111 expression_up expr
= parse_expression (exp
);
113 return evaluate_expression (expr
.get ());
116 /* Parse up to a comma (or to a closeparen)
117 in the string EXPP as an expression, evaluate it, and return the value.
118 EXPP is advanced to point to the comma. */
121 parse_to_comma_and_eval (const char **expp
)
123 expression_up expr
= parse_exp_1 (expp
, 0, nullptr, 1);
125 return evaluate_expression (expr
.get ());
128 /* Evaluate an expression in internal prefix form
129 such as is constructed by parse.y.
131 See expression.h for info on the format of an expression. */
134 evaluate_expression (struct expression
*exp
)
138 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_NORMAL
);
141 /* Evaluate an expression, avoiding all memory references
142 and getting a value whose type alone is correct. */
145 evaluate_type (struct expression
*exp
)
149 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_AVOID_SIDE_EFFECTS
);
152 /* Evaluate a subexpression, avoiding all memory references and
153 getting a value whose type alone is correct. */
156 evaluate_subexpression_type (struct expression
*exp
, int subexp
)
158 return evaluate_subexp (NULL_TYPE
, exp
, &subexp
, EVAL_AVOID_SIDE_EFFECTS
);
161 /* Find the current value of a watchpoint on EXP. Return the value in
162 *VALP and *RESULTP and the chain of intermediate and final values
163 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
166 If PRESERVE_ERRORS is true, then exceptions are passed through.
167 Otherwise, if PRESERVE_ERRORS is false, then if a memory error
168 occurs while evaluating the expression, *RESULTP will be set to
169 NULL. *RESULTP may be a lazy value, if the result could not be
170 read from memory. It is used to determine whether a value is
171 user-specified (we should watch the whole value) or intermediate
172 (we should watch only the bit used to locate the final value).
174 If the final value, or any intermediate value, could not be read
175 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
176 set to any referenced values. *VALP will never be a lazy value.
177 This is the value which we store in struct breakpoint.
179 If VAL_CHAIN is non-NULL, the values put into *VAL_CHAIN will be
180 released from the value chain. If VAL_CHAIN is NULL, all generated
181 values will be left on the value chain. */
184 fetch_subexp_value (struct expression
*exp
, int *pc
, struct value
**valp
,
185 struct value
**resultp
,
186 std::vector
<value_ref_ptr
> *val_chain
,
189 struct value
*mark
, *new_mark
, *result
;
197 /* Evaluate the expression. */
198 mark
= value_mark ();
203 result
= evaluate_subexp (NULL_TYPE
, exp
, pc
, EVAL_NORMAL
);
205 catch (const gdb_exception
&ex
)
207 /* Ignore memory errors if we want watchpoints pointing at
208 inaccessible memory to still be created; otherwise, throw the
209 error to some higher catcher. */
213 if (!preserve_errors
)
222 new_mark
= value_mark ();
223 if (mark
== new_mark
)
228 /* Make sure it's not lazy, so that after the target stops again we
229 have a non-lazy previous value to compare with. */
232 if (!value_lazy (result
))
239 value_fetch_lazy (result
);
242 catch (const gdb_exception_error
&except
)
250 /* Return the chain of intermediate values. We use this to
251 decide which addresses to watch. */
252 *val_chain
= value_release_to_mark (mark
);
256 /* Extract a field operation from an expression. If the subexpression
257 of EXP starting at *SUBEXP is not a structure dereference
258 operation, return NULL. Otherwise, return the name of the
259 dereferenced field, and advance *SUBEXP to point to the
260 subexpression of the left-hand-side of the dereference. This is
261 used when completing field names. */
264 extract_field_op (struct expression
*exp
, int *subexp
)
269 if (exp
->elts
[*subexp
].opcode
!= STRUCTOP_STRUCT
270 && exp
->elts
[*subexp
].opcode
!= STRUCTOP_PTR
)
272 tem
= longest_to_int (exp
->elts
[*subexp
+ 1].longconst
);
273 result
= &exp
->elts
[*subexp
+ 2].string
;
274 (*subexp
) += 1 + 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
278 /* This function evaluates brace-initializers (in C/C++) for
281 static struct value
*
282 evaluate_struct_tuple (struct value
*struct_val
,
283 struct expression
*exp
,
284 int *pos
, enum noside noside
, int nargs
)
286 struct type
*struct_type
= check_typedef (value_type (struct_val
));
287 struct type
*field_type
;
292 struct value
*val
= NULL
;
297 /* Skip static fields. */
298 while (fieldno
< TYPE_NFIELDS (struct_type
)
299 && field_is_static (&TYPE_FIELD (struct_type
,
302 if (fieldno
>= TYPE_NFIELDS (struct_type
))
303 error (_("too many initializers"));
304 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
305 if (TYPE_CODE (field_type
) == TYPE_CODE_UNION
306 && TYPE_FIELD_NAME (struct_type
, fieldno
)[0] == '0')
307 error (_("don't know which variant you want to set"));
309 /* Here, struct_type is the type of the inner struct,
310 while substruct_type is the type of the inner struct.
311 These are the same for normal structures, but a variant struct
312 contains anonymous union fields that contain substruct fields.
313 The value fieldno is the index of the top-level (normal or
314 anonymous union) field in struct_field, while the value
315 subfieldno is the index of the actual real (named inner) field
316 in substruct_type. */
318 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
320 val
= evaluate_subexp (field_type
, exp
, pos
, noside
);
322 /* Now actually set the field in struct_val. */
324 /* Assign val to field fieldno. */
325 if (value_type (val
) != field_type
)
326 val
= value_cast (field_type
, val
);
328 bitsize
= TYPE_FIELD_BITSIZE (struct_type
, fieldno
);
329 bitpos
= TYPE_FIELD_BITPOS (struct_type
, fieldno
);
330 addr
= value_contents_writeable (struct_val
) + bitpos
/ 8;
332 modify_field (struct_type
, addr
,
333 value_as_long (val
), bitpos
% 8, bitsize
);
335 memcpy (addr
, value_contents (val
),
336 TYPE_LENGTH (value_type (val
)));
342 /* Recursive helper function for setting elements of array tuples.
343 The target is ARRAY (which has bounds LOW_BOUND to HIGH_BOUND); the
344 element value is ELEMENT; EXP, POS and NOSIDE are as usual.
345 Evaluates index expressions and sets the specified element(s) of
346 ARRAY to ELEMENT. Returns last index value. */
349 init_array_element (struct value
*array
, struct value
*element
,
350 struct expression
*exp
, int *pos
,
351 enum noside noside
, LONGEST low_bound
, LONGEST high_bound
)
354 int element_size
= TYPE_LENGTH (value_type (element
));
356 if (exp
->elts
[*pos
].opcode
== BINOP_COMMA
)
359 init_array_element (array
, element
, exp
, pos
, noside
,
360 low_bound
, high_bound
);
361 return init_array_element (array
, element
,
362 exp
, pos
, noside
, low_bound
, high_bound
);
366 index
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
367 if (index
< low_bound
|| index
> high_bound
)
368 error (_("tuple index out of range"));
369 memcpy (value_contents_raw (array
) + (index
- low_bound
) * element_size
,
370 value_contents (element
), element_size
);
375 static struct value
*
376 value_f90_subarray (struct value
*array
,
377 struct expression
*exp
, int *pos
, enum noside noside
)
380 LONGEST low_bound
, high_bound
;
381 struct type
*range
= check_typedef (TYPE_INDEX_TYPE (value_type (array
)));
382 enum range_type range_type
383 = (enum range_type
) longest_to_int (exp
->elts
[pc
].longconst
);
387 if (range_type
== LOW_BOUND_DEFAULT
|| range_type
== BOTH_BOUND_DEFAULT
)
388 low_bound
= TYPE_LOW_BOUND (range
);
390 low_bound
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
392 if (range_type
== HIGH_BOUND_DEFAULT
|| range_type
== BOTH_BOUND_DEFAULT
)
393 high_bound
= TYPE_HIGH_BOUND (range
);
395 high_bound
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
397 return value_slice (array
, low_bound
, high_bound
- low_bound
+ 1);
401 /* Promote value ARG1 as appropriate before performing a unary operation
403 If the result is not appropriate for any particular language then it
404 needs to patch this function. */
407 unop_promote (const struct language_defn
*language
, struct gdbarch
*gdbarch
,
412 *arg1
= coerce_ref (*arg1
);
413 type1
= check_typedef (value_type (*arg1
));
415 if (is_integral_type (type1
))
417 switch (language
->la_language
)
420 /* Perform integral promotion for ANSI C/C++.
421 If not appropriate for any particular language
422 it needs to modify this function. */
424 struct type
*builtin_int
= builtin_type (gdbarch
)->builtin_int
;
426 if (TYPE_LENGTH (type1
) < TYPE_LENGTH (builtin_int
))
427 *arg1
= value_cast (builtin_int
, *arg1
);
434 /* Promote values ARG1 and ARG2 as appropriate before performing a binary
435 operation on those two operands.
436 If the result is not appropriate for any particular language then it
437 needs to patch this function. */
440 binop_promote (const struct language_defn
*language
, struct gdbarch
*gdbarch
,
441 struct value
**arg1
, struct value
**arg2
)
443 struct type
*promoted_type
= NULL
;
447 *arg1
= coerce_ref (*arg1
);
448 *arg2
= coerce_ref (*arg2
);
450 type1
= check_typedef (value_type (*arg1
));
451 type2
= check_typedef (value_type (*arg2
));
453 if ((TYPE_CODE (type1
) != TYPE_CODE_FLT
454 && TYPE_CODE (type1
) != TYPE_CODE_DECFLOAT
455 && !is_integral_type (type1
))
456 || (TYPE_CODE (type2
) != TYPE_CODE_FLT
457 && TYPE_CODE (type2
) != TYPE_CODE_DECFLOAT
458 && !is_integral_type (type2
)))
461 if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
462 || TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
)
464 /* No promotion required. */
466 else if (TYPE_CODE (type1
) == TYPE_CODE_FLT
467 || TYPE_CODE (type2
) == TYPE_CODE_FLT
)
469 switch (language
->la_language
)
475 case language_opencl
:
476 /* No promotion required. */
480 /* For other languages the result type is unchanged from gdb
481 version 6.7 for backward compatibility.
482 If either arg was long double, make sure that value is also long
483 double. Otherwise use double. */
484 if (TYPE_LENGTH (type1
) * 8 > gdbarch_double_bit (gdbarch
)
485 || TYPE_LENGTH (type2
) * 8 > gdbarch_double_bit (gdbarch
))
486 promoted_type
= builtin_type (gdbarch
)->builtin_long_double
;
488 promoted_type
= builtin_type (gdbarch
)->builtin_double
;
492 else if (TYPE_CODE (type1
) == TYPE_CODE_BOOL
493 && TYPE_CODE (type2
) == TYPE_CODE_BOOL
)
495 /* No promotion required. */
498 /* Integral operations here. */
499 /* FIXME: Also mixed integral/booleans, with result an integer. */
501 const struct builtin_type
*builtin
= builtin_type (gdbarch
);
502 unsigned int promoted_len1
= TYPE_LENGTH (type1
);
503 unsigned int promoted_len2
= TYPE_LENGTH (type2
);
504 int is_unsigned1
= TYPE_UNSIGNED (type1
);
505 int is_unsigned2
= TYPE_UNSIGNED (type2
);
506 unsigned int result_len
;
507 int unsigned_operation
;
509 /* Determine type length and signedness after promotion for
511 if (promoted_len1
< TYPE_LENGTH (builtin
->builtin_int
))
514 promoted_len1
= TYPE_LENGTH (builtin
->builtin_int
);
516 if (promoted_len2
< TYPE_LENGTH (builtin
->builtin_int
))
519 promoted_len2
= TYPE_LENGTH (builtin
->builtin_int
);
522 if (promoted_len1
> promoted_len2
)
524 unsigned_operation
= is_unsigned1
;
525 result_len
= promoted_len1
;
527 else if (promoted_len2
> promoted_len1
)
529 unsigned_operation
= is_unsigned2
;
530 result_len
= promoted_len2
;
534 unsigned_operation
= is_unsigned1
|| is_unsigned2
;
535 result_len
= promoted_len1
;
538 switch (language
->la_language
)
544 if (result_len
<= TYPE_LENGTH (builtin
->builtin_int
))
546 promoted_type
= (unsigned_operation
547 ? builtin
->builtin_unsigned_int
548 : builtin
->builtin_int
);
550 else if (result_len
<= TYPE_LENGTH (builtin
->builtin_long
))
552 promoted_type
= (unsigned_operation
553 ? builtin
->builtin_unsigned_long
554 : builtin
->builtin_long
);
558 promoted_type
= (unsigned_operation
559 ? builtin
->builtin_unsigned_long_long
560 : builtin
->builtin_long_long
);
563 case language_opencl
:
564 if (result_len
<= TYPE_LENGTH (lookup_signed_typename
569 ? lookup_unsigned_typename (language
, "int")
570 : lookup_signed_typename (language
, "int"));
572 else if (result_len
<= TYPE_LENGTH (lookup_signed_typename
577 ? lookup_unsigned_typename (language
, "long")
578 : lookup_signed_typename (language
,"long"));
582 /* For other languages the result type is unchanged from gdb
583 version 6.7 for backward compatibility.
584 If either arg was long long, make sure that value is also long
585 long. Otherwise use long. */
586 if (unsigned_operation
)
588 if (result_len
> gdbarch_long_bit (gdbarch
) / HOST_CHAR_BIT
)
589 promoted_type
= builtin
->builtin_unsigned_long_long
;
591 promoted_type
= builtin
->builtin_unsigned_long
;
595 if (result_len
> gdbarch_long_bit (gdbarch
) / HOST_CHAR_BIT
)
596 promoted_type
= builtin
->builtin_long_long
;
598 promoted_type
= builtin
->builtin_long
;
606 /* Promote both operands to common type. */
607 *arg1
= value_cast (promoted_type
, *arg1
);
608 *arg2
= value_cast (promoted_type
, *arg2
);
613 ptrmath_type_p (const struct language_defn
*lang
, struct type
*type
)
615 type
= check_typedef (type
);
616 if (TYPE_IS_REFERENCE (type
))
617 type
= TYPE_TARGET_TYPE (type
);
619 switch (TYPE_CODE (type
))
625 case TYPE_CODE_ARRAY
:
626 return TYPE_VECTOR (type
) ? 0 : lang
->c_style_arrays
;
633 /* Represents a fake method with the given parameter types. This is
634 used by the parser to construct a temporary "expected" type for
635 method overload resolution. FLAGS is used as instance flags of the
636 new type, in order to be able to make the new type represent a
637 const/volatile overload. */
642 fake_method (type_instance_flags flags
,
643 int num_types
, struct type
**param_types
);
646 /* The constructed type. */
647 struct type
*type () { return &m_type
; }
650 struct type m_type
{};
651 main_type m_main_type
{};
654 fake_method::fake_method (type_instance_flags flags
,
655 int num_types
, struct type
**param_types
)
657 struct type
*type
= &m_type
;
659 TYPE_MAIN_TYPE (type
) = &m_main_type
;
660 TYPE_LENGTH (type
) = 1;
661 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
662 TYPE_CHAIN (type
) = type
;
663 TYPE_INSTANCE_FLAGS (type
) = flags
;
666 if (param_types
[num_types
- 1] == NULL
)
669 TYPE_VARARGS (type
) = 1;
671 else if (TYPE_CODE (check_typedef (param_types
[num_types
- 1]))
675 /* Caller should have ensured this. */
676 gdb_assert (num_types
== 0);
677 TYPE_PROTOTYPED (type
) = 1;
681 /* We don't use TYPE_ZALLOC here to allocate space as TYPE is owned by
682 neither an objfile nor a gdbarch. As a result we must manually
683 allocate memory for auxiliary fields, and free the memory ourselves
684 when we are done with it. */
685 TYPE_NFIELDS (type
) = num_types
;
686 TYPE_FIELDS (type
) = (struct field
*)
687 xzalloc (sizeof (struct field
) * num_types
);
689 while (num_types
-- > 0)
690 TYPE_FIELD_TYPE (type
, num_types
) = param_types
[num_types
];
693 fake_method::~fake_method ()
695 xfree (TYPE_FIELDS (&m_type
));
698 /* Helper for evaluating an OP_VAR_VALUE. */
701 evaluate_var_value (enum noside noside
, const block
*blk
, symbol
*var
)
703 /* JYG: We used to just return value_zero of the symbol type if
704 we're asked to avoid side effects. Otherwise we return
705 value_of_variable (...). However I'm not sure if
706 value_of_variable () has any side effect. We need a full value
707 object returned here for whatis_exp () to call evaluate_type ()
708 and then pass the full value to value_rtti_target_type () if we
709 are dealing with a pointer or reference to a base class and print
712 struct value
*ret
= NULL
;
716 ret
= value_of_variable (var
, blk
);
719 catch (const gdb_exception_error
&except
)
721 if (noside
!= EVAL_AVOID_SIDE_EFFECTS
)
724 ret
= value_zero (SYMBOL_TYPE (var
), not_lval
);
730 /* Helper for evaluating an OP_VAR_MSYM_VALUE. */
733 evaluate_var_msym_value (enum noside noside
,
734 struct objfile
*objfile
, minimal_symbol
*msymbol
)
737 type
*the_type
= find_minsym_type_and_address (msymbol
, objfile
, &address
);
739 if (noside
== EVAL_AVOID_SIDE_EFFECTS
&& !TYPE_GNU_IFUNC (the_type
))
740 return value_zero (the_type
, not_lval
);
742 return value_at_lazy (the_type
, address
);
745 /* Helper for returning a value when handling EVAL_SKIP. */
748 eval_skip_value (expression
*exp
)
750 return value_from_longest (builtin_type (exp
->gdbarch
)->builtin_int
, 1);
753 /* Evaluate a function call. The function to be called is in
754 ARGVEC[0] and the arguments passed to the function are in
755 ARGVEC[1..NARGS]. FUNCTION_NAME is the name of the function, if
756 known. DEFAULT_RETURN_TYPE is used as the function's return type
757 if the return type is unknown. */
760 eval_call (expression
*exp
, enum noside noside
,
761 int nargs
, value
**argvec
,
762 const char *function_name
,
763 type
*default_return_type
)
765 if (argvec
[0] == NULL
)
766 error (_("Cannot evaluate function -- may be inlined"));
767 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
769 /* If the return type doesn't look like a function type,
770 call an error. This can happen if somebody tries to turn
771 a variable into a function call. */
773 type
*ftype
= value_type (argvec
[0]);
775 if (TYPE_CODE (ftype
) == TYPE_CODE_INTERNAL_FUNCTION
)
777 /* We don't know anything about what the internal
778 function might return, but we have to return
780 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
,
783 else if (TYPE_CODE (ftype
) == TYPE_CODE_XMETHOD
)
786 = result_type_of_xmethod (argvec
[0],
787 gdb::make_array_view (argvec
+ 1,
790 if (return_type
== NULL
)
791 error (_("Xmethod is missing return type."));
792 return value_zero (return_type
, not_lval
);
794 else if (TYPE_CODE (ftype
) == TYPE_CODE_FUNC
795 || TYPE_CODE (ftype
) == TYPE_CODE_METHOD
)
797 if (TYPE_GNU_IFUNC (ftype
))
799 CORE_ADDR address
= value_address (argvec
[0]);
800 type
*resolved_type
= find_gnu_ifunc_target_type (address
);
802 if (resolved_type
!= NULL
)
803 ftype
= resolved_type
;
806 type
*return_type
= TYPE_TARGET_TYPE (ftype
);
808 if (return_type
== NULL
)
809 return_type
= default_return_type
;
811 if (return_type
== NULL
)
812 error_call_unknown_return_type (function_name
);
814 return allocate_value (return_type
);
817 error (_("Expression of type other than "
818 "\"Function returning ...\" used as function"));
820 switch (TYPE_CODE (value_type (argvec
[0])))
822 case TYPE_CODE_INTERNAL_FUNCTION
:
823 return call_internal_function (exp
->gdbarch
, exp
->language_defn
,
824 argvec
[0], nargs
, argvec
+ 1);
825 case TYPE_CODE_XMETHOD
:
826 return call_xmethod (argvec
[0], gdb::make_array_view (argvec
+ 1, nargs
));
828 return call_function_by_hand (argvec
[0], default_return_type
,
829 gdb::make_array_view (argvec
+ 1, nargs
));
833 /* Helper for evaluating an OP_FUNCALL. */
836 evaluate_funcall (type
*expect_type
, expression
*exp
, int *pos
,
844 symbol
*function
= NULL
;
845 char *function_name
= NULL
;
846 const char *var_func_name
= NULL
;
851 exp_opcode op
= exp
->elts
[*pos
].opcode
;
852 int nargs
= longest_to_int (exp
->elts
[pc
].longconst
);
853 /* Allocate arg vector, including space for the function to be
854 called in argvec[0], a potential `this', and a terminating
856 value
**argvec
= (value
**) alloca (sizeof (value
*) * (nargs
+ 3));
857 if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
859 /* First, evaluate the structure into arg2. */
862 if (op
== STRUCTOP_MEMBER
)
864 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
868 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
871 /* If the function is a virtual function, then the aggregate
872 value (providing the structure) plays its part by providing
873 the vtable. Otherwise, it is just along for the ride: call
874 the function directly. */
876 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
878 type
*a1_type
= check_typedef (value_type (arg1
));
879 if (noside
== EVAL_SKIP
)
880 tem
= 1; /* Set it to the right arg index so that all
881 arguments can also be skipped. */
882 else if (TYPE_CODE (a1_type
) == TYPE_CODE_METHODPTR
)
884 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
885 arg1
= value_zero (TYPE_TARGET_TYPE (a1_type
), not_lval
);
887 arg1
= cplus_method_ptr_to_value (&arg2
, arg1
);
889 /* Now, say which argument to start evaluating from. */
894 else if (TYPE_CODE (a1_type
) == TYPE_CODE_MEMBERPTR
)
896 struct type
*type_ptr
897 = lookup_pointer_type (TYPE_SELF_TYPE (a1_type
));
898 struct type
*target_type_ptr
899 = lookup_pointer_type (TYPE_TARGET_TYPE (a1_type
));
901 /* Now, convert these values to an address. */
902 arg2
= value_cast (type_ptr
, arg2
);
904 long mem_offset
= value_as_long (arg1
);
906 arg1
= value_from_pointer (target_type_ptr
,
907 value_as_long (arg2
) + mem_offset
);
908 arg1
= value_ind (arg1
);
912 error (_("Non-pointer-to-member value used in pointer-to-member "
915 else if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
917 /* Hair for method invocations. */
921 /* First, evaluate the structure into arg2. */
923 tem2
= longest_to_int (exp
->elts
[pc2
+ 1].longconst
);
924 *pos
+= 3 + BYTES_TO_EXP_ELEM (tem2
+ 1);
926 if (op
== STRUCTOP_STRUCT
)
928 /* If v is a variable in a register, and the user types
929 v.method (), this will produce an error, because v has no
932 A possible way around this would be to allocate a copy of
933 the variable on the stack, copy in the contents, call the
934 function, and copy out the contents. I.e. convert this
935 from call by reference to call by copy-return (or
936 whatever it's called). However, this does not work
937 because it is not the same: the method being called could
938 stash a copy of the address, and then future uses through
939 that address (after the method returns) would be expected
940 to use the variable itself, not some copy of it. */
941 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
945 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
947 /* Check to see if the operator '->' has been overloaded.
948 If the operator has been overloaded replace arg2 with the
949 value returned by the custom operator and continue
951 while (unop_user_defined_p (op
, arg2
))
953 struct value
*value
= NULL
;
956 value
= value_x_unop (arg2
, op
, noside
);
959 catch (const gdb_exception_error
&except
)
961 if (except
.error
== NOT_FOUND_ERROR
)
970 /* Now, say which argument to start evaluating from. */
973 else if (op
== OP_SCOPE
974 && overload_resolution
975 && (exp
->language_defn
->la_language
== language_cplus
))
977 /* Unpack it locally so we can properly handle overload
983 local_tem
= longest_to_int (exp
->elts
[pc2
+ 2].longconst
);
984 (*pos
) += 4 + BYTES_TO_EXP_ELEM (local_tem
+ 1);
985 struct type
*type
= exp
->elts
[pc2
+ 1].type
;
986 name
= &exp
->elts
[pc2
+ 3].string
;
989 function_name
= NULL
;
990 if (TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
992 function
= cp_lookup_symbol_namespace (TYPE_NAME (type
),
994 get_selected_block (0),
996 if (function
== NULL
)
997 error (_("No symbol \"%s\" in namespace \"%s\"."),
998 name
, TYPE_NAME (type
));
1001 /* arg2 is left as NULL on purpose. */
1005 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_STRUCT
1006 || TYPE_CODE (type
) == TYPE_CODE_UNION
);
1007 function_name
= name
;
1009 /* We need a properly typed value for method lookup. For
1010 static methods arg2 is otherwise unused. */
1011 arg2
= value_zero (type
, lval_memory
);
1016 else if (op
== OP_ADL_FUNC
)
1018 /* Save the function position and move pos so that the arguments
1019 can be evaluated. */
1025 func_name_len
= longest_to_int (exp
->elts
[save_pos1
+ 3].longconst
);
1026 (*pos
) += 6 + BYTES_TO_EXP_ELEM (func_name_len
+ 1);
1030 /* Non-method function call. */
1034 /* If this is a C++ function wait until overload resolution. */
1035 if (op
== OP_VAR_VALUE
1036 && overload_resolution
1037 && (exp
->language_defn
->la_language
== language_cplus
))
1039 (*pos
) += 4; /* Skip the evaluation of the symbol. */
1044 if (op
== OP_VAR_MSYM_VALUE
)
1046 minimal_symbol
*msym
= exp
->elts
[*pos
+ 2].msymbol
;
1047 var_func_name
= msym
->print_name ();
1049 else if (op
== OP_VAR_VALUE
)
1051 symbol
*sym
= exp
->elts
[*pos
+ 2].symbol
;
1052 var_func_name
= sym
->print_name ();
1055 argvec
[0] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1056 type
*type
= value_type (argvec
[0]);
1057 if (type
&& TYPE_CODE (type
) == TYPE_CODE_PTR
)
1058 type
= TYPE_TARGET_TYPE (type
);
1059 if (type
&& TYPE_CODE (type
) == TYPE_CODE_FUNC
)
1061 for (; tem
<= nargs
&& tem
<= TYPE_NFIELDS (type
); tem
++)
1063 argvec
[tem
] = evaluate_subexp (TYPE_FIELD_TYPE (type
,
1071 /* Evaluate arguments (if not already done, e.g., namespace::func()
1072 and overload-resolution is off). */
1073 for (; tem
<= nargs
; tem
++)
1075 /* Ensure that array expressions are coerced into pointer
1077 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1080 /* Signal end of arglist. */
1083 if (noside
== EVAL_SKIP
)
1084 return eval_skip_value (exp
);
1086 if (op
== OP_ADL_FUNC
)
1088 struct symbol
*symp
;
1091 int string_pc
= save_pos1
+ 3;
1093 /* Extract the function name. */
1094 name_len
= longest_to_int (exp
->elts
[string_pc
].longconst
);
1095 func_name
= (char *) alloca (name_len
+ 1);
1096 strcpy (func_name
, &exp
->elts
[string_pc
+ 1].string
);
1098 find_overload_match (gdb::make_array_view (&argvec
[1], nargs
),
1100 NON_METHOD
, /* not method */
1101 NULL
, NULL
, /* pass NULL symbol since
1102 symbol is unknown */
1103 NULL
, &symp
, NULL
, 0, noside
);
1105 /* Now fix the expression being evaluated. */
1106 exp
->elts
[save_pos1
+ 2].symbol
= symp
;
1107 argvec
[0] = evaluate_subexp_with_coercion (exp
, &save_pos1
, noside
);
1110 if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
1111 || (op
== OP_SCOPE
&& function_name
!= NULL
))
1113 int static_memfuncp
;
1116 /* Method invocation: stuff "this" as first parameter. If the
1117 method turns out to be static we undo this below. */
1122 /* Name of method from expression. */
1123 tstr
= &exp
->elts
[pc2
+ 2].string
;
1126 tstr
= function_name
;
1128 if (overload_resolution
&& (exp
->language_defn
->la_language
1131 /* Language is C++, do some overload resolution before
1133 struct value
*valp
= NULL
;
1135 (void) find_overload_match (gdb::make_array_view (&argvec
[1], nargs
),
1137 METHOD
, /* method */
1138 &arg2
, /* the object */
1140 &static_memfuncp
, 0, noside
);
1142 if (op
== OP_SCOPE
&& !static_memfuncp
)
1144 /* For the time being, we don't handle this. */
1145 error (_("Call to overloaded function %s requires "
1149 argvec
[1] = arg2
; /* the ``this'' pointer */
1150 argvec
[0] = valp
; /* Use the method found after overload
1154 /* Non-C++ case -- or no overload resolution. */
1156 struct value
*temp
= arg2
;
1158 argvec
[0] = value_struct_elt (&temp
, argvec
+ 1, tstr
,
1160 op
== STRUCTOP_STRUCT
1161 ? "structure" : "structure pointer");
1162 /* value_struct_elt updates temp with the correct value of
1163 the ``this'' pointer if necessary, so modify argvec[1] to
1164 reflect any ``this'' changes. */
1166 = value_from_longest (lookup_pointer_type(value_type (temp
)),
1167 value_address (temp
)
1168 + value_embedded_offset (temp
));
1169 argvec
[1] = arg2
; /* the ``this'' pointer */
1172 /* Take out `this' if needed. */
1173 if (static_memfuncp
)
1175 argvec
[1] = argvec
[0];
1180 else if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
1182 /* Pointer to member. argvec[1] is already set up. */
1185 else if (op
== OP_VAR_VALUE
|| (op
== OP_SCOPE
&& function
!= NULL
))
1187 /* Non-member function being called. */
1188 /* fn: This can only be done for C++ functions. A C-style
1189 function in a C++ program, for instance, does not have the
1190 fields that are expected here. */
1192 if (overload_resolution
&& (exp
->language_defn
->la_language
1195 /* Language is C++, do some overload resolution before
1197 struct symbol
*symp
;
1200 /* If a scope has been specified disable ADL. */
1204 if (op
== OP_VAR_VALUE
)
1205 function
= exp
->elts
[save_pos1
+2].symbol
;
1207 (void) find_overload_match (gdb::make_array_view (&argvec
[1], nargs
),
1208 NULL
, /* no need for name */
1209 NON_METHOD
, /* not method */
1210 NULL
, function
, /* the function */
1211 NULL
, &symp
, NULL
, no_adl
, noside
);
1213 if (op
== OP_VAR_VALUE
)
1215 /* Now fix the expression being evaluated. */
1216 exp
->elts
[save_pos1
+2].symbol
= symp
;
1217 argvec
[0] = evaluate_subexp_with_coercion (exp
, &save_pos1
,
1221 argvec
[0] = value_of_variable (symp
, get_selected_block (0));
1225 /* Not C++, or no overload resolution allowed. */
1226 /* Nothing to be done; argvec already correctly set up. */
1231 /* It is probably a C-style function. */
1232 /* Nothing to be done; argvec already correctly set up. */
1235 return eval_call (exp
, noside
, nargs
, argvec
, var_func_name
, expect_type
);
1238 /* Helper for skipping all the arguments in an undetermined argument list.
1239 This function was designed for use in the OP_F77_UNDETERMINED_ARGLIST
1240 case of evaluate_subexp_standard as multiple, but not all, code paths
1241 require a generic skip. */
1244 skip_undetermined_arglist (int nargs
, struct expression
*exp
, int *pos
,
1247 for (int i
= 0; i
< nargs
; ++i
)
1248 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1252 evaluate_subexp_standard (struct type
*expect_type
,
1253 struct expression
*exp
, int *pos
,
1257 int tem
, tem2
, tem3
;
1259 struct value
*arg1
= NULL
;
1260 struct value
*arg2
= NULL
;
1264 struct value
**argvec
;
1268 struct type
**arg_types
;
1271 op
= exp
->elts
[pc
].opcode
;
1276 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
1277 (*pos
) += 4 + BYTES_TO_EXP_ELEM (tem
+ 1);
1278 if (noside
== EVAL_SKIP
)
1279 return eval_skip_value (exp
);
1280 arg1
= value_aggregate_elt (exp
->elts
[pc
+ 1].type
,
1281 &exp
->elts
[pc
+ 3].string
,
1282 expect_type
, 0, noside
);
1284 error (_("There is no field named %s"), &exp
->elts
[pc
+ 3].string
);
1289 return value_from_longest (exp
->elts
[pc
+ 1].type
,
1290 exp
->elts
[pc
+ 2].longconst
);
1294 return value_from_contents (exp
->elts
[pc
+ 1].type
,
1295 exp
->elts
[pc
+ 2].floatconst
);
1301 symbol
*var
= exp
->elts
[pc
+ 2].symbol
;
1302 if (TYPE_CODE (SYMBOL_TYPE (var
)) == TYPE_CODE_ERROR
)
1303 error_unknown_type (var
->print_name ());
1304 if (noside
!= EVAL_SKIP
)
1305 return evaluate_var_value (noside
, exp
->elts
[pc
+ 1].block
, var
);
1308 /* Return a dummy value of the correct type when skipping, so
1309 that parent functions know what is to be skipped. */
1310 return allocate_value (SYMBOL_TYPE (var
));
1314 case OP_VAR_MSYM_VALUE
:
1318 minimal_symbol
*msymbol
= exp
->elts
[pc
+ 2].msymbol
;
1319 value
*val
= evaluate_var_msym_value (noside
,
1320 exp
->elts
[pc
+ 1].objfile
,
1323 type
= value_type (val
);
1324 if (TYPE_CODE (type
) == TYPE_CODE_ERROR
1325 && (noside
!= EVAL_AVOID_SIDE_EFFECTS
|| pc
!= 0))
1326 error_unknown_type (msymbol
->print_name ());
1330 case OP_VAR_ENTRY_VALUE
:
1332 if (noside
== EVAL_SKIP
)
1333 return eval_skip_value (exp
);
1336 struct symbol
*sym
= exp
->elts
[pc
+ 1].symbol
;
1337 struct frame_info
*frame
;
1339 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1340 return value_zero (SYMBOL_TYPE (sym
), not_lval
);
1342 if (SYMBOL_COMPUTED_OPS (sym
) == NULL
1343 || SYMBOL_COMPUTED_OPS (sym
)->read_variable_at_entry
== NULL
)
1344 error (_("Symbol \"%s\" does not have any specific entry value"),
1345 sym
->print_name ());
1347 frame
= get_selected_frame (NULL
);
1348 return SYMBOL_COMPUTED_OPS (sym
)->read_variable_at_entry (sym
, frame
);
1351 case OP_FUNC_STATIC_VAR
:
1352 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1353 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1354 if (noside
== EVAL_SKIP
)
1355 return eval_skip_value (exp
);
1358 value
*func
= evaluate_subexp_standard (NULL
, exp
, pos
, noside
);
1359 CORE_ADDR addr
= value_address (func
);
1361 const block
*blk
= block_for_pc (addr
);
1362 const char *var
= &exp
->elts
[pc
+ 2].string
;
1364 struct block_symbol sym
= lookup_symbol (var
, blk
, VAR_DOMAIN
, NULL
);
1366 if (sym
.symbol
== NULL
)
1367 error (_("No symbol \"%s\" in specified context."), var
);
1369 return evaluate_var_value (noside
, sym
.block
, sym
.symbol
);
1375 access_value_history (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
1379 const char *name
= &exp
->elts
[pc
+ 2].string
;
1383 (*pos
) += 3 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
1384 regno
= user_reg_map_name_to_regnum (exp
->gdbarch
,
1385 name
, strlen (name
));
1387 error (_("Register $%s not available."), name
);
1389 /* In EVAL_AVOID_SIDE_EFFECTS mode, we only need to return
1390 a value with the appropriate register type. Unfortunately,
1391 we don't have easy access to the type of user registers.
1392 So for these registers, we fetch the register value regardless
1393 of the evaluation mode. */
1394 if (noside
== EVAL_AVOID_SIDE_EFFECTS
1395 && regno
< gdbarch_num_cooked_regs (exp
->gdbarch
))
1396 val
= value_zero (register_type (exp
->gdbarch
, regno
), not_lval
);
1398 val
= value_of_register (regno
, get_selected_frame (NULL
));
1400 error (_("Value of register %s not available."), name
);
1406 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
1407 return value_from_longest (type
, exp
->elts
[pc
+ 1].longconst
);
1409 case OP_INTERNALVAR
:
1411 return value_of_internalvar (exp
->gdbarch
,
1412 exp
->elts
[pc
+ 1].internalvar
);
1415 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1416 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1417 if (noside
== EVAL_SKIP
)
1418 return eval_skip_value (exp
);
1419 type
= language_string_char_type (exp
->language_defn
, exp
->gdbarch
);
1420 return value_string (&exp
->elts
[pc
+ 2].string
, tem
, type
);
1422 case OP_OBJC_NSSTRING
: /* Objective C Foundation Class
1423 NSString constant. */
1424 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1425 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1426 if (noside
== EVAL_SKIP
)
1427 return eval_skip_value (exp
);
1428 return value_nsstring (exp
->gdbarch
, &exp
->elts
[pc
+ 2].string
, tem
+ 1);
1432 tem2
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1433 tem3
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
1434 nargs
= tem3
- tem2
+ 1;
1435 type
= expect_type
? check_typedef (expect_type
) : NULL_TYPE
;
1437 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
1438 && TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
1440 struct value
*rec
= allocate_value (expect_type
);
1442 memset (value_contents_raw (rec
), '\0', TYPE_LENGTH (type
));
1443 return evaluate_struct_tuple (rec
, exp
, pos
, noside
, nargs
);
1446 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
1447 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
1449 struct type
*range_type
= TYPE_INDEX_TYPE (type
);
1450 struct type
*element_type
= TYPE_TARGET_TYPE (type
);
1451 struct value
*array
= allocate_value (expect_type
);
1452 int element_size
= TYPE_LENGTH (check_typedef (element_type
));
1453 LONGEST low_bound
, high_bound
, index
;
1455 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
1458 high_bound
= (TYPE_LENGTH (type
) / element_size
) - 1;
1461 memset (value_contents_raw (array
), 0, TYPE_LENGTH (expect_type
));
1462 for (tem
= nargs
; --nargs
>= 0;)
1464 struct value
*element
;
1467 element
= evaluate_subexp (element_type
, exp
, pos
, noside
);
1468 if (value_type (element
) != element_type
)
1469 element
= value_cast (element_type
, element
);
1472 int continue_pc
= *pos
;
1475 index
= init_array_element (array
, element
, exp
, pos
, noside
,
1476 low_bound
, high_bound
);
1481 if (index
> high_bound
)
1482 /* To avoid memory corruption. */
1483 error (_("Too many array elements"));
1484 memcpy (value_contents_raw (array
)
1485 + (index
- low_bound
) * element_size
,
1486 value_contents (element
),
1494 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
1495 && TYPE_CODE (type
) == TYPE_CODE_SET
)
1497 struct value
*set
= allocate_value (expect_type
);
1498 gdb_byte
*valaddr
= value_contents_raw (set
);
1499 struct type
*element_type
= TYPE_INDEX_TYPE (type
);
1500 struct type
*check_type
= element_type
;
1501 LONGEST low_bound
, high_bound
;
1503 /* Get targettype of elementtype. */
1504 while (TYPE_CODE (check_type
) == TYPE_CODE_RANGE
1505 || TYPE_CODE (check_type
) == TYPE_CODE_TYPEDEF
)
1506 check_type
= TYPE_TARGET_TYPE (check_type
);
1508 if (get_discrete_bounds (element_type
, &low_bound
, &high_bound
) < 0)
1509 error (_("(power)set type with unknown size"));
1510 memset (valaddr
, '\0', TYPE_LENGTH (type
));
1511 for (tem
= 0; tem
< nargs
; tem
++)
1513 LONGEST range_low
, range_high
;
1514 struct type
*range_low_type
, *range_high_type
;
1515 struct value
*elem_val
;
1517 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
1518 range_low_type
= range_high_type
= value_type (elem_val
);
1519 range_low
= range_high
= value_as_long (elem_val
);
1521 /* Check types of elements to avoid mixture of elements from
1522 different types. Also check if type of element is "compatible"
1523 with element type of powerset. */
1524 if (TYPE_CODE (range_low_type
) == TYPE_CODE_RANGE
)
1525 range_low_type
= TYPE_TARGET_TYPE (range_low_type
);
1526 if (TYPE_CODE (range_high_type
) == TYPE_CODE_RANGE
)
1527 range_high_type
= TYPE_TARGET_TYPE (range_high_type
);
1528 if ((TYPE_CODE (range_low_type
) != TYPE_CODE (range_high_type
))
1529 || (TYPE_CODE (range_low_type
) == TYPE_CODE_ENUM
1530 && (range_low_type
!= range_high_type
)))
1531 /* different element modes. */
1532 error (_("POWERSET tuple elements of different mode"));
1533 if ((TYPE_CODE (check_type
) != TYPE_CODE (range_low_type
))
1534 || (TYPE_CODE (check_type
) == TYPE_CODE_ENUM
1535 && range_low_type
!= check_type
))
1536 error (_("incompatible POWERSET tuple elements"));
1537 if (range_low
> range_high
)
1539 warning (_("empty POWERSET tuple range"));
1542 if (range_low
< low_bound
|| range_high
> high_bound
)
1543 error (_("POWERSET tuple element out of range"));
1544 range_low
-= low_bound
;
1545 range_high
-= low_bound
;
1546 for (; range_low
<= range_high
; range_low
++)
1548 int bit_index
= (unsigned) range_low
% TARGET_CHAR_BIT
;
1550 if (gdbarch_byte_order (exp
->gdbarch
) == BFD_ENDIAN_BIG
)
1551 bit_index
= TARGET_CHAR_BIT
- 1 - bit_index
;
1552 valaddr
[(unsigned) range_low
/ TARGET_CHAR_BIT
]
1559 argvec
= XALLOCAVEC (struct value
*, nargs
);
1560 for (tem
= 0; tem
< nargs
; tem
++)
1562 /* Ensure that array expressions are coerced into pointer
1564 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1566 if (noside
== EVAL_SKIP
)
1567 return eval_skip_value (exp
);
1568 return value_array (tem2
, tem3
, argvec
);
1572 struct value
*array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1574 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1576 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1578 if (noside
== EVAL_SKIP
)
1579 return eval_skip_value (exp
);
1580 return value_slice (array
, lowbound
, upper
- lowbound
+ 1);
1584 /* Skip third and second args to evaluate the first one. */
1585 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1586 if (value_logical_not (arg1
))
1588 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1589 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1593 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1594 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1598 case OP_OBJC_SELECTOR
:
1599 { /* Objective C @selector operator. */
1600 char *sel
= &exp
->elts
[pc
+ 2].string
;
1601 int len
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1602 struct type
*selector_type
;
1604 (*pos
) += 3 + BYTES_TO_EXP_ELEM (len
+ 1);
1605 if (noside
== EVAL_SKIP
)
1606 return eval_skip_value (exp
);
1609 sel
[len
] = 0; /* Make sure it's terminated. */
1611 selector_type
= builtin_type (exp
->gdbarch
)->builtin_data_ptr
;
1612 return value_from_longest (selector_type
,
1613 lookup_child_selector (exp
->gdbarch
, sel
));
1616 case OP_OBJC_MSGCALL
:
1617 { /* Objective C message (method) call. */
1619 CORE_ADDR responds_selector
= 0;
1620 CORE_ADDR method_selector
= 0;
1622 CORE_ADDR selector
= 0;
1624 int struct_return
= 0;
1625 enum noside sub_no_side
= EVAL_NORMAL
;
1627 struct value
*msg_send
= NULL
;
1628 struct value
*msg_send_stret
= NULL
;
1629 int gnu_runtime
= 0;
1631 struct value
*target
= NULL
;
1632 struct value
*method
= NULL
;
1633 struct value
*called_method
= NULL
;
1635 struct type
*selector_type
= NULL
;
1636 struct type
*long_type
;
1638 struct value
*ret
= NULL
;
1641 selector
= exp
->elts
[pc
+ 1].longconst
;
1642 nargs
= exp
->elts
[pc
+ 2].longconst
;
1643 argvec
= XALLOCAVEC (struct value
*, nargs
+ 5);
1647 long_type
= builtin_type (exp
->gdbarch
)->builtin_long
;
1648 selector_type
= builtin_type (exp
->gdbarch
)->builtin_data_ptr
;
1650 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1651 sub_no_side
= EVAL_NORMAL
;
1653 sub_no_side
= noside
;
1655 target
= evaluate_subexp (selector_type
, exp
, pos
, sub_no_side
);
1657 if (value_as_long (target
) == 0)
1658 return value_from_longest (long_type
, 0);
1660 if (lookup_minimal_symbol ("objc_msg_lookup", 0, 0).minsym
)
1663 /* Find the method dispatch (Apple runtime) or method lookup
1664 (GNU runtime) function for Objective-C. These will be used
1665 to lookup the symbol information for the method. If we
1666 can't find any symbol information, then we'll use these to
1667 call the method, otherwise we can call the method
1668 directly. The msg_send_stret function is used in the special
1669 case of a method that returns a structure (Apple runtime
1673 type
= selector_type
;
1675 type
= lookup_function_type (type
);
1676 type
= lookup_pointer_type (type
);
1677 type
= lookup_function_type (type
);
1678 type
= lookup_pointer_type (type
);
1680 msg_send
= find_function_in_inferior ("objc_msg_lookup", NULL
);
1682 = find_function_in_inferior ("objc_msg_lookup", NULL
);
1684 msg_send
= value_from_pointer (type
, value_as_address (msg_send
));
1685 msg_send_stret
= value_from_pointer (type
,
1686 value_as_address (msg_send_stret
));
1690 msg_send
= find_function_in_inferior ("objc_msgSend", NULL
);
1691 /* Special dispatcher for methods returning structs. */
1693 = find_function_in_inferior ("objc_msgSend_stret", NULL
);
1696 /* Verify the target object responds to this method. The
1697 standard top-level 'Object' class uses a different name for
1698 the verification method than the non-standard, but more
1699 often used, 'NSObject' class. Make sure we check for both. */
1702 = lookup_child_selector (exp
->gdbarch
, "respondsToSelector:");
1703 if (responds_selector
== 0)
1705 = lookup_child_selector (exp
->gdbarch
, "respondsTo:");
1707 if (responds_selector
== 0)
1708 error (_("no 'respondsTo:' or 'respondsToSelector:' method"));
1711 = lookup_child_selector (exp
->gdbarch
, "methodForSelector:");
1712 if (method_selector
== 0)
1714 = lookup_child_selector (exp
->gdbarch
, "methodFor:");
1716 if (method_selector
== 0)
1717 error (_("no 'methodFor:' or 'methodForSelector:' method"));
1719 /* Call the verification method, to make sure that the target
1720 class implements the desired method. */
1722 argvec
[0] = msg_send
;
1724 argvec
[2] = value_from_longest (long_type
, responds_selector
);
1725 argvec
[3] = value_from_longest (long_type
, selector
);
1728 ret
= call_function_by_hand (argvec
[0], NULL
, {argvec
+ 1, 3});
1731 /* Function objc_msg_lookup returns a pointer. */
1733 ret
= call_function_by_hand (argvec
[0], NULL
, {argvec
+ 1, 3});
1735 if (value_as_long (ret
) == 0)
1736 error (_("Target does not respond to this message selector."));
1738 /* Call "methodForSelector:" method, to get the address of a
1739 function method that implements this selector for this
1740 class. If we can find a symbol at that address, then we
1741 know the return type, parameter types etc. (that's a good
1744 argvec
[0] = msg_send
;
1746 argvec
[2] = value_from_longest (long_type
, method_selector
);
1747 argvec
[3] = value_from_longest (long_type
, selector
);
1750 ret
= call_function_by_hand (argvec
[0], NULL
, {argvec
+ 1, 3});
1754 ret
= call_function_by_hand (argvec
[0], NULL
, {argvec
+ 1, 3});
1757 /* ret should now be the selector. */
1759 addr
= value_as_long (ret
);
1762 struct symbol
*sym
= NULL
;
1764 /* The address might point to a function descriptor;
1765 resolve it to the actual code address instead. */
1766 addr
= gdbarch_convert_from_func_ptr_addr (exp
->gdbarch
, addr
,
1767 current_top_target ());
1769 /* Is it a high_level symbol? */
1770 sym
= find_pc_function (addr
);
1772 method
= value_of_variable (sym
, 0);
1775 /* If we found a method with symbol information, check to see
1776 if it returns a struct. Otherwise assume it doesn't. */
1781 struct type
*val_type
;
1783 funaddr
= find_function_addr (method
, &val_type
);
1785 block_for_pc (funaddr
);
1787 val_type
= check_typedef (val_type
);
1789 if ((val_type
== NULL
)
1790 || (TYPE_CODE(val_type
) == TYPE_CODE_ERROR
))
1792 if (expect_type
!= NULL
)
1793 val_type
= expect_type
;
1796 struct_return
= using_struct_return (exp
->gdbarch
, method
,
1799 else if (expect_type
!= NULL
)
1801 struct_return
= using_struct_return (exp
->gdbarch
, NULL
,
1802 check_typedef (expect_type
));
1805 /* Found a function symbol. Now we will substitute its
1806 value in place of the message dispatcher (obj_msgSend),
1807 so that we call the method directly instead of thru
1808 the dispatcher. The main reason for doing this is that
1809 we can now evaluate the return value and parameter values
1810 according to their known data types, in case we need to
1811 do things like promotion, dereferencing, special handling
1812 of structs and doubles, etc.
1814 We want to use the type signature of 'method', but still
1815 jump to objc_msgSend() or objc_msgSend_stret() to better
1816 mimic the behavior of the runtime. */
1820 if (TYPE_CODE (value_type (method
)) != TYPE_CODE_FUNC
)
1821 error (_("method address has symbol information "
1822 "with non-function type; skipping"));
1824 /* Create a function pointer of the appropriate type, and
1825 replace its value with the value of msg_send or
1826 msg_send_stret. We must use a pointer here, as
1827 msg_send and msg_send_stret are of pointer type, and
1828 the representation may be different on systems that use
1829 function descriptors. */
1832 = value_from_pointer (lookup_pointer_type (value_type (method
)),
1833 value_as_address (msg_send_stret
));
1836 = value_from_pointer (lookup_pointer_type (value_type (method
)),
1837 value_as_address (msg_send
));
1842 called_method
= msg_send_stret
;
1844 called_method
= msg_send
;
1847 if (noside
== EVAL_SKIP
)
1848 return eval_skip_value (exp
);
1850 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1852 /* If the return type doesn't look like a function type,
1853 call an error. This can happen if somebody tries to
1854 turn a variable into a function call. This is here
1855 because people often want to call, eg, strcmp, which
1856 gdb doesn't know is a function. If gdb isn't asked for
1857 it's opinion (ie. through "whatis"), it won't offer
1860 struct type
*callee_type
= value_type (called_method
);
1862 if (callee_type
&& TYPE_CODE (callee_type
) == TYPE_CODE_PTR
)
1863 callee_type
= TYPE_TARGET_TYPE (callee_type
);
1864 callee_type
= TYPE_TARGET_TYPE (callee_type
);
1868 if ((TYPE_CODE (callee_type
) == TYPE_CODE_ERROR
) && expect_type
)
1869 return allocate_value (expect_type
);
1871 return allocate_value (callee_type
);
1874 error (_("Expression of type other than "
1875 "\"method returning ...\" used as a method"));
1878 /* Now depending on whether we found a symbol for the method,
1879 we will either call the runtime dispatcher or the method
1882 argvec
[0] = called_method
;
1884 argvec
[2] = value_from_longest (long_type
, selector
);
1885 /* User-supplied arguments. */
1886 for (tem
= 0; tem
< nargs
; tem
++)
1887 argvec
[tem
+ 3] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1888 argvec
[tem
+ 3] = 0;
1890 auto call_args
= gdb::make_array_view (argvec
+ 1, nargs
+ 2);
1892 if (gnu_runtime
&& (method
!= NULL
))
1894 /* Function objc_msg_lookup returns a pointer. */
1895 deprecated_set_value_type (argvec
[0],
1896 lookup_pointer_type (lookup_function_type (value_type (argvec
[0]))));
1897 argvec
[0] = call_function_by_hand (argvec
[0], NULL
, call_args
);
1900 return call_function_by_hand (argvec
[0], NULL
, call_args
);
1905 return evaluate_funcall (expect_type
, exp
, pos
, noside
);
1907 case OP_F77_UNDETERMINED_ARGLIST
:
1909 /* Remember that in F77, functions, substring ops and
1910 array subscript operations cannot be disambiguated
1911 at parse time. We have made all array subscript operations,
1912 substring operations as well as function calls come here
1913 and we now have to discover what the heck this thing actually was.
1914 If it is a function, we process just as if we got an OP_FUNCALL. */
1916 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1919 /* First determine the type code we are dealing with. */
1920 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1921 type
= check_typedef (value_type (arg1
));
1922 code
= TYPE_CODE (type
);
1924 if (code
== TYPE_CODE_PTR
)
1926 /* Fortran always passes variable to subroutines as pointer.
1927 So we need to look into its target type to see if it is
1928 array, string or function. If it is, we need to switch
1929 to the target value the original one points to. */
1930 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1932 if (TYPE_CODE (target_type
) == TYPE_CODE_ARRAY
1933 || TYPE_CODE (target_type
) == TYPE_CODE_STRING
1934 || TYPE_CODE (target_type
) == TYPE_CODE_FUNC
)
1936 arg1
= value_ind (arg1
);
1937 type
= check_typedef (value_type (arg1
));
1938 code
= TYPE_CODE (type
);
1944 case TYPE_CODE_ARRAY
:
1945 if (exp
->elts
[*pos
].opcode
== OP_RANGE
)
1946 return value_f90_subarray (arg1
, exp
, pos
, noside
);
1949 if (noside
== EVAL_SKIP
)
1951 skip_undetermined_arglist (nargs
, exp
, pos
, noside
);
1952 /* Return the dummy value with the correct type. */
1955 goto multi_f77_subscript
;
1958 case TYPE_CODE_STRING
:
1959 if (exp
->elts
[*pos
].opcode
== OP_RANGE
)
1960 return value_f90_subarray (arg1
, exp
, pos
, noside
);
1963 if (noside
== EVAL_SKIP
)
1965 skip_undetermined_arglist (nargs
, exp
, pos
, noside
);
1966 /* Return the dummy value with the correct type. */
1969 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1970 return value_subscript (arg1
, value_as_long (arg2
));
1974 case TYPE_CODE_FUNC
:
1975 case TYPE_CODE_INTERNAL_FUNCTION
:
1976 /* It's a function call. */
1977 /* Allocate arg vector, including space for the function to be
1978 called in argvec[0] and a terminating NULL. */
1979 argvec
= (struct value
**)
1980 alloca (sizeof (struct value
*) * (nargs
+ 2));
1983 for (; tem
<= nargs
; tem
++)
1985 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1986 /* Arguments in Fortran are passed by address. Coerce the
1987 arguments here rather than in value_arg_coerce as otherwise
1988 the call to malloc to place the non-lvalue parameters in
1989 target memory is hit by this Fortran specific logic. This
1990 results in malloc being called with a pointer to an integer
1991 followed by an attempt to malloc the arguments to malloc in
1992 target memory. Infinite recursion ensues. */
1993 if (code
== TYPE_CODE_PTR
|| code
== TYPE_CODE_FUNC
)
1996 = TYPE_FIELD_ARTIFICIAL (value_type (arg1
), tem
- 1);
1997 argvec
[tem
] = fortran_argument_convert (argvec
[tem
],
2001 argvec
[tem
] = 0; /* signal end of arglist */
2002 if (noside
== EVAL_SKIP
)
2003 return eval_skip_value (exp
);
2004 return eval_call (exp
, noside
, nargs
, argvec
, NULL
, expect_type
);
2007 error (_("Cannot perform substring on this type"));
2011 /* We have a complex number, There should be 2 floating
2012 point numbers that compose it. */
2014 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2015 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2017 return value_literal_complex (arg1
, arg2
, exp
->elts
[pc
+ 1].type
);
2019 case STRUCTOP_STRUCT
:
2020 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
2021 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
2022 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2023 if (noside
== EVAL_SKIP
)
2024 return eval_skip_value (exp
);
2025 arg3
= value_struct_elt (&arg1
, NULL
, &exp
->elts
[pc
+ 2].string
,
2027 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2028 arg3
= value_zero (value_type (arg3
), VALUE_LVAL (arg3
));
2032 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
2033 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
2034 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2035 if (noside
== EVAL_SKIP
)
2036 return eval_skip_value (exp
);
2038 /* Check to see if operator '->' has been overloaded. If so replace
2039 arg1 with the value returned by evaluating operator->(). */
2040 while (unop_user_defined_p (op
, arg1
))
2042 struct value
*value
= NULL
;
2045 value
= value_x_unop (arg1
, op
, noside
);
2048 catch (const gdb_exception_error
&except
)
2050 if (except
.error
== NOT_FOUND_ERROR
)
2059 /* JYG: if print object is on we need to replace the base type
2060 with rtti type in order to continue on with successful
2061 lookup of member / method only available in the rtti type. */
2063 struct type
*arg_type
= value_type (arg1
);
2064 struct type
*real_type
;
2065 int full
, using_enc
;
2067 struct value_print_options opts
;
2069 get_user_print_options (&opts
);
2070 if (opts
.objectprint
&& TYPE_TARGET_TYPE (arg_type
)
2071 && (TYPE_CODE (TYPE_TARGET_TYPE (arg_type
)) == TYPE_CODE_STRUCT
))
2073 real_type
= value_rtti_indirect_type (arg1
, &full
, &top
,
2076 arg1
= value_cast (real_type
, arg1
);
2080 arg3
= value_struct_elt (&arg1
, NULL
, &exp
->elts
[pc
+ 2].string
,
2081 NULL
, "structure pointer");
2082 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2083 arg3
= value_zero (value_type (arg3
), VALUE_LVAL (arg3
));
2086 case STRUCTOP_MEMBER
:
2088 if (op
== STRUCTOP_MEMBER
)
2089 arg1
= evaluate_subexp_for_address (exp
, pos
, noside
);
2091 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2093 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2095 if (noside
== EVAL_SKIP
)
2096 return eval_skip_value (exp
);
2098 type
= check_typedef (value_type (arg2
));
2099 switch (TYPE_CODE (type
))
2101 case TYPE_CODE_METHODPTR
:
2102 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2103 return value_zero (TYPE_TARGET_TYPE (type
), not_lval
);
2106 arg2
= cplus_method_ptr_to_value (&arg1
, arg2
);
2107 gdb_assert (TYPE_CODE (value_type (arg2
)) == TYPE_CODE_PTR
);
2108 return value_ind (arg2
);
2111 case TYPE_CODE_MEMBERPTR
:
2112 /* Now, convert these values to an address. */
2113 arg1
= value_cast_pointers (lookup_pointer_type (TYPE_SELF_TYPE (type
)),
2116 mem_offset
= value_as_long (arg2
);
2118 arg3
= value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
2119 value_as_long (arg1
) + mem_offset
);
2120 return value_ind (arg3
);
2123 error (_("non-pointer-to-member value used "
2124 "in pointer-to-member construct"));
2129 type_instance_flags flags
2130 = (type_instance_flag_value
) longest_to_int (exp
->elts
[pc
+ 1].longconst
);
2131 nargs
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
2132 arg_types
= (struct type
**) alloca (nargs
* sizeof (struct type
*));
2133 for (ix
= 0; ix
< nargs
; ++ix
)
2134 arg_types
[ix
] = exp
->elts
[pc
+ 2 + ix
+ 1].type
;
2136 fake_method
fake_expect_type (flags
, nargs
, arg_types
);
2137 *(pos
) += 4 + nargs
;
2138 return evaluate_subexp_standard (fake_expect_type
.type (), exp
, pos
,
2143 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2144 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2145 if (noside
== EVAL_SKIP
)
2146 return eval_skip_value (exp
);
2147 if (binop_user_defined_p (op
, arg1
, arg2
))
2148 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2150 return value_concat (arg1
, arg2
);
2153 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2154 /* Special-case assignments where the left-hand-side is a
2155 convenience variable -- in these, don't bother setting an
2156 expected type. This avoids a weird case where re-assigning a
2157 string or array to an internal variable could error with "Too
2158 many array elements". */
2159 arg2
= evaluate_subexp (VALUE_LVAL (arg1
) == lval_internalvar
2160 ? NULL_TYPE
: value_type (arg1
),
2163 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2165 if (binop_user_defined_p (op
, arg1
, arg2
))
2166 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2168 return value_assign (arg1
, arg2
);
2170 case BINOP_ASSIGN_MODIFY
:
2172 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2173 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2174 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2176 op
= exp
->elts
[pc
+ 1].opcode
;
2177 if (binop_user_defined_p (op
, arg1
, arg2
))
2178 return value_x_binop (arg1
, arg2
, BINOP_ASSIGN_MODIFY
, op
, noside
);
2179 else if (op
== BINOP_ADD
&& ptrmath_type_p (exp
->language_defn
,
2181 && is_integral_type (value_type (arg2
)))
2182 arg2
= value_ptradd (arg1
, value_as_long (arg2
));
2183 else if (op
== BINOP_SUB
&& ptrmath_type_p (exp
->language_defn
,
2185 && is_integral_type (value_type (arg2
)))
2186 arg2
= value_ptradd (arg1
, - value_as_long (arg2
));
2189 struct value
*tmp
= arg1
;
2191 /* For shift and integer exponentiation operations,
2192 only promote the first argument. */
2193 if ((op
== BINOP_LSH
|| op
== BINOP_RSH
|| op
== BINOP_EXP
)
2194 && is_integral_type (value_type (arg2
)))
2195 unop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
);
2197 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2199 arg2
= value_binop (tmp
, arg2
, op
);
2201 return value_assign (arg1
, arg2
);
2204 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2205 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2206 if (noside
== EVAL_SKIP
)
2207 return eval_skip_value (exp
);
2208 if (binop_user_defined_p (op
, arg1
, arg2
))
2209 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2210 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
2211 && is_integral_type (value_type (arg2
)))
2212 return value_ptradd (arg1
, value_as_long (arg2
));
2213 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg2
))
2214 && is_integral_type (value_type (arg1
)))
2215 return value_ptradd (arg2
, value_as_long (arg1
));
2218 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2219 return value_binop (arg1
, arg2
, BINOP_ADD
);
2223 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2224 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2225 if (noside
== EVAL_SKIP
)
2226 return eval_skip_value (exp
);
2227 if (binop_user_defined_p (op
, arg1
, arg2
))
2228 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2229 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
2230 && ptrmath_type_p (exp
->language_defn
, value_type (arg2
)))
2232 /* FIXME -- should be ptrdiff_t */
2233 type
= builtin_type (exp
->gdbarch
)->builtin_long
;
2234 return value_from_longest (type
, value_ptrdiff (arg1
, arg2
));
2236 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
2237 && is_integral_type (value_type (arg2
)))
2238 return value_ptradd (arg1
, - value_as_long (arg2
));
2241 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2242 return value_binop (arg1
, arg2
, BINOP_SUB
);
2253 case BINOP_BITWISE_AND
:
2254 case BINOP_BITWISE_IOR
:
2255 case BINOP_BITWISE_XOR
:
2256 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2257 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2258 if (noside
== EVAL_SKIP
)
2259 return eval_skip_value (exp
);
2260 if (binop_user_defined_p (op
, arg1
, arg2
))
2261 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2264 /* If EVAL_AVOID_SIDE_EFFECTS and we're dividing by zero,
2265 fudge arg2 to avoid division-by-zero, the caller is
2266 (theoretically) only looking for the type of the result. */
2267 if (noside
== EVAL_AVOID_SIDE_EFFECTS
2268 /* ??? Do we really want to test for BINOP_MOD here?
2269 The implementation of value_binop gives it a well-defined
2272 || op
== BINOP_INTDIV
2275 && value_logical_not (arg2
))
2277 struct value
*v_one
, *retval
;
2279 v_one
= value_one (value_type (arg2
));
2280 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &v_one
);
2281 retval
= value_binop (arg1
, v_one
, op
);
2286 /* For shift and integer exponentiation operations,
2287 only promote the first argument. */
2288 if ((op
== BINOP_LSH
|| op
== BINOP_RSH
|| op
== BINOP_EXP
)
2289 && is_integral_type (value_type (arg2
)))
2290 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2292 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2294 return value_binop (arg1
, arg2
, op
);
2298 case BINOP_SUBSCRIPT
:
2299 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2300 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2301 if (noside
== EVAL_SKIP
)
2302 return eval_skip_value (exp
);
2303 if (binop_user_defined_p (op
, arg1
, arg2
))
2304 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2307 /* If the user attempts to subscript something that is not an
2308 array or pointer type (like a plain int variable for example),
2309 then report this as an error. */
2311 arg1
= coerce_ref (arg1
);
2312 type
= check_typedef (value_type (arg1
));
2313 if (TYPE_CODE (type
) != TYPE_CODE_ARRAY
2314 && TYPE_CODE (type
) != TYPE_CODE_PTR
)
2316 if (TYPE_NAME (type
))
2317 error (_("cannot subscript something of type `%s'"),
2320 error (_("cannot subscript requested type"));
2323 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2324 return value_zero (TYPE_TARGET_TYPE (type
), VALUE_LVAL (arg1
));
2326 return value_subscript (arg1
, value_as_long (arg2
));
2328 case MULTI_SUBSCRIPT
:
2330 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
2331 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2334 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2335 /* FIXME: EVAL_SKIP handling may not be correct. */
2336 if (noside
== EVAL_SKIP
)
2340 return eval_skip_value (exp
);
2342 /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
2343 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2345 /* If the user attempts to subscript something that has no target
2346 type (like a plain int variable for example), then report this
2349 type
= TYPE_TARGET_TYPE (check_typedef (value_type (arg1
)));
2352 arg1
= value_zero (type
, VALUE_LVAL (arg1
));
2358 error (_("cannot subscript something of type `%s'"),
2359 TYPE_NAME (value_type (arg1
)));
2363 if (binop_user_defined_p (op
, arg1
, arg2
))
2365 arg1
= value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2369 arg1
= coerce_ref (arg1
);
2370 type
= check_typedef (value_type (arg1
));
2372 switch (TYPE_CODE (type
))
2375 case TYPE_CODE_ARRAY
:
2376 case TYPE_CODE_STRING
:
2377 arg1
= value_subscript (arg1
, value_as_long (arg2
));
2381 if (TYPE_NAME (type
))
2382 error (_("cannot subscript something of type `%s'"),
2385 error (_("cannot subscript requested type"));
2391 multi_f77_subscript
:
2393 LONGEST subscript_array
[MAX_FORTRAN_DIMS
];
2394 int ndimensions
= 1, i
;
2395 struct value
*array
= arg1
;
2397 if (nargs
> MAX_FORTRAN_DIMS
)
2398 error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS
);
2400 ndimensions
= calc_f77_array_dims (type
);
2402 if (nargs
!= ndimensions
)
2403 error (_("Wrong number of subscripts"));
2405 gdb_assert (nargs
> 0);
2407 /* Now that we know we have a legal array subscript expression
2408 let us actually find out where this element exists in the array. */
2410 /* Take array indices left to right. */
2411 for (i
= 0; i
< nargs
; i
++)
2413 /* Evaluate each subscript; it must be a legal integer in F77. */
2414 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2416 /* Fill in the subscript array. */
2418 subscript_array
[i
] = value_as_long (arg2
);
2421 /* Internal type of array is arranged right to left. */
2422 for (i
= nargs
; i
> 0; i
--)
2424 struct type
*array_type
= check_typedef (value_type (array
));
2425 LONGEST index
= subscript_array
[i
- 1];
2427 array
= value_subscripted_rvalue (array
, index
,
2428 f77_get_lowerbound (array_type
));
2434 case BINOP_LOGICAL_AND
:
2435 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2436 if (noside
== EVAL_SKIP
)
2438 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2439 return eval_skip_value (exp
);
2443 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2446 if (binop_user_defined_p (op
, arg1
, arg2
))
2448 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2449 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2453 tem
= value_logical_not (arg1
);
2454 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
2455 (tem
? EVAL_SKIP
: noside
));
2456 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2457 return value_from_longest (type
,
2458 (LONGEST
) (!tem
&& !value_logical_not (arg2
)));
2461 case BINOP_LOGICAL_OR
:
2462 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2463 if (noside
== EVAL_SKIP
)
2465 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2466 return eval_skip_value (exp
);
2470 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2473 if (binop_user_defined_p (op
, arg1
, arg2
))
2475 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2476 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2480 tem
= value_logical_not (arg1
);
2481 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
2482 (!tem
? EVAL_SKIP
: noside
));
2483 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2484 return value_from_longest (type
,
2485 (LONGEST
) (!tem
|| !value_logical_not (arg2
)));
2489 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2490 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2491 if (noside
== EVAL_SKIP
)
2492 return eval_skip_value (exp
);
2493 if (binop_user_defined_p (op
, arg1
, arg2
))
2495 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2499 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2500 tem
= value_equal (arg1
, arg2
);
2501 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2502 return value_from_longest (type
, (LONGEST
) tem
);
2505 case BINOP_NOTEQUAL
:
2506 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2507 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2508 if (noside
== EVAL_SKIP
)
2509 return eval_skip_value (exp
);
2510 if (binop_user_defined_p (op
, arg1
, arg2
))
2512 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2516 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2517 tem
= value_equal (arg1
, arg2
);
2518 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2519 return value_from_longest (type
, (LONGEST
) ! tem
);
2523 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2524 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2525 if (noside
== EVAL_SKIP
)
2526 return eval_skip_value (exp
);
2527 if (binop_user_defined_p (op
, arg1
, arg2
))
2529 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2533 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2534 tem
= value_less (arg1
, arg2
);
2535 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2536 return value_from_longest (type
, (LONGEST
) tem
);
2540 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2541 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2542 if (noside
== EVAL_SKIP
)
2543 return eval_skip_value (exp
);
2544 if (binop_user_defined_p (op
, arg1
, arg2
))
2546 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2550 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2551 tem
= value_less (arg2
, arg1
);
2552 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2553 return value_from_longest (type
, (LONGEST
) tem
);
2557 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2558 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2559 if (noside
== EVAL_SKIP
)
2560 return eval_skip_value (exp
);
2561 if (binop_user_defined_p (op
, arg1
, arg2
))
2563 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2567 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2568 tem
= value_less (arg2
, arg1
) || value_equal (arg1
, arg2
);
2569 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2570 return value_from_longest (type
, (LONGEST
) tem
);
2574 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2575 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2576 if (noside
== EVAL_SKIP
)
2577 return eval_skip_value (exp
);
2578 if (binop_user_defined_p (op
, arg1
, arg2
))
2580 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2584 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2585 tem
= value_less (arg1
, arg2
) || value_equal (arg1
, arg2
);
2586 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2587 return value_from_longest (type
, (LONGEST
) tem
);
2591 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2592 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2593 if (noside
== EVAL_SKIP
)
2594 return eval_skip_value (exp
);
2595 type
= check_typedef (value_type (arg2
));
2596 if (TYPE_CODE (type
) != TYPE_CODE_INT
2597 && TYPE_CODE (type
) != TYPE_CODE_ENUM
)
2598 error (_("Non-integral right operand for \"@\" operator."));
2599 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2601 return allocate_repeat_value (value_type (arg1
),
2602 longest_to_int (value_as_long (arg2
)));
2605 return value_repeat (arg1
, longest_to_int (value_as_long (arg2
)));
2608 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2609 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2612 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2613 if (noside
== EVAL_SKIP
)
2614 return eval_skip_value (exp
);
2615 if (unop_user_defined_p (op
, arg1
))
2616 return value_x_unop (arg1
, op
, noside
);
2619 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2620 return value_pos (arg1
);
2624 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2625 if (noside
== EVAL_SKIP
)
2626 return eval_skip_value (exp
);
2627 if (unop_user_defined_p (op
, arg1
))
2628 return value_x_unop (arg1
, op
, noside
);
2631 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2632 return value_neg (arg1
);
2635 case UNOP_COMPLEMENT
:
2636 /* C++: check for and handle destructor names. */
2638 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2639 if (noside
== EVAL_SKIP
)
2640 return eval_skip_value (exp
);
2641 if (unop_user_defined_p (UNOP_COMPLEMENT
, arg1
))
2642 return value_x_unop (arg1
, UNOP_COMPLEMENT
, noside
);
2645 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2646 return value_complement (arg1
);
2649 case UNOP_LOGICAL_NOT
:
2650 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2651 if (noside
== EVAL_SKIP
)
2652 return eval_skip_value (exp
);
2653 if (unop_user_defined_p (op
, arg1
))
2654 return value_x_unop (arg1
, op
, noside
);
2657 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2658 return value_from_longest (type
, (LONGEST
) value_logical_not (arg1
));
2662 if (expect_type
&& TYPE_CODE (expect_type
) == TYPE_CODE_PTR
)
2663 expect_type
= TYPE_TARGET_TYPE (check_typedef (expect_type
));
2664 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2665 type
= check_typedef (value_type (arg1
));
2666 if (TYPE_CODE (type
) == TYPE_CODE_METHODPTR
2667 || TYPE_CODE (type
) == TYPE_CODE_MEMBERPTR
)
2668 error (_("Attempt to dereference pointer "
2669 "to member without an object"));
2670 if (noside
== EVAL_SKIP
)
2671 return eval_skip_value (exp
);
2672 if (unop_user_defined_p (op
, arg1
))
2673 return value_x_unop (arg1
, op
, noside
);
2674 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2676 type
= check_typedef (value_type (arg1
));
2677 if (TYPE_CODE (type
) == TYPE_CODE_PTR
2678 || TYPE_IS_REFERENCE (type
)
2679 /* In C you can dereference an array to get the 1st elt. */
2680 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
2682 return value_zero (TYPE_TARGET_TYPE (type
),
2684 else if (TYPE_CODE (type
) == TYPE_CODE_INT
)
2685 /* GDB allows dereferencing an int. */
2686 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
,
2689 error (_("Attempt to take contents of a non-pointer value."));
2692 /* Allow * on an integer so we can cast it to whatever we want.
2693 This returns an int, which seems like the most C-like thing to
2694 do. "long long" variables are rare enough that
2695 BUILTIN_TYPE_LONGEST would seem to be a mistake. */
2696 if (TYPE_CODE (type
) == TYPE_CODE_INT
)
2697 return value_at_lazy (builtin_type (exp
->gdbarch
)->builtin_int
,
2698 (CORE_ADDR
) value_as_address (arg1
));
2699 return value_ind (arg1
);
2702 /* C++: check for and handle pointer to members. */
2704 if (noside
== EVAL_SKIP
)
2706 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
2707 return eval_skip_value (exp
);
2711 struct value
*retvalp
= evaluate_subexp_for_address (exp
, pos
,
2718 if (noside
== EVAL_SKIP
)
2720 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
2721 return eval_skip_value (exp
);
2723 return evaluate_subexp_for_sizeof (exp
, pos
, noside
);
2727 type
= value_type (evaluate_subexp (NULL_TYPE
, exp
, pos
,
2728 EVAL_AVOID_SIDE_EFFECTS
));
2729 /* FIXME: This should be size_t. */
2730 struct type
*size_type
= builtin_type (exp
->gdbarch
)->builtin_int
;
2731 ULONGEST align
= type_align (type
);
2733 error (_("could not determine alignment of type"));
2734 return value_from_longest (size_type
, align
);
2739 type
= exp
->elts
[pc
+ 1].type
;
2740 return evaluate_subexp_for_cast (exp
, pos
, noside
, type
);
2742 case UNOP_CAST_TYPE
:
2743 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2744 type
= value_type (arg1
);
2745 return evaluate_subexp_for_cast (exp
, pos
, noside
, type
);
2747 case UNOP_DYNAMIC_CAST
:
2748 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2749 type
= value_type (arg1
);
2750 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
2751 if (noside
== EVAL_SKIP
)
2752 return eval_skip_value (exp
);
2753 return value_dynamic_cast (type
, arg1
);
2755 case UNOP_REINTERPRET_CAST
:
2756 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2757 type
= value_type (arg1
);
2758 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
2759 if (noside
== EVAL_SKIP
)
2760 return eval_skip_value (exp
);
2761 return value_reinterpret_cast (type
, arg1
);
2765 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2766 if (noside
== EVAL_SKIP
)
2767 return eval_skip_value (exp
);
2768 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2769 return value_zero (exp
->elts
[pc
+ 1].type
, lval_memory
);
2771 return value_at_lazy (exp
->elts
[pc
+ 1].type
,
2772 value_as_address (arg1
));
2774 case UNOP_MEMVAL_TYPE
:
2775 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2776 type
= value_type (arg1
);
2777 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2778 if (noside
== EVAL_SKIP
)
2779 return eval_skip_value (exp
);
2780 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2781 return value_zero (type
, lval_memory
);
2783 return value_at_lazy (type
, value_as_address (arg1
));
2785 case UNOP_PREINCREMENT
:
2786 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2787 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2789 else if (unop_user_defined_p (op
, arg1
))
2791 return value_x_unop (arg1
, op
, noside
);
2795 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2796 arg2
= value_ptradd (arg1
, 1);
2799 struct value
*tmp
= arg1
;
2801 arg2
= value_one (value_type (arg1
));
2802 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2803 arg2
= value_binop (tmp
, arg2
, BINOP_ADD
);
2806 return value_assign (arg1
, arg2
);
2809 case UNOP_PREDECREMENT
:
2810 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2811 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2813 else if (unop_user_defined_p (op
, arg1
))
2815 return value_x_unop (arg1
, op
, noside
);
2819 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2820 arg2
= value_ptradd (arg1
, -1);
2823 struct value
*tmp
= arg1
;
2825 arg2
= value_one (value_type (arg1
));
2826 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2827 arg2
= value_binop (tmp
, arg2
, BINOP_SUB
);
2830 return value_assign (arg1
, arg2
);
2833 case UNOP_POSTINCREMENT
:
2834 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2835 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2837 else if (unop_user_defined_p (op
, arg1
))
2839 return value_x_unop (arg1
, op
, noside
);
2843 arg3
= value_non_lval (arg1
);
2845 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2846 arg2
= value_ptradd (arg1
, 1);
2849 struct value
*tmp
= arg1
;
2851 arg2
= value_one (value_type (arg1
));
2852 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2853 arg2
= value_binop (tmp
, arg2
, BINOP_ADD
);
2856 value_assign (arg1
, arg2
);
2860 case UNOP_POSTDECREMENT
:
2861 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2862 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2864 else if (unop_user_defined_p (op
, arg1
))
2866 return value_x_unop (arg1
, op
, noside
);
2870 arg3
= value_non_lval (arg1
);
2872 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2873 arg2
= value_ptradd (arg1
, -1);
2876 struct value
*tmp
= arg1
;
2878 arg2
= value_one (value_type (arg1
));
2879 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2880 arg2
= value_binop (tmp
, arg2
, BINOP_SUB
);
2883 value_assign (arg1
, arg2
);
2889 return value_of_this (exp
->language_defn
);
2892 /* The value is not supposed to be used. This is here to make it
2893 easier to accommodate expressions that contain types. */
2895 if (noside
== EVAL_SKIP
)
2896 return eval_skip_value (exp
);
2897 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2898 return allocate_value (exp
->elts
[pc
+ 1].type
);
2900 error (_("Attempt to use a type name as an expression"));
2904 if (noside
== EVAL_SKIP
)
2906 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
2907 return eval_skip_value (exp
);
2909 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2911 enum exp_opcode sub_op
= exp
->elts
[*pos
].opcode
;
2912 struct value
*result
;
2914 result
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
2915 EVAL_AVOID_SIDE_EFFECTS
);
2917 /* 'decltype' has special semantics for lvalues. */
2918 if (op
== OP_DECLTYPE
2919 && (sub_op
== BINOP_SUBSCRIPT
2920 || sub_op
== STRUCTOP_MEMBER
2921 || sub_op
== STRUCTOP_MPTR
2922 || sub_op
== UNOP_IND
2923 || sub_op
== STRUCTOP_STRUCT
2924 || sub_op
== STRUCTOP_PTR
2925 || sub_op
== OP_SCOPE
))
2927 type
= value_type (result
);
2929 if (!TYPE_IS_REFERENCE (type
))
2931 type
= lookup_lvalue_reference_type (type
);
2932 result
= allocate_value (type
);
2939 error (_("Attempt to use a type as an expression"));
2943 struct value
*result
;
2944 enum exp_opcode sub_op
= exp
->elts
[*pos
].opcode
;
2946 if (sub_op
== OP_TYPE
|| sub_op
== OP_DECLTYPE
|| sub_op
== OP_TYPEOF
)
2947 result
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
2948 EVAL_AVOID_SIDE_EFFECTS
);
2950 result
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2952 if (noside
!= EVAL_NORMAL
)
2953 return allocate_value (cplus_typeid_type (exp
->gdbarch
));
2955 return cplus_typeid (result
);
2959 /* Removing this case and compiling with gcc -Wall reveals that
2960 a lot of cases are hitting this case. Some of these should
2961 probably be removed from expression.h; others are legitimate
2962 expressions which are (apparently) not fully implemented.
2964 If there are any cases landing here which mean a user error,
2965 then they should be separate cases, with more descriptive
2968 error (_("GDB does not (yet) know how to "
2969 "evaluate that kind of expression"));
2972 gdb_assert_not_reached ("missed return?");
2975 /* Evaluate a subexpression of EXP, at index *POS,
2976 and return the address of that subexpression.
2977 Advance *POS over the subexpression.
2978 If the subexpression isn't an lvalue, get an error.
2979 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
2980 then only the type of the result need be correct. */
2982 static struct value
*
2983 evaluate_subexp_for_address (struct expression
*exp
, int *pos
,
2993 op
= exp
->elts
[pc
].opcode
;
2999 x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
3001 /* We can't optimize out "&*" if there's a user-defined operator*. */
3002 if (unop_user_defined_p (op
, x
))
3004 x
= value_x_unop (x
, op
, noside
);
3005 goto default_case_after_eval
;
3008 return coerce_array (x
);
3012 return value_cast (lookup_pointer_type (exp
->elts
[pc
+ 1].type
),
3013 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
3015 case UNOP_MEMVAL_TYPE
:
3020 x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3021 type
= value_type (x
);
3022 return value_cast (lookup_pointer_type (type
),
3023 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
3027 var
= exp
->elts
[pc
+ 2].symbol
;
3029 /* C++: The "address" of a reference should yield the address
3030 * of the object pointed to. Let value_addr() deal with it. */
3031 if (TYPE_IS_REFERENCE (SYMBOL_TYPE (var
)))
3035 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
3038 lookup_pointer_type (SYMBOL_TYPE (var
));
3039 enum address_class sym_class
= SYMBOL_CLASS (var
);
3041 if (sym_class
== LOC_CONST
3042 || sym_class
== LOC_CONST_BYTES
3043 || sym_class
== LOC_REGISTER
)
3044 error (_("Attempt to take address of register or constant."));
3047 value_zero (type
, not_lval
);
3050 return address_of_variable (var
, exp
->elts
[pc
+ 1].block
);
3052 case OP_VAR_MSYM_VALUE
:
3056 value
*val
= evaluate_var_msym_value (noside
,
3057 exp
->elts
[pc
+ 1].objfile
,
3058 exp
->elts
[pc
+ 2].msymbol
);
3059 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
3061 struct type
*type
= lookup_pointer_type (value_type (val
));
3062 return value_zero (type
, not_lval
);
3065 return value_addr (val
);
3069 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
3070 (*pos
) += 5 + BYTES_TO_EXP_ELEM (tem
+ 1);
3071 x
= value_aggregate_elt (exp
->elts
[pc
+ 1].type
,
3072 &exp
->elts
[pc
+ 3].string
,
3075 error (_("There is no field named %s"), &exp
->elts
[pc
+ 3].string
);
3080 x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
3081 default_case_after_eval
:
3082 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
3084 struct type
*type
= check_typedef (value_type (x
));
3086 if (TYPE_IS_REFERENCE (type
))
3087 return value_zero (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
3089 else if (VALUE_LVAL (x
) == lval_memory
|| value_must_coerce_to_target (x
))
3090 return value_zero (lookup_pointer_type (value_type (x
)),
3093 error (_("Attempt to take address of "
3094 "value not located in memory."));
3096 return value_addr (x
);
3100 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
3101 When used in contexts where arrays will be coerced anyway, this is
3102 equivalent to `evaluate_subexp' but much faster because it avoids
3103 actually fetching array contents (perhaps obsolete now that we have
3106 Note that we currently only do the coercion for C expressions, where
3107 arrays are zero based and the coercion is correct. For other languages,
3108 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
3109 to decide if coercion is appropriate. */
3112 evaluate_subexp_with_coercion (struct expression
*exp
,
3113 int *pos
, enum noside noside
)
3122 op
= exp
->elts
[pc
].opcode
;
3127 var
= exp
->elts
[pc
+ 2].symbol
;
3128 type
= check_typedef (SYMBOL_TYPE (var
));
3129 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
3130 && !TYPE_VECTOR (type
)
3131 && CAST_IS_CONVERSION (exp
->language_defn
))
3134 val
= address_of_variable (var
, exp
->elts
[pc
+ 1].block
);
3135 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
3141 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
3145 /* Evaluate a subexpression of EXP, at index *POS,
3146 and return a value for the size of that subexpression.
3147 Advance *POS over the subexpression. If NOSIDE is EVAL_NORMAL
3148 we allow side-effects on the operand if its type is a variable
3151 static struct value
*
3152 evaluate_subexp_for_sizeof (struct expression
*exp
, int *pos
,
3155 /* FIXME: This should be size_t. */
3156 struct type
*size_type
= builtin_type (exp
->gdbarch
)->builtin_int
;
3163 op
= exp
->elts
[pc
].opcode
;
3167 /* This case is handled specially
3168 so that we avoid creating a value for the result type.
3169 If the result type is very big, it's desirable not to
3170 create a value unnecessarily. */
3173 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3174 type
= check_typedef (value_type (val
));
3175 if (TYPE_CODE (type
) != TYPE_CODE_PTR
3176 && !TYPE_IS_REFERENCE (type
)
3177 && TYPE_CODE (type
) != TYPE_CODE_ARRAY
)
3178 error (_("Attempt to take contents of a non-pointer value."));
3179 type
= TYPE_TARGET_TYPE (type
);
3180 if (is_dynamic_type (type
))
3181 type
= value_type (value_ind (val
));
3182 return value_from_longest (size_type
, (LONGEST
) TYPE_LENGTH (type
));
3186 type
= exp
->elts
[pc
+ 1].type
;
3189 case UNOP_MEMVAL_TYPE
:
3191 val
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3192 type
= value_type (val
);
3196 type
= SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
);
3197 if (is_dynamic_type (type
))
3199 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_NORMAL
);
3200 type
= value_type (val
);
3201 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
3202 && is_dynamic_type (TYPE_INDEX_TYPE (type
))
3203 && TYPE_HIGH_BOUND_UNDEFINED (TYPE_INDEX_TYPE (type
)))
3204 return allocate_optimized_out_value (size_type
);
3210 case OP_VAR_MSYM_VALUE
:
3214 minimal_symbol
*msymbol
= exp
->elts
[pc
+ 2].msymbol
;
3215 value
*mval
= evaluate_var_msym_value (noside
,
3216 exp
->elts
[pc
+ 1].objfile
,
3219 type
= value_type (mval
);
3220 if (TYPE_CODE (type
) == TYPE_CODE_ERROR
)
3221 error_unknown_type (msymbol
->print_name ());
3223 return value_from_longest (size_type
, TYPE_LENGTH (type
));
3227 /* Deal with the special case if NOSIDE is EVAL_NORMAL and the resulting
3228 type of the subscript is a variable length array type. In this case we
3229 must re-evaluate the right hand side of the subscription to allow
3231 case BINOP_SUBSCRIPT
:
3232 if (noside
== EVAL_NORMAL
)
3234 int npc
= (*pos
) + 1;
3236 val
= evaluate_subexp (NULL_TYPE
, exp
, &npc
, EVAL_AVOID_SIDE_EFFECTS
);
3237 type
= check_typedef (value_type (val
));
3238 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
3240 type
= check_typedef (TYPE_TARGET_TYPE (type
));
3241 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
3243 type
= TYPE_INDEX_TYPE (type
);
3244 /* Only re-evaluate the right hand side if the resulting type
3245 is a variable length type. */
3246 if (TYPE_RANGE_DATA (type
)->flag_bound_evaluated
)
3248 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_NORMAL
);
3249 return value_from_longest
3250 (size_type
, (LONGEST
) TYPE_LENGTH (value_type (val
)));
3259 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3260 type
= value_type (val
);
3264 /* $5.3.3/2 of the C++ Standard (n3290 draft) says of sizeof:
3265 "When applied to a reference or a reference type, the result is
3266 the size of the referenced type." */
3267 type
= check_typedef (type
);
3268 if (exp
->language_defn
->la_language
== language_cplus
3269 && (TYPE_IS_REFERENCE (type
)))
3270 type
= check_typedef (TYPE_TARGET_TYPE (type
));
3271 return value_from_longest (size_type
, (LONGEST
) TYPE_LENGTH (type
));
3274 /* Evaluate a subexpression of EXP, at index *POS, and return a value
3275 for that subexpression cast to TO_TYPE. Advance *POS over the
3279 evaluate_subexp_for_cast (expression
*exp
, int *pos
,
3281 struct type
*to_type
)
3285 /* Don't let symbols be evaluated with evaluate_subexp because that
3286 throws an "unknown type" error for no-debug data symbols.
3287 Instead, we want the cast to reinterpret the symbol. */
3288 if (exp
->elts
[pc
].opcode
== OP_VAR_MSYM_VALUE
3289 || exp
->elts
[pc
].opcode
== OP_VAR_VALUE
)
3294 if (exp
->elts
[pc
].opcode
== OP_VAR_MSYM_VALUE
)
3296 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
3297 return value_zero (to_type
, not_lval
);
3299 val
= evaluate_var_msym_value (noside
,
3300 exp
->elts
[pc
+ 1].objfile
,
3301 exp
->elts
[pc
+ 2].msymbol
);
3304 val
= evaluate_var_value (noside
,
3305 exp
->elts
[pc
+ 1].block
,
3306 exp
->elts
[pc
+ 2].symbol
);
3308 if (noside
== EVAL_SKIP
)
3309 return eval_skip_value (exp
);
3311 val
= value_cast (to_type
, val
);
3313 /* Don't allow e.g. '&(int)var_with_no_debug_info'. */
3314 if (VALUE_LVAL (val
) == lval_memory
)
3316 if (value_lazy (val
))
3317 value_fetch_lazy (val
);
3318 VALUE_LVAL (val
) = not_lval
;
3323 value
*val
= evaluate_subexp (to_type
, exp
, pos
, noside
);
3324 if (noside
== EVAL_SKIP
)
3325 return eval_skip_value (exp
);
3326 return value_cast (to_type
, val
);
3329 /* Parse a type expression in the string [P..P+LENGTH). */
3332 parse_and_eval_type (char *p
, int length
)
3334 char *tmp
= (char *) alloca (length
+ 4);
3337 memcpy (tmp
+ 1, p
, length
);
3338 tmp
[length
+ 1] = ')';
3339 tmp
[length
+ 2] = '0';
3340 tmp
[length
+ 3] = '\0';
3341 expression_up expr
= parse_expression (tmp
);
3342 if (expr
->elts
[0].opcode
!= UNOP_CAST
)
3343 error (_("Internal error in eval_type."));
3344 return expr
->elts
[1].type
;
3348 calc_f77_array_dims (struct type
*array_type
)
3351 struct type
*tmp_type
;
3353 if ((TYPE_CODE (array_type
) != TYPE_CODE_ARRAY
))
3354 error (_("Can't get dimensions for a non-array type"));
3356 tmp_type
= array_type
;
3358 while ((tmp_type
= TYPE_TARGET_TYPE (tmp_type
)))
3360 if (TYPE_CODE (tmp_type
) == TYPE_CODE_ARRAY
)