1 /* Evaluate expressions for GDB.
3 Copyright (C) 1986-2017 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 expression_up expr
= parse_expression (exp
);
100 return value_as_address (evaluate_expression (expr
.get ()));
103 /* Like parse_and_eval_address, but treats the value of the expression
104 as an integer, not an address, returns a LONGEST, not a CORE_ADDR. */
106 parse_and_eval_long (const char *exp
)
108 expression_up expr
= parse_expression (exp
);
110 return value_as_long (evaluate_expression (expr
.get ()));
114 parse_and_eval (const char *exp
)
116 expression_up expr
= parse_expression (exp
);
118 return evaluate_expression (expr
.get ());
121 /* Parse up to a comma (or to a closeparen)
122 in the string EXPP as an expression, evaluate it, and return the value.
123 EXPP is advanced to point to the comma. */
126 parse_to_comma_and_eval (const char **expp
)
128 expression_up expr
= parse_exp_1 (expp
, 0, (struct block
*) 0, 1);
130 return evaluate_expression (expr
.get ());
133 /* Evaluate an expression in internal prefix form
134 such as is constructed by parse.y.
136 See expression.h for info on the format of an expression. */
139 evaluate_expression (struct expression
*exp
)
143 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_NORMAL
);
146 /* Evaluate an expression, avoiding all memory references
147 and getting a value whose type alone is correct. */
150 evaluate_type (struct expression
*exp
)
154 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_AVOID_SIDE_EFFECTS
);
157 /* Evaluate a subexpression, avoiding all memory references and
158 getting a value whose type alone is correct. */
161 evaluate_subexpression_type (struct expression
*exp
, int subexp
)
163 return evaluate_subexp (NULL_TYPE
, exp
, &subexp
, EVAL_AVOID_SIDE_EFFECTS
);
166 /* Find the current value of a watchpoint on EXP. Return the value in
167 *VALP and *RESULTP and the chain of intermediate and final values
168 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
171 If PRESERVE_ERRORS is true, then exceptions are passed through.
172 Otherwise, if PRESERVE_ERRORS is false, then if a memory error
173 occurs while evaluating the expression, *RESULTP will be set to
174 NULL. *RESULTP may be a lazy value, if the result could not be
175 read from memory. It is used to determine whether a value is
176 user-specified (we should watch the whole value) or intermediate
177 (we should watch only the bit used to locate the final value).
179 If the final value, or any intermediate value, could not be read
180 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
181 set to any referenced values. *VALP will never be a lazy value.
182 This is the value which we store in struct breakpoint.
184 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
185 value chain. The caller must free the values individually. If
186 VAL_CHAIN is NULL, all generated values will be left on the value
190 fetch_subexp_value (struct expression
*exp
, int *pc
, struct value
**valp
,
191 struct value
**resultp
, struct value
**val_chain
,
194 struct value
*mark
, *new_mark
, *result
;
202 /* Evaluate the expression. */
203 mark
= value_mark ();
208 result
= evaluate_subexp (NULL_TYPE
, exp
, pc
, EVAL_NORMAL
);
210 CATCH (ex
, RETURN_MASK_ALL
)
212 /* Ignore memory errors if we want watchpoints pointing at
213 inaccessible memory to still be created; otherwise, throw the
214 error to some higher catcher. */
218 if (!preserve_errors
)
221 throw_exception (ex
);
227 new_mark
= value_mark ();
228 if (mark
== new_mark
)
233 /* Make sure it's not lazy, so that after the target stops again we
234 have a non-lazy previous value to compare with. */
237 if (!value_lazy (result
))
244 value_fetch_lazy (result
);
247 CATCH (except
, RETURN_MASK_ERROR
)
256 /* Return the chain of intermediate values. We use this to
257 decide which addresses to watch. */
258 *val_chain
= new_mark
;
259 value_release_to_mark (mark
);
263 /* Extract a field operation from an expression. If the subexpression
264 of EXP starting at *SUBEXP is not a structure dereference
265 operation, return NULL. Otherwise, return the name of the
266 dereferenced field, and advance *SUBEXP to point to the
267 subexpression of the left-hand-side of the dereference. This is
268 used when completing field names. */
271 extract_field_op (struct expression
*exp
, int *subexp
)
276 if (exp
->elts
[*subexp
].opcode
!= STRUCTOP_STRUCT
277 && exp
->elts
[*subexp
].opcode
!= STRUCTOP_PTR
)
279 tem
= longest_to_int (exp
->elts
[*subexp
+ 1].longconst
);
280 result
= &exp
->elts
[*subexp
+ 2].string
;
281 (*subexp
) += 1 + 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
285 /* This function evaluates brace-initializers (in C/C++) for
288 static struct value
*
289 evaluate_struct_tuple (struct value
*struct_val
,
290 struct expression
*exp
,
291 int *pos
, enum noside noside
, int nargs
)
293 struct type
*struct_type
= check_typedef (value_type (struct_val
));
294 struct type
*field_type
;
299 struct value
*val
= NULL
;
304 /* Skip static fields. */
305 while (fieldno
< TYPE_NFIELDS (struct_type
)
306 && field_is_static (&TYPE_FIELD (struct_type
,
309 if (fieldno
>= TYPE_NFIELDS (struct_type
))
310 error (_("too many initializers"));
311 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
312 if (TYPE_CODE (field_type
) == TYPE_CODE_UNION
313 && TYPE_FIELD_NAME (struct_type
, fieldno
)[0] == '0')
314 error (_("don't know which variant you want to set"));
316 /* Here, struct_type is the type of the inner struct,
317 while substruct_type is the type of the inner struct.
318 These are the same for normal structures, but a variant struct
319 contains anonymous union fields that contain substruct fields.
320 The value fieldno is the index of the top-level (normal or
321 anonymous union) field in struct_field, while the value
322 subfieldno is the index of the actual real (named inner) field
323 in substruct_type. */
325 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
327 val
= evaluate_subexp (field_type
, exp
, pos
, noside
);
329 /* Now actually set the field in struct_val. */
331 /* Assign val to field fieldno. */
332 if (value_type (val
) != field_type
)
333 val
= value_cast (field_type
, val
);
335 bitsize
= TYPE_FIELD_BITSIZE (struct_type
, fieldno
);
336 bitpos
= TYPE_FIELD_BITPOS (struct_type
, fieldno
);
337 addr
= value_contents_writeable (struct_val
) + bitpos
/ 8;
339 modify_field (struct_type
, addr
,
340 value_as_long (val
), bitpos
% 8, bitsize
);
342 memcpy (addr
, value_contents (val
),
343 TYPE_LENGTH (value_type (val
)));
349 /* Recursive helper function for setting elements of array tuples.
350 The target is ARRAY (which has bounds LOW_BOUND to HIGH_BOUND); the
351 element value is ELEMENT; EXP, POS and NOSIDE are as usual.
352 Evaluates index expresions and sets the specified element(s) of
353 ARRAY to ELEMENT. Returns last index value. */
356 init_array_element (struct value
*array
, struct value
*element
,
357 struct expression
*exp
, int *pos
,
358 enum noside noside
, LONGEST low_bound
, LONGEST high_bound
)
361 int element_size
= TYPE_LENGTH (value_type (element
));
363 if (exp
->elts
[*pos
].opcode
== BINOP_COMMA
)
366 init_array_element (array
, element
, exp
, pos
, noside
,
367 low_bound
, high_bound
);
368 return init_array_element (array
, element
,
369 exp
, pos
, noside
, low_bound
, high_bound
);
373 index
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
374 if (index
< low_bound
|| index
> high_bound
)
375 error (_("tuple index out of range"));
376 memcpy (value_contents_raw (array
) + (index
- low_bound
) * element_size
,
377 value_contents (element
), element_size
);
382 static struct value
*
383 value_f90_subarray (struct value
*array
,
384 struct expression
*exp
, int *pos
, enum noside noside
)
387 LONGEST low_bound
, high_bound
;
388 struct type
*range
= check_typedef (TYPE_INDEX_TYPE (value_type (array
)));
389 enum range_type range_type
390 = (enum range_type
) longest_to_int (exp
->elts
[pc
].longconst
);
394 if (range_type
== LOW_BOUND_DEFAULT
|| range_type
== BOTH_BOUND_DEFAULT
)
395 low_bound
= TYPE_LOW_BOUND (range
);
397 low_bound
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
399 if (range_type
== HIGH_BOUND_DEFAULT
|| range_type
== BOTH_BOUND_DEFAULT
)
400 high_bound
= TYPE_HIGH_BOUND (range
);
402 high_bound
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
404 return value_slice (array
, low_bound
, high_bound
- low_bound
+ 1);
408 /* Promote value ARG1 as appropriate before performing a unary operation
410 If the result is not appropriate for any particular language then it
411 needs to patch this function. */
414 unop_promote (const struct language_defn
*language
, struct gdbarch
*gdbarch
,
419 *arg1
= coerce_ref (*arg1
);
420 type1
= check_typedef (value_type (*arg1
));
422 if (is_integral_type (type1
))
424 switch (language
->la_language
)
427 /* Perform integral promotion for ANSI C/C++.
428 If not appropropriate for any particular language
429 it needs to modify this function. */
431 struct type
*builtin_int
= builtin_type (gdbarch
)->builtin_int
;
433 if (TYPE_LENGTH (type1
) < TYPE_LENGTH (builtin_int
))
434 *arg1
= value_cast (builtin_int
, *arg1
);
441 /* Promote values ARG1 and ARG2 as appropriate before performing a binary
442 operation on those two operands.
443 If the result is not appropriate for any particular language then it
444 needs to patch this function. */
447 binop_promote (const struct language_defn
*language
, struct gdbarch
*gdbarch
,
448 struct value
**arg1
, struct value
**arg2
)
450 struct type
*promoted_type
= NULL
;
454 *arg1
= coerce_ref (*arg1
);
455 *arg2
= coerce_ref (*arg2
);
457 type1
= check_typedef (value_type (*arg1
));
458 type2
= check_typedef (value_type (*arg2
));
460 if ((TYPE_CODE (type1
) != TYPE_CODE_FLT
461 && TYPE_CODE (type1
) != TYPE_CODE_DECFLOAT
462 && !is_integral_type (type1
))
463 || (TYPE_CODE (type2
) != TYPE_CODE_FLT
464 && TYPE_CODE (type2
) != TYPE_CODE_DECFLOAT
465 && !is_integral_type (type2
)))
468 if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
469 || TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
)
471 /* No promotion required. */
473 else if (TYPE_CODE (type1
) == TYPE_CODE_FLT
474 || TYPE_CODE (type2
) == TYPE_CODE_FLT
)
476 switch (language
->la_language
)
482 case language_opencl
:
483 /* No promotion required. */
487 /* For other languages the result type is unchanged from gdb
488 version 6.7 for backward compatibility.
489 If either arg was long double, make sure that value is also long
490 double. Otherwise use double. */
491 if (TYPE_LENGTH (type1
) * 8 > gdbarch_double_bit (gdbarch
)
492 || TYPE_LENGTH (type2
) * 8 > gdbarch_double_bit (gdbarch
))
493 promoted_type
= builtin_type (gdbarch
)->builtin_long_double
;
495 promoted_type
= builtin_type (gdbarch
)->builtin_double
;
499 else if (TYPE_CODE (type1
) == TYPE_CODE_BOOL
500 && TYPE_CODE (type2
) == TYPE_CODE_BOOL
)
502 /* No promotion required. */
505 /* Integral operations here. */
506 /* FIXME: Also mixed integral/booleans, with result an integer. */
508 const struct builtin_type
*builtin
= builtin_type (gdbarch
);
509 unsigned int promoted_len1
= TYPE_LENGTH (type1
);
510 unsigned int promoted_len2
= TYPE_LENGTH (type2
);
511 int is_unsigned1
= TYPE_UNSIGNED (type1
);
512 int is_unsigned2
= TYPE_UNSIGNED (type2
);
513 unsigned int result_len
;
514 int unsigned_operation
;
516 /* Determine type length and signedness after promotion for
518 if (promoted_len1
< TYPE_LENGTH (builtin
->builtin_int
))
521 promoted_len1
= TYPE_LENGTH (builtin
->builtin_int
);
523 if (promoted_len2
< TYPE_LENGTH (builtin
->builtin_int
))
526 promoted_len2
= TYPE_LENGTH (builtin
->builtin_int
);
529 if (promoted_len1
> promoted_len2
)
531 unsigned_operation
= is_unsigned1
;
532 result_len
= promoted_len1
;
534 else if (promoted_len2
> promoted_len1
)
536 unsigned_operation
= is_unsigned2
;
537 result_len
= promoted_len2
;
541 unsigned_operation
= is_unsigned1
|| is_unsigned2
;
542 result_len
= promoted_len1
;
545 switch (language
->la_language
)
551 if (result_len
<= TYPE_LENGTH (builtin
->builtin_int
))
553 promoted_type
= (unsigned_operation
554 ? builtin
->builtin_unsigned_int
555 : builtin
->builtin_int
);
557 else if (result_len
<= TYPE_LENGTH (builtin
->builtin_long
))
559 promoted_type
= (unsigned_operation
560 ? builtin
->builtin_unsigned_long
561 : builtin
->builtin_long
);
565 promoted_type
= (unsigned_operation
566 ? builtin
->builtin_unsigned_long_long
567 : builtin
->builtin_long_long
);
570 case language_opencl
:
571 if (result_len
<= TYPE_LENGTH (lookup_signed_typename
572 (language
, gdbarch
, "int")))
576 ? lookup_unsigned_typename (language
, gdbarch
, "int")
577 : lookup_signed_typename (language
, gdbarch
, "int"));
579 else if (result_len
<= TYPE_LENGTH (lookup_signed_typename
580 (language
, gdbarch
, "long")))
584 ? lookup_unsigned_typename (language
, gdbarch
, "long")
585 : lookup_signed_typename (language
, gdbarch
,"long"));
589 /* For other languages the result type is unchanged from gdb
590 version 6.7 for backward compatibility.
591 If either arg was long long, make sure that value is also long
592 long. Otherwise use long. */
593 if (unsigned_operation
)
595 if (result_len
> gdbarch_long_bit (gdbarch
) / HOST_CHAR_BIT
)
596 promoted_type
= builtin
->builtin_unsigned_long_long
;
598 promoted_type
= builtin
->builtin_unsigned_long
;
602 if (result_len
> gdbarch_long_bit (gdbarch
) / HOST_CHAR_BIT
)
603 promoted_type
= builtin
->builtin_long_long
;
605 promoted_type
= builtin
->builtin_long
;
613 /* Promote both operands to common type. */
614 *arg1
= value_cast (promoted_type
, *arg1
);
615 *arg2
= value_cast (promoted_type
, *arg2
);
620 ptrmath_type_p (const struct language_defn
*lang
, struct type
*type
)
622 type
= check_typedef (type
);
623 if (TYPE_IS_REFERENCE (type
))
624 type
= TYPE_TARGET_TYPE (type
);
626 switch (TYPE_CODE (type
))
632 case TYPE_CODE_ARRAY
:
633 return TYPE_VECTOR (type
) ? 0 : lang
->c_style_arrays
;
640 /* Constructs a fake method with the given parameter types.
641 This function is used by the parser to construct an "expected"
642 type for method overload resolution. */
645 make_params (int num_types
, struct type
**param_types
)
647 struct type
*type
= XCNEW (struct type
);
648 TYPE_MAIN_TYPE (type
) = XCNEW (struct main_type
);
649 TYPE_LENGTH (type
) = 1;
650 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
651 TYPE_CHAIN (type
) = type
;
654 if (param_types
[num_types
- 1] == NULL
)
657 TYPE_VARARGS (type
) = 1;
659 else if (TYPE_CODE (check_typedef (param_types
[num_types
- 1]))
663 /* Caller should have ensured this. */
664 gdb_assert (num_types
== 0);
665 TYPE_PROTOTYPED (type
) = 1;
669 TYPE_NFIELDS (type
) = num_types
;
670 TYPE_FIELDS (type
) = (struct field
*)
671 TYPE_ZALLOC (type
, sizeof (struct field
) * num_types
);
673 while (num_types
-- > 0)
674 TYPE_FIELD_TYPE (type
, num_types
) = param_types
[num_types
];
679 /* Helper for evaluating an OP_VAR_VALUE. */
682 evaluate_var_value (enum noside noside
, const block
*blk
, symbol
*var
)
684 /* JYG: We used to just return value_zero of the symbol type if
685 we're asked to avoid side effects. Otherwise we return
686 value_of_variable (...). However I'm not sure if
687 value_of_variable () has any side effect. We need a full value
688 object returned here for whatis_exp () to call evaluate_type ()
689 and then pass the full value to value_rtti_target_type () if we
690 are dealing with a pointer or reference to a base class and print
693 struct value
*ret
= NULL
;
697 ret
= value_of_variable (var
, blk
);
700 CATCH (except
, RETURN_MASK_ERROR
)
702 if (noside
!= EVAL_AVOID_SIDE_EFFECTS
)
703 throw_exception (except
);
705 ret
= value_zero (SYMBOL_TYPE (var
), not_lval
);
712 /* Helper for evaluating an OP_VAR_MSYM_VALUE. */
715 evaluate_var_msym_value (enum noside noside
,
716 struct objfile
*objfile
, minimal_symbol
*msymbol
)
718 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
720 type
*the_type
= find_minsym_type_and_address (msymbol
, objfile
, NULL
);
721 return value_zero (the_type
, not_lval
);
726 type
*the_type
= find_minsym_type_and_address (msymbol
, objfile
, &address
);
727 return value_at_lazy (the_type
, address
);
731 /* Helper for returning a value when handling EVAL_SKIP. */
734 eval_skip_value (expression
*exp
)
736 return value_from_longest (builtin_type (exp
->gdbarch
)->builtin_int
, 1);
740 evaluate_subexp_standard (struct type
*expect_type
,
741 struct expression
*exp
, int *pos
,
746 int pc
, pc2
= 0, oldpos
;
747 struct value
*arg1
= NULL
;
748 struct value
*arg2
= NULL
;
752 struct value
**argvec
;
756 struct type
**arg_types
;
758 struct symbol
*function
= NULL
;
759 char *function_name
= NULL
;
760 const char *var_func_name
= NULL
;
763 op
= exp
->elts
[pc
].opcode
;
768 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
769 (*pos
) += 4 + BYTES_TO_EXP_ELEM (tem
+ 1);
770 if (noside
== EVAL_SKIP
)
771 return eval_skip_value (exp
);
772 arg1
= value_aggregate_elt (exp
->elts
[pc
+ 1].type
,
773 &exp
->elts
[pc
+ 3].string
,
774 expect_type
, 0, noside
);
776 error (_("There is no field named %s"), &exp
->elts
[pc
+ 3].string
);
781 return value_from_longest (exp
->elts
[pc
+ 1].type
,
782 exp
->elts
[pc
+ 2].longconst
);
786 return value_from_double (exp
->elts
[pc
+ 1].type
,
787 exp
->elts
[pc
+ 2].doubleconst
);
791 return value_from_decfloat (exp
->elts
[pc
+ 1].type
,
792 exp
->elts
[pc
+ 2].decfloatconst
);
797 if (noside
== EVAL_SKIP
)
798 return eval_skip_value (exp
);
799 return evaluate_var_value (noside
,
800 exp
->elts
[pc
+ 1].block
,
801 exp
->elts
[pc
+ 2].symbol
);
802 case OP_VAR_MSYM_VALUE
:
804 return evaluate_var_msym_value (noside
,
805 exp
->elts
[pc
+ 1].objfile
,
806 exp
->elts
[pc
+ 2].msymbol
);
808 case OP_VAR_ENTRY_VALUE
:
810 if (noside
== EVAL_SKIP
)
811 return eval_skip_value (exp
);
814 struct symbol
*sym
= exp
->elts
[pc
+ 1].symbol
;
815 struct frame_info
*frame
;
817 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
818 return value_zero (SYMBOL_TYPE (sym
), not_lval
);
820 if (SYMBOL_COMPUTED_OPS (sym
) == NULL
821 || SYMBOL_COMPUTED_OPS (sym
)->read_variable_at_entry
== NULL
)
822 error (_("Symbol \"%s\" does not have any specific entry value"),
823 SYMBOL_PRINT_NAME (sym
));
825 frame
= get_selected_frame (NULL
);
826 return SYMBOL_COMPUTED_OPS (sym
)->read_variable_at_entry (sym
, frame
);
832 access_value_history (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
836 const char *name
= &exp
->elts
[pc
+ 2].string
;
840 (*pos
) += 3 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
841 regno
= user_reg_map_name_to_regnum (exp
->gdbarch
,
842 name
, strlen (name
));
844 error (_("Register $%s not available."), name
);
846 /* In EVAL_AVOID_SIDE_EFFECTS mode, we only need to return
847 a value with the appropriate register type. Unfortunately,
848 we don't have easy access to the type of user registers.
849 So for these registers, we fetch the register value regardless
850 of the evaluation mode. */
851 if (noside
== EVAL_AVOID_SIDE_EFFECTS
852 && regno
< gdbarch_num_regs (exp
->gdbarch
)
853 + gdbarch_num_pseudo_regs (exp
->gdbarch
))
854 val
= value_zero (register_type (exp
->gdbarch
, regno
), not_lval
);
856 val
= value_of_register (regno
, get_selected_frame (NULL
));
858 error (_("Value of register %s not available."), name
);
864 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
865 return value_from_longest (type
, exp
->elts
[pc
+ 1].longconst
);
869 return value_of_internalvar (exp
->gdbarch
,
870 exp
->elts
[pc
+ 1].internalvar
);
873 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
874 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
875 if (noside
== EVAL_SKIP
)
876 return eval_skip_value (exp
);
877 type
= language_string_char_type (exp
->language_defn
, exp
->gdbarch
);
878 return value_string (&exp
->elts
[pc
+ 2].string
, tem
, type
);
880 case OP_OBJC_NSSTRING
: /* Objective C Foundation Class
881 NSString constant. */
882 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
883 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
884 if (noside
== EVAL_SKIP
)
885 return eval_skip_value (exp
);
886 return value_nsstring (exp
->gdbarch
, &exp
->elts
[pc
+ 2].string
, tem
+ 1);
890 tem2
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
891 tem3
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
892 nargs
= tem3
- tem2
+ 1;
893 type
= expect_type
? check_typedef (expect_type
) : NULL_TYPE
;
895 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
896 && TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
898 struct value
*rec
= allocate_value (expect_type
);
900 memset (value_contents_raw (rec
), '\0', TYPE_LENGTH (type
));
901 return evaluate_struct_tuple (rec
, exp
, pos
, noside
, nargs
);
904 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
905 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
907 struct type
*range_type
= TYPE_INDEX_TYPE (type
);
908 struct type
*element_type
= TYPE_TARGET_TYPE (type
);
909 struct value
*array
= allocate_value (expect_type
);
910 int element_size
= TYPE_LENGTH (check_typedef (element_type
));
911 LONGEST low_bound
, high_bound
, index
;
913 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
916 high_bound
= (TYPE_LENGTH (type
) / element_size
) - 1;
919 memset (value_contents_raw (array
), 0, TYPE_LENGTH (expect_type
));
920 for (tem
= nargs
; --nargs
>= 0;)
922 struct value
*element
;
925 element
= evaluate_subexp (element_type
, exp
, pos
, noside
);
926 if (value_type (element
) != element_type
)
927 element
= value_cast (element_type
, element
);
930 int continue_pc
= *pos
;
933 index
= init_array_element (array
, element
, exp
, pos
, noside
,
934 low_bound
, high_bound
);
939 if (index
> high_bound
)
940 /* To avoid memory corruption. */
941 error (_("Too many array elements"));
942 memcpy (value_contents_raw (array
)
943 + (index
- low_bound
) * element_size
,
944 value_contents (element
),
952 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
953 && TYPE_CODE (type
) == TYPE_CODE_SET
)
955 struct value
*set
= allocate_value (expect_type
);
956 gdb_byte
*valaddr
= value_contents_raw (set
);
957 struct type
*element_type
= TYPE_INDEX_TYPE (type
);
958 struct type
*check_type
= element_type
;
959 LONGEST low_bound
, high_bound
;
961 /* Get targettype of elementtype. */
962 while (TYPE_CODE (check_type
) == TYPE_CODE_RANGE
963 || TYPE_CODE (check_type
) == TYPE_CODE_TYPEDEF
)
964 check_type
= TYPE_TARGET_TYPE (check_type
);
966 if (get_discrete_bounds (element_type
, &low_bound
, &high_bound
) < 0)
967 error (_("(power)set type with unknown size"));
968 memset (valaddr
, '\0', TYPE_LENGTH (type
));
969 for (tem
= 0; tem
< nargs
; tem
++)
971 LONGEST range_low
, range_high
;
972 struct type
*range_low_type
, *range_high_type
;
973 struct value
*elem_val
;
975 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
976 range_low_type
= range_high_type
= value_type (elem_val
);
977 range_low
= range_high
= value_as_long (elem_val
);
979 /* Check types of elements to avoid mixture of elements from
980 different types. Also check if type of element is "compatible"
981 with element type of powerset. */
982 if (TYPE_CODE (range_low_type
) == TYPE_CODE_RANGE
)
983 range_low_type
= TYPE_TARGET_TYPE (range_low_type
);
984 if (TYPE_CODE (range_high_type
) == TYPE_CODE_RANGE
)
985 range_high_type
= TYPE_TARGET_TYPE (range_high_type
);
986 if ((TYPE_CODE (range_low_type
) != TYPE_CODE (range_high_type
))
987 || (TYPE_CODE (range_low_type
) == TYPE_CODE_ENUM
988 && (range_low_type
!= range_high_type
)))
989 /* different element modes. */
990 error (_("POWERSET tuple elements of different mode"));
991 if ((TYPE_CODE (check_type
) != TYPE_CODE (range_low_type
))
992 || (TYPE_CODE (check_type
) == TYPE_CODE_ENUM
993 && range_low_type
!= check_type
))
994 error (_("incompatible POWERSET tuple elements"));
995 if (range_low
> range_high
)
997 warning (_("empty POWERSET tuple range"));
1000 if (range_low
< low_bound
|| range_high
> high_bound
)
1001 error (_("POWERSET tuple element out of range"));
1002 range_low
-= low_bound
;
1003 range_high
-= low_bound
;
1004 for (; range_low
<= range_high
; range_low
++)
1006 int bit_index
= (unsigned) range_low
% TARGET_CHAR_BIT
;
1008 if (gdbarch_bits_big_endian (exp
->gdbarch
))
1009 bit_index
= TARGET_CHAR_BIT
- 1 - bit_index
;
1010 valaddr
[(unsigned) range_low
/ TARGET_CHAR_BIT
]
1017 argvec
= XALLOCAVEC (struct value
*, nargs
);
1018 for (tem
= 0; tem
< nargs
; tem
++)
1020 /* Ensure that array expressions are coerced into pointer
1022 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1024 if (noside
== EVAL_SKIP
)
1025 return eval_skip_value (exp
);
1026 return value_array (tem2
, tem3
, argvec
);
1030 struct value
*array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1032 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1034 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1036 if (noside
== EVAL_SKIP
)
1037 return eval_skip_value (exp
);
1038 return value_slice (array
, lowbound
, upper
- lowbound
+ 1);
1042 /* Skip third and second args to evaluate the first one. */
1043 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1044 if (value_logical_not (arg1
))
1046 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1047 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1051 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1052 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1056 case OP_OBJC_SELECTOR
:
1057 { /* Objective C @selector operator. */
1058 char *sel
= &exp
->elts
[pc
+ 2].string
;
1059 int len
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1060 struct type
*selector_type
;
1062 (*pos
) += 3 + BYTES_TO_EXP_ELEM (len
+ 1);
1063 if (noside
== EVAL_SKIP
)
1064 return eval_skip_value (exp
);
1067 sel
[len
] = 0; /* Make sure it's terminated. */
1069 selector_type
= builtin_type (exp
->gdbarch
)->builtin_data_ptr
;
1070 return value_from_longest (selector_type
,
1071 lookup_child_selector (exp
->gdbarch
, sel
));
1074 case OP_OBJC_MSGCALL
:
1075 { /* Objective C message (method) call. */
1077 CORE_ADDR responds_selector
= 0;
1078 CORE_ADDR method_selector
= 0;
1080 CORE_ADDR selector
= 0;
1082 int struct_return
= 0;
1083 enum noside sub_no_side
= EVAL_NORMAL
;
1085 struct value
*msg_send
= NULL
;
1086 struct value
*msg_send_stret
= NULL
;
1087 int gnu_runtime
= 0;
1089 struct value
*target
= NULL
;
1090 struct value
*method
= NULL
;
1091 struct value
*called_method
= NULL
;
1093 struct type
*selector_type
= NULL
;
1094 struct type
*long_type
;
1096 struct value
*ret
= NULL
;
1099 selector
= exp
->elts
[pc
+ 1].longconst
;
1100 nargs
= exp
->elts
[pc
+ 2].longconst
;
1101 argvec
= XALLOCAVEC (struct value
*, nargs
+ 5);
1105 long_type
= builtin_type (exp
->gdbarch
)->builtin_long
;
1106 selector_type
= builtin_type (exp
->gdbarch
)->builtin_data_ptr
;
1108 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1109 sub_no_side
= EVAL_NORMAL
;
1111 sub_no_side
= noside
;
1113 target
= evaluate_subexp (selector_type
, exp
, pos
, sub_no_side
);
1115 if (value_as_long (target
) == 0)
1116 return value_from_longest (long_type
, 0);
1118 if (lookup_minimal_symbol ("objc_msg_lookup", 0, 0).minsym
)
1121 /* Find the method dispatch (Apple runtime) or method lookup
1122 (GNU runtime) function for Objective-C. These will be used
1123 to lookup the symbol information for the method. If we
1124 can't find any symbol information, then we'll use these to
1125 call the method, otherwise we can call the method
1126 directly. The msg_send_stret function is used in the special
1127 case of a method that returns a structure (Apple runtime
1131 struct type
*type
= selector_type
;
1133 type
= lookup_function_type (type
);
1134 type
= lookup_pointer_type (type
);
1135 type
= lookup_function_type (type
);
1136 type
= lookup_pointer_type (type
);
1138 msg_send
= find_function_in_inferior ("objc_msg_lookup", NULL
);
1140 = find_function_in_inferior ("objc_msg_lookup", NULL
);
1142 msg_send
= value_from_pointer (type
, value_as_address (msg_send
));
1143 msg_send_stret
= value_from_pointer (type
,
1144 value_as_address (msg_send_stret
));
1148 msg_send
= find_function_in_inferior ("objc_msgSend", NULL
);
1149 /* Special dispatcher for methods returning structs. */
1151 = find_function_in_inferior ("objc_msgSend_stret", NULL
);
1154 /* Verify the target object responds to this method. The
1155 standard top-level 'Object' class uses a different name for
1156 the verification method than the non-standard, but more
1157 often used, 'NSObject' class. Make sure we check for both. */
1160 = lookup_child_selector (exp
->gdbarch
, "respondsToSelector:");
1161 if (responds_selector
== 0)
1163 = lookup_child_selector (exp
->gdbarch
, "respondsTo:");
1165 if (responds_selector
== 0)
1166 error (_("no 'respondsTo:' or 'respondsToSelector:' method"));
1169 = lookup_child_selector (exp
->gdbarch
, "methodForSelector:");
1170 if (method_selector
== 0)
1172 = lookup_child_selector (exp
->gdbarch
, "methodFor:");
1174 if (method_selector
== 0)
1175 error (_("no 'methodFor:' or 'methodForSelector:' method"));
1177 /* Call the verification method, to make sure that the target
1178 class implements the desired method. */
1180 argvec
[0] = msg_send
;
1182 argvec
[2] = value_from_longest (long_type
, responds_selector
);
1183 argvec
[3] = value_from_longest (long_type
, selector
);
1186 ret
= call_function_by_hand (argvec
[0], NULL
, 3, argvec
+ 1);
1189 /* Function objc_msg_lookup returns a pointer. */
1191 ret
= call_function_by_hand (argvec
[0], NULL
, 3, argvec
+ 1);
1193 if (value_as_long (ret
) == 0)
1194 error (_("Target does not respond to this message selector."));
1196 /* Call "methodForSelector:" method, to get the address of a
1197 function method that implements this selector for this
1198 class. If we can find a symbol at that address, then we
1199 know the return type, parameter types etc. (that's a good
1202 argvec
[0] = msg_send
;
1204 argvec
[2] = value_from_longest (long_type
, method_selector
);
1205 argvec
[3] = value_from_longest (long_type
, selector
);
1208 ret
= call_function_by_hand (argvec
[0], NULL
, 3, argvec
+ 1);
1212 ret
= call_function_by_hand (argvec
[0], NULL
, 3, argvec
+ 1);
1215 /* ret should now be the selector. */
1217 addr
= value_as_long (ret
);
1220 struct symbol
*sym
= NULL
;
1222 /* The address might point to a function descriptor;
1223 resolve it to the actual code address instead. */
1224 addr
= gdbarch_convert_from_func_ptr_addr (exp
->gdbarch
, addr
,
1227 /* Is it a high_level symbol? */
1228 sym
= find_pc_function (addr
);
1230 method
= value_of_variable (sym
, 0);
1233 /* If we found a method with symbol information, check to see
1234 if it returns a struct. Otherwise assume it doesn't. */
1239 struct type
*val_type
;
1241 funaddr
= find_function_addr (method
, &val_type
);
1243 block_for_pc (funaddr
);
1245 val_type
= check_typedef (val_type
);
1247 if ((val_type
== NULL
)
1248 || (TYPE_CODE(val_type
) == TYPE_CODE_ERROR
))
1250 if (expect_type
!= NULL
)
1251 val_type
= expect_type
;
1254 struct_return
= using_struct_return (exp
->gdbarch
, method
,
1257 else if (expect_type
!= NULL
)
1259 struct_return
= using_struct_return (exp
->gdbarch
, NULL
,
1260 check_typedef (expect_type
));
1263 /* Found a function symbol. Now we will substitute its
1264 value in place of the message dispatcher (obj_msgSend),
1265 so that we call the method directly instead of thru
1266 the dispatcher. The main reason for doing this is that
1267 we can now evaluate the return value and parameter values
1268 according to their known data types, in case we need to
1269 do things like promotion, dereferencing, special handling
1270 of structs and doubles, etc.
1272 We want to use the type signature of 'method', but still
1273 jump to objc_msgSend() or objc_msgSend_stret() to better
1274 mimic the behavior of the runtime. */
1278 if (TYPE_CODE (value_type (method
)) != TYPE_CODE_FUNC
)
1279 error (_("method address has symbol information "
1280 "with non-function type; skipping"));
1282 /* Create a function pointer of the appropriate type, and
1283 replace its value with the value of msg_send or
1284 msg_send_stret. We must use a pointer here, as
1285 msg_send and msg_send_stret are of pointer type, and
1286 the representation may be different on systems that use
1287 function descriptors. */
1290 = value_from_pointer (lookup_pointer_type (value_type (method
)),
1291 value_as_address (msg_send_stret
));
1294 = value_from_pointer (lookup_pointer_type (value_type (method
)),
1295 value_as_address (msg_send
));
1300 called_method
= msg_send_stret
;
1302 called_method
= msg_send
;
1305 if (noside
== EVAL_SKIP
)
1306 return eval_skip_value (exp
);
1308 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1310 /* If the return type doesn't look like a function type,
1311 call an error. This can happen if somebody tries to
1312 turn a variable into a function call. This is here
1313 because people often want to call, eg, strcmp, which
1314 gdb doesn't know is a function. If gdb isn't asked for
1315 it's opinion (ie. through "whatis"), it won't offer
1318 struct type
*type
= value_type (called_method
);
1320 if (type
&& TYPE_CODE (type
) == TYPE_CODE_PTR
)
1321 type
= TYPE_TARGET_TYPE (type
);
1322 type
= TYPE_TARGET_TYPE (type
);
1326 if ((TYPE_CODE (type
) == TYPE_CODE_ERROR
) && expect_type
)
1327 return allocate_value (expect_type
);
1329 return allocate_value (type
);
1332 error (_("Expression of type other than "
1333 "\"method returning ...\" used as a method"));
1336 /* Now depending on whether we found a symbol for the method,
1337 we will either call the runtime dispatcher or the method
1340 argvec
[0] = called_method
;
1342 argvec
[2] = value_from_longest (long_type
, selector
);
1343 /* User-supplied arguments. */
1344 for (tem
= 0; tem
< nargs
; tem
++)
1345 argvec
[tem
+ 3] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1346 argvec
[tem
+ 3] = 0;
1348 if (gnu_runtime
&& (method
!= NULL
))
1350 /* Function objc_msg_lookup returns a pointer. */
1351 deprecated_set_value_type (argvec
[0],
1352 lookup_pointer_type (lookup_function_type (value_type (argvec
[0]))));
1354 = call_function_by_hand (argvec
[0], NULL
, nargs
+ 2, argvec
+ 1);
1357 ret
= call_function_by_hand (argvec
[0], NULL
, nargs
+ 2, argvec
+ 1);
1364 op
= exp
->elts
[*pos
].opcode
;
1365 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1366 /* Allocate arg vector, including space for the function to be
1367 called in argvec[0], a potential `this', and a terminating NULL. */
1368 argvec
= (struct value
**)
1369 alloca (sizeof (struct value
*) * (nargs
+ 3));
1370 if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
1372 /* First, evaluate the structure into arg2. */
1375 if (op
== STRUCTOP_MEMBER
)
1377 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
1381 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1384 /* If the function is a virtual function, then the
1385 aggregate value (providing the structure) plays
1386 its part by providing the vtable. Otherwise,
1387 it is just along for the ride: call the function
1390 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1392 type
= check_typedef (value_type (arg1
));
1393 if (noside
== EVAL_SKIP
)
1394 tem
= 1; /* Set it to the right arg index so that all arguments
1395 can also be skipped. */
1396 else if (TYPE_CODE (type
) == TYPE_CODE_METHODPTR
)
1398 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1399 arg1
= value_zero (TYPE_TARGET_TYPE (type
), not_lval
);
1401 arg1
= cplus_method_ptr_to_value (&arg2
, arg1
);
1403 /* Now, say which argument to start evaluating from. */
1408 else if (TYPE_CODE (type
) == TYPE_CODE_MEMBERPTR
)
1410 struct type
*type_ptr
1411 = lookup_pointer_type (TYPE_SELF_TYPE (type
));
1412 struct type
*target_type_ptr
1413 = lookup_pointer_type (TYPE_TARGET_TYPE (type
));
1415 /* Now, convert these values to an address. */
1416 arg2
= value_cast (type_ptr
, arg2
);
1418 mem_offset
= value_as_long (arg1
);
1420 arg1
= value_from_pointer (target_type_ptr
,
1421 value_as_long (arg2
) + mem_offset
);
1422 arg1
= value_ind (arg1
);
1426 error (_("Non-pointer-to-member value used in pointer-to-member "
1429 else if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
1431 /* Hair for method invocations. */
1435 /* First, evaluate the structure into arg2. */
1437 tem2
= longest_to_int (exp
->elts
[pc2
+ 1].longconst
);
1438 *pos
+= 3 + BYTES_TO_EXP_ELEM (tem2
+ 1);
1440 if (op
== STRUCTOP_STRUCT
)
1442 /* If v is a variable in a register, and the user types
1443 v.method (), this will produce an error, because v has
1446 A possible way around this would be to allocate a
1447 copy of the variable on the stack, copy in the
1448 contents, call the function, and copy out the
1449 contents. I.e. convert this from call by reference
1450 to call by copy-return (or whatever it's called).
1451 However, this does not work because it is not the
1452 same: the method being called could stash a copy of
1453 the address, and then future uses through that address
1454 (after the method returns) would be expected to
1455 use the variable itself, not some copy of it. */
1456 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
1460 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1462 /* Check to see if the operator '->' has been
1463 overloaded. If the operator has been overloaded
1464 replace arg2 with the value returned by the custom
1465 operator and continue evaluation. */
1466 while (unop_user_defined_p (op
, arg2
))
1468 struct value
*value
= NULL
;
1471 value
= value_x_unop (arg2
, op
, noside
);
1474 CATCH (except
, RETURN_MASK_ERROR
)
1476 if (except
.error
== NOT_FOUND_ERROR
)
1479 throw_exception (except
);
1486 /* Now, say which argument to start evaluating from. */
1489 else if (op
== OP_SCOPE
1490 && overload_resolution
1491 && (exp
->language_defn
->la_language
== language_cplus
))
1493 /* Unpack it locally so we can properly handle overload
1499 local_tem
= longest_to_int (exp
->elts
[pc2
+ 2].longconst
);
1500 (*pos
) += 4 + BYTES_TO_EXP_ELEM (local_tem
+ 1);
1501 type
= exp
->elts
[pc2
+ 1].type
;
1502 name
= &exp
->elts
[pc2
+ 3].string
;
1505 function_name
= NULL
;
1506 if (TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
1508 function
= cp_lookup_symbol_namespace (TYPE_TAG_NAME (type
),
1510 get_selected_block (0),
1512 if (function
== NULL
)
1513 error (_("No symbol \"%s\" in namespace \"%s\"."),
1514 name
, TYPE_TAG_NAME (type
));
1517 /* arg2 is left as NULL on purpose. */
1521 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_STRUCT
1522 || TYPE_CODE (type
) == TYPE_CODE_UNION
);
1523 function_name
= name
;
1525 /* We need a properly typed value for method lookup. For
1526 static methods arg2 is otherwise unused. */
1527 arg2
= value_zero (type
, lval_memory
);
1532 else if (op
== OP_ADL_FUNC
)
1534 /* Save the function position and move pos so that the arguments
1535 can be evaluated. */
1541 func_name_len
= longest_to_int (exp
->elts
[save_pos1
+ 3].longconst
);
1542 (*pos
) += 6 + BYTES_TO_EXP_ELEM (func_name_len
+ 1);
1546 /* Non-method function call. */
1550 /* If this is a C++ function wait until overload resolution. */
1551 if (op
== OP_VAR_VALUE
1552 && overload_resolution
1553 && (exp
->language_defn
->la_language
== language_cplus
))
1555 (*pos
) += 4; /* Skip the evaluation of the symbol. */
1560 if (op
== OP_VAR_MSYM_VALUE
)
1562 symbol
*sym
= exp
->elts
[*pos
+ 2].symbol
;
1563 var_func_name
= SYMBOL_PRINT_NAME (sym
);
1565 else if (op
== OP_VAR_VALUE
)
1567 minimal_symbol
*msym
= exp
->elts
[*pos
+ 2].msymbol
;
1568 var_func_name
= MSYMBOL_PRINT_NAME (msym
);
1571 argvec
[0] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1572 type
= value_type (argvec
[0]);
1573 if (type
&& TYPE_CODE (type
) == TYPE_CODE_PTR
)
1574 type
= TYPE_TARGET_TYPE (type
);
1575 if (type
&& TYPE_CODE (type
) == TYPE_CODE_FUNC
)
1577 for (; tem
<= nargs
&& tem
<= TYPE_NFIELDS (type
); tem
++)
1579 argvec
[tem
] = evaluate_subexp (TYPE_FIELD_TYPE (type
,
1587 /* Evaluate arguments (if not already done, e.g., namespace::func()
1588 and overload-resolution is off). */
1589 for (; tem
<= nargs
; tem
++)
1591 /* Ensure that array expressions are coerced into pointer
1593 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1596 /* Signal end of arglist. */
1599 if (noside
== EVAL_SKIP
)
1600 return eval_skip_value (exp
);
1602 if (op
== OP_ADL_FUNC
)
1604 struct symbol
*symp
;
1607 int string_pc
= save_pos1
+ 3;
1609 /* Extract the function name. */
1610 name_len
= longest_to_int (exp
->elts
[string_pc
].longconst
);
1611 func_name
= (char *) alloca (name_len
+ 1);
1612 strcpy (func_name
, &exp
->elts
[string_pc
+ 1].string
);
1614 find_overload_match (&argvec
[1], nargs
, func_name
,
1615 NON_METHOD
, /* not method */
1616 NULL
, NULL
, /* pass NULL symbol since
1617 symbol is unknown */
1618 NULL
, &symp
, NULL
, 0, noside
);
1620 /* Now fix the expression being evaluated. */
1621 exp
->elts
[save_pos1
+ 2].symbol
= symp
;
1622 argvec
[0] = evaluate_subexp_with_coercion (exp
, &save_pos1
, noside
);
1625 if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
1626 || (op
== OP_SCOPE
&& function_name
!= NULL
))
1628 int static_memfuncp
;
1631 /* Method invocation: stuff "this" as first parameter.
1632 If the method turns out to be static we undo this below. */
1637 /* Name of method from expression. */
1638 tstr
= &exp
->elts
[pc2
+ 2].string
;
1641 tstr
= function_name
;
1643 if (overload_resolution
&& (exp
->language_defn
->la_language
1646 /* Language is C++, do some overload resolution before
1648 struct value
*valp
= NULL
;
1650 (void) find_overload_match (&argvec
[1], nargs
, tstr
,
1651 METHOD
, /* method */
1652 &arg2
, /* the object */
1654 &static_memfuncp
, 0, noside
);
1656 if (op
== OP_SCOPE
&& !static_memfuncp
)
1658 /* For the time being, we don't handle this. */
1659 error (_("Call to overloaded function %s requires "
1663 argvec
[1] = arg2
; /* the ``this'' pointer */
1664 argvec
[0] = valp
; /* Use the method found after overload
1668 /* Non-C++ case -- or no overload resolution. */
1670 struct value
*temp
= arg2
;
1672 argvec
[0] = value_struct_elt (&temp
, argvec
+ 1, tstr
,
1674 op
== STRUCTOP_STRUCT
1675 ? "structure" : "structure pointer");
1676 /* value_struct_elt updates temp with the correct value
1677 of the ``this'' pointer if necessary, so modify argvec[1] to
1678 reflect any ``this'' changes. */
1680 = value_from_longest (lookup_pointer_type(value_type (temp
)),
1681 value_address (temp
)
1682 + value_embedded_offset (temp
));
1683 argvec
[1] = arg2
; /* the ``this'' pointer */
1686 /* Take out `this' if needed. */
1687 if (static_memfuncp
)
1689 argvec
[1] = argvec
[0];
1694 else if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
1696 /* Pointer to member. argvec[1] is already set up. */
1699 else if (op
== OP_VAR_VALUE
|| (op
== OP_SCOPE
&& function
!= NULL
))
1701 /* Non-member function being called. */
1702 /* fn: This can only be done for C++ functions. A C-style function
1703 in a C++ program, for instance, does not have the fields that
1704 are expected here. */
1706 if (overload_resolution
&& (exp
->language_defn
->la_language
1709 /* Language is C++, do some overload resolution before
1711 struct symbol
*symp
;
1714 /* If a scope has been specified disable ADL. */
1718 if (op
== OP_VAR_VALUE
)
1719 function
= exp
->elts
[save_pos1
+2].symbol
;
1721 (void) find_overload_match (&argvec
[1], nargs
,
1722 NULL
, /* no need for name */
1723 NON_METHOD
, /* not method */
1724 NULL
, function
, /* the function */
1725 NULL
, &symp
, NULL
, no_adl
, noside
);
1727 if (op
== OP_VAR_VALUE
)
1729 /* Now fix the expression being evaluated. */
1730 exp
->elts
[save_pos1
+2].symbol
= symp
;
1731 argvec
[0] = evaluate_subexp_with_coercion (exp
, &save_pos1
,
1735 argvec
[0] = value_of_variable (symp
, get_selected_block (0));
1739 /* Not C++, or no overload resolution allowed. */
1740 /* Nothing to be done; argvec already correctly set up. */
1745 /* It is probably a C-style function. */
1746 /* Nothing to be done; argvec already correctly set up. */
1751 if (argvec
[0] == NULL
)
1752 error (_("Cannot evaluate function -- may be inlined"));
1753 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1755 /* If the return type doesn't look like a function type,
1756 call an error. This can happen if somebody tries to turn
1757 a variable into a function call. */
1759 struct type
*ftype
= value_type (argvec
[0]);
1761 if (TYPE_CODE (ftype
) == TYPE_CODE_INTERNAL_FUNCTION
)
1763 /* We don't know anything about what the internal
1764 function might return, but we have to return
1766 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
,
1769 else if (TYPE_CODE (ftype
) == TYPE_CODE_XMETHOD
)
1771 struct type
*return_type
1772 = result_type_of_xmethod (argvec
[0], nargs
, argvec
+ 1);
1774 if (return_type
== NULL
)
1775 error (_("Xmethod is missing return type."));
1776 return value_zero (return_type
, not_lval
);
1778 else if (TYPE_CODE (ftype
) == TYPE_CODE_FUNC
1779 || TYPE_CODE (ftype
) == TYPE_CODE_METHOD
)
1781 struct type
*return_type
= TYPE_TARGET_TYPE (ftype
);
1783 if (return_type
== NULL
)
1784 return_type
= expect_type
;
1786 if (return_type
== NULL
)
1787 error_call_unknown_return_type (var_func_name
);
1789 return allocate_value (return_type
);
1792 error (_("Expression of type other than "
1793 "\"Function returning ...\" used as function"));
1795 switch (TYPE_CODE (value_type (argvec
[0])))
1797 case TYPE_CODE_INTERNAL_FUNCTION
:
1798 return call_internal_function (exp
->gdbarch
, exp
->language_defn
,
1799 argvec
[0], nargs
, argvec
+ 1);
1800 case TYPE_CODE_XMETHOD
:
1801 return call_xmethod (argvec
[0], nargs
, argvec
+ 1);
1803 return call_function_by_hand (argvec
[0],
1804 expect_type
, nargs
, argvec
+ 1);
1806 /* pai: FIXME save value from call_function_by_hand, then adjust
1807 pc by adjust_fn_pc if +ve. */
1809 case OP_F77_UNDETERMINED_ARGLIST
:
1811 /* Remember that in F77, functions, substring ops and
1812 array subscript operations cannot be disambiguated
1813 at parse time. We have made all array subscript operations,
1814 substring operations as well as function calls come here
1815 and we now have to discover what the heck this thing actually was.
1816 If it is a function, we process just as if we got an OP_FUNCALL. */
1818 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1821 /* First determine the type code we are dealing with. */
1822 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1823 type
= check_typedef (value_type (arg1
));
1824 code
= TYPE_CODE (type
);
1826 if (code
== TYPE_CODE_PTR
)
1828 /* Fortran always passes variable to subroutines as pointer.
1829 So we need to look into its target type to see if it is
1830 array, string or function. If it is, we need to switch
1831 to the target value the original one points to. */
1832 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1834 if (TYPE_CODE (target_type
) == TYPE_CODE_ARRAY
1835 || TYPE_CODE (target_type
) == TYPE_CODE_STRING
1836 || TYPE_CODE (target_type
) == TYPE_CODE_FUNC
)
1838 arg1
= value_ind (arg1
);
1839 type
= check_typedef (value_type (arg1
));
1840 code
= TYPE_CODE (type
);
1846 case TYPE_CODE_ARRAY
:
1847 if (exp
->elts
[*pos
].opcode
== OP_RANGE
)
1848 return value_f90_subarray (arg1
, exp
, pos
, noside
);
1850 goto multi_f77_subscript
;
1852 case TYPE_CODE_STRING
:
1853 if (exp
->elts
[*pos
].opcode
== OP_RANGE
)
1854 return value_f90_subarray (arg1
, exp
, pos
, noside
);
1857 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1858 return value_subscript (arg1
, value_as_long (arg2
));
1862 case TYPE_CODE_FUNC
:
1863 /* It's a function call. */
1864 /* Allocate arg vector, including space for the function to be
1865 called in argvec[0] and a terminating NULL. */
1866 argvec
= (struct value
**)
1867 alloca (sizeof (struct value
*) * (nargs
+ 2));
1870 for (; tem
<= nargs
; tem
++)
1871 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1872 argvec
[tem
] = 0; /* signal end of arglist */
1873 if (noside
== EVAL_SKIP
)
1874 return eval_skip_value (exp
);
1878 error (_("Cannot perform substring on this type"));
1882 /* We have a complex number, There should be 2 floating
1883 point numbers that compose it. */
1885 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1886 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1888 return value_literal_complex (arg1
, arg2
, exp
->elts
[pc
+ 1].type
);
1890 case STRUCTOP_STRUCT
:
1891 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1892 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1893 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1894 if (noside
== EVAL_SKIP
)
1895 return eval_skip_value (exp
);
1896 arg3
= value_struct_elt (&arg1
, NULL
, &exp
->elts
[pc
+ 2].string
,
1898 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1899 arg3
= value_zero (value_type (arg3
), VALUE_LVAL (arg3
));
1903 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1904 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1905 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1906 if (noside
== EVAL_SKIP
)
1907 return eval_skip_value (exp
);
1909 /* Check to see if operator '->' has been overloaded. If so replace
1910 arg1 with the value returned by evaluating operator->(). */
1911 while (unop_user_defined_p (op
, arg1
))
1913 struct value
*value
= NULL
;
1916 value
= value_x_unop (arg1
, op
, noside
);
1919 CATCH (except
, RETURN_MASK_ERROR
)
1921 if (except
.error
== NOT_FOUND_ERROR
)
1924 throw_exception (except
);
1931 /* JYG: if print object is on we need to replace the base type
1932 with rtti type in order to continue on with successful
1933 lookup of member / method only available in the rtti type. */
1935 struct type
*type
= value_type (arg1
);
1936 struct type
*real_type
;
1937 int full
, using_enc
;
1939 struct value_print_options opts
;
1941 get_user_print_options (&opts
);
1942 if (opts
.objectprint
&& TYPE_TARGET_TYPE(type
)
1943 && (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_STRUCT
))
1945 real_type
= value_rtti_indirect_type (arg1
, &full
, &top
,
1948 arg1
= value_cast (real_type
, arg1
);
1952 arg3
= value_struct_elt (&arg1
, NULL
, &exp
->elts
[pc
+ 2].string
,
1953 NULL
, "structure pointer");
1954 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1955 arg3
= value_zero (value_type (arg3
), VALUE_LVAL (arg3
));
1958 case STRUCTOP_MEMBER
:
1960 if (op
== STRUCTOP_MEMBER
)
1961 arg1
= evaluate_subexp_for_address (exp
, pos
, noside
);
1963 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1965 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1967 if (noside
== EVAL_SKIP
)
1968 return eval_skip_value (exp
);
1970 type
= check_typedef (value_type (arg2
));
1971 switch (TYPE_CODE (type
))
1973 case TYPE_CODE_METHODPTR
:
1974 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1975 return value_zero (TYPE_TARGET_TYPE (type
), not_lval
);
1978 arg2
= cplus_method_ptr_to_value (&arg1
, arg2
);
1979 gdb_assert (TYPE_CODE (value_type (arg2
)) == TYPE_CODE_PTR
);
1980 return value_ind (arg2
);
1983 case TYPE_CODE_MEMBERPTR
:
1984 /* Now, convert these values to an address. */
1985 arg1
= value_cast_pointers (lookup_pointer_type (TYPE_SELF_TYPE (type
)),
1988 mem_offset
= value_as_long (arg2
);
1990 arg3
= value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
1991 value_as_long (arg1
) + mem_offset
);
1992 return value_ind (arg3
);
1995 error (_("non-pointer-to-member value used "
1996 "in pointer-to-member construct"));
2000 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
2001 arg_types
= (struct type
**) alloca (nargs
* sizeof (struct type
*));
2002 for (ix
= 0; ix
< nargs
; ++ix
)
2003 arg_types
[ix
] = exp
->elts
[pc
+ 1 + ix
+ 1].type
;
2005 expect_type
= make_params (nargs
, arg_types
);
2006 *(pos
) += 3 + nargs
;
2007 arg1
= evaluate_subexp_standard (expect_type
, exp
, pos
, noside
);
2008 xfree (TYPE_FIELDS (expect_type
));
2009 xfree (TYPE_MAIN_TYPE (expect_type
));
2010 xfree (expect_type
);
2014 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2015 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2016 if (noside
== EVAL_SKIP
)
2017 return eval_skip_value (exp
);
2018 if (binop_user_defined_p (op
, arg1
, arg2
))
2019 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2021 return value_concat (arg1
, arg2
);
2024 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2025 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2027 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2029 if (binop_user_defined_p (op
, arg1
, arg2
))
2030 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2032 return value_assign (arg1
, arg2
);
2034 case BINOP_ASSIGN_MODIFY
:
2036 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2037 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2038 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2040 op
= exp
->elts
[pc
+ 1].opcode
;
2041 if (binop_user_defined_p (op
, arg1
, arg2
))
2042 return value_x_binop (arg1
, arg2
, BINOP_ASSIGN_MODIFY
, op
, noside
);
2043 else if (op
== BINOP_ADD
&& ptrmath_type_p (exp
->language_defn
,
2045 && is_integral_type (value_type (arg2
)))
2046 arg2
= value_ptradd (arg1
, value_as_long (arg2
));
2047 else if (op
== BINOP_SUB
&& ptrmath_type_p (exp
->language_defn
,
2049 && is_integral_type (value_type (arg2
)))
2050 arg2
= value_ptradd (arg1
, - value_as_long (arg2
));
2053 struct value
*tmp
= arg1
;
2055 /* For shift and integer exponentiation operations,
2056 only promote the first argument. */
2057 if ((op
== BINOP_LSH
|| op
== BINOP_RSH
|| op
== BINOP_EXP
)
2058 && is_integral_type (value_type (arg2
)))
2059 unop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
);
2061 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2063 arg2
= value_binop (tmp
, arg2
, op
);
2065 return value_assign (arg1
, arg2
);
2068 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2069 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2070 if (noside
== EVAL_SKIP
)
2071 return eval_skip_value (exp
);
2072 if (binop_user_defined_p (op
, arg1
, arg2
))
2073 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2074 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
2075 && is_integral_type (value_type (arg2
)))
2076 return value_ptradd (arg1
, value_as_long (arg2
));
2077 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg2
))
2078 && is_integral_type (value_type (arg1
)))
2079 return value_ptradd (arg2
, value_as_long (arg1
));
2082 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2083 return value_binop (arg1
, arg2
, BINOP_ADD
);
2087 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2088 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2089 if (noside
== EVAL_SKIP
)
2090 return eval_skip_value (exp
);
2091 if (binop_user_defined_p (op
, arg1
, arg2
))
2092 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2093 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
2094 && ptrmath_type_p (exp
->language_defn
, value_type (arg2
)))
2096 /* FIXME -- should be ptrdiff_t */
2097 type
= builtin_type (exp
->gdbarch
)->builtin_long
;
2098 return value_from_longest (type
, value_ptrdiff (arg1
, arg2
));
2100 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
2101 && is_integral_type (value_type (arg2
)))
2102 return value_ptradd (arg1
, - value_as_long (arg2
));
2105 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2106 return value_binop (arg1
, arg2
, BINOP_SUB
);
2117 case BINOP_BITWISE_AND
:
2118 case BINOP_BITWISE_IOR
:
2119 case BINOP_BITWISE_XOR
:
2120 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2121 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2122 if (noside
== EVAL_SKIP
)
2123 return eval_skip_value (exp
);
2124 if (binop_user_defined_p (op
, arg1
, arg2
))
2125 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2128 /* If EVAL_AVOID_SIDE_EFFECTS and we're dividing by zero,
2129 fudge arg2 to avoid division-by-zero, the caller is
2130 (theoretically) only looking for the type of the result. */
2131 if (noside
== EVAL_AVOID_SIDE_EFFECTS
2132 /* ??? Do we really want to test for BINOP_MOD here?
2133 The implementation of value_binop gives it a well-defined
2136 || op
== BINOP_INTDIV
2139 && value_logical_not (arg2
))
2141 struct value
*v_one
, *retval
;
2143 v_one
= value_one (value_type (arg2
));
2144 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &v_one
);
2145 retval
= value_binop (arg1
, v_one
, op
);
2150 /* For shift and integer exponentiation operations,
2151 only promote the first argument. */
2152 if ((op
== BINOP_LSH
|| op
== BINOP_RSH
|| op
== BINOP_EXP
)
2153 && is_integral_type (value_type (arg2
)))
2154 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2156 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2158 return value_binop (arg1
, arg2
, op
);
2162 case BINOP_SUBSCRIPT
:
2163 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2164 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2165 if (noside
== EVAL_SKIP
)
2166 return eval_skip_value (exp
);
2167 if (binop_user_defined_p (op
, arg1
, arg2
))
2168 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2171 /* If the user attempts to subscript something that is not an
2172 array or pointer type (like a plain int variable for example),
2173 then report this as an error. */
2175 arg1
= coerce_ref (arg1
);
2176 type
= check_typedef (value_type (arg1
));
2177 if (TYPE_CODE (type
) != TYPE_CODE_ARRAY
2178 && TYPE_CODE (type
) != TYPE_CODE_PTR
)
2180 if (TYPE_NAME (type
))
2181 error (_("cannot subscript something of type `%s'"),
2184 error (_("cannot subscript requested type"));
2187 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2188 return value_zero (TYPE_TARGET_TYPE (type
), VALUE_LVAL (arg1
));
2190 return value_subscript (arg1
, value_as_long (arg2
));
2192 case MULTI_SUBSCRIPT
:
2194 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
2195 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2198 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2199 /* FIXME: EVAL_SKIP handling may not be correct. */
2200 if (noside
== EVAL_SKIP
)
2204 return eval_skip_value (exp
);
2206 /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
2207 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2209 /* If the user attempts to subscript something that has no target
2210 type (like a plain int variable for example), then report this
2213 type
= TYPE_TARGET_TYPE (check_typedef (value_type (arg1
)));
2216 arg1
= value_zero (type
, VALUE_LVAL (arg1
));
2222 error (_("cannot subscript something of type `%s'"),
2223 TYPE_NAME (value_type (arg1
)));
2227 if (binop_user_defined_p (op
, arg1
, arg2
))
2229 arg1
= value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2233 arg1
= coerce_ref (arg1
);
2234 type
= check_typedef (value_type (arg1
));
2236 switch (TYPE_CODE (type
))
2239 case TYPE_CODE_ARRAY
:
2240 case TYPE_CODE_STRING
:
2241 arg1
= value_subscript (arg1
, value_as_long (arg2
));
2245 if (TYPE_NAME (type
))
2246 error (_("cannot subscript something of type `%s'"),
2249 error (_("cannot subscript requested type"));
2255 multi_f77_subscript
:
2257 LONGEST subscript_array
[MAX_FORTRAN_DIMS
];
2258 int ndimensions
= 1, i
;
2259 struct value
*array
= arg1
;
2261 if (nargs
> MAX_FORTRAN_DIMS
)
2262 error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS
);
2264 ndimensions
= calc_f77_array_dims (type
);
2266 if (nargs
!= ndimensions
)
2267 error (_("Wrong number of subscripts"));
2269 gdb_assert (nargs
> 0);
2271 /* Now that we know we have a legal array subscript expression
2272 let us actually find out where this element exists in the array. */
2274 /* Take array indices left to right. */
2275 for (i
= 0; i
< nargs
; i
++)
2277 /* Evaluate each subscript; it must be a legal integer in F77. */
2278 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2280 /* Fill in the subscript array. */
2282 subscript_array
[i
] = value_as_long (arg2
);
2285 /* Internal type of array is arranged right to left. */
2286 for (i
= nargs
; i
> 0; i
--)
2288 struct type
*array_type
= check_typedef (value_type (array
));
2289 LONGEST index
= subscript_array
[i
- 1];
2291 array
= value_subscripted_rvalue (array
, index
,
2292 f77_get_lowerbound (array_type
));
2298 case BINOP_LOGICAL_AND
:
2299 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2300 if (noside
== EVAL_SKIP
)
2302 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2303 return eval_skip_value (exp
);
2307 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2310 if (binop_user_defined_p (op
, arg1
, arg2
))
2312 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2313 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2317 tem
= value_logical_not (arg1
);
2318 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
2319 (tem
? EVAL_SKIP
: noside
));
2320 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2321 return value_from_longest (type
,
2322 (LONGEST
) (!tem
&& !value_logical_not (arg2
)));
2325 case BINOP_LOGICAL_OR
:
2326 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2327 if (noside
== EVAL_SKIP
)
2329 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2330 return eval_skip_value (exp
);
2334 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2337 if (binop_user_defined_p (op
, arg1
, arg2
))
2339 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2340 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2344 tem
= value_logical_not (arg1
);
2345 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
2346 (!tem
? EVAL_SKIP
: noside
));
2347 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2348 return value_from_longest (type
,
2349 (LONGEST
) (!tem
|| !value_logical_not (arg2
)));
2353 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2354 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2355 if (noside
== EVAL_SKIP
)
2356 return eval_skip_value (exp
);
2357 if (binop_user_defined_p (op
, arg1
, arg2
))
2359 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2363 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2364 tem
= value_equal (arg1
, arg2
);
2365 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2366 return value_from_longest (type
, (LONGEST
) tem
);
2369 case BINOP_NOTEQUAL
:
2370 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2371 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2372 if (noside
== EVAL_SKIP
)
2373 return eval_skip_value (exp
);
2374 if (binop_user_defined_p (op
, arg1
, arg2
))
2376 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2380 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2381 tem
= value_equal (arg1
, arg2
);
2382 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2383 return value_from_longest (type
, (LONGEST
) ! tem
);
2387 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2388 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2389 if (noside
== EVAL_SKIP
)
2390 return eval_skip_value (exp
);
2391 if (binop_user_defined_p (op
, arg1
, arg2
))
2393 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2397 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2398 tem
= value_less (arg1
, arg2
);
2399 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2400 return value_from_longest (type
, (LONGEST
) tem
);
2404 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2405 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2406 if (noside
== EVAL_SKIP
)
2407 return eval_skip_value (exp
);
2408 if (binop_user_defined_p (op
, arg1
, arg2
))
2410 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2414 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2415 tem
= value_less (arg2
, arg1
);
2416 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2417 return value_from_longest (type
, (LONGEST
) tem
);
2421 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2422 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2423 if (noside
== EVAL_SKIP
)
2424 return eval_skip_value (exp
);
2425 if (binop_user_defined_p (op
, arg1
, arg2
))
2427 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2431 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2432 tem
= value_less (arg2
, arg1
) || value_equal (arg1
, arg2
);
2433 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2434 return value_from_longest (type
, (LONGEST
) tem
);
2438 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2439 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2440 if (noside
== EVAL_SKIP
)
2441 return eval_skip_value (exp
);
2442 if (binop_user_defined_p (op
, arg1
, arg2
))
2444 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2448 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2449 tem
= value_less (arg1
, arg2
) || value_equal (arg1
, arg2
);
2450 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2451 return value_from_longest (type
, (LONGEST
) tem
);
2455 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2456 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2457 if (noside
== EVAL_SKIP
)
2458 return eval_skip_value (exp
);
2459 type
= check_typedef (value_type (arg2
));
2460 if (TYPE_CODE (type
) != TYPE_CODE_INT
2461 && TYPE_CODE (type
) != TYPE_CODE_ENUM
)
2462 error (_("Non-integral right operand for \"@\" operator."));
2463 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2465 return allocate_repeat_value (value_type (arg1
),
2466 longest_to_int (value_as_long (arg2
)));
2469 return value_repeat (arg1
, longest_to_int (value_as_long (arg2
)));
2472 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2473 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2476 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2477 if (noside
== EVAL_SKIP
)
2478 return eval_skip_value (exp
);
2479 if (unop_user_defined_p (op
, arg1
))
2480 return value_x_unop (arg1
, op
, noside
);
2483 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2484 return value_pos (arg1
);
2488 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2489 if (noside
== EVAL_SKIP
)
2490 return eval_skip_value (exp
);
2491 if (unop_user_defined_p (op
, arg1
))
2492 return value_x_unop (arg1
, op
, noside
);
2495 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2496 return value_neg (arg1
);
2499 case UNOP_COMPLEMENT
:
2500 /* C++: check for and handle destructor names. */
2502 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2503 if (noside
== EVAL_SKIP
)
2504 return eval_skip_value (exp
);
2505 if (unop_user_defined_p (UNOP_COMPLEMENT
, arg1
))
2506 return value_x_unop (arg1
, UNOP_COMPLEMENT
, noside
);
2509 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2510 return value_complement (arg1
);
2513 case UNOP_LOGICAL_NOT
:
2514 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2515 if (noside
== EVAL_SKIP
)
2516 return eval_skip_value (exp
);
2517 if (unop_user_defined_p (op
, arg1
))
2518 return value_x_unop (arg1
, op
, noside
);
2521 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2522 return value_from_longest (type
, (LONGEST
) value_logical_not (arg1
));
2526 if (expect_type
&& TYPE_CODE (expect_type
) == TYPE_CODE_PTR
)
2527 expect_type
= TYPE_TARGET_TYPE (check_typedef (expect_type
));
2528 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2529 type
= check_typedef (value_type (arg1
));
2530 if (TYPE_CODE (type
) == TYPE_CODE_METHODPTR
2531 || TYPE_CODE (type
) == TYPE_CODE_MEMBERPTR
)
2532 error (_("Attempt to dereference pointer "
2533 "to member without an object"));
2534 if (noside
== EVAL_SKIP
)
2535 return eval_skip_value (exp
);
2536 if (unop_user_defined_p (op
, arg1
))
2537 return value_x_unop (arg1
, op
, noside
);
2538 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2540 type
= check_typedef (value_type (arg1
));
2541 if (TYPE_CODE (type
) == TYPE_CODE_PTR
2542 || TYPE_IS_REFERENCE (type
)
2543 /* In C you can dereference an array to get the 1st elt. */
2544 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
2546 return value_zero (TYPE_TARGET_TYPE (type
),
2548 else if (TYPE_CODE (type
) == TYPE_CODE_INT
)
2549 /* GDB allows dereferencing an int. */
2550 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
,
2553 error (_("Attempt to take contents of a non-pointer value."));
2556 /* Allow * on an integer so we can cast it to whatever we want.
2557 This returns an int, which seems like the most C-like thing to
2558 do. "long long" variables are rare enough that
2559 BUILTIN_TYPE_LONGEST would seem to be a mistake. */
2560 if (TYPE_CODE (type
) == TYPE_CODE_INT
)
2561 return value_at_lazy (builtin_type (exp
->gdbarch
)->builtin_int
,
2562 (CORE_ADDR
) value_as_address (arg1
));
2563 return value_ind (arg1
);
2566 /* C++: check for and handle pointer to members. */
2568 if (noside
== EVAL_SKIP
)
2570 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
2571 return eval_skip_value (exp
);
2575 struct value
*retvalp
= evaluate_subexp_for_address (exp
, pos
,
2582 if (noside
== EVAL_SKIP
)
2584 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
2585 return eval_skip_value (exp
);
2587 return evaluate_subexp_for_sizeof (exp
, pos
, noside
);
2591 type
= exp
->elts
[pc
+ 1].type
;
2592 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
2593 if (noside
== EVAL_SKIP
)
2594 return eval_skip_value (exp
);
2595 if (type
!= value_type (arg1
))
2596 arg1
= value_cast (type
, arg1
);
2599 case UNOP_CAST_TYPE
:
2600 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2601 type
= value_type (arg1
);
2602 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
2603 if (noside
== EVAL_SKIP
)
2604 return eval_skip_value (exp
);
2605 if (type
!= value_type (arg1
))
2606 arg1
= value_cast (type
, arg1
);
2609 case UNOP_DYNAMIC_CAST
:
2610 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2611 type
= value_type (arg1
);
2612 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
2613 if (noside
== EVAL_SKIP
)
2614 return eval_skip_value (exp
);
2615 return value_dynamic_cast (type
, arg1
);
2617 case UNOP_REINTERPRET_CAST
:
2618 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2619 type
= value_type (arg1
);
2620 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
2621 if (noside
== EVAL_SKIP
)
2622 return eval_skip_value (exp
);
2623 return value_reinterpret_cast (type
, arg1
);
2627 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2628 if (noside
== EVAL_SKIP
)
2629 return eval_skip_value (exp
);
2630 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2631 return value_zero (exp
->elts
[pc
+ 1].type
, lval_memory
);
2633 return value_at_lazy (exp
->elts
[pc
+ 1].type
,
2634 value_as_address (arg1
));
2636 case UNOP_MEMVAL_TYPE
:
2637 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2638 type
= value_type (arg1
);
2639 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2640 if (noside
== EVAL_SKIP
)
2641 return eval_skip_value (exp
);
2642 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2643 return value_zero (type
, lval_memory
);
2645 return value_at_lazy (type
, value_as_address (arg1
));
2647 case UNOP_MEMVAL_TLS
:
2649 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2650 if (noside
== EVAL_SKIP
)
2651 return eval_skip_value (exp
);
2652 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2653 return value_zero (exp
->elts
[pc
+ 2].type
, lval_memory
);
2658 tls_addr
= target_translate_tls_address (exp
->elts
[pc
+ 1].objfile
,
2659 value_as_address (arg1
));
2660 return value_at_lazy (exp
->elts
[pc
+ 2].type
, tls_addr
);
2663 case UNOP_PREINCREMENT
:
2664 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2665 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2667 else if (unop_user_defined_p (op
, arg1
))
2669 return value_x_unop (arg1
, op
, noside
);
2673 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2674 arg2
= value_ptradd (arg1
, 1);
2677 struct value
*tmp
= arg1
;
2679 arg2
= value_one (value_type (arg1
));
2680 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2681 arg2
= value_binop (tmp
, arg2
, BINOP_ADD
);
2684 return value_assign (arg1
, arg2
);
2687 case UNOP_PREDECREMENT
:
2688 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2689 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2691 else if (unop_user_defined_p (op
, arg1
))
2693 return value_x_unop (arg1
, op
, noside
);
2697 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2698 arg2
= value_ptradd (arg1
, -1);
2701 struct value
*tmp
= arg1
;
2703 arg2
= value_one (value_type (arg1
));
2704 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2705 arg2
= value_binop (tmp
, arg2
, BINOP_SUB
);
2708 return value_assign (arg1
, arg2
);
2711 case UNOP_POSTINCREMENT
:
2712 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2713 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2715 else if (unop_user_defined_p (op
, arg1
))
2717 return value_x_unop (arg1
, op
, noside
);
2721 arg3
= value_non_lval (arg1
);
2723 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2724 arg2
= value_ptradd (arg1
, 1);
2727 struct value
*tmp
= arg1
;
2729 arg2
= value_one (value_type (arg1
));
2730 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2731 arg2
= value_binop (tmp
, arg2
, BINOP_ADD
);
2734 value_assign (arg1
, arg2
);
2738 case UNOP_POSTDECREMENT
:
2739 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2740 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2742 else if (unop_user_defined_p (op
, arg1
))
2744 return value_x_unop (arg1
, op
, noside
);
2748 arg3
= value_non_lval (arg1
);
2750 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2751 arg2
= value_ptradd (arg1
, -1);
2754 struct value
*tmp
= arg1
;
2756 arg2
= value_one (value_type (arg1
));
2757 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2758 arg2
= value_binop (tmp
, arg2
, BINOP_SUB
);
2761 value_assign (arg1
, arg2
);
2767 return value_of_this (exp
->language_defn
);
2770 /* The value is not supposed to be used. This is here to make it
2771 easier to accommodate expressions that contain types. */
2773 if (noside
== EVAL_SKIP
)
2774 return eval_skip_value (exp
);
2775 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2776 return allocate_value (exp
->elts
[pc
+ 1].type
);
2778 error (_("Attempt to use a type name as an expression"));
2782 if (noside
== EVAL_SKIP
)
2784 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
2785 return eval_skip_value (exp
);
2787 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2789 enum exp_opcode sub_op
= exp
->elts
[*pos
].opcode
;
2790 struct value
*result
;
2792 result
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
2793 EVAL_AVOID_SIDE_EFFECTS
);
2795 /* 'decltype' has special semantics for lvalues. */
2796 if (op
== OP_DECLTYPE
2797 && (sub_op
== BINOP_SUBSCRIPT
2798 || sub_op
== STRUCTOP_MEMBER
2799 || sub_op
== STRUCTOP_MPTR
2800 || sub_op
== UNOP_IND
2801 || sub_op
== STRUCTOP_STRUCT
2802 || sub_op
== STRUCTOP_PTR
2803 || sub_op
== OP_SCOPE
))
2805 struct type
*type
= value_type (result
);
2807 if (!TYPE_IS_REFERENCE (type
))
2809 type
= lookup_lvalue_reference_type (type
);
2810 result
= allocate_value (type
);
2817 error (_("Attempt to use a type as an expression"));
2821 struct value
*result
;
2822 enum exp_opcode sub_op
= exp
->elts
[*pos
].opcode
;
2824 if (sub_op
== OP_TYPE
|| sub_op
== OP_DECLTYPE
|| sub_op
== OP_TYPEOF
)
2825 result
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
2826 EVAL_AVOID_SIDE_EFFECTS
);
2828 result
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2830 if (noside
!= EVAL_NORMAL
)
2831 return allocate_value (cplus_typeid_type (exp
->gdbarch
));
2833 return cplus_typeid (result
);
2837 /* Removing this case and compiling with gcc -Wall reveals that
2838 a lot of cases are hitting this case. Some of these should
2839 probably be removed from expression.h; others are legitimate
2840 expressions which are (apparently) not fully implemented.
2842 If there are any cases landing here which mean a user error,
2843 then they should be separate cases, with more descriptive
2846 error (_("GDB does not (yet) know how to "
2847 "evaluate that kind of expression"));
2850 gdb_assert_not_reached ("missed return?");
2853 /* Evaluate a subexpression of EXP, at index *POS,
2854 and return the address of that subexpression.
2855 Advance *POS over the subexpression.
2856 If the subexpression isn't an lvalue, get an error.
2857 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
2858 then only the type of the result need be correct. */
2860 static struct value
*
2861 evaluate_subexp_for_address (struct expression
*exp
, int *pos
,
2871 op
= exp
->elts
[pc
].opcode
;
2877 x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2879 /* We can't optimize out "&*" if there's a user-defined operator*. */
2880 if (unop_user_defined_p (op
, x
))
2882 x
= value_x_unop (x
, op
, noside
);
2883 goto default_case_after_eval
;
2886 return coerce_array (x
);
2890 return value_cast (lookup_pointer_type (exp
->elts
[pc
+ 1].type
),
2891 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
2893 case UNOP_MEMVAL_TYPE
:
2898 x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2899 type
= value_type (x
);
2900 return value_cast (lookup_pointer_type (type
),
2901 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
2905 var
= exp
->elts
[pc
+ 2].symbol
;
2907 /* C++: The "address" of a reference should yield the address
2908 * of the object pointed to. Let value_addr() deal with it. */
2909 if (TYPE_IS_REFERENCE (SYMBOL_TYPE (var
)))
2913 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2916 lookup_pointer_type (SYMBOL_TYPE (var
));
2917 enum address_class sym_class
= SYMBOL_CLASS (var
);
2919 if (sym_class
== LOC_CONST
2920 || sym_class
== LOC_CONST_BYTES
2921 || sym_class
== LOC_REGISTER
)
2922 error (_("Attempt to take address of register or constant."));
2925 value_zero (type
, not_lval
);
2928 return address_of_variable (var
, exp
->elts
[pc
+ 1].block
);
2931 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
2932 (*pos
) += 5 + BYTES_TO_EXP_ELEM (tem
+ 1);
2933 x
= value_aggregate_elt (exp
->elts
[pc
+ 1].type
,
2934 &exp
->elts
[pc
+ 3].string
,
2937 error (_("There is no field named %s"), &exp
->elts
[pc
+ 3].string
);
2942 x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2943 default_case_after_eval
:
2944 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2946 struct type
*type
= check_typedef (value_type (x
));
2948 if (TYPE_IS_REFERENCE (type
))
2949 return value_zero (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
2951 else if (VALUE_LVAL (x
) == lval_memory
|| value_must_coerce_to_target (x
))
2952 return value_zero (lookup_pointer_type (value_type (x
)),
2955 error (_("Attempt to take address of "
2956 "value not located in memory."));
2958 return value_addr (x
);
2962 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
2963 When used in contexts where arrays will be coerced anyway, this is
2964 equivalent to `evaluate_subexp' but much faster because it avoids
2965 actually fetching array contents (perhaps obsolete now that we have
2968 Note that we currently only do the coercion for C expressions, where
2969 arrays are zero based and the coercion is correct. For other languages,
2970 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
2971 to decide if coercion is appropriate. */
2974 evaluate_subexp_with_coercion (struct expression
*exp
,
2975 int *pos
, enum noside noside
)
2984 op
= exp
->elts
[pc
].opcode
;
2989 var
= exp
->elts
[pc
+ 2].symbol
;
2990 type
= check_typedef (SYMBOL_TYPE (var
));
2991 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
2992 && !TYPE_VECTOR (type
)
2993 && CAST_IS_CONVERSION (exp
->language_defn
))
2996 val
= address_of_variable (var
, exp
->elts
[pc
+ 1].block
);
2997 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
3003 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
3007 /* Evaluate a subexpression of EXP, at index *POS,
3008 and return a value for the size of that subexpression.
3009 Advance *POS over the subexpression. If NOSIDE is EVAL_NORMAL
3010 we allow side-effects on the operand if its type is a variable
3013 static struct value
*
3014 evaluate_subexp_for_sizeof (struct expression
*exp
, int *pos
,
3017 /* FIXME: This should be size_t. */
3018 struct type
*size_type
= builtin_type (exp
->gdbarch
)->builtin_int
;
3025 op
= exp
->elts
[pc
].opcode
;
3029 /* This case is handled specially
3030 so that we avoid creating a value for the result type.
3031 If the result type is very big, it's desirable not to
3032 create a value unnecessarily. */
3035 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3036 type
= check_typedef (value_type (val
));
3037 if (TYPE_CODE (type
) != TYPE_CODE_PTR
3038 && !TYPE_IS_REFERENCE (type
)
3039 && TYPE_CODE (type
) != TYPE_CODE_ARRAY
)
3040 error (_("Attempt to take contents of a non-pointer value."));
3041 type
= TYPE_TARGET_TYPE (type
);
3042 if (is_dynamic_type (type
))
3043 type
= value_type (value_ind (val
));
3044 return value_from_longest (size_type
, (LONGEST
) TYPE_LENGTH (type
));
3048 type
= exp
->elts
[pc
+ 1].type
;
3051 case UNOP_MEMVAL_TYPE
:
3053 val
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3054 type
= value_type (val
);
3058 type
= SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
);
3059 if (is_dynamic_type (type
))
3061 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_NORMAL
);
3062 type
= value_type (val
);
3068 /* Deal with the special case if NOSIDE is EVAL_NORMAL and the resulting
3069 type of the subscript is a variable length array type. In this case we
3070 must re-evaluate the right hand side of the subcription to allow
3072 case BINOP_SUBSCRIPT
:
3073 if (noside
== EVAL_NORMAL
)
3075 int pc
= (*pos
) + 1;
3077 val
= evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_AVOID_SIDE_EFFECTS
);
3078 type
= check_typedef (value_type (val
));
3079 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
3081 type
= check_typedef (TYPE_TARGET_TYPE (type
));
3082 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
3084 type
= TYPE_INDEX_TYPE (type
);
3085 /* Only re-evaluate the right hand side if the resulting type
3086 is a variable length type. */
3087 if (TYPE_RANGE_DATA (type
)->flag_bound_evaluated
)
3089 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_NORMAL
);
3090 return value_from_longest
3091 (size_type
, (LONGEST
) TYPE_LENGTH (value_type (val
)));
3100 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3101 type
= value_type (val
);
3105 /* $5.3.3/2 of the C++ Standard (n3290 draft) says of sizeof:
3106 "When applied to a reference or a reference type, the result is
3107 the size of the referenced type." */
3108 type
= check_typedef (type
);
3109 if (exp
->language_defn
->la_language
== language_cplus
3110 && (TYPE_IS_REFERENCE (type
)))
3111 type
= check_typedef (TYPE_TARGET_TYPE (type
));
3112 return value_from_longest (size_type
, (LONGEST
) TYPE_LENGTH (type
));
3115 /* Parse a type expression in the string [P..P+LENGTH). */
3118 parse_and_eval_type (char *p
, int length
)
3120 char *tmp
= (char *) alloca (length
+ 4);
3123 memcpy (tmp
+ 1, p
, length
);
3124 tmp
[length
+ 1] = ')';
3125 tmp
[length
+ 2] = '0';
3126 tmp
[length
+ 3] = '\0';
3127 expression_up expr
= parse_expression (tmp
);
3128 if (expr
->elts
[0].opcode
!= UNOP_CAST
)
3129 error (_("Internal error in eval_type."));
3130 return expr
->elts
[1].type
;
3134 calc_f77_array_dims (struct type
*array_type
)
3137 struct type
*tmp_type
;
3139 if ((TYPE_CODE (array_type
) != TYPE_CODE_ARRAY
))
3140 error (_("Can't get dimensions for a non-array type"));
3142 tmp_type
= array_type
;
3144 while ((tmp_type
= TYPE_TARGET_TYPE (tmp_type
)))
3146 if (TYPE_CODE (tmp_type
) == TYPE_CODE_ARRAY
)