1 /* Evaluate expressions for GDB.
3 Copyright (C) 1986-2015 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"
44 /* This is defined in valops.c */
45 extern int overload_resolution
;
47 /* Prototypes for local functions. */
49 static struct value
*evaluate_subexp_for_sizeof (struct expression
*, int *,
52 static struct value
*evaluate_subexp_for_address (struct expression
*,
55 static struct value
*evaluate_struct_tuple (struct value
*,
56 struct expression
*, int *,
59 static LONGEST
init_array_element (struct value
*, struct value
*,
60 struct expression
*, int *, enum noside
,
64 evaluate_subexp (struct type
*expect_type
, struct expression
*exp
,
65 int *pos
, enum noside noside
)
67 struct cleanup
*cleanups
;
69 int cleanup_temps
= 0;
71 if (*pos
== 0 && target_has_execution
72 && exp
->language_defn
->la_language
== language_cplus
73 && !thread_stack_temporaries_enabled_p (inferior_ptid
))
75 cleanups
= enable_thread_stack_temporaries (inferior_ptid
);
79 retval
= (*exp
->language_defn
->la_exp_desc
->evaluate_exp
)
80 (expect_type
, exp
, pos
, noside
);
84 if (value_in_thread_stack_temporaries (retval
, inferior_ptid
))
85 retval
= value_non_lval (retval
);
86 do_cleanups (cleanups
);
92 /* Parse the string EXP as a C expression, evaluate it,
93 and return the result as a number. */
96 parse_and_eval_address (const char *exp
)
98 struct expression
*expr
= parse_expression (exp
);
100 struct cleanup
*old_chain
=
101 make_cleanup (free_current_contents
, &expr
);
103 addr
= value_as_address (evaluate_expression (expr
));
104 do_cleanups (old_chain
);
108 /* Like parse_and_eval_address, but treats the value of the expression
109 as an integer, not an address, returns a LONGEST, not a CORE_ADDR. */
111 parse_and_eval_long (const char *exp
)
113 struct expression
*expr
= parse_expression (exp
);
115 struct cleanup
*old_chain
=
116 make_cleanup (free_current_contents
, &expr
);
118 retval
= value_as_long (evaluate_expression (expr
));
119 do_cleanups (old_chain
);
124 parse_and_eval (const char *exp
)
126 struct expression
*expr
= parse_expression (exp
);
128 struct cleanup
*old_chain
=
129 make_cleanup (free_current_contents
, &expr
);
131 val
= evaluate_expression (expr
);
132 do_cleanups (old_chain
);
136 /* Parse up to a comma (or to a closeparen)
137 in the string EXPP as an expression, evaluate it, and return the value.
138 EXPP is advanced to point to the comma. */
141 parse_to_comma_and_eval (const char **expp
)
143 struct expression
*expr
= parse_exp_1 (expp
, 0, (struct block
*) 0, 1);
145 struct cleanup
*old_chain
=
146 make_cleanup (free_current_contents
, &expr
);
148 val
= evaluate_expression (expr
);
149 do_cleanups (old_chain
);
153 /* Evaluate an expression in internal prefix form
154 such as is constructed by parse.y.
156 See expression.h for info on the format of an expression. */
159 evaluate_expression (struct expression
*exp
)
163 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_NORMAL
);
166 /* Evaluate an expression, avoiding all memory references
167 and getting a value whose type alone is correct. */
170 evaluate_type (struct expression
*exp
)
174 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_AVOID_SIDE_EFFECTS
);
177 /* Evaluate a subexpression, avoiding all memory references and
178 getting a value whose type alone is correct. */
181 evaluate_subexpression_type (struct expression
*exp
, int subexp
)
183 return evaluate_subexp (NULL_TYPE
, exp
, &subexp
, EVAL_AVOID_SIDE_EFFECTS
);
186 /* Find the current value of a watchpoint on EXP. Return the value in
187 *VALP and *RESULTP and the chain of intermediate and final values
188 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
191 If PRESERVE_ERRORS is true, then exceptions are passed through.
192 Otherwise, if PRESERVE_ERRORS is false, then if a memory error
193 occurs while evaluating the expression, *RESULTP will be set to
194 NULL. *RESULTP may be a lazy value, if the result could not be
195 read from memory. It is used to determine whether a value is
196 user-specified (we should watch the whole value) or intermediate
197 (we should watch only the bit used to locate the final value).
199 If the final value, or any intermediate value, could not be read
200 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
201 set to any referenced values. *VALP will never be a lazy value.
202 This is the value which we store in struct breakpoint.
204 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
205 value chain. The caller must free the values individually. If
206 VAL_CHAIN is NULL, all generated values will be left on the value
210 fetch_subexp_value (struct expression
*exp
, int *pc
, struct value
**valp
,
211 struct value
**resultp
, struct value
**val_chain
,
214 struct value
*mark
, *new_mark
, *result
;
215 volatile struct gdb_exception ex
;
223 /* Evaluate the expression. */
224 mark
= value_mark ();
227 TRY_CATCH (ex
, RETURN_MASK_ALL
)
229 result
= evaluate_subexp (NULL_TYPE
, exp
, pc
, EVAL_NORMAL
);
233 /* Ignore memory errors if we want watchpoints pointing at
234 inaccessible memory to still be created; otherwise, throw the
235 error to some higher catcher. */
239 if (!preserve_errors
)
242 throw_exception (ex
);
247 new_mark
= value_mark ();
248 if (mark
== new_mark
)
253 /* Make sure it's not lazy, so that after the target stops again we
254 have a non-lazy previous value to compare with. */
257 if (!value_lazy (result
))
261 volatile struct gdb_exception except
;
263 TRY_CATCH (except
, RETURN_MASK_ERROR
)
265 value_fetch_lazy (result
);
273 /* Return the chain of intermediate values. We use this to
274 decide which addresses to watch. */
275 *val_chain
= new_mark
;
276 value_release_to_mark (mark
);
280 /* Extract a field operation from an expression. If the subexpression
281 of EXP starting at *SUBEXP is not a structure dereference
282 operation, return NULL. Otherwise, return the name of the
283 dereferenced field, and advance *SUBEXP to point to the
284 subexpression of the left-hand-side of the dereference. This is
285 used when completing field names. */
288 extract_field_op (struct expression
*exp
, int *subexp
)
293 if (exp
->elts
[*subexp
].opcode
!= STRUCTOP_STRUCT
294 && exp
->elts
[*subexp
].opcode
!= STRUCTOP_PTR
)
296 tem
= longest_to_int (exp
->elts
[*subexp
+ 1].longconst
);
297 result
= &exp
->elts
[*subexp
+ 2].string
;
298 (*subexp
) += 1 + 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
302 /* This function evaluates brace-initializers (in C/C++) for
305 static struct value
*
306 evaluate_struct_tuple (struct value
*struct_val
,
307 struct expression
*exp
,
308 int *pos
, enum noside noside
, int nargs
)
310 struct type
*struct_type
= check_typedef (value_type (struct_val
));
311 struct type
*field_type
;
316 struct value
*val
= NULL
;
321 /* Skip static fields. */
322 while (fieldno
< TYPE_NFIELDS (struct_type
)
323 && field_is_static (&TYPE_FIELD (struct_type
,
326 if (fieldno
>= TYPE_NFIELDS (struct_type
))
327 error (_("too many initializers"));
328 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
329 if (TYPE_CODE (field_type
) == TYPE_CODE_UNION
330 && TYPE_FIELD_NAME (struct_type
, fieldno
)[0] == '0')
331 error (_("don't know which variant you want to set"));
333 /* Here, struct_type is the type of the inner struct,
334 while substruct_type is the type of the inner struct.
335 These are the same for normal structures, but a variant struct
336 contains anonymous union fields that contain substruct fields.
337 The value fieldno is the index of the top-level (normal or
338 anonymous union) field in struct_field, while the value
339 subfieldno is the index of the actual real (named inner) field
340 in substruct_type. */
342 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
344 val
= evaluate_subexp (field_type
, exp
, pos
, noside
);
346 /* Now actually set the field in struct_val. */
348 /* Assign val to field fieldno. */
349 if (value_type (val
) != field_type
)
350 val
= value_cast (field_type
, val
);
352 bitsize
= TYPE_FIELD_BITSIZE (struct_type
, fieldno
);
353 bitpos
= TYPE_FIELD_BITPOS (struct_type
, fieldno
);
354 addr
= value_contents_writeable (struct_val
) + bitpos
/ 8;
356 modify_field (struct_type
, addr
,
357 value_as_long (val
), bitpos
% 8, bitsize
);
359 memcpy (addr
, value_contents (val
),
360 TYPE_LENGTH (value_type (val
)));
366 /* Recursive helper function for setting elements of array tuples.
367 The target is ARRAY (which has bounds LOW_BOUND to HIGH_BOUND); the
368 element value is ELEMENT; EXP, POS and NOSIDE are as usual.
369 Evaluates index expresions and sets the specified element(s) of
370 ARRAY to ELEMENT. Returns last index value. */
373 init_array_element (struct value
*array
, struct value
*element
,
374 struct expression
*exp
, int *pos
,
375 enum noside noside
, LONGEST low_bound
, LONGEST high_bound
)
378 int element_size
= TYPE_LENGTH (value_type (element
));
380 if (exp
->elts
[*pos
].opcode
== BINOP_COMMA
)
383 init_array_element (array
, element
, exp
, pos
, noside
,
384 low_bound
, high_bound
);
385 return init_array_element (array
, element
,
386 exp
, pos
, noside
, low_bound
, high_bound
);
390 index
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
391 if (index
< low_bound
|| index
> high_bound
)
392 error (_("tuple index out of range"));
393 memcpy (value_contents_raw (array
) + (index
- low_bound
) * element_size
,
394 value_contents (element
), element_size
);
399 static struct value
*
400 value_f90_subarray (struct value
*array
,
401 struct expression
*exp
, int *pos
, enum noside noside
)
404 LONGEST low_bound
, high_bound
;
405 struct type
*range
= check_typedef (TYPE_INDEX_TYPE (value_type (array
)));
406 enum f90_range_type range_type
= longest_to_int (exp
->elts
[pc
].longconst
);
410 if (range_type
== LOW_BOUND_DEFAULT
|| range_type
== BOTH_BOUND_DEFAULT
)
411 low_bound
= TYPE_LOW_BOUND (range
);
413 low_bound
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
415 if (range_type
== HIGH_BOUND_DEFAULT
|| range_type
== BOTH_BOUND_DEFAULT
)
416 high_bound
= TYPE_HIGH_BOUND (range
);
418 high_bound
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
420 return value_slice (array
, low_bound
, high_bound
- low_bound
+ 1);
424 /* Promote value ARG1 as appropriate before performing a unary operation
426 If the result is not appropriate for any particular language then it
427 needs to patch this function. */
430 unop_promote (const struct language_defn
*language
, struct gdbarch
*gdbarch
,
435 *arg1
= coerce_ref (*arg1
);
436 type1
= check_typedef (value_type (*arg1
));
438 if (is_integral_type (type1
))
440 switch (language
->la_language
)
443 /* Perform integral promotion for ANSI C/C++.
444 If not appropropriate for any particular language
445 it needs to modify this function. */
447 struct type
*builtin_int
= builtin_type (gdbarch
)->builtin_int
;
449 if (TYPE_LENGTH (type1
) < TYPE_LENGTH (builtin_int
))
450 *arg1
= value_cast (builtin_int
, *arg1
);
457 /* Promote values ARG1 and ARG2 as appropriate before performing a binary
458 operation on those two operands.
459 If the result is not appropriate for any particular language then it
460 needs to patch this function. */
463 binop_promote (const struct language_defn
*language
, struct gdbarch
*gdbarch
,
464 struct value
**arg1
, struct value
**arg2
)
466 struct type
*promoted_type
= NULL
;
470 *arg1
= coerce_ref (*arg1
);
471 *arg2
= coerce_ref (*arg2
);
473 type1
= check_typedef (value_type (*arg1
));
474 type2
= check_typedef (value_type (*arg2
));
476 if ((TYPE_CODE (type1
) != TYPE_CODE_FLT
477 && TYPE_CODE (type1
) != TYPE_CODE_DECFLOAT
478 && !is_integral_type (type1
))
479 || (TYPE_CODE (type2
) != TYPE_CODE_FLT
480 && TYPE_CODE (type2
) != TYPE_CODE_DECFLOAT
481 && !is_integral_type (type2
)))
484 if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
485 || TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
)
487 /* No promotion required. */
489 else if (TYPE_CODE (type1
) == TYPE_CODE_FLT
490 || TYPE_CODE (type2
) == TYPE_CODE_FLT
)
492 switch (language
->la_language
)
498 case language_opencl
:
499 /* No promotion required. */
503 /* For other languages the result type is unchanged from gdb
504 version 6.7 for backward compatibility.
505 If either arg was long double, make sure that value is also long
506 double. Otherwise use double. */
507 if (TYPE_LENGTH (type1
) * 8 > gdbarch_double_bit (gdbarch
)
508 || TYPE_LENGTH (type2
) * 8 > gdbarch_double_bit (gdbarch
))
509 promoted_type
= builtin_type (gdbarch
)->builtin_long_double
;
511 promoted_type
= builtin_type (gdbarch
)->builtin_double
;
515 else if (TYPE_CODE (type1
) == TYPE_CODE_BOOL
516 && TYPE_CODE (type2
) == TYPE_CODE_BOOL
)
518 /* No promotion required. */
521 /* Integral operations here. */
522 /* FIXME: Also mixed integral/booleans, with result an integer. */
524 const struct builtin_type
*builtin
= builtin_type (gdbarch
);
525 unsigned int promoted_len1
= TYPE_LENGTH (type1
);
526 unsigned int promoted_len2
= TYPE_LENGTH (type2
);
527 int is_unsigned1
= TYPE_UNSIGNED (type1
);
528 int is_unsigned2
= TYPE_UNSIGNED (type2
);
529 unsigned int result_len
;
530 int unsigned_operation
;
532 /* Determine type length and signedness after promotion for
534 if (promoted_len1
< TYPE_LENGTH (builtin
->builtin_int
))
537 promoted_len1
= TYPE_LENGTH (builtin
->builtin_int
);
539 if (promoted_len2
< TYPE_LENGTH (builtin
->builtin_int
))
542 promoted_len2
= TYPE_LENGTH (builtin
->builtin_int
);
545 if (promoted_len1
> promoted_len2
)
547 unsigned_operation
= is_unsigned1
;
548 result_len
= promoted_len1
;
550 else if (promoted_len2
> promoted_len1
)
552 unsigned_operation
= is_unsigned2
;
553 result_len
= promoted_len2
;
557 unsigned_operation
= is_unsigned1
|| is_unsigned2
;
558 result_len
= promoted_len1
;
561 switch (language
->la_language
)
567 if (result_len
<= TYPE_LENGTH (builtin
->builtin_int
))
569 promoted_type
= (unsigned_operation
570 ? builtin
->builtin_unsigned_int
571 : builtin
->builtin_int
);
573 else if (result_len
<= TYPE_LENGTH (builtin
->builtin_long
))
575 promoted_type
= (unsigned_operation
576 ? builtin
->builtin_unsigned_long
577 : builtin
->builtin_long
);
581 promoted_type
= (unsigned_operation
582 ? builtin
->builtin_unsigned_long_long
583 : builtin
->builtin_long_long
);
586 case language_opencl
:
587 if (result_len
<= TYPE_LENGTH (lookup_signed_typename
588 (language
, gdbarch
, "int")))
592 ? lookup_unsigned_typename (language
, gdbarch
, "int")
593 : lookup_signed_typename (language
, gdbarch
, "int"));
595 else if (result_len
<= TYPE_LENGTH (lookup_signed_typename
596 (language
, gdbarch
, "long")))
600 ? lookup_unsigned_typename (language
, gdbarch
, "long")
601 : lookup_signed_typename (language
, gdbarch
,"long"));
605 /* For other languages the result type is unchanged from gdb
606 version 6.7 for backward compatibility.
607 If either arg was long long, make sure that value is also long
608 long. Otherwise use long. */
609 if (unsigned_operation
)
611 if (result_len
> gdbarch_long_bit (gdbarch
) / HOST_CHAR_BIT
)
612 promoted_type
= builtin
->builtin_unsigned_long_long
;
614 promoted_type
= builtin
->builtin_unsigned_long
;
618 if (result_len
> gdbarch_long_bit (gdbarch
) / HOST_CHAR_BIT
)
619 promoted_type
= builtin
->builtin_long_long
;
621 promoted_type
= builtin
->builtin_long
;
629 /* Promote both operands to common type. */
630 *arg1
= value_cast (promoted_type
, *arg1
);
631 *arg2
= value_cast (promoted_type
, *arg2
);
636 ptrmath_type_p (const struct language_defn
*lang
, struct type
*type
)
638 type
= check_typedef (type
);
639 if (TYPE_CODE (type
) == TYPE_CODE_REF
)
640 type
= TYPE_TARGET_TYPE (type
);
642 switch (TYPE_CODE (type
))
648 case TYPE_CODE_ARRAY
:
649 return TYPE_VECTOR (type
) ? 0 : lang
->c_style_arrays
;
656 /* Constructs a fake method with the given parameter types.
657 This function is used by the parser to construct an "expected"
658 type for method overload resolution. */
661 make_params (int num_types
, struct type
**param_types
)
663 struct type
*type
= XCNEW (struct type
);
664 TYPE_MAIN_TYPE (type
) = XCNEW (struct main_type
);
665 TYPE_LENGTH (type
) = 1;
666 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
667 TYPE_CHAIN (type
) = type
;
670 if (param_types
[num_types
- 1] == NULL
)
673 TYPE_VARARGS (type
) = 1;
675 else if (TYPE_CODE (check_typedef (param_types
[num_types
- 1]))
679 /* Caller should have ensured this. */
680 gdb_assert (num_types
== 0);
681 TYPE_PROTOTYPED (type
) = 1;
685 TYPE_NFIELDS (type
) = num_types
;
686 TYPE_FIELDS (type
) = (struct field
*)
687 TYPE_ZALLOC (type
, sizeof (struct field
) * num_types
);
689 while (num_types
-- > 0)
690 TYPE_FIELD_TYPE (type
, num_types
) = param_types
[num_types
];
696 evaluate_subexp_standard (struct type
*expect_type
,
697 struct expression
*exp
, int *pos
,
702 int pc
, pc2
= 0, oldpos
;
703 struct value
*arg1
= NULL
;
704 struct value
*arg2
= NULL
;
708 struct value
**argvec
;
712 struct type
**arg_types
;
714 struct symbol
*function
= NULL
;
715 char *function_name
= NULL
;
718 op
= exp
->elts
[pc
].opcode
;
723 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
724 (*pos
) += 4 + BYTES_TO_EXP_ELEM (tem
+ 1);
725 if (noside
== EVAL_SKIP
)
727 arg1
= value_aggregate_elt (exp
->elts
[pc
+ 1].type
,
728 &exp
->elts
[pc
+ 3].string
,
729 expect_type
, 0, noside
);
731 error (_("There is no field named %s"), &exp
->elts
[pc
+ 3].string
);
736 return value_from_longest (exp
->elts
[pc
+ 1].type
,
737 exp
->elts
[pc
+ 2].longconst
);
741 return value_from_double (exp
->elts
[pc
+ 1].type
,
742 exp
->elts
[pc
+ 2].doubleconst
);
746 return value_from_decfloat (exp
->elts
[pc
+ 1].type
,
747 exp
->elts
[pc
+ 2].decfloatconst
);
752 if (noside
== EVAL_SKIP
)
755 /* JYG: We used to just return value_zero of the symbol type
756 if we're asked to avoid side effects. Otherwise we return
757 value_of_variable (...). However I'm not sure if
758 value_of_variable () has any side effect.
759 We need a full value object returned here for whatis_exp ()
760 to call evaluate_type () and then pass the full value to
761 value_rtti_target_type () if we are dealing with a pointer
762 or reference to a base class and print object is on. */
765 volatile struct gdb_exception except
;
766 struct value
*ret
= NULL
;
768 TRY_CATCH (except
, RETURN_MASK_ERROR
)
770 ret
= value_of_variable (exp
->elts
[pc
+ 2].symbol
,
771 exp
->elts
[pc
+ 1].block
);
774 if (except
.reason
< 0)
776 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
777 ret
= value_zero (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
),
780 throw_exception (except
);
786 case OP_VAR_ENTRY_VALUE
:
788 if (noside
== EVAL_SKIP
)
792 struct symbol
*sym
= exp
->elts
[pc
+ 1].symbol
;
793 struct frame_info
*frame
;
795 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
796 return value_zero (SYMBOL_TYPE (sym
), not_lval
);
798 if (SYMBOL_COMPUTED_OPS (sym
) == NULL
799 || SYMBOL_COMPUTED_OPS (sym
)->read_variable_at_entry
== NULL
)
800 error (_("Symbol \"%s\" does not have any specific entry value"),
801 SYMBOL_PRINT_NAME (sym
));
803 frame
= get_selected_frame (NULL
);
804 return SYMBOL_COMPUTED_OPS (sym
)->read_variable_at_entry (sym
, frame
);
810 access_value_history (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
814 const char *name
= &exp
->elts
[pc
+ 2].string
;
818 (*pos
) += 3 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
819 regno
= user_reg_map_name_to_regnum (exp
->gdbarch
,
820 name
, strlen (name
));
822 error (_("Register $%s not available."), name
);
824 /* In EVAL_AVOID_SIDE_EFFECTS mode, we only need to return
825 a value with the appropriate register type. Unfortunately,
826 we don't have easy access to the type of user registers.
827 So for these registers, we fetch the register value regardless
828 of the evaluation mode. */
829 if (noside
== EVAL_AVOID_SIDE_EFFECTS
830 && regno
< gdbarch_num_regs (exp
->gdbarch
)
831 + gdbarch_num_pseudo_regs (exp
->gdbarch
))
832 val
= value_zero (register_type (exp
->gdbarch
, regno
), not_lval
);
834 val
= value_of_register (regno
, get_selected_frame (NULL
));
836 error (_("Value of register %s not available."), name
);
842 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
843 return value_from_longest (type
, exp
->elts
[pc
+ 1].longconst
);
847 return value_of_internalvar (exp
->gdbarch
,
848 exp
->elts
[pc
+ 1].internalvar
);
851 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
852 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
853 if (noside
== EVAL_SKIP
)
855 type
= language_string_char_type (exp
->language_defn
, exp
->gdbarch
);
856 return value_string (&exp
->elts
[pc
+ 2].string
, tem
, type
);
858 case OP_OBJC_NSSTRING
: /* Objective C Foundation Class
859 NSString constant. */
860 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
861 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
862 if (noside
== EVAL_SKIP
)
866 return value_nsstring (exp
->gdbarch
, &exp
->elts
[pc
+ 2].string
, tem
+ 1);
870 tem2
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
871 tem3
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
872 nargs
= tem3
- tem2
+ 1;
873 type
= expect_type
? check_typedef (expect_type
) : NULL_TYPE
;
875 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
876 && TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
878 struct value
*rec
= allocate_value (expect_type
);
880 memset (value_contents_raw (rec
), '\0', TYPE_LENGTH (type
));
881 return evaluate_struct_tuple (rec
, exp
, pos
, noside
, nargs
);
884 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
885 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
887 struct type
*range_type
= TYPE_INDEX_TYPE (type
);
888 struct type
*element_type
= TYPE_TARGET_TYPE (type
);
889 struct value
*array
= allocate_value (expect_type
);
890 int element_size
= TYPE_LENGTH (check_typedef (element_type
));
891 LONGEST low_bound
, high_bound
, index
;
893 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
896 high_bound
= (TYPE_LENGTH (type
) / element_size
) - 1;
899 memset (value_contents_raw (array
), 0, TYPE_LENGTH (expect_type
));
900 for (tem
= nargs
; --nargs
>= 0;)
902 struct value
*element
;
905 element
= evaluate_subexp (element_type
, exp
, pos
, noside
);
906 if (value_type (element
) != element_type
)
907 element
= value_cast (element_type
, element
);
910 int continue_pc
= *pos
;
913 index
= init_array_element (array
, element
, exp
, pos
, noside
,
914 low_bound
, high_bound
);
919 if (index
> high_bound
)
920 /* To avoid memory corruption. */
921 error (_("Too many array elements"));
922 memcpy (value_contents_raw (array
)
923 + (index
- low_bound
) * element_size
,
924 value_contents (element
),
932 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
933 && TYPE_CODE (type
) == TYPE_CODE_SET
)
935 struct value
*set
= allocate_value (expect_type
);
936 gdb_byte
*valaddr
= value_contents_raw (set
);
937 struct type
*element_type
= TYPE_INDEX_TYPE (type
);
938 struct type
*check_type
= element_type
;
939 LONGEST low_bound
, high_bound
;
941 /* Get targettype of elementtype. */
942 while (TYPE_CODE (check_type
) == TYPE_CODE_RANGE
943 || TYPE_CODE (check_type
) == TYPE_CODE_TYPEDEF
)
944 check_type
= TYPE_TARGET_TYPE (check_type
);
946 if (get_discrete_bounds (element_type
, &low_bound
, &high_bound
) < 0)
947 error (_("(power)set type with unknown size"));
948 memset (valaddr
, '\0', TYPE_LENGTH (type
));
949 for (tem
= 0; tem
< nargs
; tem
++)
951 LONGEST range_low
, range_high
;
952 struct type
*range_low_type
, *range_high_type
;
953 struct value
*elem_val
;
955 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
956 range_low_type
= range_high_type
= value_type (elem_val
);
957 range_low
= range_high
= value_as_long (elem_val
);
959 /* Check types of elements to avoid mixture of elements from
960 different types. Also check if type of element is "compatible"
961 with element type of powerset. */
962 if (TYPE_CODE (range_low_type
) == TYPE_CODE_RANGE
)
963 range_low_type
= TYPE_TARGET_TYPE (range_low_type
);
964 if (TYPE_CODE (range_high_type
) == TYPE_CODE_RANGE
)
965 range_high_type
= TYPE_TARGET_TYPE (range_high_type
);
966 if ((TYPE_CODE (range_low_type
) != TYPE_CODE (range_high_type
))
967 || (TYPE_CODE (range_low_type
) == TYPE_CODE_ENUM
968 && (range_low_type
!= range_high_type
)))
969 /* different element modes. */
970 error (_("POWERSET tuple elements of different mode"));
971 if ((TYPE_CODE (check_type
) != TYPE_CODE (range_low_type
))
972 || (TYPE_CODE (check_type
) == TYPE_CODE_ENUM
973 && range_low_type
!= check_type
))
974 error (_("incompatible POWERSET tuple elements"));
975 if (range_low
> range_high
)
977 warning (_("empty POWERSET tuple range"));
980 if (range_low
< low_bound
|| range_high
> high_bound
)
981 error (_("POWERSET tuple element out of range"));
982 range_low
-= low_bound
;
983 range_high
-= low_bound
;
984 for (; range_low
<= range_high
; range_low
++)
986 int bit_index
= (unsigned) range_low
% TARGET_CHAR_BIT
;
988 if (gdbarch_bits_big_endian (exp
->gdbarch
))
989 bit_index
= TARGET_CHAR_BIT
- 1 - bit_index
;
990 valaddr
[(unsigned) range_low
/ TARGET_CHAR_BIT
]
997 argvec
= (struct value
**) alloca (sizeof (struct value
*) * nargs
);
998 for (tem
= 0; tem
< nargs
; tem
++)
1000 /* Ensure that array expressions are coerced into pointer
1002 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1004 if (noside
== EVAL_SKIP
)
1006 return value_array (tem2
, tem3
, argvec
);
1010 struct value
*array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1012 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1014 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1016 if (noside
== EVAL_SKIP
)
1018 return value_slice (array
, lowbound
, upper
- lowbound
+ 1);
1022 /* Skip third and second args to evaluate the first one. */
1023 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1024 if (value_logical_not (arg1
))
1026 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1027 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1031 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1032 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1036 case OP_OBJC_SELECTOR
:
1037 { /* Objective C @selector operator. */
1038 char *sel
= &exp
->elts
[pc
+ 2].string
;
1039 int len
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1040 struct type
*selector_type
;
1042 (*pos
) += 3 + BYTES_TO_EXP_ELEM (len
+ 1);
1043 if (noside
== EVAL_SKIP
)
1047 sel
[len
] = 0; /* Make sure it's terminated. */
1049 selector_type
= builtin_type (exp
->gdbarch
)->builtin_data_ptr
;
1050 return value_from_longest (selector_type
,
1051 lookup_child_selector (exp
->gdbarch
, sel
));
1054 case OP_OBJC_MSGCALL
:
1055 { /* Objective C message (method) call. */
1057 CORE_ADDR responds_selector
= 0;
1058 CORE_ADDR method_selector
= 0;
1060 CORE_ADDR selector
= 0;
1062 int struct_return
= 0;
1063 int sub_no_side
= 0;
1065 struct value
*msg_send
= NULL
;
1066 struct value
*msg_send_stret
= NULL
;
1067 int gnu_runtime
= 0;
1069 struct value
*target
= NULL
;
1070 struct value
*method
= NULL
;
1071 struct value
*called_method
= NULL
;
1073 struct type
*selector_type
= NULL
;
1074 struct type
*long_type
;
1076 struct value
*ret
= NULL
;
1079 selector
= exp
->elts
[pc
+ 1].longconst
;
1080 nargs
= exp
->elts
[pc
+ 2].longconst
;
1081 argvec
= (struct value
**) alloca (sizeof (struct value
*)
1086 long_type
= builtin_type (exp
->gdbarch
)->builtin_long
;
1087 selector_type
= builtin_type (exp
->gdbarch
)->builtin_data_ptr
;
1089 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1090 sub_no_side
= EVAL_NORMAL
;
1092 sub_no_side
= noside
;
1094 target
= evaluate_subexp (selector_type
, exp
, pos
, sub_no_side
);
1096 if (value_as_long (target
) == 0)
1097 return value_from_longest (long_type
, 0);
1099 if (lookup_minimal_symbol ("objc_msg_lookup", 0, 0).minsym
)
1102 /* Find the method dispatch (Apple runtime) or method lookup
1103 (GNU runtime) function for Objective-C. These will be used
1104 to lookup the symbol information for the method. If we
1105 can't find any symbol information, then we'll use these to
1106 call the method, otherwise we can call the method
1107 directly. The msg_send_stret function is used in the special
1108 case of a method that returns a structure (Apple runtime
1112 struct type
*type
= selector_type
;
1114 type
= lookup_function_type (type
);
1115 type
= lookup_pointer_type (type
);
1116 type
= lookup_function_type (type
);
1117 type
= lookup_pointer_type (type
);
1119 msg_send
= find_function_in_inferior ("objc_msg_lookup", NULL
);
1121 = find_function_in_inferior ("objc_msg_lookup", NULL
);
1123 msg_send
= value_from_pointer (type
, value_as_address (msg_send
));
1124 msg_send_stret
= value_from_pointer (type
,
1125 value_as_address (msg_send_stret
));
1129 msg_send
= find_function_in_inferior ("objc_msgSend", NULL
);
1130 /* Special dispatcher for methods returning structs. */
1132 = find_function_in_inferior ("objc_msgSend_stret", NULL
);
1135 /* Verify the target object responds to this method. The
1136 standard top-level 'Object' class uses a different name for
1137 the verification method than the non-standard, but more
1138 often used, 'NSObject' class. Make sure we check for both. */
1141 = lookup_child_selector (exp
->gdbarch
, "respondsToSelector:");
1142 if (responds_selector
== 0)
1144 = lookup_child_selector (exp
->gdbarch
, "respondsTo:");
1146 if (responds_selector
== 0)
1147 error (_("no 'respondsTo:' or 'respondsToSelector:' method"));
1150 = lookup_child_selector (exp
->gdbarch
, "methodForSelector:");
1151 if (method_selector
== 0)
1153 = lookup_child_selector (exp
->gdbarch
, "methodFor:");
1155 if (method_selector
== 0)
1156 error (_("no 'methodFor:' or 'methodForSelector:' method"));
1158 /* Call the verification method, to make sure that the target
1159 class implements the desired method. */
1161 argvec
[0] = msg_send
;
1163 argvec
[2] = value_from_longest (long_type
, responds_selector
);
1164 argvec
[3] = value_from_longest (long_type
, selector
);
1167 ret
= call_function_by_hand (argvec
[0], 3, argvec
+ 1);
1170 /* Function objc_msg_lookup returns a pointer. */
1172 ret
= call_function_by_hand (argvec
[0], 3, argvec
+ 1);
1174 if (value_as_long (ret
) == 0)
1175 error (_("Target does not respond to this message selector."));
1177 /* Call "methodForSelector:" method, to get the address of a
1178 function method that implements this selector for this
1179 class. If we can find a symbol at that address, then we
1180 know the return type, parameter types etc. (that's a good
1183 argvec
[0] = msg_send
;
1185 argvec
[2] = value_from_longest (long_type
, method_selector
);
1186 argvec
[3] = value_from_longest (long_type
, selector
);
1189 ret
= call_function_by_hand (argvec
[0], 3, argvec
+ 1);
1193 ret
= call_function_by_hand (argvec
[0], 3, argvec
+ 1);
1196 /* ret should now be the selector. */
1198 addr
= value_as_long (ret
);
1201 struct symbol
*sym
= NULL
;
1203 /* The address might point to a function descriptor;
1204 resolve it to the actual code address instead. */
1205 addr
= gdbarch_convert_from_func_ptr_addr (exp
->gdbarch
, addr
,
1208 /* Is it a high_level symbol? */
1209 sym
= find_pc_function (addr
);
1211 method
= value_of_variable (sym
, 0);
1214 /* If we found a method with symbol information, check to see
1215 if it returns a struct. Otherwise assume it doesn't. */
1220 struct type
*val_type
;
1222 funaddr
= find_function_addr (method
, &val_type
);
1224 block_for_pc (funaddr
);
1226 CHECK_TYPEDEF (val_type
);
1228 if ((val_type
== NULL
)
1229 || (TYPE_CODE(val_type
) == TYPE_CODE_ERROR
))
1231 if (expect_type
!= NULL
)
1232 val_type
= expect_type
;
1235 struct_return
= using_struct_return (exp
->gdbarch
, method
,
1238 else if (expect_type
!= NULL
)
1240 struct_return
= using_struct_return (exp
->gdbarch
, NULL
,
1241 check_typedef (expect_type
));
1244 /* Found a function symbol. Now we will substitute its
1245 value in place of the message dispatcher (obj_msgSend),
1246 so that we call the method directly instead of thru
1247 the dispatcher. The main reason for doing this is that
1248 we can now evaluate the return value and parameter values
1249 according to their known data types, in case we need to
1250 do things like promotion, dereferencing, special handling
1251 of structs and doubles, etc.
1253 We want to use the type signature of 'method', but still
1254 jump to objc_msgSend() or objc_msgSend_stret() to better
1255 mimic the behavior of the runtime. */
1259 if (TYPE_CODE (value_type (method
)) != TYPE_CODE_FUNC
)
1260 error (_("method address has symbol information "
1261 "with non-function type; skipping"));
1263 /* Create a function pointer of the appropriate type, and
1264 replace its value with the value of msg_send or
1265 msg_send_stret. We must use a pointer here, as
1266 msg_send and msg_send_stret are of pointer type, and
1267 the representation may be different on systems that use
1268 function descriptors. */
1271 = value_from_pointer (lookup_pointer_type (value_type (method
)),
1272 value_as_address (msg_send_stret
));
1275 = value_from_pointer (lookup_pointer_type (value_type (method
)),
1276 value_as_address (msg_send
));
1281 called_method
= msg_send_stret
;
1283 called_method
= msg_send
;
1286 if (noside
== EVAL_SKIP
)
1289 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1291 /* If the return type doesn't look like a function type,
1292 call an error. This can happen if somebody tries to
1293 turn a variable into a function call. This is here
1294 because people often want to call, eg, strcmp, which
1295 gdb doesn't know is a function. If gdb isn't asked for
1296 it's opinion (ie. through "whatis"), it won't offer
1299 struct type
*type
= value_type (called_method
);
1301 if (type
&& TYPE_CODE (type
) == TYPE_CODE_PTR
)
1302 type
= TYPE_TARGET_TYPE (type
);
1303 type
= TYPE_TARGET_TYPE (type
);
1307 if ((TYPE_CODE (type
) == TYPE_CODE_ERROR
) && expect_type
)
1308 return allocate_value (expect_type
);
1310 return allocate_value (type
);
1313 error (_("Expression of type other than "
1314 "\"method returning ...\" used as a method"));
1317 /* Now depending on whether we found a symbol for the method,
1318 we will either call the runtime dispatcher or the method
1321 argvec
[0] = called_method
;
1323 argvec
[2] = value_from_longest (long_type
, selector
);
1324 /* User-supplied arguments. */
1325 for (tem
= 0; tem
< nargs
; tem
++)
1326 argvec
[tem
+ 3] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1327 argvec
[tem
+ 3] = 0;
1329 if (gnu_runtime
&& (method
!= NULL
))
1331 /* Function objc_msg_lookup returns a pointer. */
1332 deprecated_set_value_type (argvec
[0],
1333 lookup_pointer_type (lookup_function_type (value_type (argvec
[0]))));
1335 = call_function_by_hand (argvec
[0], nargs
+ 2, argvec
+ 1);
1338 ret
= call_function_by_hand (argvec
[0], nargs
+ 2, argvec
+ 1);
1345 op
= exp
->elts
[*pos
].opcode
;
1346 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1347 /* Allocate arg vector, including space for the function to be
1348 called in argvec[0], a potential `this', and a terminating NULL. */
1349 argvec
= (struct value
**)
1350 alloca (sizeof (struct value
*) * (nargs
+ 3));
1351 if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
1353 /* First, evaluate the structure into arg2. */
1356 if (op
== STRUCTOP_MEMBER
)
1358 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
1362 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1365 /* If the function is a virtual function, then the
1366 aggregate value (providing the structure) plays
1367 its part by providing the vtable. Otherwise,
1368 it is just along for the ride: call the function
1371 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1373 type
= check_typedef (value_type (arg1
));
1374 if (noside
== EVAL_SKIP
)
1375 tem
= 1; /* Set it to the right arg index so that all arguments
1376 can also be skipped. */
1377 else if (TYPE_CODE (type
) == TYPE_CODE_METHODPTR
)
1379 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1380 arg1
= value_zero (TYPE_TARGET_TYPE (type
), not_lval
);
1382 arg1
= cplus_method_ptr_to_value (&arg2
, arg1
);
1384 /* Now, say which argument to start evaluating from. */
1389 else if (TYPE_CODE (type
) == TYPE_CODE_MEMBERPTR
)
1391 struct type
*type_ptr
1392 = lookup_pointer_type (TYPE_SELF_TYPE (type
));
1393 struct type
*target_type_ptr
1394 = lookup_pointer_type (TYPE_TARGET_TYPE (type
));
1396 /* Now, convert these values to an address. */
1397 arg2
= value_cast (type_ptr
, arg2
);
1399 mem_offset
= value_as_long (arg1
);
1401 arg1
= value_from_pointer (target_type_ptr
,
1402 value_as_long (arg2
) + mem_offset
);
1403 arg1
= value_ind (arg1
);
1407 error (_("Non-pointer-to-member value used in pointer-to-member "
1410 else if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
1412 /* Hair for method invocations. */
1416 /* First, evaluate the structure into arg2. */
1418 tem2
= longest_to_int (exp
->elts
[pc2
+ 1].longconst
);
1419 *pos
+= 3 + BYTES_TO_EXP_ELEM (tem2
+ 1);
1421 if (op
== STRUCTOP_STRUCT
)
1423 /* If v is a variable in a register, and the user types
1424 v.method (), this will produce an error, because v has
1427 A possible way around this would be to allocate a
1428 copy of the variable on the stack, copy in the
1429 contents, call the function, and copy out the
1430 contents. I.e. convert this from call by reference
1431 to call by copy-return (or whatever it's called).
1432 However, this does not work because it is not the
1433 same: the method being called could stash a copy of
1434 the address, and then future uses through that address
1435 (after the method returns) would be expected to
1436 use the variable itself, not some copy of it. */
1437 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
1441 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1443 /* Check to see if the operator '->' has been
1444 overloaded. If the operator has been overloaded
1445 replace arg2 with the value returned by the custom
1446 operator and continue evaluation. */
1447 while (unop_user_defined_p (op
, arg2
))
1449 volatile struct gdb_exception except
;
1450 struct value
*value
= NULL
;
1451 TRY_CATCH (except
, RETURN_MASK_ERROR
)
1453 value
= value_x_unop (arg2
, op
, noside
);
1456 if (except
.reason
< 0)
1458 if (except
.error
== NOT_FOUND_ERROR
)
1461 throw_exception (except
);
1466 /* Now, say which argument to start evaluating from. */
1469 else if (op
== OP_SCOPE
1470 && overload_resolution
1471 && (exp
->language_defn
->la_language
== language_cplus
))
1473 /* Unpack it locally so we can properly handle overload
1479 local_tem
= longest_to_int (exp
->elts
[pc2
+ 2].longconst
);
1480 (*pos
) += 4 + BYTES_TO_EXP_ELEM (local_tem
+ 1);
1481 type
= exp
->elts
[pc2
+ 1].type
;
1482 name
= &exp
->elts
[pc2
+ 3].string
;
1485 function_name
= NULL
;
1486 if (TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
1488 function
= cp_lookup_symbol_namespace (TYPE_TAG_NAME (type
),
1490 get_selected_block (0),
1492 if (function
== NULL
)
1493 error (_("No symbol \"%s\" in namespace \"%s\"."),
1494 name
, TYPE_TAG_NAME (type
));
1497 /* arg2 is left as NULL on purpose. */
1501 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_STRUCT
1502 || TYPE_CODE (type
) == TYPE_CODE_UNION
);
1503 function_name
= name
;
1505 /* We need a properly typed value for method lookup. For
1506 static methods arg2 is otherwise unused. */
1507 arg2
= value_zero (type
, lval_memory
);
1512 else if (op
== OP_ADL_FUNC
)
1514 /* Save the function position and move pos so that the arguments
1515 can be evaluated. */
1521 func_name_len
= longest_to_int (exp
->elts
[save_pos1
+ 3].longconst
);
1522 (*pos
) += 6 + BYTES_TO_EXP_ELEM (func_name_len
+ 1);
1526 /* Non-method function call. */
1530 /* If this is a C++ function wait until overload resolution. */
1531 if (op
== OP_VAR_VALUE
1532 && overload_resolution
1533 && (exp
->language_defn
->la_language
== language_cplus
))
1535 (*pos
) += 4; /* Skip the evaluation of the symbol. */
1540 argvec
[0] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1541 type
= value_type (argvec
[0]);
1542 if (type
&& TYPE_CODE (type
) == TYPE_CODE_PTR
)
1543 type
= TYPE_TARGET_TYPE (type
);
1544 if (type
&& TYPE_CODE (type
) == TYPE_CODE_FUNC
)
1546 for (; tem
<= nargs
&& tem
<= TYPE_NFIELDS (type
); tem
++)
1548 argvec
[tem
] = evaluate_subexp (TYPE_FIELD_TYPE (type
,
1556 /* Evaluate arguments (if not already done, e.g., namespace::func()
1557 and overload-resolution is off). */
1558 for (; tem
<= nargs
; tem
++)
1560 /* Ensure that array expressions are coerced into pointer
1562 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1565 /* Signal end of arglist. */
1568 if (noside
== EVAL_SKIP
)
1571 if (op
== OP_ADL_FUNC
)
1573 struct symbol
*symp
;
1576 int string_pc
= save_pos1
+ 3;
1578 /* Extract the function name. */
1579 name_len
= longest_to_int (exp
->elts
[string_pc
].longconst
);
1580 func_name
= (char *) alloca (name_len
+ 1);
1581 strcpy (func_name
, &exp
->elts
[string_pc
+ 1].string
);
1583 find_overload_match (&argvec
[1], nargs
, func_name
,
1584 NON_METHOD
, /* not method */
1585 NULL
, NULL
, /* pass NULL symbol since
1586 symbol is unknown */
1587 NULL
, &symp
, NULL
, 0, noside
);
1589 /* Now fix the expression being evaluated. */
1590 exp
->elts
[save_pos1
+ 2].symbol
= symp
;
1591 argvec
[0] = evaluate_subexp_with_coercion (exp
, &save_pos1
, noside
);
1594 if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
1595 || (op
== OP_SCOPE
&& function_name
!= NULL
))
1597 int static_memfuncp
;
1600 /* Method invocation: stuff "this" as first parameter.
1601 If the method turns out to be static we undo this below. */
1606 /* Name of method from expression. */
1607 tstr
= &exp
->elts
[pc2
+ 2].string
;
1610 tstr
= function_name
;
1612 if (overload_resolution
&& (exp
->language_defn
->la_language
1615 /* Language is C++, do some overload resolution before
1617 struct value
*valp
= NULL
;
1619 (void) find_overload_match (&argvec
[1], nargs
, tstr
,
1620 METHOD
, /* method */
1621 &arg2
, /* the object */
1623 &static_memfuncp
, 0, noside
);
1625 if (op
== OP_SCOPE
&& !static_memfuncp
)
1627 /* For the time being, we don't handle this. */
1628 error (_("Call to overloaded function %s requires "
1632 argvec
[1] = arg2
; /* the ``this'' pointer */
1633 argvec
[0] = valp
; /* Use the method found after overload
1637 /* Non-C++ case -- or no overload resolution. */
1639 struct value
*temp
= arg2
;
1641 argvec
[0] = value_struct_elt (&temp
, argvec
+ 1, tstr
,
1643 op
== STRUCTOP_STRUCT
1644 ? "structure" : "structure pointer");
1645 /* value_struct_elt updates temp with the correct value
1646 of the ``this'' pointer if necessary, so modify argvec[1] to
1647 reflect any ``this'' changes. */
1649 = value_from_longest (lookup_pointer_type(value_type (temp
)),
1650 value_address (temp
)
1651 + value_embedded_offset (temp
));
1652 argvec
[1] = arg2
; /* the ``this'' pointer */
1655 /* Take out `this' if needed. */
1656 if (static_memfuncp
)
1658 argvec
[1] = argvec
[0];
1663 else if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
1665 /* Pointer to member. argvec[1] is already set up. */
1668 else if (op
== OP_VAR_VALUE
|| (op
== OP_SCOPE
&& function
!= NULL
))
1670 /* Non-member function being called. */
1671 /* fn: This can only be done for C++ functions. A C-style function
1672 in a C++ program, for instance, does not have the fields that
1673 are expected here. */
1675 if (overload_resolution
&& (exp
->language_defn
->la_language
1678 /* Language is C++, do some overload resolution before
1680 struct symbol
*symp
;
1683 /* If a scope has been specified disable ADL. */
1687 if (op
== OP_VAR_VALUE
)
1688 function
= exp
->elts
[save_pos1
+2].symbol
;
1690 (void) find_overload_match (&argvec
[1], nargs
,
1691 NULL
, /* no need for name */
1692 NON_METHOD
, /* not method */
1693 NULL
, function
, /* the function */
1694 NULL
, &symp
, NULL
, no_adl
, noside
);
1696 if (op
== OP_VAR_VALUE
)
1698 /* Now fix the expression being evaluated. */
1699 exp
->elts
[save_pos1
+2].symbol
= symp
;
1700 argvec
[0] = evaluate_subexp_with_coercion (exp
, &save_pos1
,
1704 argvec
[0] = value_of_variable (symp
, get_selected_block (0));
1708 /* Not C++, or no overload resolution allowed. */
1709 /* Nothing to be done; argvec already correctly set up. */
1714 /* It is probably a C-style function. */
1715 /* Nothing to be done; argvec already correctly set up. */
1720 if (argvec
[0] == NULL
)
1721 error (_("Cannot evaluate function -- may be inlined"));
1722 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1724 /* If the return type doesn't look like a function type, call an
1725 error. This can happen if somebody tries to turn a variable into
1726 a function call. This is here because people often want to
1727 call, eg, strcmp, which gdb doesn't know is a function. If
1728 gdb isn't asked for it's opinion (ie. through "whatis"),
1729 it won't offer it. */
1731 struct type
*ftype
= value_type (argvec
[0]);
1733 if (TYPE_CODE (ftype
) == TYPE_CODE_INTERNAL_FUNCTION
)
1735 /* We don't know anything about what the internal
1736 function might return, but we have to return
1738 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
,
1741 else if (TYPE_GNU_IFUNC (ftype
))
1742 return allocate_value (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (ftype
)));
1743 else if (TYPE_TARGET_TYPE (ftype
))
1744 return allocate_value (TYPE_TARGET_TYPE (ftype
));
1746 error (_("Expression of type other than "
1747 "\"Function returning ...\" used as function"));
1749 switch (TYPE_CODE (value_type (argvec
[0])))
1751 case TYPE_CODE_INTERNAL_FUNCTION
:
1752 return call_internal_function (exp
->gdbarch
, exp
->language_defn
,
1753 argvec
[0], nargs
, argvec
+ 1);
1754 case TYPE_CODE_XMETHOD
:
1755 return call_xmethod (argvec
[0], nargs
, argvec
+ 1);
1757 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
1759 /* pai: FIXME save value from call_function_by_hand, then adjust
1760 pc by adjust_fn_pc if +ve. */
1762 case OP_F77_UNDETERMINED_ARGLIST
:
1764 /* Remember that in F77, functions, substring ops and
1765 array subscript operations cannot be disambiguated
1766 at parse time. We have made all array subscript operations,
1767 substring operations as well as function calls come here
1768 and we now have to discover what the heck this thing actually was.
1769 If it is a function, we process just as if we got an OP_FUNCALL. */
1771 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1774 /* First determine the type code we are dealing with. */
1775 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1776 type
= check_typedef (value_type (arg1
));
1777 code
= TYPE_CODE (type
);
1779 if (code
== TYPE_CODE_PTR
)
1781 /* Fortran always passes variable to subroutines as pointer.
1782 So we need to look into its target type to see if it is
1783 array, string or function. If it is, we need to switch
1784 to the target value the original one points to. */
1785 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1787 if (TYPE_CODE (target_type
) == TYPE_CODE_ARRAY
1788 || TYPE_CODE (target_type
) == TYPE_CODE_STRING
1789 || TYPE_CODE (target_type
) == TYPE_CODE_FUNC
)
1791 arg1
= value_ind (arg1
);
1792 type
= check_typedef (value_type (arg1
));
1793 code
= TYPE_CODE (type
);
1799 case TYPE_CODE_ARRAY
:
1800 if (exp
->elts
[*pos
].opcode
== OP_F90_RANGE
)
1801 return value_f90_subarray (arg1
, exp
, pos
, noside
);
1803 goto multi_f77_subscript
;
1805 case TYPE_CODE_STRING
:
1806 if (exp
->elts
[*pos
].opcode
== OP_F90_RANGE
)
1807 return value_f90_subarray (arg1
, exp
, pos
, noside
);
1810 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1811 return value_subscript (arg1
, value_as_long (arg2
));
1815 case TYPE_CODE_FUNC
:
1816 /* It's a function call. */
1817 /* Allocate arg vector, including space for the function to be
1818 called in argvec[0] and a terminating NULL. */
1819 argvec
= (struct value
**)
1820 alloca (sizeof (struct value
*) * (nargs
+ 2));
1823 for (; tem
<= nargs
; tem
++)
1824 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1825 argvec
[tem
] = 0; /* signal end of arglist */
1826 if (noside
== EVAL_SKIP
)
1831 error (_("Cannot perform substring on this type"));
1835 /* We have a complex number, There should be 2 floating
1836 point numbers that compose it. */
1838 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1839 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1841 return value_literal_complex (arg1
, arg2
, exp
->elts
[pc
+ 1].type
);
1843 case STRUCTOP_STRUCT
:
1844 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1845 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1846 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1847 if (noside
== EVAL_SKIP
)
1849 arg3
= value_struct_elt (&arg1
, NULL
, &exp
->elts
[pc
+ 2].string
,
1851 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1852 arg3
= value_zero (value_type (arg3
), not_lval
);
1856 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1857 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1858 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1859 if (noside
== EVAL_SKIP
)
1862 /* Check to see if operator '->' has been overloaded. If so replace
1863 arg1 with the value returned by evaluating operator->(). */
1864 while (unop_user_defined_p (op
, arg1
))
1866 volatile struct gdb_exception except
;
1867 struct value
*value
= NULL
;
1868 TRY_CATCH (except
, RETURN_MASK_ERROR
)
1870 value
= value_x_unop (arg1
, op
, noside
);
1873 if (except
.reason
< 0)
1875 if (except
.error
== NOT_FOUND_ERROR
)
1878 throw_exception (except
);
1883 /* JYG: if print object is on we need to replace the base type
1884 with rtti type in order to continue on with successful
1885 lookup of member / method only available in the rtti type. */
1887 struct type
*type
= value_type (arg1
);
1888 struct type
*real_type
;
1889 int full
, top
, using_enc
;
1890 struct value_print_options opts
;
1892 get_user_print_options (&opts
);
1893 if (opts
.objectprint
&& TYPE_TARGET_TYPE(type
)
1894 && (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_STRUCT
))
1896 real_type
= value_rtti_indirect_type (arg1
, &full
, &top
,
1899 arg1
= value_cast (real_type
, arg1
);
1903 arg3
= value_struct_elt (&arg1
, NULL
, &exp
->elts
[pc
+ 2].string
,
1904 NULL
, "structure pointer");
1905 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1906 arg3
= value_zero (value_type (arg3
), not_lval
);
1909 case STRUCTOP_MEMBER
:
1911 if (op
== STRUCTOP_MEMBER
)
1912 arg1
= evaluate_subexp_for_address (exp
, pos
, noside
);
1914 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1916 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1918 if (noside
== EVAL_SKIP
)
1921 type
= check_typedef (value_type (arg2
));
1922 switch (TYPE_CODE (type
))
1924 case TYPE_CODE_METHODPTR
:
1925 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1926 return value_zero (TYPE_TARGET_TYPE (type
), not_lval
);
1929 arg2
= cplus_method_ptr_to_value (&arg1
, arg2
);
1930 gdb_assert (TYPE_CODE (value_type (arg2
)) == TYPE_CODE_PTR
);
1931 return value_ind (arg2
);
1934 case TYPE_CODE_MEMBERPTR
:
1935 /* Now, convert these values to an address. */
1936 arg1
= value_cast_pointers (lookup_pointer_type (TYPE_SELF_TYPE (type
)),
1939 mem_offset
= value_as_long (arg2
);
1941 arg3
= value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
1942 value_as_long (arg1
) + mem_offset
);
1943 return value_ind (arg3
);
1946 error (_("non-pointer-to-member value used "
1947 "in pointer-to-member construct"));
1951 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1952 arg_types
= (struct type
**) alloca (nargs
* sizeof (struct type
*));
1953 for (ix
= 0; ix
< nargs
; ++ix
)
1954 arg_types
[ix
] = exp
->elts
[pc
+ 1 + ix
+ 1].type
;
1956 expect_type
= make_params (nargs
, arg_types
);
1957 *(pos
) += 3 + nargs
;
1958 arg1
= evaluate_subexp_standard (expect_type
, exp
, pos
, noside
);
1959 xfree (TYPE_FIELDS (expect_type
));
1960 xfree (TYPE_MAIN_TYPE (expect_type
));
1961 xfree (expect_type
);
1965 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1966 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1967 if (noside
== EVAL_SKIP
)
1969 if (binop_user_defined_p (op
, arg1
, arg2
))
1970 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1972 return value_concat (arg1
, arg2
);
1975 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1976 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
1978 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1980 if (binop_user_defined_p (op
, arg1
, arg2
))
1981 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1983 return value_assign (arg1
, arg2
);
1985 case BINOP_ASSIGN_MODIFY
:
1987 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1988 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
1989 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1991 op
= exp
->elts
[pc
+ 1].opcode
;
1992 if (binop_user_defined_p (op
, arg1
, arg2
))
1993 return value_x_binop (arg1
, arg2
, BINOP_ASSIGN_MODIFY
, op
, noside
);
1994 else if (op
== BINOP_ADD
&& ptrmath_type_p (exp
->language_defn
,
1996 && is_integral_type (value_type (arg2
)))
1997 arg2
= value_ptradd (arg1
, value_as_long (arg2
));
1998 else if (op
== BINOP_SUB
&& ptrmath_type_p (exp
->language_defn
,
2000 && is_integral_type (value_type (arg2
)))
2001 arg2
= value_ptradd (arg1
, - value_as_long (arg2
));
2004 struct value
*tmp
= arg1
;
2006 /* For shift and integer exponentiation operations,
2007 only promote the first argument. */
2008 if ((op
== BINOP_LSH
|| op
== BINOP_RSH
|| op
== BINOP_EXP
)
2009 && is_integral_type (value_type (arg2
)))
2010 unop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
);
2012 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2014 arg2
= value_binop (tmp
, arg2
, op
);
2016 return value_assign (arg1
, arg2
);
2019 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2020 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2021 if (noside
== EVAL_SKIP
)
2023 if (binop_user_defined_p (op
, arg1
, arg2
))
2024 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2025 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
2026 && is_integral_type (value_type (arg2
)))
2027 return value_ptradd (arg1
, value_as_long (arg2
));
2028 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg2
))
2029 && is_integral_type (value_type (arg1
)))
2030 return value_ptradd (arg2
, value_as_long (arg1
));
2033 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2034 return value_binop (arg1
, arg2
, BINOP_ADD
);
2038 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2039 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2040 if (noside
== EVAL_SKIP
)
2042 if (binop_user_defined_p (op
, arg1
, arg2
))
2043 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2044 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
2045 && ptrmath_type_p (exp
->language_defn
, value_type (arg2
)))
2047 /* FIXME -- should be ptrdiff_t */
2048 type
= builtin_type (exp
->gdbarch
)->builtin_long
;
2049 return value_from_longest (type
, value_ptrdiff (arg1
, arg2
));
2051 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
2052 && is_integral_type (value_type (arg2
)))
2053 return value_ptradd (arg1
, - value_as_long (arg2
));
2056 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2057 return value_binop (arg1
, arg2
, BINOP_SUB
);
2068 case BINOP_BITWISE_AND
:
2069 case BINOP_BITWISE_IOR
:
2070 case BINOP_BITWISE_XOR
:
2071 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2072 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2073 if (noside
== EVAL_SKIP
)
2075 if (binop_user_defined_p (op
, arg1
, arg2
))
2076 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2079 /* If EVAL_AVOID_SIDE_EFFECTS and we're dividing by zero,
2080 fudge arg2 to avoid division-by-zero, the caller is
2081 (theoretically) only looking for the type of the result. */
2082 if (noside
== EVAL_AVOID_SIDE_EFFECTS
2083 /* ??? Do we really want to test for BINOP_MOD here?
2084 The implementation of value_binop gives it a well-defined
2087 || op
== BINOP_INTDIV
2090 && value_logical_not (arg2
))
2092 struct value
*v_one
, *retval
;
2094 v_one
= value_one (value_type (arg2
));
2095 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &v_one
);
2096 retval
= value_binop (arg1
, v_one
, op
);
2101 /* For shift and integer exponentiation operations,
2102 only promote the first argument. */
2103 if ((op
== BINOP_LSH
|| op
== BINOP_RSH
|| op
== BINOP_EXP
)
2104 && is_integral_type (value_type (arg2
)))
2105 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2107 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2109 return value_binop (arg1
, arg2
, op
);
2113 case BINOP_SUBSCRIPT
:
2114 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2115 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2116 if (noside
== EVAL_SKIP
)
2118 if (binop_user_defined_p (op
, arg1
, arg2
))
2119 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2122 /* If the user attempts to subscript something that is not an
2123 array or pointer type (like a plain int variable for example),
2124 then report this as an error. */
2126 arg1
= coerce_ref (arg1
);
2127 type
= check_typedef (value_type (arg1
));
2128 if (TYPE_CODE (type
) != TYPE_CODE_ARRAY
2129 && TYPE_CODE (type
) != TYPE_CODE_PTR
)
2131 if (TYPE_NAME (type
))
2132 error (_("cannot subscript something of type `%s'"),
2135 error (_("cannot subscript requested type"));
2138 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2139 return value_zero (TYPE_TARGET_TYPE (type
), VALUE_LVAL (arg1
));
2141 return value_subscript (arg1
, value_as_long (arg2
));
2143 case MULTI_SUBSCRIPT
:
2145 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
2146 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2149 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2150 /* FIXME: EVAL_SKIP handling may not be correct. */
2151 if (noside
== EVAL_SKIP
)
2162 /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
2163 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2165 /* If the user attempts to subscript something that has no target
2166 type (like a plain int variable for example), then report this
2169 type
= TYPE_TARGET_TYPE (check_typedef (value_type (arg1
)));
2172 arg1
= value_zero (type
, VALUE_LVAL (arg1
));
2178 error (_("cannot subscript something of type `%s'"),
2179 TYPE_NAME (value_type (arg1
)));
2183 if (binop_user_defined_p (op
, arg1
, arg2
))
2185 arg1
= value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2189 arg1
= coerce_ref (arg1
);
2190 type
= check_typedef (value_type (arg1
));
2192 switch (TYPE_CODE (type
))
2195 case TYPE_CODE_ARRAY
:
2196 case TYPE_CODE_STRING
:
2197 arg1
= value_subscript (arg1
, value_as_long (arg2
));
2201 if (TYPE_NAME (type
))
2202 error (_("cannot subscript something of type `%s'"),
2205 error (_("cannot subscript requested type"));
2211 multi_f77_subscript
:
2213 LONGEST subscript_array
[MAX_FORTRAN_DIMS
];
2214 int ndimensions
= 1, i
;
2215 struct value
*array
= arg1
;
2217 if (nargs
> MAX_FORTRAN_DIMS
)
2218 error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS
);
2220 ndimensions
= calc_f77_array_dims (type
);
2222 if (nargs
!= ndimensions
)
2223 error (_("Wrong number of subscripts"));
2225 gdb_assert (nargs
> 0);
2227 /* Now that we know we have a legal array subscript expression
2228 let us actually find out where this element exists in the array. */
2230 /* Take array indices left to right. */
2231 for (i
= 0; i
< nargs
; i
++)
2233 /* Evaluate each subscript; it must be a legal integer in F77. */
2234 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2236 /* Fill in the subscript array. */
2238 subscript_array
[i
] = value_as_long (arg2
);
2241 /* Internal type of array is arranged right to left. */
2242 for (i
= nargs
; i
> 0; i
--)
2244 struct type
*array_type
= check_typedef (value_type (array
));
2245 LONGEST index
= subscript_array
[i
- 1];
2247 array
= value_subscripted_rvalue (array
, index
,
2248 f77_get_lowerbound (array_type
));
2254 case BINOP_LOGICAL_AND
:
2255 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2256 if (noside
== EVAL_SKIP
)
2258 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2263 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2266 if (binop_user_defined_p (op
, arg1
, arg2
))
2268 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2269 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2273 tem
= value_logical_not (arg1
);
2274 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
2275 (tem
? EVAL_SKIP
: noside
));
2276 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2277 return value_from_longest (type
,
2278 (LONGEST
) (!tem
&& !value_logical_not (arg2
)));
2281 case BINOP_LOGICAL_OR
:
2282 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2283 if (noside
== EVAL_SKIP
)
2285 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2290 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2293 if (binop_user_defined_p (op
, arg1
, arg2
))
2295 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2296 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2300 tem
= value_logical_not (arg1
);
2301 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
2302 (!tem
? EVAL_SKIP
: noside
));
2303 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2304 return value_from_longest (type
,
2305 (LONGEST
) (!tem
|| !value_logical_not (arg2
)));
2309 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2310 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2311 if (noside
== EVAL_SKIP
)
2313 if (binop_user_defined_p (op
, arg1
, arg2
))
2315 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2319 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2320 tem
= value_equal (arg1
, arg2
);
2321 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2322 return value_from_longest (type
, (LONGEST
) tem
);
2325 case BINOP_NOTEQUAL
:
2326 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2327 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2328 if (noside
== EVAL_SKIP
)
2330 if (binop_user_defined_p (op
, arg1
, arg2
))
2332 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2336 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2337 tem
= value_equal (arg1
, arg2
);
2338 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2339 return value_from_longest (type
, (LONGEST
) ! tem
);
2343 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2344 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2345 if (noside
== EVAL_SKIP
)
2347 if (binop_user_defined_p (op
, arg1
, arg2
))
2349 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2353 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2354 tem
= value_less (arg1
, arg2
);
2355 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2356 return value_from_longest (type
, (LONGEST
) tem
);
2360 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2361 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2362 if (noside
== EVAL_SKIP
)
2364 if (binop_user_defined_p (op
, arg1
, arg2
))
2366 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2370 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2371 tem
= value_less (arg2
, arg1
);
2372 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2373 return value_from_longest (type
, (LONGEST
) tem
);
2377 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2378 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2379 if (noside
== EVAL_SKIP
)
2381 if (binop_user_defined_p (op
, arg1
, arg2
))
2383 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2387 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2388 tem
= value_less (arg2
, arg1
) || value_equal (arg1
, arg2
);
2389 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2390 return value_from_longest (type
, (LONGEST
) tem
);
2394 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2395 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2396 if (noside
== EVAL_SKIP
)
2398 if (binop_user_defined_p (op
, arg1
, arg2
))
2400 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2404 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2405 tem
= value_less (arg1
, arg2
) || value_equal (arg1
, arg2
);
2406 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2407 return value_from_longest (type
, (LONGEST
) tem
);
2411 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2412 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2413 if (noside
== EVAL_SKIP
)
2415 type
= check_typedef (value_type (arg2
));
2416 if (TYPE_CODE (type
) != TYPE_CODE_INT
)
2417 error (_("Non-integral right operand for \"@\" operator."));
2418 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2420 return allocate_repeat_value (value_type (arg1
),
2421 longest_to_int (value_as_long (arg2
)));
2424 return value_repeat (arg1
, longest_to_int (value_as_long (arg2
)));
2427 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2428 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2431 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2432 if (noside
== EVAL_SKIP
)
2434 if (unop_user_defined_p (op
, arg1
))
2435 return value_x_unop (arg1
, op
, noside
);
2438 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2439 return value_pos (arg1
);
2443 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2444 if (noside
== EVAL_SKIP
)
2446 if (unop_user_defined_p (op
, arg1
))
2447 return value_x_unop (arg1
, op
, noside
);
2450 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2451 return value_neg (arg1
);
2454 case UNOP_COMPLEMENT
:
2455 /* C++: check for and handle destructor names. */
2456 op
= exp
->elts
[*pos
].opcode
;
2458 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2459 if (noside
== EVAL_SKIP
)
2461 if (unop_user_defined_p (UNOP_COMPLEMENT
, arg1
))
2462 return value_x_unop (arg1
, UNOP_COMPLEMENT
, noside
);
2465 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2466 return value_complement (arg1
);
2469 case UNOP_LOGICAL_NOT
:
2470 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2471 if (noside
== EVAL_SKIP
)
2473 if (unop_user_defined_p (op
, arg1
))
2474 return value_x_unop (arg1
, op
, noside
);
2477 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2478 return value_from_longest (type
, (LONGEST
) value_logical_not (arg1
));
2482 if (expect_type
&& TYPE_CODE (expect_type
) == TYPE_CODE_PTR
)
2483 expect_type
= TYPE_TARGET_TYPE (check_typedef (expect_type
));
2484 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2485 type
= check_typedef (value_type (arg1
));
2486 if (TYPE_CODE (type
) == TYPE_CODE_METHODPTR
2487 || TYPE_CODE (type
) == TYPE_CODE_MEMBERPTR
)
2488 error (_("Attempt to dereference pointer "
2489 "to member without an object"));
2490 if (noside
== EVAL_SKIP
)
2492 if (unop_user_defined_p (op
, arg1
))
2493 return value_x_unop (arg1
, op
, noside
);
2494 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2496 type
= check_typedef (value_type (arg1
));
2497 if (TYPE_CODE (type
) == TYPE_CODE_PTR
2498 || TYPE_CODE (type
) == TYPE_CODE_REF
2499 /* In C you can dereference an array to get the 1st elt. */
2500 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
2502 return value_zero (TYPE_TARGET_TYPE (type
),
2504 else if (TYPE_CODE (type
) == TYPE_CODE_INT
)
2505 /* GDB allows dereferencing an int. */
2506 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
,
2509 error (_("Attempt to take contents of a non-pointer value."));
2512 /* Allow * on an integer so we can cast it to whatever we want.
2513 This returns an int, which seems like the most C-like thing to
2514 do. "long long" variables are rare enough that
2515 BUILTIN_TYPE_LONGEST would seem to be a mistake. */
2516 if (TYPE_CODE (type
) == TYPE_CODE_INT
)
2517 return value_at_lazy (builtin_type (exp
->gdbarch
)->builtin_int
,
2518 (CORE_ADDR
) value_as_address (arg1
));
2519 return value_ind (arg1
);
2522 /* C++: check for and handle pointer to members. */
2524 op
= exp
->elts
[*pos
].opcode
;
2526 if (noside
== EVAL_SKIP
)
2528 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
2533 struct value
*retvalp
= evaluate_subexp_for_address (exp
, pos
,
2540 if (noside
== EVAL_SKIP
)
2542 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
2545 return evaluate_subexp_for_sizeof (exp
, pos
, noside
);
2549 type
= exp
->elts
[pc
+ 1].type
;
2550 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
2551 if (noside
== EVAL_SKIP
)
2553 if (type
!= value_type (arg1
))
2554 arg1
= value_cast (type
, arg1
);
2557 case UNOP_CAST_TYPE
:
2558 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2559 type
= value_type (arg1
);
2560 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
2561 if (noside
== EVAL_SKIP
)
2563 if (type
!= value_type (arg1
))
2564 arg1
= value_cast (type
, arg1
);
2567 case UNOP_DYNAMIC_CAST
:
2568 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2569 type
= value_type (arg1
);
2570 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
2571 if (noside
== EVAL_SKIP
)
2573 return value_dynamic_cast (type
, arg1
);
2575 case UNOP_REINTERPRET_CAST
:
2576 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2577 type
= value_type (arg1
);
2578 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
2579 if (noside
== EVAL_SKIP
)
2581 return value_reinterpret_cast (type
, arg1
);
2585 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2586 if (noside
== EVAL_SKIP
)
2588 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2589 return value_zero (exp
->elts
[pc
+ 1].type
, lval_memory
);
2591 return value_at_lazy (exp
->elts
[pc
+ 1].type
,
2592 value_as_address (arg1
));
2594 case UNOP_MEMVAL_TYPE
:
2595 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2596 type
= value_type (arg1
);
2597 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2598 if (noside
== EVAL_SKIP
)
2600 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2601 return value_zero (type
, lval_memory
);
2603 return value_at_lazy (type
, value_as_address (arg1
));
2605 case UNOP_MEMVAL_TLS
:
2607 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2608 if (noside
== EVAL_SKIP
)
2610 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2611 return value_zero (exp
->elts
[pc
+ 2].type
, lval_memory
);
2616 tls_addr
= target_translate_tls_address (exp
->elts
[pc
+ 1].objfile
,
2617 value_as_address (arg1
));
2618 return value_at_lazy (exp
->elts
[pc
+ 2].type
, tls_addr
);
2621 case UNOP_PREINCREMENT
:
2622 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2623 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2625 else if (unop_user_defined_p (op
, arg1
))
2627 return value_x_unop (arg1
, op
, noside
);
2631 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2632 arg2
= value_ptradd (arg1
, 1);
2635 struct value
*tmp
= arg1
;
2637 arg2
= value_one (value_type (arg1
));
2638 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2639 arg2
= value_binop (tmp
, arg2
, BINOP_ADD
);
2642 return value_assign (arg1
, arg2
);
2645 case UNOP_PREDECREMENT
:
2646 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2647 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2649 else if (unop_user_defined_p (op
, arg1
))
2651 return value_x_unop (arg1
, op
, noside
);
2655 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2656 arg2
= value_ptradd (arg1
, -1);
2659 struct value
*tmp
= arg1
;
2661 arg2
= value_one (value_type (arg1
));
2662 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2663 arg2
= value_binop (tmp
, arg2
, BINOP_SUB
);
2666 return value_assign (arg1
, arg2
);
2669 case UNOP_POSTINCREMENT
:
2670 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2671 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2673 else if (unop_user_defined_p (op
, arg1
))
2675 return value_x_unop (arg1
, op
, noside
);
2679 arg3
= value_non_lval (arg1
);
2681 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2682 arg2
= value_ptradd (arg1
, 1);
2685 struct value
*tmp
= arg1
;
2687 arg2
= value_one (value_type (arg1
));
2688 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2689 arg2
= value_binop (tmp
, arg2
, BINOP_ADD
);
2692 value_assign (arg1
, arg2
);
2696 case UNOP_POSTDECREMENT
:
2697 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2698 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2700 else if (unop_user_defined_p (op
, arg1
))
2702 return value_x_unop (arg1
, op
, noside
);
2706 arg3
= value_non_lval (arg1
);
2708 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2709 arg2
= value_ptradd (arg1
, -1);
2712 struct value
*tmp
= arg1
;
2714 arg2
= value_one (value_type (arg1
));
2715 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2716 arg2
= value_binop (tmp
, arg2
, BINOP_SUB
);
2719 value_assign (arg1
, arg2
);
2725 return value_of_this (exp
->language_defn
);
2728 /* The value is not supposed to be used. This is here to make it
2729 easier to accommodate expressions that contain types. */
2731 if (noside
== EVAL_SKIP
)
2733 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2735 struct type
*type
= exp
->elts
[pc
+ 1].type
;
2737 /* If this is a typedef, then find its immediate target. We
2738 use check_typedef to resolve stubs, but we ignore its
2739 result because we do not want to dig past all
2741 check_typedef (type
);
2742 if (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
2743 type
= TYPE_TARGET_TYPE (type
);
2744 return allocate_value (type
);
2747 error (_("Attempt to use a type name as an expression"));
2751 if (noside
== EVAL_SKIP
)
2753 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
2756 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2758 enum exp_opcode sub_op
= exp
->elts
[*pos
].opcode
;
2759 struct value
*result
;
2761 result
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
2762 EVAL_AVOID_SIDE_EFFECTS
);
2764 /* 'decltype' has special semantics for lvalues. */
2765 if (op
== OP_DECLTYPE
2766 && (sub_op
== BINOP_SUBSCRIPT
2767 || sub_op
== STRUCTOP_MEMBER
2768 || sub_op
== STRUCTOP_MPTR
2769 || sub_op
== UNOP_IND
2770 || sub_op
== STRUCTOP_STRUCT
2771 || sub_op
== STRUCTOP_PTR
2772 || sub_op
== OP_SCOPE
))
2774 struct type
*type
= value_type (result
);
2776 if (TYPE_CODE (check_typedef (type
)) != TYPE_CODE_REF
)
2778 type
= lookup_reference_type (type
);
2779 result
= allocate_value (type
);
2786 error (_("Attempt to use a type as an expression"));
2790 struct value
*result
;
2791 enum exp_opcode sub_op
= exp
->elts
[*pos
].opcode
;
2793 if (sub_op
== OP_TYPE
|| sub_op
== OP_DECLTYPE
|| sub_op
== OP_TYPEOF
)
2794 result
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
2795 EVAL_AVOID_SIDE_EFFECTS
);
2797 result
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2799 if (noside
!= EVAL_NORMAL
)
2800 return allocate_value (cplus_typeid_type (exp
->gdbarch
));
2802 return cplus_typeid (result
);
2806 /* Removing this case and compiling with gcc -Wall reveals that
2807 a lot of cases are hitting this case. Some of these should
2808 probably be removed from expression.h; others are legitimate
2809 expressions which are (apparently) not fully implemented.
2811 If there are any cases landing here which mean a user error,
2812 then they should be separate cases, with more descriptive
2815 error (_("GDB does not (yet) know how to "
2816 "evaluate that kind of expression"));
2820 return value_from_longest (builtin_type (exp
->gdbarch
)->builtin_int
, 1);
2823 /* Evaluate a subexpression of EXP, at index *POS,
2824 and return the address of that subexpression.
2825 Advance *POS over the subexpression.
2826 If the subexpression isn't an lvalue, get an error.
2827 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
2828 then only the type of the result need be correct. */
2830 static struct value
*
2831 evaluate_subexp_for_address (struct expression
*exp
, int *pos
,
2841 op
= exp
->elts
[pc
].opcode
;
2847 x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2849 /* We can't optimize out "&*" if there's a user-defined operator*. */
2850 if (unop_user_defined_p (op
, x
))
2852 x
= value_x_unop (x
, op
, noside
);
2853 goto default_case_after_eval
;
2856 return coerce_array (x
);
2860 return value_cast (lookup_pointer_type (exp
->elts
[pc
+ 1].type
),
2861 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
2863 case UNOP_MEMVAL_TYPE
:
2868 x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2869 type
= value_type (x
);
2870 return value_cast (lookup_pointer_type (type
),
2871 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
2875 var
= exp
->elts
[pc
+ 2].symbol
;
2877 /* C++: The "address" of a reference should yield the address
2878 * of the object pointed to. Let value_addr() deal with it. */
2879 if (TYPE_CODE (SYMBOL_TYPE (var
)) == TYPE_CODE_REF
)
2883 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2886 lookup_pointer_type (SYMBOL_TYPE (var
));
2887 enum address_class sym_class
= SYMBOL_CLASS (var
);
2889 if (sym_class
== LOC_CONST
2890 || sym_class
== LOC_CONST_BYTES
2891 || sym_class
== LOC_REGISTER
)
2892 error (_("Attempt to take address of register or constant."));
2895 value_zero (type
, not_lval
);
2898 return address_of_variable (var
, exp
->elts
[pc
+ 1].block
);
2901 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
2902 (*pos
) += 5 + BYTES_TO_EXP_ELEM (tem
+ 1);
2903 x
= value_aggregate_elt (exp
->elts
[pc
+ 1].type
,
2904 &exp
->elts
[pc
+ 3].string
,
2907 error (_("There is no field named %s"), &exp
->elts
[pc
+ 3].string
);
2912 x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2913 default_case_after_eval
:
2914 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2916 struct type
*type
= check_typedef (value_type (x
));
2918 if (TYPE_CODE (type
) == TYPE_CODE_REF
)
2919 return value_zero (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
2921 else if (VALUE_LVAL (x
) == lval_memory
|| value_must_coerce_to_target (x
))
2922 return value_zero (lookup_pointer_type (value_type (x
)),
2925 error (_("Attempt to take address of "
2926 "value not located in memory."));
2928 return value_addr (x
);
2932 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
2933 When used in contexts where arrays will be coerced anyway, this is
2934 equivalent to `evaluate_subexp' but much faster because it avoids
2935 actually fetching array contents (perhaps obsolete now that we have
2938 Note that we currently only do the coercion for C expressions, where
2939 arrays are zero based and the coercion is correct. For other languages,
2940 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
2941 to decide if coercion is appropriate. */
2944 evaluate_subexp_with_coercion (struct expression
*exp
,
2945 int *pos
, enum noside noside
)
2954 op
= exp
->elts
[pc
].opcode
;
2959 var
= exp
->elts
[pc
+ 2].symbol
;
2960 type
= check_typedef (SYMBOL_TYPE (var
));
2961 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
2962 && !TYPE_VECTOR (type
)
2963 && CAST_IS_CONVERSION (exp
->language_defn
))
2966 val
= address_of_variable (var
, exp
->elts
[pc
+ 1].block
);
2967 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
2973 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2977 /* Evaluate a subexpression of EXP, at index *POS,
2978 and return a value for the size of that subexpression.
2979 Advance *POS over the subexpression. If NOSIDE is EVAL_NORMAL
2980 we allow side-effects on the operand if its type is a variable
2983 static struct value
*
2984 evaluate_subexp_for_sizeof (struct expression
*exp
, int *pos
,
2987 /* FIXME: This should be size_t. */
2988 struct type
*size_type
= builtin_type (exp
->gdbarch
)->builtin_int
;
2995 op
= exp
->elts
[pc
].opcode
;
2999 /* This case is handled specially
3000 so that we avoid creating a value for the result type.
3001 If the result type is very big, it's desirable not to
3002 create a value unnecessarily. */
3005 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3006 type
= check_typedef (value_type (val
));
3007 if (TYPE_CODE (type
) != TYPE_CODE_PTR
3008 && TYPE_CODE (type
) != TYPE_CODE_REF
3009 && TYPE_CODE (type
) != TYPE_CODE_ARRAY
)
3010 error (_("Attempt to take contents of a non-pointer value."));
3011 type
= TYPE_TARGET_TYPE (type
);
3012 if (is_dynamic_type (type
))
3013 type
= value_type (value_ind (val
));
3014 return value_from_longest (size_type
, (LONGEST
) TYPE_LENGTH (type
));
3018 type
= exp
->elts
[pc
+ 1].type
;
3021 case UNOP_MEMVAL_TYPE
:
3023 val
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3024 type
= value_type (val
);
3028 type
= SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
);
3029 if (is_dynamic_type (type
))
3031 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_NORMAL
);
3032 type
= value_type (val
);
3038 /* Deal with the special case if NOSIDE is EVAL_NORMAL and the resulting
3039 type of the subscript is a variable length array type. In this case we
3040 must re-evaluate the right hand side of the subcription to allow
3042 case BINOP_SUBSCRIPT
:
3043 if (noside
== EVAL_NORMAL
)
3045 int pc
= (*pos
) + 1;
3047 val
= evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_AVOID_SIDE_EFFECTS
);
3048 type
= check_typedef (value_type (val
));
3049 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
3051 type
= check_typedef (TYPE_TARGET_TYPE (type
));
3052 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
3054 type
= TYPE_INDEX_TYPE (type
);
3055 /* Only re-evaluate the right hand side if the resulting type
3056 is a variable length type. */
3057 if (TYPE_RANGE_DATA (type
)->flag_bound_evaluated
)
3059 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_NORMAL
);
3060 return value_from_longest
3061 (size_type
, (LONGEST
) TYPE_LENGTH (value_type (val
)));
3070 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3071 type
= value_type (val
);
3075 /* $5.3.3/2 of the C++ Standard (n3290 draft) says of sizeof:
3076 "When applied to a reference or a reference type, the result is
3077 the size of the referenced type." */
3078 CHECK_TYPEDEF (type
);
3079 if (exp
->language_defn
->la_language
== language_cplus
3080 && TYPE_CODE (type
) == TYPE_CODE_REF
)
3081 type
= check_typedef (TYPE_TARGET_TYPE (type
));
3082 return value_from_longest (size_type
, (LONGEST
) TYPE_LENGTH (type
));
3085 /* Parse a type expression in the string [P..P+LENGTH). */
3088 parse_and_eval_type (char *p
, int length
)
3090 char *tmp
= (char *) alloca (length
+ 4);
3091 struct expression
*expr
;
3094 memcpy (tmp
+ 1, p
, length
);
3095 tmp
[length
+ 1] = ')';
3096 tmp
[length
+ 2] = '0';
3097 tmp
[length
+ 3] = '\0';
3098 expr
= parse_expression (tmp
);
3099 if (expr
->elts
[0].opcode
!= UNOP_CAST
)
3100 error (_("Internal error in eval_type."));
3101 return expr
->elts
[1].type
;
3105 calc_f77_array_dims (struct type
*array_type
)
3108 struct type
*tmp_type
;
3110 if ((TYPE_CODE (array_type
) != TYPE_CODE_ARRAY
))
3111 error (_("Can't get dimensions for a non-array type"));
3113 tmp_type
= array_type
;
3115 while ((tmp_type
= TYPE_TARGET_TYPE (tmp_type
)))
3117 if (TYPE_CODE (tmp_type
) == TYPE_CODE_ARRAY
)