1 /* Evaluate expressions for GDB.
3 Copyright (C) 1986-2003, 2005-2012 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/>. */
21 #include "gdb_string.h"
25 #include "expression.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"
37 #include "exceptions.h"
39 #include "user-regs.h"
41 #include "gdb_obstack.h"
43 #include "python/python.h"
46 #include "gdb_assert.h"
50 /* This is defined in valops.c */
51 extern int overload_resolution
;
53 /* Prototypes for local functions. */
55 static struct value
*evaluate_subexp_for_sizeof (struct expression
*, int *);
57 static struct value
*evaluate_subexp_for_address (struct expression
*,
60 static char *get_label (struct expression
*, int *);
62 static struct value
*evaluate_struct_tuple (struct value
*,
63 struct expression
*, int *,
66 static LONGEST
init_array_element (struct value
*, struct value
*,
67 struct expression
*, int *, enum noside
,
71 evaluate_subexp (struct type
*expect_type
, struct expression
*exp
,
72 int *pos
, enum noside noside
)
74 return (*exp
->language_defn
->la_exp_desc
->evaluate_exp
)
75 (expect_type
, exp
, pos
, noside
);
78 /* Parse the string EXP as a C expression, evaluate it,
79 and return the result as a number. */
82 parse_and_eval_address (char *exp
)
84 struct expression
*expr
= parse_expression (exp
);
86 struct cleanup
*old_chain
=
87 make_cleanup (free_current_contents
, &expr
);
89 addr
= value_as_address (evaluate_expression (expr
));
90 do_cleanups (old_chain
);
94 /* Like parse_and_eval_address, but treats the value of the expression
95 as an integer, not an address, returns a LONGEST, not a CORE_ADDR. */
97 parse_and_eval_long (char *exp
)
99 struct expression
*expr
= parse_expression (exp
);
101 struct cleanup
*old_chain
=
102 make_cleanup (free_current_contents
, &expr
);
104 retval
= value_as_long (evaluate_expression (expr
));
105 do_cleanups (old_chain
);
110 parse_and_eval (char *exp
)
112 struct expression
*expr
= parse_expression (exp
);
114 struct cleanup
*old_chain
=
115 make_cleanup (free_current_contents
, &expr
);
117 val
= evaluate_expression (expr
);
118 do_cleanups (old_chain
);
122 /* Parse up to a comma (or to a closeparen)
123 in the string EXPP as an expression, evaluate it, and return the value.
124 EXPP is advanced to point to the comma. */
127 parse_to_comma_and_eval (char **expp
)
129 struct expression
*expr
= parse_exp_1 (expp
, (struct block
*) 0, 1);
131 struct cleanup
*old_chain
=
132 make_cleanup (free_current_contents
, &expr
);
134 val
= evaluate_expression (expr
);
135 do_cleanups (old_chain
);
139 /* Evaluate an expression in internal prefix form
140 such as is constructed by parse.y.
142 See expression.h for info on the format of an expression. */
145 evaluate_expression (struct expression
*exp
)
149 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_NORMAL
);
152 /* Evaluate an expression, avoiding all memory references
153 and getting a value whose type alone is correct. */
156 evaluate_type (struct expression
*exp
)
160 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_AVOID_SIDE_EFFECTS
);
163 /* Evaluate a subexpression, avoiding all memory references and
164 getting a value whose type alone is correct. */
167 evaluate_subexpression_type (struct expression
*exp
, int subexp
)
169 return evaluate_subexp (NULL_TYPE
, exp
, &subexp
, EVAL_AVOID_SIDE_EFFECTS
);
172 /* Find the current value of a watchpoint on EXP. Return the value in
173 *VALP and *RESULTP and the chain of intermediate and final values
174 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
177 If a memory error occurs while evaluating the expression, *RESULTP will
178 be set to NULL. *RESULTP may be a lazy value, if the result could
179 not be read from memory. It is used to determine whether a value
180 is user-specified (we should watch the whole value) or intermediate
181 (we should watch only the bit used to locate the final value).
183 If the final value, or any intermediate value, could not be read
184 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
185 set to any referenced values. *VALP will never be a lazy value.
186 This is the value which we store in struct breakpoint.
188 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
189 value chain. The caller must free the values individually. If
190 VAL_CHAIN is NULL, all generated values will be left on the value
194 fetch_subexp_value (struct expression
*exp
, int *pc
, struct value
**valp
,
195 struct value
**resultp
, struct value
**val_chain
)
197 struct value
*mark
, *new_mark
, *result
;
198 volatile struct gdb_exception ex
;
206 /* Evaluate the expression. */
207 mark
= value_mark ();
210 TRY_CATCH (ex
, RETURN_MASK_ALL
)
212 result
= evaluate_subexp (NULL_TYPE
, exp
, pc
, EVAL_NORMAL
);
216 /* Ignore memory errors, we want watchpoints pointing at
217 inaccessible memory to still be created; otherwise, throw the
218 error to some higher catcher. */
224 throw_exception (ex
);
229 new_mark
= value_mark ();
230 if (mark
== new_mark
)
235 /* Make sure it's not lazy, so that after the target stops again we
236 have a non-lazy previous value to compare with. */
238 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
243 /* Return the chain of intermediate values. We use this to
244 decide which addresses to watch. */
245 *val_chain
= new_mark
;
246 value_release_to_mark (mark
);
250 /* Extract a field operation from an expression. If the subexpression
251 of EXP starting at *SUBEXP is not a structure dereference
252 operation, return NULL. Otherwise, return the name of the
253 dereferenced field, and advance *SUBEXP to point to the
254 subexpression of the left-hand-side of the dereference. This is
255 used when completing field names. */
258 extract_field_op (struct expression
*exp
, int *subexp
)
263 if (exp
->elts
[*subexp
].opcode
!= STRUCTOP_STRUCT
264 && exp
->elts
[*subexp
].opcode
!= STRUCTOP_PTR
)
266 tem
= longest_to_int (exp
->elts
[*subexp
+ 1].longconst
);
267 result
= &exp
->elts
[*subexp
+ 2].string
;
268 (*subexp
) += 1 + 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
272 /* If the next expression is an OP_LABELED, skips past it,
273 returning the label. Otherwise, does nothing and returns NULL. */
276 get_label (struct expression
*exp
, int *pos
)
278 if (exp
->elts
[*pos
].opcode
== OP_LABELED
)
281 char *name
= &exp
->elts
[pc
+ 2].string
;
282 int tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
284 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
291 /* This function evaluates tuples (in (the deleted) Chill) or
292 brace-initializers (in C/C++) for structure types. */
294 static struct value
*
295 evaluate_struct_tuple (struct value
*struct_val
,
296 struct expression
*exp
,
297 int *pos
, enum noside noside
, int nargs
)
299 struct type
*struct_type
= check_typedef (value_type (struct_val
));
300 struct type
*substruct_type
= struct_type
;
301 struct type
*field_type
;
309 struct value
*val
= NULL
;
314 /* Skip past the labels, and count them. */
315 while (get_label (exp
, pos
) != NULL
)
320 char *label
= get_label (exp
, &pc
);
324 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (struct_type
);
327 char *field_name
= TYPE_FIELD_NAME (struct_type
, fieldno
);
329 if (field_name
!= NULL
&& strcmp (field_name
, label
) == 0)
332 subfieldno
= fieldno
;
333 substruct_type
= struct_type
;
337 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (struct_type
);
340 char *field_name
= TYPE_FIELD_NAME (struct_type
, fieldno
);
342 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
343 if ((field_name
== 0 || *field_name
== '\0')
344 && TYPE_CODE (field_type
) == TYPE_CODE_UNION
)
347 for (; variantno
< TYPE_NFIELDS (field_type
);
351 = TYPE_FIELD_TYPE (field_type
, variantno
);
352 if (TYPE_CODE (substruct_type
) == TYPE_CODE_STRUCT
)
355 subfieldno
< TYPE_NFIELDS (substruct_type
);
358 if (strcmp(TYPE_FIELD_NAME (substruct_type
,
369 error (_("there is no field named %s"), label
);
375 /* Unlabelled tuple element - go to next field. */
379 if (subfieldno
>= TYPE_NFIELDS (substruct_type
))
382 substruct_type
= struct_type
;
388 /* Skip static fields. */
389 while (fieldno
< TYPE_NFIELDS (struct_type
)
390 && field_is_static (&TYPE_FIELD (struct_type
,
393 subfieldno
= fieldno
;
394 if (fieldno
>= TYPE_NFIELDS (struct_type
))
395 error (_("too many initializers"));
396 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
397 if (TYPE_CODE (field_type
) == TYPE_CODE_UNION
398 && TYPE_FIELD_NAME (struct_type
, fieldno
)[0] == '0')
399 error (_("don't know which variant you want to set"));
403 /* Here, struct_type is the type of the inner struct,
404 while substruct_type is the type of the inner struct.
405 These are the same for normal structures, but a variant struct
406 contains anonymous union fields that contain substruct fields.
407 The value fieldno is the index of the top-level (normal or
408 anonymous union) field in struct_field, while the value
409 subfieldno is the index of the actual real (named inner) field
410 in substruct_type. */
412 field_type
= TYPE_FIELD_TYPE (substruct_type
, subfieldno
);
414 val
= evaluate_subexp (field_type
, exp
, pos
, noside
);
416 /* Now actually set the field in struct_val. */
418 /* Assign val to field fieldno. */
419 if (value_type (val
) != field_type
)
420 val
= value_cast (field_type
, val
);
422 bitsize
= TYPE_FIELD_BITSIZE (substruct_type
, subfieldno
);
423 bitpos
= TYPE_FIELD_BITPOS (struct_type
, fieldno
);
425 bitpos
+= TYPE_FIELD_BITPOS (substruct_type
, subfieldno
);
426 addr
= value_contents_writeable (struct_val
) + bitpos
/ 8;
428 modify_field (struct_type
, addr
,
429 value_as_long (val
), bitpos
% 8, bitsize
);
431 memcpy (addr
, value_contents (val
),
432 TYPE_LENGTH (value_type (val
)));
434 while (--nlabels
> 0);
439 /* Recursive helper function for setting elements of array tuples for
440 (the deleted) Chill. The target is ARRAY (which has bounds
441 LOW_BOUND to HIGH_BOUND); the element value is ELEMENT; EXP, POS
442 and NOSIDE are as usual. Evaluates index expresions and sets the
443 specified element(s) of ARRAY to ELEMENT. Returns last index
447 init_array_element (struct value
*array
, struct value
*element
,
448 struct expression
*exp
, int *pos
,
449 enum noside noside
, LONGEST low_bound
, LONGEST high_bound
)
452 int element_size
= TYPE_LENGTH (value_type (element
));
454 if (exp
->elts
[*pos
].opcode
== BINOP_COMMA
)
457 init_array_element (array
, element
, exp
, pos
, noside
,
458 low_bound
, high_bound
);
459 return init_array_element (array
, element
,
460 exp
, pos
, noside
, low_bound
, high_bound
);
462 else if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
467 low
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
468 high
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
469 if (low
< low_bound
|| high
> high_bound
)
470 error (_("tuple range index out of range"));
471 for (index
= low
; index
<= high
; index
++)
473 memcpy (value_contents_raw (array
)
474 + (index
- low_bound
) * element_size
,
475 value_contents (element
), element_size
);
480 index
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
481 if (index
< low_bound
|| index
> high_bound
)
482 error (_("tuple index out of range"));
483 memcpy (value_contents_raw (array
) + (index
- low_bound
) * element_size
,
484 value_contents (element
), element_size
);
489 static struct value
*
490 value_f90_subarray (struct value
*array
,
491 struct expression
*exp
, int *pos
, enum noside noside
)
494 LONGEST low_bound
, high_bound
;
495 struct type
*range
= check_typedef (TYPE_INDEX_TYPE (value_type (array
)));
496 enum f90_range_type range_type
= longest_to_int (exp
->elts
[pc
].longconst
);
500 if (range_type
== LOW_BOUND_DEFAULT
|| range_type
== BOTH_BOUND_DEFAULT
)
501 low_bound
= TYPE_LOW_BOUND (range
);
503 low_bound
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
505 if (range_type
== HIGH_BOUND_DEFAULT
|| range_type
== BOTH_BOUND_DEFAULT
)
506 high_bound
= TYPE_HIGH_BOUND (range
);
508 high_bound
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
510 return value_slice (array
, low_bound
, high_bound
- low_bound
+ 1);
514 /* Promote value ARG1 as appropriate before performing a unary operation
516 If the result is not appropriate for any particular language then it
517 needs to patch this function. */
520 unop_promote (const struct language_defn
*language
, struct gdbarch
*gdbarch
,
525 *arg1
= coerce_ref (*arg1
);
526 type1
= check_typedef (value_type (*arg1
));
528 if (is_integral_type (type1
))
530 switch (language
->la_language
)
533 /* Perform integral promotion for ANSI C/C++.
534 If not appropropriate for any particular language
535 it needs to modify this function. */
537 struct type
*builtin_int
= builtin_type (gdbarch
)->builtin_int
;
539 if (TYPE_LENGTH (type1
) < TYPE_LENGTH (builtin_int
))
540 *arg1
= value_cast (builtin_int
, *arg1
);
547 /* Promote values ARG1 and ARG2 as appropriate before performing a binary
548 operation on those two operands.
549 If the result is not appropriate for any particular language then it
550 needs to patch this function. */
553 binop_promote (const struct language_defn
*language
, struct gdbarch
*gdbarch
,
554 struct value
**arg1
, struct value
**arg2
)
556 struct type
*promoted_type
= NULL
;
560 *arg1
= coerce_ref (*arg1
);
561 *arg2
= coerce_ref (*arg2
);
563 type1
= check_typedef (value_type (*arg1
));
564 type2
= check_typedef (value_type (*arg2
));
566 if ((TYPE_CODE (type1
) != TYPE_CODE_FLT
567 && TYPE_CODE (type1
) != TYPE_CODE_DECFLOAT
568 && !is_integral_type (type1
))
569 || (TYPE_CODE (type2
) != TYPE_CODE_FLT
570 && TYPE_CODE (type2
) != TYPE_CODE_DECFLOAT
571 && !is_integral_type (type2
)))
574 if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
575 || TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
)
577 /* No promotion required. */
579 else if (TYPE_CODE (type1
) == TYPE_CODE_FLT
580 || TYPE_CODE (type2
) == TYPE_CODE_FLT
)
582 switch (language
->la_language
)
588 case language_opencl
:
589 /* No promotion required. */
593 /* For other languages the result type is unchanged from gdb
594 version 6.7 for backward compatibility.
595 If either arg was long double, make sure that value is also long
596 double. Otherwise use double. */
597 if (TYPE_LENGTH (type1
) * 8 > gdbarch_double_bit (gdbarch
)
598 || TYPE_LENGTH (type2
) * 8 > gdbarch_double_bit (gdbarch
))
599 promoted_type
= builtin_type (gdbarch
)->builtin_long_double
;
601 promoted_type
= builtin_type (gdbarch
)->builtin_double
;
605 else if (TYPE_CODE (type1
) == TYPE_CODE_BOOL
606 && TYPE_CODE (type2
) == TYPE_CODE_BOOL
)
608 /* No promotion required. */
611 /* Integral operations here. */
612 /* FIXME: Also mixed integral/booleans, with result an integer. */
614 const struct builtin_type
*builtin
= builtin_type (gdbarch
);
615 unsigned int promoted_len1
= TYPE_LENGTH (type1
);
616 unsigned int promoted_len2
= TYPE_LENGTH (type2
);
617 int is_unsigned1
= TYPE_UNSIGNED (type1
);
618 int is_unsigned2
= TYPE_UNSIGNED (type2
);
619 unsigned int result_len
;
620 int unsigned_operation
;
622 /* Determine type length and signedness after promotion for
624 if (promoted_len1
< TYPE_LENGTH (builtin
->builtin_int
))
627 promoted_len1
= TYPE_LENGTH (builtin
->builtin_int
);
629 if (promoted_len2
< TYPE_LENGTH (builtin
->builtin_int
))
632 promoted_len2
= TYPE_LENGTH (builtin
->builtin_int
);
635 if (promoted_len1
> promoted_len2
)
637 unsigned_operation
= is_unsigned1
;
638 result_len
= promoted_len1
;
640 else if (promoted_len2
> promoted_len1
)
642 unsigned_operation
= is_unsigned2
;
643 result_len
= promoted_len2
;
647 unsigned_operation
= is_unsigned1
|| is_unsigned2
;
648 result_len
= promoted_len1
;
651 switch (language
->la_language
)
657 if (result_len
<= TYPE_LENGTH (builtin
->builtin_int
))
659 promoted_type
= (unsigned_operation
660 ? builtin
->builtin_unsigned_int
661 : builtin
->builtin_int
);
663 else if (result_len
<= TYPE_LENGTH (builtin
->builtin_long
))
665 promoted_type
= (unsigned_operation
666 ? builtin
->builtin_unsigned_long
667 : builtin
->builtin_long
);
671 promoted_type
= (unsigned_operation
672 ? builtin
->builtin_unsigned_long_long
673 : builtin
->builtin_long_long
);
676 case language_opencl
:
677 if (result_len
<= TYPE_LENGTH (lookup_signed_typename
678 (language
, gdbarch
, "int")))
682 ? lookup_unsigned_typename (language
, gdbarch
, "int")
683 : lookup_signed_typename (language
, gdbarch
, "int"));
685 else if (result_len
<= TYPE_LENGTH (lookup_signed_typename
686 (language
, gdbarch
, "long")))
690 ? lookup_unsigned_typename (language
, gdbarch
, "long")
691 : lookup_signed_typename (language
, gdbarch
,"long"));
695 /* For other languages the result type is unchanged from gdb
696 version 6.7 for backward compatibility.
697 If either arg was long long, make sure that value is also long
698 long. Otherwise use long. */
699 if (unsigned_operation
)
701 if (result_len
> gdbarch_long_bit (gdbarch
) / HOST_CHAR_BIT
)
702 promoted_type
= builtin
->builtin_unsigned_long_long
;
704 promoted_type
= builtin
->builtin_unsigned_long
;
708 if (result_len
> gdbarch_long_bit (gdbarch
) / HOST_CHAR_BIT
)
709 promoted_type
= builtin
->builtin_long_long
;
711 promoted_type
= builtin
->builtin_long
;
719 /* Promote both operands to common type. */
720 *arg1
= value_cast (promoted_type
, *arg1
);
721 *arg2
= value_cast (promoted_type
, *arg2
);
726 ptrmath_type_p (const struct language_defn
*lang
, struct type
*type
)
728 type
= check_typedef (type
);
729 if (TYPE_CODE (type
) == TYPE_CODE_REF
)
730 type
= TYPE_TARGET_TYPE (type
);
732 switch (TYPE_CODE (type
))
738 case TYPE_CODE_ARRAY
:
739 return TYPE_VECTOR (type
) ? 0 : lang
->c_style_arrays
;
746 /* Constructs a fake method with the given parameter types.
747 This function is used by the parser to construct an "expected"
748 type for method overload resolution. */
751 make_params (int num_types
, struct type
**param_types
)
753 struct type
*type
= XZALLOC (struct type
);
754 TYPE_MAIN_TYPE (type
) = XZALLOC (struct main_type
);
755 TYPE_LENGTH (type
) = 1;
756 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
757 TYPE_VPTR_FIELDNO (type
) = -1;
758 TYPE_CHAIN (type
) = type
;
759 TYPE_NFIELDS (type
) = num_types
;
760 TYPE_FIELDS (type
) = (struct field
*)
761 TYPE_ZALLOC (type
, sizeof (struct field
) * num_types
);
763 while (num_types
-- > 0)
764 TYPE_FIELD_TYPE (type
, num_types
) = param_types
[num_types
];
770 evaluate_subexp_standard (struct type
*expect_type
,
771 struct expression
*exp
, int *pos
,
776 int pc
, pc2
= 0, oldpos
;
777 struct value
*arg1
= NULL
;
778 struct value
*arg2
= NULL
;
782 struct value
**argvec
;
787 struct type
**arg_types
;
789 struct symbol
*function
= NULL
;
790 char *function_name
= NULL
;
793 op
= exp
->elts
[pc
].opcode
;
798 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
799 (*pos
) += 4 + BYTES_TO_EXP_ELEM (tem
+ 1);
800 if (noside
== EVAL_SKIP
)
802 arg1
= value_aggregate_elt (exp
->elts
[pc
+ 1].type
,
803 &exp
->elts
[pc
+ 3].string
,
804 expect_type
, 0, noside
);
806 error (_("There is no field named %s"), &exp
->elts
[pc
+ 3].string
);
811 return value_from_longest (exp
->elts
[pc
+ 1].type
,
812 exp
->elts
[pc
+ 2].longconst
);
816 return value_from_double (exp
->elts
[pc
+ 1].type
,
817 exp
->elts
[pc
+ 2].doubleconst
);
821 return value_from_decfloat (exp
->elts
[pc
+ 1].type
,
822 exp
->elts
[pc
+ 2].decfloatconst
);
827 if (noside
== EVAL_SKIP
)
830 /* JYG: We used to just return value_zero of the symbol type
831 if we're asked to avoid side effects. Otherwise we return
832 value_of_variable (...). However I'm not sure if
833 value_of_variable () has any side effect.
834 We need a full value object returned here for whatis_exp ()
835 to call evaluate_type () and then pass the full value to
836 value_rtti_target_type () if we are dealing with a pointer
837 or reference to a base class and print object is on. */
840 volatile struct gdb_exception except
;
841 struct value
*ret
= NULL
;
843 TRY_CATCH (except
, RETURN_MASK_ERROR
)
845 ret
= value_of_variable (exp
->elts
[pc
+ 2].symbol
,
846 exp
->elts
[pc
+ 1].block
);
849 if (except
.reason
< 0)
851 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
852 ret
= value_zero (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
),
855 throw_exception (except
);
861 case OP_VAR_ENTRY_VALUE
:
863 if (noside
== EVAL_SKIP
)
867 struct symbol
*sym
= exp
->elts
[pc
+ 1].symbol
;
868 struct frame_info
*frame
;
870 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
871 return value_zero (SYMBOL_TYPE (sym
), not_lval
);
873 if (SYMBOL_CLASS (sym
) != LOC_COMPUTED
874 || SYMBOL_COMPUTED_OPS (sym
)->read_variable_at_entry
== NULL
)
875 error (_("Symbol \"%s\" does not have any specific entry value"),
876 SYMBOL_PRINT_NAME (sym
));
878 frame
= get_selected_frame (NULL
);
879 return SYMBOL_COMPUTED_OPS (sym
)->read_variable_at_entry (sym
, frame
);
885 access_value_history (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
889 const char *name
= &exp
->elts
[pc
+ 2].string
;
893 (*pos
) += 3 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
894 regno
= user_reg_map_name_to_regnum (exp
->gdbarch
,
895 name
, strlen (name
));
897 error (_("Register $%s not available."), name
);
899 /* In EVAL_AVOID_SIDE_EFFECTS mode, we only need to return
900 a value with the appropriate register type. Unfortunately,
901 we don't have easy access to the type of user registers.
902 So for these registers, we fetch the register value regardless
903 of the evaluation mode. */
904 if (noside
== EVAL_AVOID_SIDE_EFFECTS
905 && regno
< gdbarch_num_regs (exp
->gdbarch
)
906 + gdbarch_num_pseudo_regs (exp
->gdbarch
))
907 val
= value_zero (register_type (exp
->gdbarch
, regno
), not_lval
);
909 val
= value_of_register (regno
, get_selected_frame (NULL
));
911 error (_("Value of register %s not available."), name
);
917 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
918 return value_from_longest (type
, exp
->elts
[pc
+ 1].longconst
);
922 return value_of_internalvar (exp
->gdbarch
,
923 exp
->elts
[pc
+ 1].internalvar
);
926 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
927 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
928 if (noside
== EVAL_SKIP
)
930 type
= language_string_char_type (exp
->language_defn
, exp
->gdbarch
);
931 return value_string (&exp
->elts
[pc
+ 2].string
, tem
, type
);
933 case OP_OBJC_NSSTRING
: /* Objective C Foundation Class
934 NSString constant. */
935 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
936 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
937 if (noside
== EVAL_SKIP
)
941 return value_nsstring (exp
->gdbarch
, &exp
->elts
[pc
+ 2].string
, tem
+ 1);
944 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
946 += 3 + BYTES_TO_EXP_ELEM ((tem
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
);
947 if (noside
== EVAL_SKIP
)
949 return value_bitstring (&exp
->elts
[pc
+ 2].string
, tem
,
950 builtin_type (exp
->gdbarch
)->builtin_int
);
955 tem2
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
956 tem3
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
957 nargs
= tem3
- tem2
+ 1;
958 type
= expect_type
? check_typedef (expect_type
) : NULL_TYPE
;
960 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
961 && TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
963 struct value
*rec
= allocate_value (expect_type
);
965 memset (value_contents_raw (rec
), '\0', TYPE_LENGTH (type
));
966 return evaluate_struct_tuple (rec
, exp
, pos
, noside
, nargs
);
969 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
970 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
972 struct type
*range_type
= TYPE_INDEX_TYPE (type
);
973 struct type
*element_type
= TYPE_TARGET_TYPE (type
);
974 struct value
*array
= allocate_value (expect_type
);
975 int element_size
= TYPE_LENGTH (check_typedef (element_type
));
976 LONGEST low_bound
, high_bound
, index
;
978 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
981 high_bound
= (TYPE_LENGTH (type
) / element_size
) - 1;
984 memset (value_contents_raw (array
), 0, TYPE_LENGTH (expect_type
));
985 for (tem
= nargs
; --nargs
>= 0;)
987 struct value
*element
;
990 if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
993 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
995 element
= evaluate_subexp (element_type
, exp
, pos
, noside
);
996 if (value_type (element
) != element_type
)
997 element
= value_cast (element_type
, element
);
1000 int continue_pc
= *pos
;
1003 index
= init_array_element (array
, element
, exp
, pos
, noside
,
1004 low_bound
, high_bound
);
1009 if (index
> high_bound
)
1010 /* To avoid memory corruption. */
1011 error (_("Too many array elements"));
1012 memcpy (value_contents_raw (array
)
1013 + (index
- low_bound
) * element_size
,
1014 value_contents (element
),
1022 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
1023 && TYPE_CODE (type
) == TYPE_CODE_SET
)
1025 struct value
*set
= allocate_value (expect_type
);
1026 gdb_byte
*valaddr
= value_contents_raw (set
);
1027 struct type
*element_type
= TYPE_INDEX_TYPE (type
);
1028 struct type
*check_type
= element_type
;
1029 LONGEST low_bound
, high_bound
;
1031 /* Get targettype of elementtype. */
1032 while (TYPE_CODE (check_type
) == TYPE_CODE_RANGE
1033 || TYPE_CODE (check_type
) == TYPE_CODE_TYPEDEF
)
1034 check_type
= TYPE_TARGET_TYPE (check_type
);
1036 if (get_discrete_bounds (element_type
, &low_bound
, &high_bound
) < 0)
1037 error (_("(power)set type with unknown size"));
1038 memset (valaddr
, '\0', TYPE_LENGTH (type
));
1039 for (tem
= 0; tem
< nargs
; tem
++)
1041 LONGEST range_low
, range_high
;
1042 struct type
*range_low_type
, *range_high_type
;
1043 struct value
*elem_val
;
1045 if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
1048 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
1049 range_low_type
= value_type (elem_val
);
1050 range_low
= value_as_long (elem_val
);
1051 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
1052 range_high_type
= value_type (elem_val
);
1053 range_high
= value_as_long (elem_val
);
1057 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
1058 range_low_type
= range_high_type
= value_type (elem_val
);
1059 range_low
= range_high
= value_as_long (elem_val
);
1061 /* Check types of elements to avoid mixture of elements from
1062 different types. Also check if type of element is "compatible"
1063 with element type of powerset. */
1064 if (TYPE_CODE (range_low_type
) == TYPE_CODE_RANGE
)
1065 range_low_type
= TYPE_TARGET_TYPE (range_low_type
);
1066 if (TYPE_CODE (range_high_type
) == TYPE_CODE_RANGE
)
1067 range_high_type
= TYPE_TARGET_TYPE (range_high_type
);
1068 if ((TYPE_CODE (range_low_type
) != TYPE_CODE (range_high_type
))
1069 || (TYPE_CODE (range_low_type
) == TYPE_CODE_ENUM
1070 && (range_low_type
!= range_high_type
)))
1071 /* different element modes. */
1072 error (_("POWERSET tuple elements of different mode"));
1073 if ((TYPE_CODE (check_type
) != TYPE_CODE (range_low_type
))
1074 || (TYPE_CODE (check_type
) == TYPE_CODE_ENUM
1075 && range_low_type
!= check_type
))
1076 error (_("incompatible POWERSET tuple elements"));
1077 if (range_low
> range_high
)
1079 warning (_("empty POWERSET tuple range"));
1082 if (range_low
< low_bound
|| range_high
> high_bound
)
1083 error (_("POWERSET tuple element out of range"));
1084 range_low
-= low_bound
;
1085 range_high
-= low_bound
;
1086 for (; range_low
<= range_high
; range_low
++)
1088 int bit_index
= (unsigned) range_low
% TARGET_CHAR_BIT
;
1090 if (gdbarch_bits_big_endian (exp
->gdbarch
))
1091 bit_index
= TARGET_CHAR_BIT
- 1 - bit_index
;
1092 valaddr
[(unsigned) range_low
/ TARGET_CHAR_BIT
]
1099 argvec
= (struct value
**) alloca (sizeof (struct value
*) * nargs
);
1100 for (tem
= 0; tem
< nargs
; tem
++)
1102 /* Ensure that array expressions are coerced into pointer
1104 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1106 if (noside
== EVAL_SKIP
)
1108 return value_array (tem2
, tem3
, argvec
);
1112 struct value
*array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1114 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1116 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1118 if (noside
== EVAL_SKIP
)
1120 return value_slice (array
, lowbound
, upper
- lowbound
+ 1);
1123 case TERNOP_SLICE_COUNT
:
1125 struct value
*array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1127 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1129 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1131 return value_slice (array
, lowbound
, length
);
1135 /* Skip third and second args to evaluate the first one. */
1136 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1137 if (value_logical_not (arg1
))
1139 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1140 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1144 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1145 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1149 case OP_OBJC_SELECTOR
:
1150 { /* Objective C @selector operator. */
1151 char *sel
= &exp
->elts
[pc
+ 2].string
;
1152 int len
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1153 struct type
*selector_type
;
1155 (*pos
) += 3 + BYTES_TO_EXP_ELEM (len
+ 1);
1156 if (noside
== EVAL_SKIP
)
1160 sel
[len
] = 0; /* Make sure it's terminated. */
1162 selector_type
= builtin_type (exp
->gdbarch
)->builtin_data_ptr
;
1163 return value_from_longest (selector_type
,
1164 lookup_child_selector (exp
->gdbarch
, sel
));
1167 case OP_OBJC_MSGCALL
:
1168 { /* Objective C message (method) call. */
1170 CORE_ADDR responds_selector
= 0;
1171 CORE_ADDR method_selector
= 0;
1173 CORE_ADDR selector
= 0;
1175 int struct_return
= 0;
1176 int sub_no_side
= 0;
1178 struct value
*msg_send
= NULL
;
1179 struct value
*msg_send_stret
= NULL
;
1180 int gnu_runtime
= 0;
1182 struct value
*target
= NULL
;
1183 struct value
*method
= NULL
;
1184 struct value
*called_method
= NULL
;
1186 struct type
*selector_type
= NULL
;
1187 struct type
*long_type
;
1189 struct value
*ret
= NULL
;
1192 selector
= exp
->elts
[pc
+ 1].longconst
;
1193 nargs
= exp
->elts
[pc
+ 2].longconst
;
1194 argvec
= (struct value
**) alloca (sizeof (struct value
*)
1199 long_type
= builtin_type (exp
->gdbarch
)->builtin_long
;
1200 selector_type
= builtin_type (exp
->gdbarch
)->builtin_data_ptr
;
1202 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1203 sub_no_side
= EVAL_NORMAL
;
1205 sub_no_side
= noside
;
1207 target
= evaluate_subexp (selector_type
, exp
, pos
, sub_no_side
);
1209 if (value_as_long (target
) == 0)
1210 return value_from_longest (long_type
, 0);
1212 if (lookup_minimal_symbol ("objc_msg_lookup", 0, 0))
1215 /* Find the method dispatch (Apple runtime) or method lookup
1216 (GNU runtime) function for Objective-C. These will be used
1217 to lookup the symbol information for the method. If we
1218 can't find any symbol information, then we'll use these to
1219 call the method, otherwise we can call the method
1220 directly. The msg_send_stret function is used in the special
1221 case of a method that returns a structure (Apple runtime
1225 struct type
*type
= selector_type
;
1227 type
= lookup_function_type (type
);
1228 type
= lookup_pointer_type (type
);
1229 type
= lookup_function_type (type
);
1230 type
= lookup_pointer_type (type
);
1232 msg_send
= find_function_in_inferior ("objc_msg_lookup", NULL
);
1234 = find_function_in_inferior ("objc_msg_lookup", NULL
);
1236 msg_send
= value_from_pointer (type
, value_as_address (msg_send
));
1237 msg_send_stret
= value_from_pointer (type
,
1238 value_as_address (msg_send_stret
));
1242 msg_send
= find_function_in_inferior ("objc_msgSend", NULL
);
1243 /* Special dispatcher for methods returning structs. */
1245 = find_function_in_inferior ("objc_msgSend_stret", NULL
);
1248 /* Verify the target object responds to this method. The
1249 standard top-level 'Object' class uses a different name for
1250 the verification method than the non-standard, but more
1251 often used, 'NSObject' class. Make sure we check for both. */
1254 = lookup_child_selector (exp
->gdbarch
, "respondsToSelector:");
1255 if (responds_selector
== 0)
1257 = lookup_child_selector (exp
->gdbarch
, "respondsTo:");
1259 if (responds_selector
== 0)
1260 error (_("no 'respondsTo:' or 'respondsToSelector:' method"));
1263 = lookup_child_selector (exp
->gdbarch
, "methodForSelector:");
1264 if (method_selector
== 0)
1266 = lookup_child_selector (exp
->gdbarch
, "methodFor:");
1268 if (method_selector
== 0)
1269 error (_("no 'methodFor:' or 'methodForSelector:' method"));
1271 /* Call the verification method, to make sure that the target
1272 class implements the desired method. */
1274 argvec
[0] = msg_send
;
1276 argvec
[2] = value_from_longest (long_type
, responds_selector
);
1277 argvec
[3] = value_from_longest (long_type
, selector
);
1280 ret
= call_function_by_hand (argvec
[0], 3, argvec
+ 1);
1283 /* Function objc_msg_lookup returns a pointer. */
1285 ret
= call_function_by_hand (argvec
[0], 3, argvec
+ 1);
1287 if (value_as_long (ret
) == 0)
1288 error (_("Target does not respond to this message selector."));
1290 /* Call "methodForSelector:" method, to get the address of a
1291 function method that implements this selector for this
1292 class. If we can find a symbol at that address, then we
1293 know the return type, parameter types etc. (that's a good
1296 argvec
[0] = msg_send
;
1298 argvec
[2] = value_from_longest (long_type
, method_selector
);
1299 argvec
[3] = value_from_longest (long_type
, selector
);
1302 ret
= call_function_by_hand (argvec
[0], 3, argvec
+ 1);
1306 ret
= call_function_by_hand (argvec
[0], 3, argvec
+ 1);
1309 /* ret should now be the selector. */
1311 addr
= value_as_long (ret
);
1314 struct symbol
*sym
= NULL
;
1316 /* The address might point to a function descriptor;
1317 resolve it to the actual code address instead. */
1318 addr
= gdbarch_convert_from_func_ptr_addr (exp
->gdbarch
, addr
,
1321 /* Is it a high_level symbol? */
1322 sym
= find_pc_function (addr
);
1324 method
= value_of_variable (sym
, 0);
1327 /* If we found a method with symbol information, check to see
1328 if it returns a struct. Otherwise assume it doesn't. */
1333 struct type
*val_type
;
1335 funaddr
= find_function_addr (method
, &val_type
);
1337 block_for_pc (funaddr
);
1339 CHECK_TYPEDEF (val_type
);
1341 if ((val_type
== NULL
)
1342 || (TYPE_CODE(val_type
) == TYPE_CODE_ERROR
))
1344 if (expect_type
!= NULL
)
1345 val_type
= expect_type
;
1348 struct_return
= using_struct_return (exp
->gdbarch
,
1349 value_type (method
),
1352 else if (expect_type
!= NULL
)
1354 struct_return
= using_struct_return (exp
->gdbarch
, NULL
,
1355 check_typedef (expect_type
));
1358 /* Found a function symbol. Now we will substitute its
1359 value in place of the message dispatcher (obj_msgSend),
1360 so that we call the method directly instead of thru
1361 the dispatcher. The main reason for doing this is that
1362 we can now evaluate the return value and parameter values
1363 according to their known data types, in case we need to
1364 do things like promotion, dereferencing, special handling
1365 of structs and doubles, etc.
1367 We want to use the type signature of 'method', but still
1368 jump to objc_msgSend() or objc_msgSend_stret() to better
1369 mimic the behavior of the runtime. */
1373 if (TYPE_CODE (value_type (method
)) != TYPE_CODE_FUNC
)
1374 error (_("method address has symbol information "
1375 "with non-function type; skipping"));
1377 /* Create a function pointer of the appropriate type, and
1378 replace its value with the value of msg_send or
1379 msg_send_stret. We must use a pointer here, as
1380 msg_send and msg_send_stret are of pointer type, and
1381 the representation may be different on systems that use
1382 function descriptors. */
1385 = value_from_pointer (lookup_pointer_type (value_type (method
)),
1386 value_as_address (msg_send_stret
));
1389 = value_from_pointer (lookup_pointer_type (value_type (method
)),
1390 value_as_address (msg_send
));
1395 called_method
= msg_send_stret
;
1397 called_method
= msg_send
;
1400 if (noside
== EVAL_SKIP
)
1403 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1405 /* If the return type doesn't look like a function type,
1406 call an error. This can happen if somebody tries to
1407 turn a variable into a function call. This is here
1408 because people often want to call, eg, strcmp, which
1409 gdb doesn't know is a function. If gdb isn't asked for
1410 it's opinion (ie. through "whatis"), it won't offer
1413 struct type
*type
= value_type (called_method
);
1415 if (type
&& TYPE_CODE (type
) == TYPE_CODE_PTR
)
1416 type
= TYPE_TARGET_TYPE (type
);
1417 type
= TYPE_TARGET_TYPE (type
);
1421 if ((TYPE_CODE (type
) == TYPE_CODE_ERROR
) && expect_type
)
1422 return allocate_value (expect_type
);
1424 return allocate_value (type
);
1427 error (_("Expression of type other than "
1428 "\"method returning ...\" used as a method"));
1431 /* Now depending on whether we found a symbol for the method,
1432 we will either call the runtime dispatcher or the method
1435 argvec
[0] = called_method
;
1437 argvec
[2] = value_from_longest (long_type
, selector
);
1438 /* User-supplied arguments. */
1439 for (tem
= 0; tem
< nargs
; tem
++)
1440 argvec
[tem
+ 3] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1441 argvec
[tem
+ 3] = 0;
1443 if (gnu_runtime
&& (method
!= NULL
))
1445 /* Function objc_msg_lookup returns a pointer. */
1446 deprecated_set_value_type (argvec
[0],
1447 lookup_pointer_type (lookup_function_type (value_type (argvec
[0]))));
1449 = call_function_by_hand (argvec
[0], nargs
+ 2, argvec
+ 1);
1452 ret
= call_function_by_hand (argvec
[0], nargs
+ 2, argvec
+ 1);
1459 op
= exp
->elts
[*pos
].opcode
;
1460 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1461 /* Allocate arg vector, including space for the function to be
1462 called in argvec[0] and a terminating NULL. */
1463 argvec
= (struct value
**)
1464 alloca (sizeof (struct value
*) * (nargs
+ 3));
1465 if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
1468 /* First, evaluate the structure into arg2. */
1471 if (noside
== EVAL_SKIP
)
1474 if (op
== STRUCTOP_MEMBER
)
1476 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
1480 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1483 /* If the function is a virtual function, then the
1484 aggregate value (providing the structure) plays
1485 its part by providing the vtable. Otherwise,
1486 it is just along for the ride: call the function
1489 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1491 if (TYPE_CODE (check_typedef (value_type (arg1
)))
1492 != TYPE_CODE_METHODPTR
)
1493 error (_("Non-pointer-to-member value used in pointer-to-member "
1496 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1498 struct type
*method_type
= check_typedef (value_type (arg1
));
1500 arg1
= value_zero (method_type
, not_lval
);
1503 arg1
= cplus_method_ptr_to_value (&arg2
, arg1
);
1505 /* Now, say which argument to start evaluating from. */
1508 else if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
1510 /* Hair for method invocations. */
1514 /* First, evaluate the structure into arg2. */
1516 tem2
= longest_to_int (exp
->elts
[pc2
+ 1].longconst
);
1517 *pos
+= 3 + BYTES_TO_EXP_ELEM (tem2
+ 1);
1518 if (noside
== EVAL_SKIP
)
1521 if (op
== STRUCTOP_STRUCT
)
1523 /* If v is a variable in a register, and the user types
1524 v.method (), this will produce an error, because v has
1527 A possible way around this would be to allocate a
1528 copy of the variable on the stack, copy in the
1529 contents, call the function, and copy out the
1530 contents. I.e. convert this from call by reference
1531 to call by copy-return (or whatever it's called).
1532 However, this does not work because it is not the
1533 same: the method being called could stash a copy of
1534 the address, and then future uses through that address
1535 (after the method returns) would be expected to
1536 use the variable itself, not some copy of it. */
1537 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
1541 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1543 /* Check to see if the operator '->' has been
1544 overloaded. If the operator has been overloaded
1545 replace arg2 with the value returned by the custom
1546 operator and continue evaluation. */
1547 while (unop_user_defined_p (op
, arg2
))
1549 volatile struct gdb_exception except
;
1550 struct value
*value
= NULL
;
1551 TRY_CATCH (except
, RETURN_MASK_ERROR
)
1553 value
= value_x_unop (arg2
, op
, noside
);
1556 if (except
.reason
< 0)
1558 if (except
.error
== NOT_FOUND_ERROR
)
1561 throw_exception (except
);
1566 /* Now, say which argument to start evaluating from. */
1569 else if (op
== OP_SCOPE
1570 && overload_resolution
1571 && (exp
->language_defn
->la_language
== language_cplus
))
1573 /* Unpack it locally so we can properly handle overload
1579 local_tem
= longest_to_int (exp
->elts
[pc2
+ 2].longconst
);
1580 (*pos
) += 4 + BYTES_TO_EXP_ELEM (local_tem
+ 1);
1581 type
= exp
->elts
[pc2
+ 1].type
;
1582 name
= &exp
->elts
[pc2
+ 3].string
;
1585 function_name
= NULL
;
1586 if (TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
1588 function
= cp_lookup_symbol_namespace (TYPE_TAG_NAME (type
),
1590 get_selected_block (0),
1592 if (function
== NULL
)
1593 error (_("No symbol \"%s\" in namespace \"%s\"."),
1594 name
, TYPE_TAG_NAME (type
));
1600 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_STRUCT
1601 || TYPE_CODE (type
) == TYPE_CODE_UNION
);
1602 function_name
= name
;
1604 arg2
= value_zero (type
, lval_memory
);
1609 else if (op
== OP_ADL_FUNC
)
1611 /* Save the function position and move pos so that the arguments
1612 can be evaluated. */
1618 func_name_len
= longest_to_int (exp
->elts
[save_pos1
+ 3].longconst
);
1619 (*pos
) += 6 + BYTES_TO_EXP_ELEM (func_name_len
+ 1);
1623 /* Non-method function call. */
1627 /* If this is a C++ function wait until overload resolution. */
1628 if (op
== OP_VAR_VALUE
1629 && overload_resolution
1630 && (exp
->language_defn
->la_language
== language_cplus
))
1632 (*pos
) += 4; /* Skip the evaluation of the symbol. */
1637 argvec
[0] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1638 type
= value_type (argvec
[0]);
1639 if (type
&& TYPE_CODE (type
) == TYPE_CODE_PTR
)
1640 type
= TYPE_TARGET_TYPE (type
);
1641 if (type
&& TYPE_CODE (type
) == TYPE_CODE_FUNC
)
1643 for (; tem
<= nargs
&& tem
<= TYPE_NFIELDS (type
); tem
++)
1645 argvec
[tem
] = evaluate_subexp (TYPE_FIELD_TYPE (type
,
1653 /* Evaluate arguments. */
1654 for (; tem
<= nargs
; tem
++)
1656 /* Ensure that array expressions are coerced into pointer
1658 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1661 /* Signal end of arglist. */
1663 if (op
== OP_ADL_FUNC
)
1665 struct symbol
*symp
;
1668 int string_pc
= save_pos1
+ 3;
1670 /* Extract the function name. */
1671 name_len
= longest_to_int (exp
->elts
[string_pc
].longconst
);
1672 func_name
= (char *) alloca (name_len
+ 1);
1673 strcpy (func_name
, &exp
->elts
[string_pc
+ 1].string
);
1675 find_overload_match (&argvec
[1], nargs
, func_name
,
1676 NON_METHOD
, /* not method */
1677 0, /* strict match */
1678 NULL
, NULL
, /* pass NULL symbol since
1679 symbol is unknown */
1680 NULL
, &symp
, NULL
, 0);
1682 /* Now fix the expression being evaluated. */
1683 exp
->elts
[save_pos1
+ 2].symbol
= symp
;
1684 argvec
[0] = evaluate_subexp_with_coercion (exp
, &save_pos1
, noside
);
1687 if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
1688 || (op
== OP_SCOPE
&& function_name
!= NULL
))
1690 int static_memfuncp
;
1693 /* Method invocation : stuff "this" as first parameter. */
1698 /* Name of method from expression. */
1699 tstr
= &exp
->elts
[pc2
+ 2].string
;
1702 tstr
= function_name
;
1704 if (overload_resolution
&& (exp
->language_defn
->la_language
1707 /* Language is C++, do some overload resolution before
1709 struct value
*valp
= NULL
;
1711 (void) find_overload_match (&argvec
[1], nargs
, tstr
,
1712 METHOD
, /* method */
1713 0, /* strict match */
1714 &arg2
, /* the object */
1716 &static_memfuncp
, 0);
1718 if (op
== OP_SCOPE
&& !static_memfuncp
)
1720 /* For the time being, we don't handle this. */
1721 error (_("Call to overloaded function %s requires "
1725 argvec
[1] = arg2
; /* the ``this'' pointer */
1726 argvec
[0] = valp
; /* Use the method found after overload
1730 /* Non-C++ case -- or no overload resolution. */
1732 struct value
*temp
= arg2
;
1734 argvec
[0] = value_struct_elt (&temp
, argvec
+ 1, tstr
,
1736 op
== STRUCTOP_STRUCT
1737 ? "structure" : "structure pointer");
1738 /* value_struct_elt updates temp with the correct value
1739 of the ``this'' pointer if necessary, so modify argvec[1] to
1740 reflect any ``this'' changes. */
1742 = value_from_longest (lookup_pointer_type(value_type (temp
)),
1743 value_address (temp
)
1744 + value_embedded_offset (temp
));
1745 argvec
[1] = arg2
; /* the ``this'' pointer */
1748 if (static_memfuncp
)
1750 argvec
[1] = argvec
[0];
1755 else if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
1760 else if (op
== OP_VAR_VALUE
|| (op
== OP_SCOPE
&& function
!= NULL
))
1762 /* Non-member function being called. */
1763 /* fn: This can only be done for C++ functions. A C-style function
1764 in a C++ program, for instance, does not have the fields that
1765 are expected here. */
1767 if (overload_resolution
&& (exp
->language_defn
->la_language
1770 /* Language is C++, do some overload resolution before
1772 struct symbol
*symp
;
1775 /* If a scope has been specified disable ADL. */
1779 if (op
== OP_VAR_VALUE
)
1780 function
= exp
->elts
[save_pos1
+2].symbol
;
1782 (void) find_overload_match (&argvec
[1], nargs
,
1783 NULL
, /* no need for name */
1784 NON_METHOD
, /* not method */
1785 0, /* strict match */
1786 NULL
, function
, /* the function */
1787 NULL
, &symp
, NULL
, no_adl
);
1789 if (op
== OP_VAR_VALUE
)
1791 /* Now fix the expression being evaluated. */
1792 exp
->elts
[save_pos1
+2].symbol
= symp
;
1793 argvec
[0] = evaluate_subexp_with_coercion (exp
, &save_pos1
,
1797 argvec
[0] = value_of_variable (symp
, get_selected_block (0));
1801 /* Not C++, or no overload resolution allowed. */
1802 /* Nothing to be done; argvec already correctly set up. */
1807 /* It is probably a C-style function. */
1808 /* Nothing to be done; argvec already correctly set up. */
1813 if (noside
== EVAL_SKIP
)
1815 if (argvec
[0] == NULL
)
1816 error (_("Cannot evaluate function -- may be inlined"));
1817 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1819 /* If the return type doesn't look like a function type, call an
1820 error. This can happen if somebody tries to turn a variable into
1821 a function call. This is here because people often want to
1822 call, eg, strcmp, which gdb doesn't know is a function. If
1823 gdb isn't asked for it's opinion (ie. through "whatis"),
1824 it won't offer it. */
1826 struct type
*ftype
= value_type (argvec
[0]);
1828 if (TYPE_CODE (ftype
) == TYPE_CODE_INTERNAL_FUNCTION
)
1830 /* We don't know anything about what the internal
1831 function might return, but we have to return
1833 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
,
1836 else if (TYPE_GNU_IFUNC (ftype
))
1837 return allocate_value (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (ftype
)));
1838 else if (TYPE_TARGET_TYPE (ftype
))
1839 return allocate_value (TYPE_TARGET_TYPE (ftype
));
1841 error (_("Expression of type other than "
1842 "\"Function returning ...\" used as function"));
1844 if (TYPE_CODE (value_type (argvec
[0])) == TYPE_CODE_INTERNAL_FUNCTION
)
1845 return call_internal_function (exp
->gdbarch
, exp
->language_defn
,
1846 argvec
[0], nargs
, argvec
+ 1);
1848 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
1849 /* pai: FIXME save value from call_function_by_hand, then adjust
1850 pc by adjust_fn_pc if +ve. */
1852 case OP_F77_UNDETERMINED_ARGLIST
:
1854 /* Remember that in F77, functions, substring ops and
1855 array subscript operations cannot be disambiguated
1856 at parse time. We have made all array subscript operations,
1857 substring operations as well as function calls come here
1858 and we now have to discover what the heck this thing actually was.
1859 If it is a function, we process just as if we got an OP_FUNCALL. */
1861 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1864 /* First determine the type code we are dealing with. */
1865 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1866 type
= check_typedef (value_type (arg1
));
1867 code
= TYPE_CODE (type
);
1869 if (code
== TYPE_CODE_PTR
)
1871 /* Fortran always passes variable to subroutines as pointer.
1872 So we need to look into its target type to see if it is
1873 array, string or function. If it is, we need to switch
1874 to the target value the original one points to. */
1875 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1877 if (TYPE_CODE (target_type
) == TYPE_CODE_ARRAY
1878 || TYPE_CODE (target_type
) == TYPE_CODE_STRING
1879 || TYPE_CODE (target_type
) == TYPE_CODE_FUNC
)
1881 arg1
= value_ind (arg1
);
1882 type
= check_typedef (value_type (arg1
));
1883 code
= TYPE_CODE (type
);
1889 case TYPE_CODE_ARRAY
:
1890 if (exp
->elts
[*pos
].opcode
== OP_F90_RANGE
)
1891 return value_f90_subarray (arg1
, exp
, pos
, noside
);
1893 goto multi_f77_subscript
;
1895 case TYPE_CODE_STRING
:
1896 if (exp
->elts
[*pos
].opcode
== OP_F90_RANGE
)
1897 return value_f90_subarray (arg1
, exp
, pos
, noside
);
1900 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1901 return value_subscript (arg1
, value_as_long (arg2
));
1905 case TYPE_CODE_FUNC
:
1906 /* It's a function call. */
1907 /* Allocate arg vector, including space for the function to be
1908 called in argvec[0] and a terminating NULL. */
1909 argvec
= (struct value
**)
1910 alloca (sizeof (struct value
*) * (nargs
+ 2));
1913 for (; tem
<= nargs
; tem
++)
1914 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1915 argvec
[tem
] = 0; /* signal end of arglist */
1919 error (_("Cannot perform substring on this type"));
1923 /* We have a complex number, There should be 2 floating
1924 point numbers that compose it. */
1926 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1927 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1929 return value_literal_complex (arg1
, arg2
, exp
->elts
[pc
+ 1].type
);
1931 case STRUCTOP_STRUCT
:
1932 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1933 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1934 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1935 if (noside
== EVAL_SKIP
)
1937 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1938 return value_zero (lookup_struct_elt_type (value_type (arg1
),
1939 &exp
->elts
[pc
+ 2].string
,
1944 struct value
*temp
= arg1
;
1946 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
1951 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1952 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1953 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1954 if (noside
== EVAL_SKIP
)
1957 /* Check to see if operator '->' has been overloaded. If so replace
1958 arg1 with the value returned by evaluating operator->(). */
1959 while (unop_user_defined_p (op
, arg1
))
1961 volatile struct gdb_exception except
;
1962 struct value
*value
= NULL
;
1963 TRY_CATCH (except
, RETURN_MASK_ERROR
)
1965 value
= value_x_unop (arg1
, op
, noside
);
1968 if (except
.reason
< 0)
1970 if (except
.error
== NOT_FOUND_ERROR
)
1973 throw_exception (except
);
1978 /* JYG: if print object is on we need to replace the base type
1979 with rtti type in order to continue on with successful
1980 lookup of member / method only available in the rtti type. */
1982 struct type
*type
= value_type (arg1
);
1983 struct type
*real_type
;
1984 int full
, top
, using_enc
;
1985 struct value_print_options opts
;
1987 get_user_print_options (&opts
);
1988 if (opts
.objectprint
&& TYPE_TARGET_TYPE(type
)
1989 && (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_CLASS
))
1991 real_type
= value_rtti_target_type (arg1
, &full
, &top
, &using_enc
);
1994 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
1995 real_type
= lookup_pointer_type (real_type
);
1997 real_type
= lookup_reference_type (real_type
);
1999 arg1
= value_cast (real_type
, arg1
);
2004 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2005 return value_zero (lookup_struct_elt_type (value_type (arg1
),
2006 &exp
->elts
[pc
+ 2].string
,
2011 struct value
*temp
= arg1
;
2013 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
2014 NULL
, "structure pointer");
2017 case STRUCTOP_MEMBER
:
2019 if (op
== STRUCTOP_MEMBER
)
2020 arg1
= evaluate_subexp_for_address (exp
, pos
, noside
);
2022 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2024 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2026 if (noside
== EVAL_SKIP
)
2029 type
= check_typedef (value_type (arg2
));
2030 switch (TYPE_CODE (type
))
2032 case TYPE_CODE_METHODPTR
:
2033 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2034 return value_zero (TYPE_TARGET_TYPE (type
), not_lval
);
2037 arg2
= cplus_method_ptr_to_value (&arg1
, arg2
);
2038 gdb_assert (TYPE_CODE (value_type (arg2
)) == TYPE_CODE_PTR
);
2039 return value_ind (arg2
);
2042 case TYPE_CODE_MEMBERPTR
:
2043 /* Now, convert these values to an address. */
2044 arg1
= value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type
)),
2047 mem_offset
= value_as_long (arg2
);
2049 arg3
= value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
2050 value_as_long (arg1
) + mem_offset
);
2051 return value_ind (arg3
);
2054 error (_("non-pointer-to-member value used "
2055 "in pointer-to-member construct"));
2059 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
2060 arg_types
= (struct type
**) alloca (nargs
* sizeof (struct type
*));
2061 for (ix
= 0; ix
< nargs
; ++ix
)
2062 arg_types
[ix
] = exp
->elts
[pc
+ 1 + ix
+ 1].type
;
2064 expect_type
= make_params (nargs
, arg_types
);
2065 *(pos
) += 3 + nargs
;
2066 arg1
= evaluate_subexp_standard (expect_type
, exp
, pos
, noside
);
2067 xfree (TYPE_FIELDS (expect_type
));
2068 xfree (TYPE_MAIN_TYPE (expect_type
));
2069 xfree (expect_type
);
2073 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2074 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2075 if (noside
== EVAL_SKIP
)
2077 if (binop_user_defined_p (op
, arg1
, arg2
))
2078 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2080 return value_concat (arg1
, arg2
);
2083 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2084 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2086 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2088 if (binop_user_defined_p (op
, arg1
, arg2
))
2089 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2091 return value_assign (arg1
, arg2
);
2093 case BINOP_ASSIGN_MODIFY
:
2095 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2096 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2097 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2099 op
= exp
->elts
[pc
+ 1].opcode
;
2100 if (binop_user_defined_p (op
, arg1
, arg2
))
2101 return value_x_binop (arg1
, arg2
, BINOP_ASSIGN_MODIFY
, op
, noside
);
2102 else if (op
== BINOP_ADD
&& ptrmath_type_p (exp
->language_defn
,
2104 && is_integral_type (value_type (arg2
)))
2105 arg2
= value_ptradd (arg1
, value_as_long (arg2
));
2106 else if (op
== BINOP_SUB
&& ptrmath_type_p (exp
->language_defn
,
2108 && is_integral_type (value_type (arg2
)))
2109 arg2
= value_ptradd (arg1
, - value_as_long (arg2
));
2112 struct value
*tmp
= arg1
;
2114 /* For shift and integer exponentiation operations,
2115 only promote the first argument. */
2116 if ((op
== BINOP_LSH
|| op
== BINOP_RSH
|| op
== BINOP_EXP
)
2117 && is_integral_type (value_type (arg2
)))
2118 unop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
);
2120 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2122 arg2
= value_binop (tmp
, arg2
, op
);
2124 return value_assign (arg1
, arg2
);
2127 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2128 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2129 if (noside
== EVAL_SKIP
)
2131 if (binop_user_defined_p (op
, arg1
, arg2
))
2132 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2133 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
2134 && is_integral_type (value_type (arg2
)))
2135 return value_ptradd (arg1
, value_as_long (arg2
));
2136 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg2
))
2137 && is_integral_type (value_type (arg1
)))
2138 return value_ptradd (arg2
, value_as_long (arg1
));
2141 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2142 return value_binop (arg1
, arg2
, BINOP_ADD
);
2146 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2147 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2148 if (noside
== EVAL_SKIP
)
2150 if (binop_user_defined_p (op
, arg1
, arg2
))
2151 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2152 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
2153 && ptrmath_type_p (exp
->language_defn
, value_type (arg2
)))
2155 /* FIXME -- should be ptrdiff_t */
2156 type
= builtin_type (exp
->gdbarch
)->builtin_long
;
2157 return value_from_longest (type
, value_ptrdiff (arg1
, arg2
));
2159 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
2160 && is_integral_type (value_type (arg2
)))
2161 return value_ptradd (arg1
, - value_as_long (arg2
));
2164 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2165 return value_binop (arg1
, arg2
, BINOP_SUB
);
2176 case BINOP_BITWISE_AND
:
2177 case BINOP_BITWISE_IOR
:
2178 case BINOP_BITWISE_XOR
:
2179 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2180 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2181 if (noside
== EVAL_SKIP
)
2183 if (binop_user_defined_p (op
, arg1
, arg2
))
2184 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2187 /* If EVAL_AVOID_SIDE_EFFECTS and we're dividing by zero,
2188 fudge arg2 to avoid division-by-zero, the caller is
2189 (theoretically) only looking for the type of the result. */
2190 if (noside
== EVAL_AVOID_SIDE_EFFECTS
2191 /* ??? Do we really want to test for BINOP_MOD here?
2192 The implementation of value_binop gives it a well-defined
2195 || op
== BINOP_INTDIV
2198 && value_logical_not (arg2
))
2200 struct value
*v_one
, *retval
;
2202 v_one
= value_one (value_type (arg2
));
2203 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &v_one
);
2204 retval
= value_binop (arg1
, v_one
, op
);
2209 /* For shift and integer exponentiation operations,
2210 only promote the first argument. */
2211 if ((op
== BINOP_LSH
|| op
== BINOP_RSH
|| op
== BINOP_EXP
)
2212 && is_integral_type (value_type (arg2
)))
2213 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2215 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2217 return value_binop (arg1
, arg2
, op
);
2222 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2223 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2224 if (noside
== EVAL_SKIP
)
2226 error (_("':' operator used in invalid context"));
2228 case BINOP_SUBSCRIPT
:
2229 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2230 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2231 if (noside
== EVAL_SKIP
)
2233 if (binop_user_defined_p (op
, arg1
, arg2
))
2234 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2237 /* If the user attempts to subscript something that is not an
2238 array or pointer type (like a plain int variable for example),
2239 then report this as an error. */
2241 arg1
= coerce_ref (arg1
);
2242 type
= check_typedef (value_type (arg1
));
2243 if (TYPE_CODE (type
) != TYPE_CODE_ARRAY
2244 && TYPE_CODE (type
) != TYPE_CODE_PTR
)
2246 if (TYPE_NAME (type
))
2247 error (_("cannot subscript something of type `%s'"),
2250 error (_("cannot subscript requested type"));
2253 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2254 return value_zero (TYPE_TARGET_TYPE (type
), VALUE_LVAL (arg1
));
2256 return value_subscript (arg1
, value_as_long (arg2
));
2260 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2261 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2262 if (noside
== EVAL_SKIP
)
2264 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2265 return value_from_longest (type
, (LONGEST
) value_in (arg1
, arg2
));
2267 case MULTI_SUBSCRIPT
:
2269 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
2270 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2273 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2274 /* FIXME: EVAL_SKIP handling may not be correct. */
2275 if (noside
== EVAL_SKIP
)
2286 /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
2287 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2289 /* If the user attempts to subscript something that has no target
2290 type (like a plain int variable for example), then report this
2293 type
= TYPE_TARGET_TYPE (check_typedef (value_type (arg1
)));
2296 arg1
= value_zero (type
, VALUE_LVAL (arg1
));
2302 error (_("cannot subscript something of type `%s'"),
2303 TYPE_NAME (value_type (arg1
)));
2307 if (binop_user_defined_p (op
, arg1
, arg2
))
2309 arg1
= value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2313 arg1
= coerce_ref (arg1
);
2314 type
= check_typedef (value_type (arg1
));
2316 switch (TYPE_CODE (type
))
2319 case TYPE_CODE_ARRAY
:
2320 case TYPE_CODE_STRING
:
2321 arg1
= value_subscript (arg1
, value_as_long (arg2
));
2324 case TYPE_CODE_BITSTRING
:
2325 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2326 arg1
= value_bitstring_subscript (type
, arg1
,
2327 value_as_long (arg2
));
2331 if (TYPE_NAME (type
))
2332 error (_("cannot subscript something of type `%s'"),
2335 error (_("cannot subscript requested type"));
2341 multi_f77_subscript
:
2343 LONGEST subscript_array
[MAX_FORTRAN_DIMS
];
2344 int ndimensions
= 1, i
;
2345 struct value
*array
= arg1
;
2347 if (nargs
> MAX_FORTRAN_DIMS
)
2348 error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS
);
2350 ndimensions
= calc_f77_array_dims (type
);
2352 if (nargs
!= ndimensions
)
2353 error (_("Wrong number of subscripts"));
2355 gdb_assert (nargs
> 0);
2357 /* Now that we know we have a legal array subscript expression
2358 let us actually find out where this element exists in the array. */
2360 /* Take array indices left to right. */
2361 for (i
= 0; i
< nargs
; i
++)
2363 /* Evaluate each subscript; it must be a legal integer in F77. */
2364 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2366 /* Fill in the subscript array. */
2368 subscript_array
[i
] = value_as_long (arg2
);
2371 /* Internal type of array is arranged right to left. */
2372 for (i
= nargs
; i
> 0; i
--)
2374 struct type
*array_type
= check_typedef (value_type (array
));
2375 LONGEST index
= subscript_array
[i
- 1];
2377 lower
= f77_get_lowerbound (array_type
);
2378 array
= value_subscripted_rvalue (array
, index
, lower
);
2384 case BINOP_LOGICAL_AND
:
2385 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2386 if (noside
== EVAL_SKIP
)
2388 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2393 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2396 if (binop_user_defined_p (op
, arg1
, arg2
))
2398 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2399 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2403 tem
= value_logical_not (arg1
);
2404 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
2405 (tem
? EVAL_SKIP
: noside
));
2406 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2407 return value_from_longest (type
,
2408 (LONGEST
) (!tem
&& !value_logical_not (arg2
)));
2411 case BINOP_LOGICAL_OR
:
2412 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2413 if (noside
== EVAL_SKIP
)
2415 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2420 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2423 if (binop_user_defined_p (op
, arg1
, arg2
))
2425 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2426 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2430 tem
= value_logical_not (arg1
);
2431 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
2432 (!tem
? EVAL_SKIP
: noside
));
2433 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2434 return value_from_longest (type
,
2435 (LONGEST
) (!tem
|| !value_logical_not (arg2
)));
2439 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2440 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2441 if (noside
== EVAL_SKIP
)
2443 if (binop_user_defined_p (op
, arg1
, arg2
))
2445 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2449 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2450 tem
= value_equal (arg1
, arg2
);
2451 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2452 return value_from_longest (type
, (LONGEST
) tem
);
2455 case BINOP_NOTEQUAL
:
2456 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2457 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2458 if (noside
== EVAL_SKIP
)
2460 if (binop_user_defined_p (op
, arg1
, arg2
))
2462 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2466 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2467 tem
= value_equal (arg1
, arg2
);
2468 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2469 return value_from_longest (type
, (LONGEST
) ! tem
);
2473 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2474 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2475 if (noside
== EVAL_SKIP
)
2477 if (binop_user_defined_p (op
, arg1
, arg2
))
2479 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2483 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2484 tem
= value_less (arg1
, arg2
);
2485 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2486 return value_from_longest (type
, (LONGEST
) tem
);
2490 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2491 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2492 if (noside
== EVAL_SKIP
)
2494 if (binop_user_defined_p (op
, arg1
, arg2
))
2496 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2500 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2501 tem
= value_less (arg2
, arg1
);
2502 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2503 return value_from_longest (type
, (LONGEST
) tem
);
2507 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2508 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2509 if (noside
== EVAL_SKIP
)
2511 if (binop_user_defined_p (op
, arg1
, arg2
))
2513 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2517 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2518 tem
= value_less (arg2
, arg1
) || value_equal (arg1
, arg2
);
2519 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2520 return value_from_longest (type
, (LONGEST
) tem
);
2524 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2525 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2526 if (noside
== EVAL_SKIP
)
2528 if (binop_user_defined_p (op
, arg1
, arg2
))
2530 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2534 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2535 tem
= value_less (arg1
, arg2
) || value_equal (arg1
, arg2
);
2536 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2537 return value_from_longest (type
, (LONGEST
) tem
);
2541 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2542 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2543 if (noside
== EVAL_SKIP
)
2545 type
= check_typedef (value_type (arg2
));
2546 if (TYPE_CODE (type
) != TYPE_CODE_INT
)
2547 error (_("Non-integral right operand for \"@\" operator."));
2548 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2550 return allocate_repeat_value (value_type (arg1
),
2551 longest_to_int (value_as_long (arg2
)));
2554 return value_repeat (arg1
, longest_to_int (value_as_long (arg2
)));
2557 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2558 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2561 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2562 if (noside
== EVAL_SKIP
)
2564 if (unop_user_defined_p (op
, arg1
))
2565 return value_x_unop (arg1
, op
, noside
);
2568 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2569 return value_pos (arg1
);
2573 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2574 if (noside
== EVAL_SKIP
)
2576 if (unop_user_defined_p (op
, arg1
))
2577 return value_x_unop (arg1
, op
, noside
);
2580 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2581 return value_neg (arg1
);
2584 case UNOP_COMPLEMENT
:
2585 /* C++: check for and handle destructor names. */
2586 op
= exp
->elts
[*pos
].opcode
;
2588 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2589 if (noside
== EVAL_SKIP
)
2591 if (unop_user_defined_p (UNOP_COMPLEMENT
, arg1
))
2592 return value_x_unop (arg1
, UNOP_COMPLEMENT
, noside
);
2595 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2596 return value_complement (arg1
);
2599 case UNOP_LOGICAL_NOT
:
2600 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2601 if (noside
== EVAL_SKIP
)
2603 if (unop_user_defined_p (op
, arg1
))
2604 return value_x_unop (arg1
, op
, noside
);
2607 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2608 return value_from_longest (type
, (LONGEST
) value_logical_not (arg1
));
2612 if (expect_type
&& TYPE_CODE (expect_type
) == TYPE_CODE_PTR
)
2613 expect_type
= TYPE_TARGET_TYPE (check_typedef (expect_type
));
2614 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2615 type
= check_typedef (value_type (arg1
));
2616 if (TYPE_CODE (type
) == TYPE_CODE_METHODPTR
2617 || TYPE_CODE (type
) == TYPE_CODE_MEMBERPTR
)
2618 error (_("Attempt to dereference pointer "
2619 "to member without an object"));
2620 if (noside
== EVAL_SKIP
)
2622 if (unop_user_defined_p (op
, arg1
))
2623 return value_x_unop (arg1
, op
, noside
);
2624 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2626 type
= check_typedef (value_type (arg1
));
2627 if (TYPE_CODE (type
) == TYPE_CODE_PTR
2628 || TYPE_CODE (type
) == TYPE_CODE_REF
2629 /* In C you can dereference an array to get the 1st elt. */
2630 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
2632 return value_zero (TYPE_TARGET_TYPE (type
),
2634 else if (TYPE_CODE (type
) == TYPE_CODE_INT
)
2635 /* GDB allows dereferencing an int. */
2636 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
,
2639 error (_("Attempt to take contents of a non-pointer value."));
2642 /* Allow * on an integer so we can cast it to whatever we want.
2643 This returns an int, which seems like the most C-like thing to
2644 do. "long long" variables are rare enough that
2645 BUILTIN_TYPE_LONGEST would seem to be a mistake. */
2646 if (TYPE_CODE (type
) == TYPE_CODE_INT
)
2647 return value_at_lazy (builtin_type (exp
->gdbarch
)->builtin_int
,
2648 (CORE_ADDR
) value_as_address (arg1
));
2649 return value_ind (arg1
);
2652 /* C++: check for and handle pointer to members. */
2654 op
= exp
->elts
[*pos
].opcode
;
2656 if (noside
== EVAL_SKIP
)
2658 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
2663 struct value
*retvalp
= evaluate_subexp_for_address (exp
, pos
,
2670 if (noside
== EVAL_SKIP
)
2672 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
2675 return evaluate_subexp_for_sizeof (exp
, pos
);
2679 type
= exp
->elts
[pc
+ 1].type
;
2680 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
2681 if (noside
== EVAL_SKIP
)
2683 if (type
!= value_type (arg1
))
2684 arg1
= value_cast (type
, arg1
);
2687 case UNOP_DYNAMIC_CAST
:
2689 type
= exp
->elts
[pc
+ 1].type
;
2690 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
2691 if (noside
== EVAL_SKIP
)
2693 return value_dynamic_cast (type
, arg1
);
2695 case UNOP_REINTERPRET_CAST
:
2697 type
= exp
->elts
[pc
+ 1].type
;
2698 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
2699 if (noside
== EVAL_SKIP
)
2701 return value_reinterpret_cast (type
, arg1
);
2705 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2706 if (noside
== EVAL_SKIP
)
2708 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2709 return value_zero (exp
->elts
[pc
+ 1].type
, lval_memory
);
2711 return value_at_lazy (exp
->elts
[pc
+ 1].type
,
2712 value_as_address (arg1
));
2714 case UNOP_MEMVAL_TLS
:
2716 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2717 if (noside
== EVAL_SKIP
)
2719 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2720 return value_zero (exp
->elts
[pc
+ 2].type
, lval_memory
);
2725 tls_addr
= target_translate_tls_address (exp
->elts
[pc
+ 1].objfile
,
2726 value_as_address (arg1
));
2727 return value_at_lazy (exp
->elts
[pc
+ 2].type
, tls_addr
);
2730 case UNOP_PREINCREMENT
:
2731 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2732 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2734 else if (unop_user_defined_p (op
, arg1
))
2736 return value_x_unop (arg1
, op
, noside
);
2740 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2741 arg2
= value_ptradd (arg1
, 1);
2744 struct value
*tmp
= arg1
;
2746 arg2
= value_one (value_type (arg1
));
2747 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2748 arg2
= value_binop (tmp
, arg2
, BINOP_ADD
);
2751 return value_assign (arg1
, arg2
);
2754 case UNOP_PREDECREMENT
:
2755 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2756 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2758 else if (unop_user_defined_p (op
, arg1
))
2760 return value_x_unop (arg1
, op
, noside
);
2764 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2765 arg2
= value_ptradd (arg1
, -1);
2768 struct value
*tmp
= arg1
;
2770 arg2
= value_one (value_type (arg1
));
2771 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2772 arg2
= value_binop (tmp
, arg2
, BINOP_SUB
);
2775 return value_assign (arg1
, arg2
);
2778 case UNOP_POSTINCREMENT
:
2779 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2780 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2782 else if (unop_user_defined_p (op
, arg1
))
2784 return value_x_unop (arg1
, op
, noside
);
2788 arg3
= value_non_lval (arg1
);
2790 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2791 arg2
= value_ptradd (arg1
, 1);
2794 struct value
*tmp
= arg1
;
2796 arg2
= value_one (value_type (arg1
));
2797 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2798 arg2
= value_binop (tmp
, arg2
, BINOP_ADD
);
2801 value_assign (arg1
, arg2
);
2805 case UNOP_POSTDECREMENT
:
2806 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2807 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2809 else if (unop_user_defined_p (op
, arg1
))
2811 return value_x_unop (arg1
, op
, noside
);
2815 arg3
= value_non_lval (arg1
);
2817 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2818 arg2
= value_ptradd (arg1
, -1);
2821 struct value
*tmp
= arg1
;
2823 arg2
= value_one (value_type (arg1
));
2824 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2825 arg2
= value_binop (tmp
, arg2
, BINOP_SUB
);
2828 value_assign (arg1
, arg2
);
2834 return value_of_this (exp
->language_defn
);
2837 /* The value is not supposed to be used. This is here to make it
2838 easier to accommodate expressions that contain types. */
2840 if (noside
== EVAL_SKIP
)
2842 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2844 struct type
*type
= exp
->elts
[pc
+ 1].type
;
2846 /* If this is a typedef, then find its immediate target. We
2847 use check_typedef to resolve stubs, but we ignore its
2848 result because we do not want to dig past all
2850 check_typedef (type
);
2851 if (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
2852 type
= TYPE_TARGET_TYPE (type
);
2853 return allocate_value (type
);
2856 error (_("Attempt to use a type name as an expression"));
2859 /* Removing this case and compiling with gcc -Wall reveals that
2860 a lot of cases are hitting this case. Some of these should
2861 probably be removed from expression.h; others are legitimate
2862 expressions which are (apparently) not fully implemented.
2864 If there are any cases landing here which mean a user error,
2865 then they should be separate cases, with more descriptive
2868 error (_("GDB does not (yet) know how to "
2869 "evaluate that kind of expression"));
2873 return value_from_longest (builtin_type (exp
->gdbarch
)->builtin_int
, 1);
2876 /* Evaluate a subexpression of EXP, at index *POS,
2877 and return the address of that subexpression.
2878 Advance *POS over the subexpression.
2879 If the subexpression isn't an lvalue, get an error.
2880 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
2881 then only the type of the result need be correct. */
2883 static struct value
*
2884 evaluate_subexp_for_address (struct expression
*exp
, int *pos
,
2894 op
= exp
->elts
[pc
].opcode
;
2900 x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2902 /* We can't optimize out "&*" if there's a user-defined operator*. */
2903 if (unop_user_defined_p (op
, x
))
2905 x
= value_x_unop (x
, op
, noside
);
2906 goto default_case_after_eval
;
2909 return coerce_array (x
);
2913 return value_cast (lookup_pointer_type (exp
->elts
[pc
+ 1].type
),
2914 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
2917 var
= exp
->elts
[pc
+ 2].symbol
;
2919 /* C++: The "address" of a reference should yield the address
2920 * of the object pointed to. Let value_addr() deal with it. */
2921 if (TYPE_CODE (SYMBOL_TYPE (var
)) == TYPE_CODE_REF
)
2925 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2928 lookup_pointer_type (SYMBOL_TYPE (var
));
2929 enum address_class sym_class
= SYMBOL_CLASS (var
);
2931 if (sym_class
== LOC_CONST
2932 || sym_class
== LOC_CONST_BYTES
2933 || sym_class
== LOC_REGISTER
)
2934 error (_("Attempt to take address of register or constant."));
2937 value_zero (type
, not_lval
);
2940 return address_of_variable (var
, exp
->elts
[pc
+ 1].block
);
2943 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
2944 (*pos
) += 5 + BYTES_TO_EXP_ELEM (tem
+ 1);
2945 x
= value_aggregate_elt (exp
->elts
[pc
+ 1].type
,
2946 &exp
->elts
[pc
+ 3].string
,
2949 error (_("There is no field named %s"), &exp
->elts
[pc
+ 3].string
);
2954 x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2955 default_case_after_eval
:
2956 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2958 struct type
*type
= check_typedef (value_type (x
));
2960 if (VALUE_LVAL (x
) == lval_memory
|| value_must_coerce_to_target (x
))
2961 return value_zero (lookup_pointer_type (value_type (x
)),
2963 else if (TYPE_CODE (type
) == TYPE_CODE_REF
)
2964 return value_zero (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
2967 error (_("Attempt to take address of "
2968 "value not located in memory."));
2970 return value_addr (x
);
2974 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
2975 When used in contexts where arrays will be coerced anyway, this is
2976 equivalent to `evaluate_subexp' but much faster because it avoids
2977 actually fetching array contents (perhaps obsolete now that we have
2980 Note that we currently only do the coercion for C expressions, where
2981 arrays are zero based and the coercion is correct. For other languages,
2982 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
2983 to decide if coercion is appropriate. */
2986 evaluate_subexp_with_coercion (struct expression
*exp
,
2987 int *pos
, enum noside noside
)
2996 op
= exp
->elts
[pc
].opcode
;
3001 var
= exp
->elts
[pc
+ 2].symbol
;
3002 type
= check_typedef (SYMBOL_TYPE (var
));
3003 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
3004 && !TYPE_VECTOR (type
)
3005 && CAST_IS_CONVERSION (exp
->language_defn
))
3008 val
= address_of_variable (var
, exp
->elts
[pc
+ 1].block
);
3009 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
3015 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
3019 /* Evaluate a subexpression of EXP, at index *POS,
3020 and return a value for the size of that subexpression.
3021 Advance *POS over the subexpression. */
3023 static struct value
*
3024 evaluate_subexp_for_sizeof (struct expression
*exp
, int *pos
)
3026 /* FIXME: This should be size_t. */
3027 struct type
*size_type
= builtin_type (exp
->gdbarch
)->builtin_int
;
3034 op
= exp
->elts
[pc
].opcode
;
3038 /* This case is handled specially
3039 so that we avoid creating a value for the result type.
3040 If the result type is very big, it's desirable not to
3041 create a value unnecessarily. */
3044 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3045 type
= check_typedef (value_type (val
));
3046 if (TYPE_CODE (type
) != TYPE_CODE_PTR
3047 && TYPE_CODE (type
) != TYPE_CODE_REF
3048 && TYPE_CODE (type
) != TYPE_CODE_ARRAY
)
3049 error (_("Attempt to take contents of a non-pointer value."));
3050 type
= check_typedef (TYPE_TARGET_TYPE (type
));
3051 return value_from_longest (size_type
, (LONGEST
) TYPE_LENGTH (type
));
3055 type
= check_typedef (exp
->elts
[pc
+ 1].type
);
3056 return value_from_longest (size_type
, (LONGEST
) TYPE_LENGTH (type
));
3060 type
= check_typedef (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
));
3062 value_from_longest (size_type
, (LONGEST
) TYPE_LENGTH (type
));
3065 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3066 return value_from_longest (size_type
,
3067 (LONGEST
) TYPE_LENGTH (value_type (val
)));
3071 /* Parse a type expression in the string [P..P+LENGTH). */
3074 parse_and_eval_type (char *p
, int length
)
3076 char *tmp
= (char *) alloca (length
+ 4);
3077 struct expression
*expr
;
3080 memcpy (tmp
+ 1, p
, length
);
3081 tmp
[length
+ 1] = ')';
3082 tmp
[length
+ 2] = '0';
3083 tmp
[length
+ 3] = '\0';
3084 expr
= parse_expression (tmp
);
3085 if (expr
->elts
[0].opcode
!= UNOP_CAST
)
3086 error (_("Internal error in eval_type."));
3087 return expr
->elts
[1].type
;
3091 calc_f77_array_dims (struct type
*array_type
)
3094 struct type
*tmp_type
;
3096 if ((TYPE_CODE (array_type
) != TYPE_CODE_ARRAY
))
3097 error (_("Can't get dimensions for a non-array type"));
3099 tmp_type
= array_type
;
3101 while ((tmp_type
= TYPE_TARGET_TYPE (tmp_type
)))
3103 if (TYPE_CODE (tmp_type
) == TYPE_CODE_ARRAY
)