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"
45 #include "gdb_assert.h"
49 /* This is defined in valops.c */
50 extern int overload_resolution
;
52 /* Prototypes for local functions. */
54 static struct value
*evaluate_subexp_for_sizeof (struct expression
*, int *);
56 static struct value
*evaluate_subexp_for_address (struct expression
*,
59 static struct value
*evaluate_struct_tuple (struct value
*,
60 struct expression
*, int *,
63 static LONGEST
init_array_element (struct value
*, struct value
*,
64 struct expression
*, int *, enum noside
,
68 evaluate_subexp (struct type
*expect_type
, struct expression
*exp
,
69 int *pos
, enum noside noside
)
71 return (*exp
->language_defn
->la_exp_desc
->evaluate_exp
)
72 (expect_type
, exp
, pos
, noside
);
75 /* Parse the string EXP as a C expression, evaluate it,
76 and return the result as a number. */
79 parse_and_eval_address (char *exp
)
81 struct expression
*expr
= parse_expression (exp
);
83 struct cleanup
*old_chain
=
84 make_cleanup (free_current_contents
, &expr
);
86 addr
= value_as_address (evaluate_expression (expr
));
87 do_cleanups (old_chain
);
91 /* Like parse_and_eval_address, but treats the value of the expression
92 as an integer, not an address, returns a LONGEST, not a CORE_ADDR. */
94 parse_and_eval_long (char *exp
)
96 struct expression
*expr
= parse_expression (exp
);
98 struct cleanup
*old_chain
=
99 make_cleanup (free_current_contents
, &expr
);
101 retval
= value_as_long (evaluate_expression (expr
));
102 do_cleanups (old_chain
);
107 parse_and_eval (char *exp
)
109 struct expression
*expr
= parse_expression (exp
);
111 struct cleanup
*old_chain
=
112 make_cleanup (free_current_contents
, &expr
);
114 val
= evaluate_expression (expr
);
115 do_cleanups (old_chain
);
119 /* Parse up to a comma (or to a closeparen)
120 in the string EXPP as an expression, evaluate it, and return the value.
121 EXPP is advanced to point to the comma. */
124 parse_to_comma_and_eval (char **expp
)
126 struct expression
*expr
= parse_exp_1 (expp
, 0, (struct block
*) 0, 1);
128 struct cleanup
*old_chain
=
129 make_cleanup (free_current_contents
, &expr
);
131 val
= evaluate_expression (expr
);
132 do_cleanups (old_chain
);
136 /* Evaluate an expression in internal prefix form
137 such as is constructed by parse.y.
139 See expression.h for info on the format of an expression. */
142 evaluate_expression (struct expression
*exp
)
146 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_NORMAL
);
149 /* Evaluate an expression, avoiding all memory references
150 and getting a value whose type alone is correct. */
153 evaluate_type (struct expression
*exp
)
157 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_AVOID_SIDE_EFFECTS
);
160 /* Evaluate a subexpression, avoiding all memory references and
161 getting a value whose type alone is correct. */
164 evaluate_subexpression_type (struct expression
*exp
, int subexp
)
166 return evaluate_subexp (NULL_TYPE
, exp
, &subexp
, EVAL_AVOID_SIDE_EFFECTS
);
169 /* Find the current value of a watchpoint on EXP. Return the value in
170 *VALP and *RESULTP and the chain of intermediate and final values
171 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
174 If a memory error occurs while evaluating the expression, *RESULTP will
175 be set to NULL. *RESULTP may be a lazy value, if the result could
176 not be read from memory. It is used to determine whether a value
177 is user-specified (we should watch the whole value) or intermediate
178 (we should watch only the bit used to locate the final value).
180 If the final value, or any intermediate value, could not be read
181 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
182 set to any referenced values. *VALP will never be a lazy value.
183 This is the value which we store in struct breakpoint.
185 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
186 value chain. The caller must free the values individually. If
187 VAL_CHAIN is NULL, all generated values will be left on the value
191 fetch_subexp_value (struct expression
*exp
, int *pc
, struct value
**valp
,
192 struct value
**resultp
, struct value
**val_chain
)
194 struct value
*mark
, *new_mark
, *result
;
195 volatile struct gdb_exception ex
;
203 /* Evaluate the expression. */
204 mark
= value_mark ();
207 TRY_CATCH (ex
, RETURN_MASK_ALL
)
209 result
= evaluate_subexp (NULL_TYPE
, exp
, pc
, EVAL_NORMAL
);
213 /* Ignore memory errors, we want watchpoints pointing at
214 inaccessible memory to still be created; otherwise, throw the
215 error to some higher catcher. */
221 throw_exception (ex
);
226 new_mark
= value_mark ();
227 if (mark
== new_mark
)
232 /* Make sure it's not lazy, so that after the target stops again we
233 have a non-lazy previous value to compare with. */
236 if (!value_lazy (result
))
240 volatile struct gdb_exception except
;
242 TRY_CATCH (except
, RETURN_MASK_ERROR
)
244 value_fetch_lazy (result
);
252 /* Return the chain of intermediate values. We use this to
253 decide which addresses to watch. */
254 *val_chain
= new_mark
;
255 value_release_to_mark (mark
);
259 /* Extract a field operation from an expression. If the subexpression
260 of EXP starting at *SUBEXP is not a structure dereference
261 operation, return NULL. Otherwise, return the name of the
262 dereferenced field, and advance *SUBEXP to point to the
263 subexpression of the left-hand-side of the dereference. This is
264 used when completing field names. */
267 extract_field_op (struct expression
*exp
, int *subexp
)
272 if (exp
->elts
[*subexp
].opcode
!= STRUCTOP_STRUCT
273 && exp
->elts
[*subexp
].opcode
!= STRUCTOP_PTR
)
275 tem
= longest_to_int (exp
->elts
[*subexp
+ 1].longconst
);
276 result
= &exp
->elts
[*subexp
+ 2].string
;
277 (*subexp
) += 1 + 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
281 /* This function evaluates brace-initializers (in C/C++) for
284 static struct value
*
285 evaluate_struct_tuple (struct value
*struct_val
,
286 struct expression
*exp
,
287 int *pos
, enum noside noside
, int nargs
)
289 struct type
*struct_type
= check_typedef (value_type (struct_val
));
290 struct type
*field_type
;
295 struct value
*val
= NULL
;
300 /* Skip static fields. */
301 while (fieldno
< TYPE_NFIELDS (struct_type
)
302 && field_is_static (&TYPE_FIELD (struct_type
,
305 if (fieldno
>= TYPE_NFIELDS (struct_type
))
306 error (_("too many initializers"));
307 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
308 if (TYPE_CODE (field_type
) == TYPE_CODE_UNION
309 && TYPE_FIELD_NAME (struct_type
, fieldno
)[0] == '0')
310 error (_("don't know which variant you want to set"));
312 /* Here, struct_type is the type of the inner struct,
313 while substruct_type is the type of the inner struct.
314 These are the same for normal structures, but a variant struct
315 contains anonymous union fields that contain substruct fields.
316 The value fieldno is the index of the top-level (normal or
317 anonymous union) field in struct_field, while the value
318 subfieldno is the index of the actual real (named inner) field
319 in substruct_type. */
321 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
323 val
= evaluate_subexp (field_type
, exp
, pos
, noside
);
325 /* Now actually set the field in struct_val. */
327 /* Assign val to field fieldno. */
328 if (value_type (val
) != field_type
)
329 val
= value_cast (field_type
, val
);
331 bitsize
= TYPE_FIELD_BITSIZE (struct_type
, fieldno
);
332 bitpos
= TYPE_FIELD_BITPOS (struct_type
, fieldno
);
333 addr
= value_contents_writeable (struct_val
) + bitpos
/ 8;
335 modify_field (struct_type
, addr
,
336 value_as_long (val
), bitpos
% 8, bitsize
);
338 memcpy (addr
, value_contents (val
),
339 TYPE_LENGTH (value_type (val
)));
345 /* Recursive helper function for setting elements of array tuples for
346 (the deleted) Chill. The target is ARRAY (which has bounds
347 LOW_BOUND to HIGH_BOUND); the element value is ELEMENT; EXP, POS
348 and NOSIDE are as usual. Evaluates index expresions and sets the
349 specified element(s) of ARRAY to ELEMENT. Returns last index
353 init_array_element (struct value
*array
, struct value
*element
,
354 struct expression
*exp
, int *pos
,
355 enum noside noside
, LONGEST low_bound
, LONGEST high_bound
)
358 int element_size
= TYPE_LENGTH (value_type (element
));
360 if (exp
->elts
[*pos
].opcode
== BINOP_COMMA
)
363 init_array_element (array
, element
, exp
, pos
, noside
,
364 low_bound
, high_bound
);
365 return init_array_element (array
, element
,
366 exp
, pos
, noside
, low_bound
, high_bound
);
368 else if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
373 low
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
374 high
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
375 if (low
< low_bound
|| high
> high_bound
)
376 error (_("tuple range index out of range"));
377 for (index
= low
; index
<= high
; index
++)
379 memcpy (value_contents_raw (array
)
380 + (index
- low_bound
) * element_size
,
381 value_contents (element
), element_size
);
386 index
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
387 if (index
< low_bound
|| index
> high_bound
)
388 error (_("tuple index out of range"));
389 memcpy (value_contents_raw (array
) + (index
- low_bound
) * element_size
,
390 value_contents (element
), element_size
);
395 static struct value
*
396 value_f90_subarray (struct value
*array
,
397 struct expression
*exp
, int *pos
, enum noside noside
)
400 LONGEST low_bound
, high_bound
;
401 struct type
*range
= check_typedef (TYPE_INDEX_TYPE (value_type (array
)));
402 enum f90_range_type range_type
= longest_to_int (exp
->elts
[pc
].longconst
);
406 if (range_type
== LOW_BOUND_DEFAULT
|| range_type
== BOTH_BOUND_DEFAULT
)
407 low_bound
= TYPE_LOW_BOUND (range
);
409 low_bound
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
411 if (range_type
== HIGH_BOUND_DEFAULT
|| range_type
== BOTH_BOUND_DEFAULT
)
412 high_bound
= TYPE_HIGH_BOUND (range
);
414 high_bound
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
416 return value_slice (array
, low_bound
, high_bound
- low_bound
+ 1);
420 /* Promote value ARG1 as appropriate before performing a unary operation
422 If the result is not appropriate for any particular language then it
423 needs to patch this function. */
426 unop_promote (const struct language_defn
*language
, struct gdbarch
*gdbarch
,
431 *arg1
= coerce_ref (*arg1
);
432 type1
= check_typedef (value_type (*arg1
));
434 if (is_integral_type (type1
))
436 switch (language
->la_language
)
439 /* Perform integral promotion for ANSI C/C++.
440 If not appropropriate for any particular language
441 it needs to modify this function. */
443 struct type
*builtin_int
= builtin_type (gdbarch
)->builtin_int
;
445 if (TYPE_LENGTH (type1
) < TYPE_LENGTH (builtin_int
))
446 *arg1
= value_cast (builtin_int
, *arg1
);
453 /* Promote values ARG1 and ARG2 as appropriate before performing a binary
454 operation on those two operands.
455 If the result is not appropriate for any particular language then it
456 needs to patch this function. */
459 binop_promote (const struct language_defn
*language
, struct gdbarch
*gdbarch
,
460 struct value
**arg1
, struct value
**arg2
)
462 struct type
*promoted_type
= NULL
;
466 *arg1
= coerce_ref (*arg1
);
467 *arg2
= coerce_ref (*arg2
);
469 type1
= check_typedef (value_type (*arg1
));
470 type2
= check_typedef (value_type (*arg2
));
472 if ((TYPE_CODE (type1
) != TYPE_CODE_FLT
473 && TYPE_CODE (type1
) != TYPE_CODE_DECFLOAT
474 && !is_integral_type (type1
))
475 || (TYPE_CODE (type2
) != TYPE_CODE_FLT
476 && TYPE_CODE (type2
) != TYPE_CODE_DECFLOAT
477 && !is_integral_type (type2
)))
480 if (TYPE_CODE (type1
) == TYPE_CODE_DECFLOAT
481 || TYPE_CODE (type2
) == TYPE_CODE_DECFLOAT
)
483 /* No promotion required. */
485 else if (TYPE_CODE (type1
) == TYPE_CODE_FLT
486 || TYPE_CODE (type2
) == TYPE_CODE_FLT
)
488 switch (language
->la_language
)
494 case language_opencl
:
495 /* No promotion required. */
499 /* For other languages the result type is unchanged from gdb
500 version 6.7 for backward compatibility.
501 If either arg was long double, make sure that value is also long
502 double. Otherwise use double. */
503 if (TYPE_LENGTH (type1
) * 8 > gdbarch_double_bit (gdbarch
)
504 || TYPE_LENGTH (type2
) * 8 > gdbarch_double_bit (gdbarch
))
505 promoted_type
= builtin_type (gdbarch
)->builtin_long_double
;
507 promoted_type
= builtin_type (gdbarch
)->builtin_double
;
511 else if (TYPE_CODE (type1
) == TYPE_CODE_BOOL
512 && TYPE_CODE (type2
) == TYPE_CODE_BOOL
)
514 /* No promotion required. */
517 /* Integral operations here. */
518 /* FIXME: Also mixed integral/booleans, with result an integer. */
520 const struct builtin_type
*builtin
= builtin_type (gdbarch
);
521 unsigned int promoted_len1
= TYPE_LENGTH (type1
);
522 unsigned int promoted_len2
= TYPE_LENGTH (type2
);
523 int is_unsigned1
= TYPE_UNSIGNED (type1
);
524 int is_unsigned2
= TYPE_UNSIGNED (type2
);
525 unsigned int result_len
;
526 int unsigned_operation
;
528 /* Determine type length and signedness after promotion for
530 if (promoted_len1
< TYPE_LENGTH (builtin
->builtin_int
))
533 promoted_len1
= TYPE_LENGTH (builtin
->builtin_int
);
535 if (promoted_len2
< TYPE_LENGTH (builtin
->builtin_int
))
538 promoted_len2
= TYPE_LENGTH (builtin
->builtin_int
);
541 if (promoted_len1
> promoted_len2
)
543 unsigned_operation
= is_unsigned1
;
544 result_len
= promoted_len1
;
546 else if (promoted_len2
> promoted_len1
)
548 unsigned_operation
= is_unsigned2
;
549 result_len
= promoted_len2
;
553 unsigned_operation
= is_unsigned1
|| is_unsigned2
;
554 result_len
= promoted_len1
;
557 switch (language
->la_language
)
563 if (result_len
<= TYPE_LENGTH (builtin
->builtin_int
))
565 promoted_type
= (unsigned_operation
566 ? builtin
->builtin_unsigned_int
567 : builtin
->builtin_int
);
569 else if (result_len
<= TYPE_LENGTH (builtin
->builtin_long
))
571 promoted_type
= (unsigned_operation
572 ? builtin
->builtin_unsigned_long
573 : builtin
->builtin_long
);
577 promoted_type
= (unsigned_operation
578 ? builtin
->builtin_unsigned_long_long
579 : builtin
->builtin_long_long
);
582 case language_opencl
:
583 if (result_len
<= TYPE_LENGTH (lookup_signed_typename
584 (language
, gdbarch
, "int")))
588 ? lookup_unsigned_typename (language
, gdbarch
, "int")
589 : lookup_signed_typename (language
, gdbarch
, "int"));
591 else if (result_len
<= TYPE_LENGTH (lookup_signed_typename
592 (language
, gdbarch
, "long")))
596 ? lookup_unsigned_typename (language
, gdbarch
, "long")
597 : lookup_signed_typename (language
, gdbarch
,"long"));
601 /* For other languages the result type is unchanged from gdb
602 version 6.7 for backward compatibility.
603 If either arg was long long, make sure that value is also long
604 long. Otherwise use long. */
605 if (unsigned_operation
)
607 if (result_len
> gdbarch_long_bit (gdbarch
) / HOST_CHAR_BIT
)
608 promoted_type
= builtin
->builtin_unsigned_long_long
;
610 promoted_type
= builtin
->builtin_unsigned_long
;
614 if (result_len
> gdbarch_long_bit (gdbarch
) / HOST_CHAR_BIT
)
615 promoted_type
= builtin
->builtin_long_long
;
617 promoted_type
= builtin
->builtin_long
;
625 /* Promote both operands to common type. */
626 *arg1
= value_cast (promoted_type
, *arg1
);
627 *arg2
= value_cast (promoted_type
, *arg2
);
632 ptrmath_type_p (const struct language_defn
*lang
, struct type
*type
)
634 type
= check_typedef (type
);
635 if (TYPE_CODE (type
) == TYPE_CODE_REF
)
636 type
= TYPE_TARGET_TYPE (type
);
638 switch (TYPE_CODE (type
))
644 case TYPE_CODE_ARRAY
:
645 return TYPE_VECTOR (type
) ? 0 : lang
->c_style_arrays
;
652 /* Constructs a fake method with the given parameter types.
653 This function is used by the parser to construct an "expected"
654 type for method overload resolution. */
657 make_params (int num_types
, struct type
**param_types
)
659 struct type
*type
= XZALLOC (struct type
);
660 TYPE_MAIN_TYPE (type
) = XZALLOC (struct main_type
);
661 TYPE_LENGTH (type
) = 1;
662 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
663 TYPE_VPTR_FIELDNO (type
) = -1;
664 TYPE_CHAIN (type
) = type
;
667 if (param_types
[num_types
- 1] == NULL
)
670 TYPE_VARARGS (type
) = 1;
672 else if (TYPE_CODE (check_typedef (param_types
[num_types
- 1]))
676 /* Caller should have ensured this. */
677 gdb_assert (num_types
== 0);
678 TYPE_PROTOTYPED (type
) = 1;
682 TYPE_NFIELDS (type
) = num_types
;
683 TYPE_FIELDS (type
) = (struct field
*)
684 TYPE_ZALLOC (type
, sizeof (struct field
) * num_types
);
686 while (num_types
-- > 0)
687 TYPE_FIELD_TYPE (type
, num_types
) = param_types
[num_types
];
693 evaluate_subexp_standard (struct type
*expect_type
,
694 struct expression
*exp
, int *pos
,
699 int pc
, pc2
= 0, oldpos
;
700 struct value
*arg1
= NULL
;
701 struct value
*arg2
= NULL
;
705 struct value
**argvec
;
709 struct type
**arg_types
;
711 struct symbol
*function
= NULL
;
712 char *function_name
= NULL
;
715 op
= exp
->elts
[pc
].opcode
;
720 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
721 (*pos
) += 4 + BYTES_TO_EXP_ELEM (tem
+ 1);
722 if (noside
== EVAL_SKIP
)
724 arg1
= value_aggregate_elt (exp
->elts
[pc
+ 1].type
,
725 &exp
->elts
[pc
+ 3].string
,
726 expect_type
, 0, noside
);
728 error (_("There is no field named %s"), &exp
->elts
[pc
+ 3].string
);
733 return value_from_longest (exp
->elts
[pc
+ 1].type
,
734 exp
->elts
[pc
+ 2].longconst
);
738 return value_from_double (exp
->elts
[pc
+ 1].type
,
739 exp
->elts
[pc
+ 2].doubleconst
);
743 return value_from_decfloat (exp
->elts
[pc
+ 1].type
,
744 exp
->elts
[pc
+ 2].decfloatconst
);
749 if (noside
== EVAL_SKIP
)
752 /* JYG: We used to just return value_zero of the symbol type
753 if we're asked to avoid side effects. Otherwise we return
754 value_of_variable (...). However I'm not sure if
755 value_of_variable () has any side effect.
756 We need a full value object returned here for whatis_exp ()
757 to call evaluate_type () and then pass the full value to
758 value_rtti_target_type () if we are dealing with a pointer
759 or reference to a base class and print object is on. */
762 volatile struct gdb_exception except
;
763 struct value
*ret
= NULL
;
765 TRY_CATCH (except
, RETURN_MASK_ERROR
)
767 ret
= value_of_variable (exp
->elts
[pc
+ 2].symbol
,
768 exp
->elts
[pc
+ 1].block
);
771 if (except
.reason
< 0)
773 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
774 ret
= value_zero (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
),
777 throw_exception (except
);
783 case OP_VAR_ENTRY_VALUE
:
785 if (noside
== EVAL_SKIP
)
789 struct symbol
*sym
= exp
->elts
[pc
+ 1].symbol
;
790 struct frame_info
*frame
;
792 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
793 return value_zero (SYMBOL_TYPE (sym
), not_lval
);
795 if (SYMBOL_CLASS (sym
) != LOC_COMPUTED
796 || SYMBOL_COMPUTED_OPS (sym
)->read_variable_at_entry
== NULL
)
797 error (_("Symbol \"%s\" does not have any specific entry value"),
798 SYMBOL_PRINT_NAME (sym
));
800 frame
= get_selected_frame (NULL
);
801 return SYMBOL_COMPUTED_OPS (sym
)->read_variable_at_entry (sym
, frame
);
807 access_value_history (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
811 const char *name
= &exp
->elts
[pc
+ 2].string
;
815 (*pos
) += 3 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
816 regno
= user_reg_map_name_to_regnum (exp
->gdbarch
,
817 name
, strlen (name
));
819 error (_("Register $%s not available."), name
);
821 /* In EVAL_AVOID_SIDE_EFFECTS mode, we only need to return
822 a value with the appropriate register type. Unfortunately,
823 we don't have easy access to the type of user registers.
824 So for these registers, we fetch the register value regardless
825 of the evaluation mode. */
826 if (noside
== EVAL_AVOID_SIDE_EFFECTS
827 && regno
< gdbarch_num_regs (exp
->gdbarch
)
828 + gdbarch_num_pseudo_regs (exp
->gdbarch
))
829 val
= value_zero (register_type (exp
->gdbarch
, regno
), not_lval
);
831 val
= value_of_register (regno
, get_selected_frame (NULL
));
833 error (_("Value of register %s not available."), name
);
839 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
840 return value_from_longest (type
, exp
->elts
[pc
+ 1].longconst
);
844 return value_of_internalvar (exp
->gdbarch
,
845 exp
->elts
[pc
+ 1].internalvar
);
848 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
849 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
850 if (noside
== EVAL_SKIP
)
852 type
= language_string_char_type (exp
->language_defn
, exp
->gdbarch
);
853 return value_string (&exp
->elts
[pc
+ 2].string
, tem
, type
);
855 case OP_OBJC_NSSTRING
: /* Objective C Foundation Class
856 NSString constant. */
857 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
858 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
859 if (noside
== EVAL_SKIP
)
863 return value_nsstring (exp
->gdbarch
, &exp
->elts
[pc
+ 2].string
, tem
+ 1);
867 tem2
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
868 tem3
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
869 nargs
= tem3
- tem2
+ 1;
870 type
= expect_type
? check_typedef (expect_type
) : NULL_TYPE
;
872 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
873 && TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
875 struct value
*rec
= allocate_value (expect_type
);
877 memset (value_contents_raw (rec
), '\0', TYPE_LENGTH (type
));
878 return evaluate_struct_tuple (rec
, exp
, pos
, noside
, nargs
);
881 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
882 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
884 struct type
*range_type
= TYPE_INDEX_TYPE (type
);
885 struct type
*element_type
= TYPE_TARGET_TYPE (type
);
886 struct value
*array
= allocate_value (expect_type
);
887 int element_size
= TYPE_LENGTH (check_typedef (element_type
));
888 LONGEST low_bound
, high_bound
, index
;
890 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
893 high_bound
= (TYPE_LENGTH (type
) / element_size
) - 1;
896 memset (value_contents_raw (array
), 0, TYPE_LENGTH (expect_type
));
897 for (tem
= nargs
; --nargs
>= 0;)
899 struct value
*element
;
902 if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
905 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
907 element
= evaluate_subexp (element_type
, exp
, pos
, noside
);
908 if (value_type (element
) != element_type
)
909 element
= value_cast (element_type
, element
);
912 int continue_pc
= *pos
;
915 index
= init_array_element (array
, element
, exp
, pos
, noside
,
916 low_bound
, high_bound
);
921 if (index
> high_bound
)
922 /* To avoid memory corruption. */
923 error (_("Too many array elements"));
924 memcpy (value_contents_raw (array
)
925 + (index
- low_bound
) * element_size
,
926 value_contents (element
),
934 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
935 && TYPE_CODE (type
) == TYPE_CODE_SET
)
937 struct value
*set
= allocate_value (expect_type
);
938 gdb_byte
*valaddr
= value_contents_raw (set
);
939 struct type
*element_type
= TYPE_INDEX_TYPE (type
);
940 struct type
*check_type
= element_type
;
941 LONGEST low_bound
, high_bound
;
943 /* Get targettype of elementtype. */
944 while (TYPE_CODE (check_type
) == TYPE_CODE_RANGE
945 || TYPE_CODE (check_type
) == TYPE_CODE_TYPEDEF
)
946 check_type
= TYPE_TARGET_TYPE (check_type
);
948 if (get_discrete_bounds (element_type
, &low_bound
, &high_bound
) < 0)
949 error (_("(power)set type with unknown size"));
950 memset (valaddr
, '\0', TYPE_LENGTH (type
));
951 for (tem
= 0; tem
< nargs
; tem
++)
953 LONGEST range_low
, range_high
;
954 struct type
*range_low_type
, *range_high_type
;
955 struct value
*elem_val
;
957 if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
960 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
961 range_low_type
= value_type (elem_val
);
962 range_low
= value_as_long (elem_val
);
963 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
964 range_high_type
= value_type (elem_val
);
965 range_high
= value_as_long (elem_val
);
969 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
970 range_low_type
= range_high_type
= value_type (elem_val
);
971 range_low
= range_high
= value_as_long (elem_val
);
973 /* Check types of elements to avoid mixture of elements from
974 different types. Also check if type of element is "compatible"
975 with element type of powerset. */
976 if (TYPE_CODE (range_low_type
) == TYPE_CODE_RANGE
)
977 range_low_type
= TYPE_TARGET_TYPE (range_low_type
);
978 if (TYPE_CODE (range_high_type
) == TYPE_CODE_RANGE
)
979 range_high_type
= TYPE_TARGET_TYPE (range_high_type
);
980 if ((TYPE_CODE (range_low_type
) != TYPE_CODE (range_high_type
))
981 || (TYPE_CODE (range_low_type
) == TYPE_CODE_ENUM
982 && (range_low_type
!= range_high_type
)))
983 /* different element modes. */
984 error (_("POWERSET tuple elements of different mode"));
985 if ((TYPE_CODE (check_type
) != TYPE_CODE (range_low_type
))
986 || (TYPE_CODE (check_type
) == TYPE_CODE_ENUM
987 && range_low_type
!= check_type
))
988 error (_("incompatible POWERSET tuple elements"));
989 if (range_low
> range_high
)
991 warning (_("empty POWERSET tuple range"));
994 if (range_low
< low_bound
|| range_high
> high_bound
)
995 error (_("POWERSET tuple element out of range"));
996 range_low
-= low_bound
;
997 range_high
-= low_bound
;
998 for (; range_low
<= range_high
; range_low
++)
1000 int bit_index
= (unsigned) range_low
% TARGET_CHAR_BIT
;
1002 if (gdbarch_bits_big_endian (exp
->gdbarch
))
1003 bit_index
= TARGET_CHAR_BIT
- 1 - bit_index
;
1004 valaddr
[(unsigned) range_low
/ TARGET_CHAR_BIT
]
1011 argvec
= (struct value
**) alloca (sizeof (struct value
*) * nargs
);
1012 for (tem
= 0; tem
< nargs
; tem
++)
1014 /* Ensure that array expressions are coerced into pointer
1016 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1018 if (noside
== EVAL_SKIP
)
1020 return value_array (tem2
, tem3
, argvec
);
1024 struct value
*array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1026 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1028 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1030 if (noside
== EVAL_SKIP
)
1032 return value_slice (array
, lowbound
, upper
- lowbound
+ 1);
1036 /* Skip third and second args to evaluate the first one. */
1037 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1038 if (value_logical_not (arg1
))
1040 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1041 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1045 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1046 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1050 case OP_OBJC_SELECTOR
:
1051 { /* Objective C @selector operator. */
1052 char *sel
= &exp
->elts
[pc
+ 2].string
;
1053 int len
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1054 struct type
*selector_type
;
1056 (*pos
) += 3 + BYTES_TO_EXP_ELEM (len
+ 1);
1057 if (noside
== EVAL_SKIP
)
1061 sel
[len
] = 0; /* Make sure it's terminated. */
1063 selector_type
= builtin_type (exp
->gdbarch
)->builtin_data_ptr
;
1064 return value_from_longest (selector_type
,
1065 lookup_child_selector (exp
->gdbarch
, sel
));
1068 case OP_OBJC_MSGCALL
:
1069 { /* Objective C message (method) call. */
1071 CORE_ADDR responds_selector
= 0;
1072 CORE_ADDR method_selector
= 0;
1074 CORE_ADDR selector
= 0;
1076 int struct_return
= 0;
1077 int sub_no_side
= 0;
1079 struct value
*msg_send
= NULL
;
1080 struct value
*msg_send_stret
= NULL
;
1081 int gnu_runtime
= 0;
1083 struct value
*target
= NULL
;
1084 struct value
*method
= NULL
;
1085 struct value
*called_method
= NULL
;
1087 struct type
*selector_type
= NULL
;
1088 struct type
*long_type
;
1090 struct value
*ret
= NULL
;
1093 selector
= exp
->elts
[pc
+ 1].longconst
;
1094 nargs
= exp
->elts
[pc
+ 2].longconst
;
1095 argvec
= (struct value
**) alloca (sizeof (struct value
*)
1100 long_type
= builtin_type (exp
->gdbarch
)->builtin_long
;
1101 selector_type
= builtin_type (exp
->gdbarch
)->builtin_data_ptr
;
1103 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1104 sub_no_side
= EVAL_NORMAL
;
1106 sub_no_side
= noside
;
1108 target
= evaluate_subexp (selector_type
, exp
, pos
, sub_no_side
);
1110 if (value_as_long (target
) == 0)
1111 return value_from_longest (long_type
, 0);
1113 if (lookup_minimal_symbol ("objc_msg_lookup", 0, 0))
1116 /* Find the method dispatch (Apple runtime) or method lookup
1117 (GNU runtime) function for Objective-C. These will be used
1118 to lookup the symbol information for the method. If we
1119 can't find any symbol information, then we'll use these to
1120 call the method, otherwise we can call the method
1121 directly. The msg_send_stret function is used in the special
1122 case of a method that returns a structure (Apple runtime
1126 struct type
*type
= selector_type
;
1128 type
= lookup_function_type (type
);
1129 type
= lookup_pointer_type (type
);
1130 type
= lookup_function_type (type
);
1131 type
= lookup_pointer_type (type
);
1133 msg_send
= find_function_in_inferior ("objc_msg_lookup", NULL
);
1135 = find_function_in_inferior ("objc_msg_lookup", NULL
);
1137 msg_send
= value_from_pointer (type
, value_as_address (msg_send
));
1138 msg_send_stret
= value_from_pointer (type
,
1139 value_as_address (msg_send_stret
));
1143 msg_send
= find_function_in_inferior ("objc_msgSend", NULL
);
1144 /* Special dispatcher for methods returning structs. */
1146 = find_function_in_inferior ("objc_msgSend_stret", NULL
);
1149 /* Verify the target object responds to this method. The
1150 standard top-level 'Object' class uses a different name for
1151 the verification method than the non-standard, but more
1152 often used, 'NSObject' class. Make sure we check for both. */
1155 = lookup_child_selector (exp
->gdbarch
, "respondsToSelector:");
1156 if (responds_selector
== 0)
1158 = lookup_child_selector (exp
->gdbarch
, "respondsTo:");
1160 if (responds_selector
== 0)
1161 error (_("no 'respondsTo:' or 'respondsToSelector:' method"));
1164 = lookup_child_selector (exp
->gdbarch
, "methodForSelector:");
1165 if (method_selector
== 0)
1167 = lookup_child_selector (exp
->gdbarch
, "methodFor:");
1169 if (method_selector
== 0)
1170 error (_("no 'methodFor:' or 'methodForSelector:' method"));
1172 /* Call the verification method, to make sure that the target
1173 class implements the desired method. */
1175 argvec
[0] = msg_send
;
1177 argvec
[2] = value_from_longest (long_type
, responds_selector
);
1178 argvec
[3] = value_from_longest (long_type
, selector
);
1181 ret
= call_function_by_hand (argvec
[0], 3, argvec
+ 1);
1184 /* Function objc_msg_lookup returns a pointer. */
1186 ret
= call_function_by_hand (argvec
[0], 3, argvec
+ 1);
1188 if (value_as_long (ret
) == 0)
1189 error (_("Target does not respond to this message selector."));
1191 /* Call "methodForSelector:" method, to get the address of a
1192 function method that implements this selector for this
1193 class. If we can find a symbol at that address, then we
1194 know the return type, parameter types etc. (that's a good
1197 argvec
[0] = msg_send
;
1199 argvec
[2] = value_from_longest (long_type
, method_selector
);
1200 argvec
[3] = value_from_longest (long_type
, selector
);
1203 ret
= call_function_by_hand (argvec
[0], 3, argvec
+ 1);
1207 ret
= call_function_by_hand (argvec
[0], 3, argvec
+ 1);
1210 /* ret should now be the selector. */
1212 addr
= value_as_long (ret
);
1215 struct symbol
*sym
= NULL
;
1217 /* The address might point to a function descriptor;
1218 resolve it to the actual code address instead. */
1219 addr
= gdbarch_convert_from_func_ptr_addr (exp
->gdbarch
, addr
,
1222 /* Is it a high_level symbol? */
1223 sym
= find_pc_function (addr
);
1225 method
= value_of_variable (sym
, 0);
1228 /* If we found a method with symbol information, check to see
1229 if it returns a struct. Otherwise assume it doesn't. */
1234 struct type
*val_type
;
1236 funaddr
= find_function_addr (method
, &val_type
);
1238 block_for_pc (funaddr
);
1240 CHECK_TYPEDEF (val_type
);
1242 if ((val_type
== NULL
)
1243 || (TYPE_CODE(val_type
) == TYPE_CODE_ERROR
))
1245 if (expect_type
!= NULL
)
1246 val_type
= expect_type
;
1249 struct_return
= using_struct_return (exp
->gdbarch
, method
,
1252 else if (expect_type
!= NULL
)
1254 struct_return
= using_struct_return (exp
->gdbarch
, NULL
,
1255 check_typedef (expect_type
));
1258 /* Found a function symbol. Now we will substitute its
1259 value in place of the message dispatcher (obj_msgSend),
1260 so that we call the method directly instead of thru
1261 the dispatcher. The main reason for doing this is that
1262 we can now evaluate the return value and parameter values
1263 according to their known data types, in case we need to
1264 do things like promotion, dereferencing, special handling
1265 of structs and doubles, etc.
1267 We want to use the type signature of 'method', but still
1268 jump to objc_msgSend() or objc_msgSend_stret() to better
1269 mimic the behavior of the runtime. */
1273 if (TYPE_CODE (value_type (method
)) != TYPE_CODE_FUNC
)
1274 error (_("method address has symbol information "
1275 "with non-function type; skipping"));
1277 /* Create a function pointer of the appropriate type, and
1278 replace its value with the value of msg_send or
1279 msg_send_stret. We must use a pointer here, as
1280 msg_send and msg_send_stret are of pointer type, and
1281 the representation may be different on systems that use
1282 function descriptors. */
1285 = value_from_pointer (lookup_pointer_type (value_type (method
)),
1286 value_as_address (msg_send_stret
));
1289 = value_from_pointer (lookup_pointer_type (value_type (method
)),
1290 value_as_address (msg_send
));
1295 called_method
= msg_send_stret
;
1297 called_method
= msg_send
;
1300 if (noside
== EVAL_SKIP
)
1303 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1305 /* If the return type doesn't look like a function type,
1306 call an error. This can happen if somebody tries to
1307 turn a variable into a function call. This is here
1308 because people often want to call, eg, strcmp, which
1309 gdb doesn't know is a function. If gdb isn't asked for
1310 it's opinion (ie. through "whatis"), it won't offer
1313 struct type
*type
= value_type (called_method
);
1315 if (type
&& TYPE_CODE (type
) == TYPE_CODE_PTR
)
1316 type
= TYPE_TARGET_TYPE (type
);
1317 type
= TYPE_TARGET_TYPE (type
);
1321 if ((TYPE_CODE (type
) == TYPE_CODE_ERROR
) && expect_type
)
1322 return allocate_value (expect_type
);
1324 return allocate_value (type
);
1327 error (_("Expression of type other than "
1328 "\"method returning ...\" used as a method"));
1331 /* Now depending on whether we found a symbol for the method,
1332 we will either call the runtime dispatcher or the method
1335 argvec
[0] = called_method
;
1337 argvec
[2] = value_from_longest (long_type
, selector
);
1338 /* User-supplied arguments. */
1339 for (tem
= 0; tem
< nargs
; tem
++)
1340 argvec
[tem
+ 3] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1341 argvec
[tem
+ 3] = 0;
1343 if (gnu_runtime
&& (method
!= NULL
))
1345 /* Function objc_msg_lookup returns a pointer. */
1346 deprecated_set_value_type (argvec
[0],
1347 lookup_pointer_type (lookup_function_type (value_type (argvec
[0]))));
1349 = call_function_by_hand (argvec
[0], nargs
+ 2, argvec
+ 1);
1352 ret
= call_function_by_hand (argvec
[0], nargs
+ 2, argvec
+ 1);
1359 op
= exp
->elts
[*pos
].opcode
;
1360 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1361 /* Allocate arg vector, including space for the function to be
1362 called in argvec[0] and a terminating NULL. */
1363 argvec
= (struct value
**)
1364 alloca (sizeof (struct value
*) * (nargs
+ 3));
1365 if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
1367 /* First, evaluate the structure into arg2. */
1370 if (noside
== EVAL_SKIP
)
1373 if (op
== STRUCTOP_MEMBER
)
1375 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
1379 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1382 /* If the function is a virtual function, then the
1383 aggregate value (providing the structure) plays
1384 its part by providing the vtable. Otherwise,
1385 it is just along for the ride: call the function
1388 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1390 type
= check_typedef (value_type (arg1
));
1391 if (TYPE_CODE (type
) == TYPE_CODE_METHODPTR
)
1393 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1394 arg1
= value_zero (TYPE_TARGET_TYPE (type
), not_lval
);
1396 arg1
= cplus_method_ptr_to_value (&arg2
, arg1
);
1398 /* Now, say which argument to start evaluating from. */
1403 else if (TYPE_CODE (type
) == TYPE_CODE_MEMBERPTR
)
1405 struct type
*type_ptr
1406 = lookup_pointer_type (TYPE_DOMAIN_TYPE (type
));
1408 /* Now, convert these values to an address. */
1409 arg2
= value_cast (type_ptr
, arg2
);
1411 mem_offset
= value_as_long (arg1
);
1413 arg1
= value_from_pointer (type_ptr
,
1414 value_as_long (arg2
) + mem_offset
);
1415 arg1
= value_ind (arg1
);
1419 error (_("Non-pointer-to-member value used in pointer-to-member "
1422 else if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
1424 /* Hair for method invocations. */
1428 /* First, evaluate the structure into arg2. */
1430 tem2
= longest_to_int (exp
->elts
[pc2
+ 1].longconst
);
1431 *pos
+= 3 + BYTES_TO_EXP_ELEM (tem2
+ 1);
1432 if (noside
== EVAL_SKIP
)
1435 if (op
== STRUCTOP_STRUCT
)
1437 /* If v is a variable in a register, and the user types
1438 v.method (), this will produce an error, because v has
1441 A possible way around this would be to allocate a
1442 copy of the variable on the stack, copy in the
1443 contents, call the function, and copy out the
1444 contents. I.e. convert this from call by reference
1445 to call by copy-return (or whatever it's called).
1446 However, this does not work because it is not the
1447 same: the method being called could stash a copy of
1448 the address, and then future uses through that address
1449 (after the method returns) would be expected to
1450 use the variable itself, not some copy of it. */
1451 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
1455 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1457 /* Check to see if the operator '->' has been
1458 overloaded. If the operator has been overloaded
1459 replace arg2 with the value returned by the custom
1460 operator and continue evaluation. */
1461 while (unop_user_defined_p (op
, arg2
))
1463 volatile struct gdb_exception except
;
1464 struct value
*value
= NULL
;
1465 TRY_CATCH (except
, RETURN_MASK_ERROR
)
1467 value
= value_x_unop (arg2
, op
, noside
);
1470 if (except
.reason
< 0)
1472 if (except
.error
== NOT_FOUND_ERROR
)
1475 throw_exception (except
);
1480 /* Now, say which argument to start evaluating from. */
1483 else if (op
== OP_SCOPE
1484 && overload_resolution
1485 && (exp
->language_defn
->la_language
== language_cplus
))
1487 /* Unpack it locally so we can properly handle overload
1493 local_tem
= longest_to_int (exp
->elts
[pc2
+ 2].longconst
);
1494 (*pos
) += 4 + BYTES_TO_EXP_ELEM (local_tem
+ 1);
1495 type
= exp
->elts
[pc2
+ 1].type
;
1496 name
= &exp
->elts
[pc2
+ 3].string
;
1499 function_name
= NULL
;
1500 if (TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
1502 function
= cp_lookup_symbol_namespace (TYPE_TAG_NAME (type
),
1504 get_selected_block (0),
1506 if (function
== NULL
)
1507 error (_("No symbol \"%s\" in namespace \"%s\"."),
1508 name
, TYPE_TAG_NAME (type
));
1514 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_STRUCT
1515 || TYPE_CODE (type
) == TYPE_CODE_UNION
);
1516 function_name
= name
;
1518 arg2
= value_zero (type
, lval_memory
);
1523 else if (op
== OP_ADL_FUNC
)
1525 /* Save the function position and move pos so that the arguments
1526 can be evaluated. */
1532 func_name_len
= longest_to_int (exp
->elts
[save_pos1
+ 3].longconst
);
1533 (*pos
) += 6 + BYTES_TO_EXP_ELEM (func_name_len
+ 1);
1537 /* Non-method function call. */
1541 /* If this is a C++ function wait until overload resolution. */
1542 if (op
== OP_VAR_VALUE
1543 && overload_resolution
1544 && (exp
->language_defn
->la_language
== language_cplus
))
1546 (*pos
) += 4; /* Skip the evaluation of the symbol. */
1551 argvec
[0] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1552 type
= value_type (argvec
[0]);
1553 if (type
&& TYPE_CODE (type
) == TYPE_CODE_PTR
)
1554 type
= TYPE_TARGET_TYPE (type
);
1555 if (type
&& TYPE_CODE (type
) == TYPE_CODE_FUNC
)
1557 for (; tem
<= nargs
&& tem
<= TYPE_NFIELDS (type
); tem
++)
1559 argvec
[tem
] = evaluate_subexp (TYPE_FIELD_TYPE (type
,
1567 /* Evaluate arguments. */
1568 for (; tem
<= nargs
; tem
++)
1570 /* Ensure that array expressions are coerced into pointer
1572 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1575 /* Signal end of arglist. */
1577 if (op
== OP_ADL_FUNC
)
1579 struct symbol
*symp
;
1582 int string_pc
= save_pos1
+ 3;
1584 /* Extract the function name. */
1585 name_len
= longest_to_int (exp
->elts
[string_pc
].longconst
);
1586 func_name
= (char *) alloca (name_len
+ 1);
1587 strcpy (func_name
, &exp
->elts
[string_pc
+ 1].string
);
1589 find_overload_match (&argvec
[1], nargs
, func_name
,
1590 NON_METHOD
, /* not method */
1591 0, /* strict match */
1592 NULL
, NULL
, /* pass NULL symbol since
1593 symbol is unknown */
1594 NULL
, &symp
, NULL
, 0);
1596 /* Now fix the expression being evaluated. */
1597 exp
->elts
[save_pos1
+ 2].symbol
= symp
;
1598 argvec
[0] = evaluate_subexp_with_coercion (exp
, &save_pos1
, noside
);
1601 if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
1602 || (op
== OP_SCOPE
&& function_name
!= NULL
))
1604 int static_memfuncp
;
1607 /* Method invocation : stuff "this" as first parameter. */
1612 /* Name of method from expression. */
1613 tstr
= &exp
->elts
[pc2
+ 2].string
;
1616 tstr
= function_name
;
1618 if (overload_resolution
&& (exp
->language_defn
->la_language
1621 /* Language is C++, do some overload resolution before
1623 struct value
*valp
= NULL
;
1625 (void) find_overload_match (&argvec
[1], nargs
, tstr
,
1626 METHOD
, /* method */
1627 0, /* strict match */
1628 &arg2
, /* the object */
1630 &static_memfuncp
, 0);
1632 if (op
== OP_SCOPE
&& !static_memfuncp
)
1634 /* For the time being, we don't handle this. */
1635 error (_("Call to overloaded function %s requires "
1639 argvec
[1] = arg2
; /* the ``this'' pointer */
1640 argvec
[0] = valp
; /* Use the method found after overload
1644 /* Non-C++ case -- or no overload resolution. */
1646 struct value
*temp
= arg2
;
1648 argvec
[0] = value_struct_elt (&temp
, argvec
+ 1, tstr
,
1650 op
== STRUCTOP_STRUCT
1651 ? "structure" : "structure pointer");
1652 /* value_struct_elt updates temp with the correct value
1653 of the ``this'' pointer if necessary, so modify argvec[1] to
1654 reflect any ``this'' changes. */
1656 = value_from_longest (lookup_pointer_type(value_type (temp
)),
1657 value_address (temp
)
1658 + value_embedded_offset (temp
));
1659 argvec
[1] = arg2
; /* the ``this'' pointer */
1662 if (static_memfuncp
)
1664 argvec
[1] = argvec
[0];
1669 else if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
1671 /* Pointer to member. argvec[1] is already set up. */
1674 else if (op
== OP_VAR_VALUE
|| (op
== OP_SCOPE
&& function
!= NULL
))
1676 /* Non-member function being called. */
1677 /* fn: This can only be done for C++ functions. A C-style function
1678 in a C++ program, for instance, does not have the fields that
1679 are expected here. */
1681 if (overload_resolution
&& (exp
->language_defn
->la_language
1684 /* Language is C++, do some overload resolution before
1686 struct symbol
*symp
;
1689 /* If a scope has been specified disable ADL. */
1693 if (op
== OP_VAR_VALUE
)
1694 function
= exp
->elts
[save_pos1
+2].symbol
;
1696 (void) find_overload_match (&argvec
[1], nargs
,
1697 NULL
, /* no need for name */
1698 NON_METHOD
, /* not method */
1699 0, /* strict match */
1700 NULL
, function
, /* the function */
1701 NULL
, &symp
, NULL
, no_adl
);
1703 if (op
== OP_VAR_VALUE
)
1705 /* Now fix the expression being evaluated. */
1706 exp
->elts
[save_pos1
+2].symbol
= symp
;
1707 argvec
[0] = evaluate_subexp_with_coercion (exp
, &save_pos1
,
1711 argvec
[0] = value_of_variable (symp
, get_selected_block (0));
1715 /* Not C++, or no overload resolution allowed. */
1716 /* Nothing to be done; argvec already correctly set up. */
1721 /* It is probably a C-style function. */
1722 /* Nothing to be done; argvec already correctly set up. */
1727 if (noside
== EVAL_SKIP
)
1729 if (argvec
[0] == NULL
)
1730 error (_("Cannot evaluate function -- may be inlined"));
1731 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1733 /* If the return type doesn't look like a function type, call an
1734 error. This can happen if somebody tries to turn a variable into
1735 a function call. This is here because people often want to
1736 call, eg, strcmp, which gdb doesn't know is a function. If
1737 gdb isn't asked for it's opinion (ie. through "whatis"),
1738 it won't offer it. */
1740 struct type
*ftype
= value_type (argvec
[0]);
1742 if (TYPE_CODE (ftype
) == TYPE_CODE_INTERNAL_FUNCTION
)
1744 /* We don't know anything about what the internal
1745 function might return, but we have to return
1747 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
,
1750 else if (TYPE_GNU_IFUNC (ftype
))
1751 return allocate_value (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (ftype
)));
1752 else if (TYPE_TARGET_TYPE (ftype
))
1753 return allocate_value (TYPE_TARGET_TYPE (ftype
));
1755 error (_("Expression of type other than "
1756 "\"Function returning ...\" used as function"));
1758 if (TYPE_CODE (value_type (argvec
[0])) == TYPE_CODE_INTERNAL_FUNCTION
)
1759 return call_internal_function (exp
->gdbarch
, exp
->language_defn
,
1760 argvec
[0], nargs
, argvec
+ 1);
1762 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
1763 /* pai: FIXME save value from call_function_by_hand, then adjust
1764 pc by adjust_fn_pc if +ve. */
1766 case OP_F77_UNDETERMINED_ARGLIST
:
1768 /* Remember that in F77, functions, substring ops and
1769 array subscript operations cannot be disambiguated
1770 at parse time. We have made all array subscript operations,
1771 substring operations as well as function calls come here
1772 and we now have to discover what the heck this thing actually was.
1773 If it is a function, we process just as if we got an OP_FUNCALL. */
1775 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1778 /* First determine the type code we are dealing with. */
1779 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1780 type
= check_typedef (value_type (arg1
));
1781 code
= TYPE_CODE (type
);
1783 if (code
== TYPE_CODE_PTR
)
1785 /* Fortran always passes variable to subroutines as pointer.
1786 So we need to look into its target type to see if it is
1787 array, string or function. If it is, we need to switch
1788 to the target value the original one points to. */
1789 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1791 if (TYPE_CODE (target_type
) == TYPE_CODE_ARRAY
1792 || TYPE_CODE (target_type
) == TYPE_CODE_STRING
1793 || TYPE_CODE (target_type
) == TYPE_CODE_FUNC
)
1795 arg1
= value_ind (arg1
);
1796 type
= check_typedef (value_type (arg1
));
1797 code
= TYPE_CODE (type
);
1803 case TYPE_CODE_ARRAY
:
1804 if (exp
->elts
[*pos
].opcode
== OP_F90_RANGE
)
1805 return value_f90_subarray (arg1
, exp
, pos
, noside
);
1807 goto multi_f77_subscript
;
1809 case TYPE_CODE_STRING
:
1810 if (exp
->elts
[*pos
].opcode
== OP_F90_RANGE
)
1811 return value_f90_subarray (arg1
, exp
, pos
, noside
);
1814 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1815 return value_subscript (arg1
, value_as_long (arg2
));
1819 case TYPE_CODE_FUNC
:
1820 /* It's a function call. */
1821 /* Allocate arg vector, including space for the function to be
1822 called in argvec[0] and a terminating NULL. */
1823 argvec
= (struct value
**)
1824 alloca (sizeof (struct value
*) * (nargs
+ 2));
1827 for (; tem
<= nargs
; tem
++)
1828 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1829 argvec
[tem
] = 0; /* signal end of arglist */
1833 error (_("Cannot perform substring on this type"));
1837 /* We have a complex number, There should be 2 floating
1838 point numbers that compose it. */
1840 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1841 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1843 return value_literal_complex (arg1
, arg2
, exp
->elts
[pc
+ 1].type
);
1845 case STRUCTOP_STRUCT
:
1846 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1847 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1848 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1849 if (noside
== EVAL_SKIP
)
1851 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1852 return value_zero (lookup_struct_elt_type (value_type (arg1
),
1853 &exp
->elts
[pc
+ 2].string
,
1858 struct value
*temp
= arg1
;
1860 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
1865 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1866 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1867 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1868 if (noside
== EVAL_SKIP
)
1871 /* Check to see if operator '->' has been overloaded. If so replace
1872 arg1 with the value returned by evaluating operator->(). */
1873 while (unop_user_defined_p (op
, arg1
))
1875 volatile struct gdb_exception except
;
1876 struct value
*value
= NULL
;
1877 TRY_CATCH (except
, RETURN_MASK_ERROR
)
1879 value
= value_x_unop (arg1
, op
, noside
);
1882 if (except
.reason
< 0)
1884 if (except
.error
== NOT_FOUND_ERROR
)
1887 throw_exception (except
);
1892 /* JYG: if print object is on we need to replace the base type
1893 with rtti type in order to continue on with successful
1894 lookup of member / method only available in the rtti type. */
1896 struct type
*type
= value_type (arg1
);
1897 struct type
*real_type
;
1898 int full
, top
, using_enc
;
1899 struct value_print_options opts
;
1901 get_user_print_options (&opts
);
1902 if (opts
.objectprint
&& TYPE_TARGET_TYPE(type
)
1903 && (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_CLASS
))
1905 real_type
= value_rtti_indirect_type (arg1
, &full
, &top
,
1908 arg1
= value_cast (real_type
, arg1
);
1912 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1913 return value_zero (lookup_struct_elt_type (value_type (arg1
),
1914 &exp
->elts
[pc
+ 2].string
,
1919 struct value
*temp
= arg1
;
1921 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
1922 NULL
, "structure pointer");
1925 case STRUCTOP_MEMBER
:
1927 if (op
== STRUCTOP_MEMBER
)
1928 arg1
= evaluate_subexp_for_address (exp
, pos
, noside
);
1930 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1932 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1934 if (noside
== EVAL_SKIP
)
1937 type
= check_typedef (value_type (arg2
));
1938 switch (TYPE_CODE (type
))
1940 case TYPE_CODE_METHODPTR
:
1941 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1942 return value_zero (TYPE_TARGET_TYPE (type
), not_lval
);
1945 arg2
= cplus_method_ptr_to_value (&arg1
, arg2
);
1946 gdb_assert (TYPE_CODE (value_type (arg2
)) == TYPE_CODE_PTR
);
1947 return value_ind (arg2
);
1950 case TYPE_CODE_MEMBERPTR
:
1951 /* Now, convert these values to an address. */
1952 arg1
= value_cast_pointers (lookup_pointer_type (TYPE_DOMAIN_TYPE (type
)),
1955 mem_offset
= value_as_long (arg2
);
1957 arg3
= value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
1958 value_as_long (arg1
) + mem_offset
);
1959 return value_ind (arg3
);
1962 error (_("non-pointer-to-member value used "
1963 "in pointer-to-member construct"));
1967 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1968 arg_types
= (struct type
**) alloca (nargs
* sizeof (struct type
*));
1969 for (ix
= 0; ix
< nargs
; ++ix
)
1970 arg_types
[ix
] = exp
->elts
[pc
+ 1 + ix
+ 1].type
;
1972 expect_type
= make_params (nargs
, arg_types
);
1973 *(pos
) += 3 + nargs
;
1974 arg1
= evaluate_subexp_standard (expect_type
, exp
, pos
, noside
);
1975 xfree (TYPE_FIELDS (expect_type
));
1976 xfree (TYPE_MAIN_TYPE (expect_type
));
1977 xfree (expect_type
);
1981 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1982 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1983 if (noside
== EVAL_SKIP
)
1985 if (binop_user_defined_p (op
, arg1
, arg2
))
1986 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1988 return value_concat (arg1
, arg2
);
1991 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1992 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
1994 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1996 if (binop_user_defined_p (op
, arg1
, arg2
))
1997 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1999 return value_assign (arg1
, arg2
);
2001 case BINOP_ASSIGN_MODIFY
:
2003 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2004 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2005 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2007 op
= exp
->elts
[pc
+ 1].opcode
;
2008 if (binop_user_defined_p (op
, arg1
, arg2
))
2009 return value_x_binop (arg1
, arg2
, BINOP_ASSIGN_MODIFY
, op
, noside
);
2010 else if (op
== BINOP_ADD
&& ptrmath_type_p (exp
->language_defn
,
2012 && is_integral_type (value_type (arg2
)))
2013 arg2
= value_ptradd (arg1
, value_as_long (arg2
));
2014 else if (op
== BINOP_SUB
&& ptrmath_type_p (exp
->language_defn
,
2016 && is_integral_type (value_type (arg2
)))
2017 arg2
= value_ptradd (arg1
, - value_as_long (arg2
));
2020 struct value
*tmp
= arg1
;
2022 /* For shift and integer exponentiation operations,
2023 only promote the first argument. */
2024 if ((op
== BINOP_LSH
|| op
== BINOP_RSH
|| op
== BINOP_EXP
)
2025 && is_integral_type (value_type (arg2
)))
2026 unop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
);
2028 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2030 arg2
= value_binop (tmp
, arg2
, op
);
2032 return value_assign (arg1
, arg2
);
2035 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2036 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2037 if (noside
== EVAL_SKIP
)
2039 if (binop_user_defined_p (op
, arg1
, arg2
))
2040 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2041 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
2042 && is_integral_type (value_type (arg2
)))
2043 return value_ptradd (arg1
, value_as_long (arg2
));
2044 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg2
))
2045 && is_integral_type (value_type (arg1
)))
2046 return value_ptradd (arg2
, value_as_long (arg1
));
2049 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2050 return value_binop (arg1
, arg2
, BINOP_ADD
);
2054 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2055 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2056 if (noside
== EVAL_SKIP
)
2058 if (binop_user_defined_p (op
, arg1
, arg2
))
2059 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2060 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
2061 && ptrmath_type_p (exp
->language_defn
, value_type (arg2
)))
2063 /* FIXME -- should be ptrdiff_t */
2064 type
= builtin_type (exp
->gdbarch
)->builtin_long
;
2065 return value_from_longest (type
, value_ptrdiff (arg1
, arg2
));
2067 else if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
))
2068 && is_integral_type (value_type (arg2
)))
2069 return value_ptradd (arg1
, - value_as_long (arg2
));
2072 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2073 return value_binop (arg1
, arg2
, BINOP_SUB
);
2084 case BINOP_BITWISE_AND
:
2085 case BINOP_BITWISE_IOR
:
2086 case BINOP_BITWISE_XOR
:
2087 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2088 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2089 if (noside
== EVAL_SKIP
)
2091 if (binop_user_defined_p (op
, arg1
, arg2
))
2092 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2095 /* If EVAL_AVOID_SIDE_EFFECTS and we're dividing by zero,
2096 fudge arg2 to avoid division-by-zero, the caller is
2097 (theoretically) only looking for the type of the result. */
2098 if (noside
== EVAL_AVOID_SIDE_EFFECTS
2099 /* ??? Do we really want to test for BINOP_MOD here?
2100 The implementation of value_binop gives it a well-defined
2103 || op
== BINOP_INTDIV
2106 && value_logical_not (arg2
))
2108 struct value
*v_one
, *retval
;
2110 v_one
= value_one (value_type (arg2
));
2111 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &v_one
);
2112 retval
= value_binop (arg1
, v_one
, op
);
2117 /* For shift and integer exponentiation operations,
2118 only promote the first argument. */
2119 if ((op
== BINOP_LSH
|| op
== BINOP_RSH
|| op
== BINOP_EXP
)
2120 && is_integral_type (value_type (arg2
)))
2121 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2123 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2125 return value_binop (arg1
, arg2
, op
);
2130 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2131 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2132 if (noside
== EVAL_SKIP
)
2134 error (_("':' operator used in invalid context"));
2136 case BINOP_SUBSCRIPT
:
2137 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2138 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2139 if (noside
== EVAL_SKIP
)
2141 if (binop_user_defined_p (op
, arg1
, arg2
))
2142 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2145 /* If the user attempts to subscript something that is not an
2146 array or pointer type (like a plain int variable for example),
2147 then report this as an error. */
2149 arg1
= coerce_ref (arg1
);
2150 type
= check_typedef (value_type (arg1
));
2151 if (TYPE_CODE (type
) != TYPE_CODE_ARRAY
2152 && TYPE_CODE (type
) != TYPE_CODE_PTR
)
2154 if (TYPE_NAME (type
))
2155 error (_("cannot subscript something of type `%s'"),
2158 error (_("cannot subscript requested type"));
2161 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2162 return value_zero (TYPE_TARGET_TYPE (type
), VALUE_LVAL (arg1
));
2164 return value_subscript (arg1
, value_as_long (arg2
));
2168 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2169 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2170 if (noside
== EVAL_SKIP
)
2172 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2173 return value_from_longest (type
, (LONGEST
) value_in (arg1
, arg2
));
2175 case MULTI_SUBSCRIPT
:
2177 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
2178 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2181 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2182 /* FIXME: EVAL_SKIP handling may not be correct. */
2183 if (noside
== EVAL_SKIP
)
2194 /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
2195 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2197 /* If the user attempts to subscript something that has no target
2198 type (like a plain int variable for example), then report this
2201 type
= TYPE_TARGET_TYPE (check_typedef (value_type (arg1
)));
2204 arg1
= value_zero (type
, VALUE_LVAL (arg1
));
2210 error (_("cannot subscript something of type `%s'"),
2211 TYPE_NAME (value_type (arg1
)));
2215 if (binop_user_defined_p (op
, arg1
, arg2
))
2217 arg1
= value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2221 arg1
= coerce_ref (arg1
);
2222 type
= check_typedef (value_type (arg1
));
2224 switch (TYPE_CODE (type
))
2227 case TYPE_CODE_ARRAY
:
2228 case TYPE_CODE_STRING
:
2229 arg1
= value_subscript (arg1
, value_as_long (arg2
));
2233 if (TYPE_NAME (type
))
2234 error (_("cannot subscript something of type `%s'"),
2237 error (_("cannot subscript requested type"));
2243 multi_f77_subscript
:
2245 LONGEST subscript_array
[MAX_FORTRAN_DIMS
];
2246 int ndimensions
= 1, i
;
2247 struct value
*array
= arg1
;
2249 if (nargs
> MAX_FORTRAN_DIMS
)
2250 error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS
);
2252 ndimensions
= calc_f77_array_dims (type
);
2254 if (nargs
!= ndimensions
)
2255 error (_("Wrong number of subscripts"));
2257 gdb_assert (nargs
> 0);
2259 /* Now that we know we have a legal array subscript expression
2260 let us actually find out where this element exists in the array. */
2262 /* Take array indices left to right. */
2263 for (i
= 0; i
< nargs
; i
++)
2265 /* Evaluate each subscript; it must be a legal integer in F77. */
2266 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
2268 /* Fill in the subscript array. */
2270 subscript_array
[i
] = value_as_long (arg2
);
2273 /* Internal type of array is arranged right to left. */
2274 for (i
= nargs
; i
> 0; i
--)
2276 struct type
*array_type
= check_typedef (value_type (array
));
2277 LONGEST index
= subscript_array
[i
- 1];
2279 array
= value_subscripted_rvalue (array
, index
,
2280 f77_get_lowerbound (array_type
));
2286 case BINOP_LOGICAL_AND
:
2287 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2288 if (noside
== EVAL_SKIP
)
2290 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2295 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2298 if (binop_user_defined_p (op
, arg1
, arg2
))
2300 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2301 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2305 tem
= value_logical_not (arg1
);
2306 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
2307 (tem
? EVAL_SKIP
: noside
));
2308 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2309 return value_from_longest (type
,
2310 (LONGEST
) (!tem
&& !value_logical_not (arg2
)));
2313 case BINOP_LOGICAL_OR
:
2314 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2315 if (noside
== EVAL_SKIP
)
2317 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2322 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2325 if (binop_user_defined_p (op
, arg1
, arg2
))
2327 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2328 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2332 tem
= value_logical_not (arg1
);
2333 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
2334 (!tem
? EVAL_SKIP
: noside
));
2335 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2336 return value_from_longest (type
,
2337 (LONGEST
) (!tem
|| !value_logical_not (arg2
)));
2341 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2342 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2343 if (noside
== EVAL_SKIP
)
2345 if (binop_user_defined_p (op
, arg1
, arg2
))
2347 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2351 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2352 tem
= value_equal (arg1
, arg2
);
2353 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2354 return value_from_longest (type
, (LONGEST
) tem
);
2357 case BINOP_NOTEQUAL
:
2358 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2359 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2360 if (noside
== EVAL_SKIP
)
2362 if (binop_user_defined_p (op
, arg1
, arg2
))
2364 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2368 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2369 tem
= value_equal (arg1
, arg2
);
2370 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2371 return value_from_longest (type
, (LONGEST
) ! tem
);
2375 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2376 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2377 if (noside
== EVAL_SKIP
)
2379 if (binop_user_defined_p (op
, arg1
, arg2
))
2381 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2385 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2386 tem
= value_less (arg1
, arg2
);
2387 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2388 return value_from_longest (type
, (LONGEST
) tem
);
2392 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2393 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2394 if (noside
== EVAL_SKIP
)
2396 if (binop_user_defined_p (op
, arg1
, arg2
))
2398 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2402 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2403 tem
= value_less (arg2
, arg1
);
2404 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2405 return value_from_longest (type
, (LONGEST
) tem
);
2409 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2410 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2411 if (noside
== EVAL_SKIP
)
2413 if (binop_user_defined_p (op
, arg1
, arg2
))
2415 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2419 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2420 tem
= value_less (arg2
, arg1
) || value_equal (arg1
, arg2
);
2421 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2422 return value_from_longest (type
, (LONGEST
) tem
);
2426 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2427 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
2428 if (noside
== EVAL_SKIP
)
2430 if (binop_user_defined_p (op
, arg1
, arg2
))
2432 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
2436 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
2437 tem
= value_less (arg1
, arg2
) || value_equal (arg1
, arg2
);
2438 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2439 return value_from_longest (type
, (LONGEST
) tem
);
2443 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2444 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2445 if (noside
== EVAL_SKIP
)
2447 type
= check_typedef (value_type (arg2
));
2448 if (TYPE_CODE (type
) != TYPE_CODE_INT
)
2449 error (_("Non-integral right operand for \"@\" operator."));
2450 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2452 return allocate_repeat_value (value_type (arg1
),
2453 longest_to_int (value_as_long (arg2
)));
2456 return value_repeat (arg1
, longest_to_int (value_as_long (arg2
)));
2459 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2460 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2463 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2464 if (noside
== EVAL_SKIP
)
2466 if (unop_user_defined_p (op
, arg1
))
2467 return value_x_unop (arg1
, op
, noside
);
2470 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2471 return value_pos (arg1
);
2475 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2476 if (noside
== EVAL_SKIP
)
2478 if (unop_user_defined_p (op
, arg1
))
2479 return value_x_unop (arg1
, op
, noside
);
2482 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2483 return value_neg (arg1
);
2486 case UNOP_COMPLEMENT
:
2487 /* C++: check for and handle destructor names. */
2488 op
= exp
->elts
[*pos
].opcode
;
2490 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2491 if (noside
== EVAL_SKIP
)
2493 if (unop_user_defined_p (UNOP_COMPLEMENT
, arg1
))
2494 return value_x_unop (arg1
, UNOP_COMPLEMENT
, noside
);
2497 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
2498 return value_complement (arg1
);
2501 case UNOP_LOGICAL_NOT
:
2502 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2503 if (noside
== EVAL_SKIP
)
2505 if (unop_user_defined_p (op
, arg1
))
2506 return value_x_unop (arg1
, op
, noside
);
2509 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
2510 return value_from_longest (type
, (LONGEST
) value_logical_not (arg1
));
2514 if (expect_type
&& TYPE_CODE (expect_type
) == TYPE_CODE_PTR
)
2515 expect_type
= TYPE_TARGET_TYPE (check_typedef (expect_type
));
2516 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2517 type
= check_typedef (value_type (arg1
));
2518 if (TYPE_CODE (type
) == TYPE_CODE_METHODPTR
2519 || TYPE_CODE (type
) == TYPE_CODE_MEMBERPTR
)
2520 error (_("Attempt to dereference pointer "
2521 "to member without an object"));
2522 if (noside
== EVAL_SKIP
)
2524 if (unop_user_defined_p (op
, arg1
))
2525 return value_x_unop (arg1
, op
, noside
);
2526 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2528 type
= check_typedef (value_type (arg1
));
2529 if (TYPE_CODE (type
) == TYPE_CODE_PTR
2530 || TYPE_CODE (type
) == TYPE_CODE_REF
2531 /* In C you can dereference an array to get the 1st elt. */
2532 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
2534 return value_zero (TYPE_TARGET_TYPE (type
),
2536 else if (TYPE_CODE (type
) == TYPE_CODE_INT
)
2537 /* GDB allows dereferencing an int. */
2538 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
,
2541 error (_("Attempt to take contents of a non-pointer value."));
2544 /* Allow * on an integer so we can cast it to whatever we want.
2545 This returns an int, which seems like the most C-like thing to
2546 do. "long long" variables are rare enough that
2547 BUILTIN_TYPE_LONGEST would seem to be a mistake. */
2548 if (TYPE_CODE (type
) == TYPE_CODE_INT
)
2549 return value_at_lazy (builtin_type (exp
->gdbarch
)->builtin_int
,
2550 (CORE_ADDR
) value_as_address (arg1
));
2551 return value_ind (arg1
);
2554 /* C++: check for and handle pointer to members. */
2556 op
= exp
->elts
[*pos
].opcode
;
2558 if (noside
== EVAL_SKIP
)
2560 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
2565 struct value
*retvalp
= evaluate_subexp_for_address (exp
, pos
,
2572 if (noside
== EVAL_SKIP
)
2574 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
2577 return evaluate_subexp_for_sizeof (exp
, pos
);
2581 type
= exp
->elts
[pc
+ 1].type
;
2582 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
2583 if (noside
== EVAL_SKIP
)
2585 if (type
!= value_type (arg1
))
2586 arg1
= value_cast (type
, arg1
);
2589 case UNOP_CAST_TYPE
:
2590 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2591 type
= value_type (arg1
);
2592 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
2593 if (noside
== EVAL_SKIP
)
2595 if (type
!= value_type (arg1
))
2596 arg1
= value_cast (type
, arg1
);
2599 case UNOP_DYNAMIC_CAST
:
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
)
2605 return value_dynamic_cast (type
, arg1
);
2607 case UNOP_REINTERPRET_CAST
:
2608 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2609 type
= value_type (arg1
);
2610 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
2611 if (noside
== EVAL_SKIP
)
2613 return value_reinterpret_cast (type
, arg1
);
2617 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2618 if (noside
== EVAL_SKIP
)
2620 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2621 return value_zero (exp
->elts
[pc
+ 1].type
, lval_memory
);
2623 return value_at_lazy (exp
->elts
[pc
+ 1].type
,
2624 value_as_address (arg1
));
2626 case UNOP_MEMVAL_TYPE
:
2627 arg1
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2628 type
= value_type (arg1
);
2629 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2630 if (noside
== EVAL_SKIP
)
2632 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2633 return value_zero (type
, lval_memory
);
2635 return value_at_lazy (type
, value_as_address (arg1
));
2637 case UNOP_MEMVAL_TLS
:
2639 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2640 if (noside
== EVAL_SKIP
)
2642 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2643 return value_zero (exp
->elts
[pc
+ 2].type
, lval_memory
);
2648 tls_addr
= target_translate_tls_address (exp
->elts
[pc
+ 1].objfile
,
2649 value_as_address (arg1
));
2650 return value_at_lazy (exp
->elts
[pc
+ 2].type
, tls_addr
);
2653 case UNOP_PREINCREMENT
:
2654 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2655 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2657 else if (unop_user_defined_p (op
, arg1
))
2659 return value_x_unop (arg1
, op
, noside
);
2663 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2664 arg2
= value_ptradd (arg1
, 1);
2667 struct value
*tmp
= arg1
;
2669 arg2
= value_one (value_type (arg1
));
2670 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2671 arg2
= value_binop (tmp
, arg2
, BINOP_ADD
);
2674 return value_assign (arg1
, arg2
);
2677 case UNOP_PREDECREMENT
:
2678 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2679 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2681 else if (unop_user_defined_p (op
, arg1
))
2683 return value_x_unop (arg1
, op
, noside
);
2687 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2688 arg2
= value_ptradd (arg1
, -1);
2691 struct value
*tmp
= arg1
;
2693 arg2
= value_one (value_type (arg1
));
2694 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2695 arg2
= value_binop (tmp
, arg2
, BINOP_SUB
);
2698 return value_assign (arg1
, arg2
);
2701 case UNOP_POSTINCREMENT
:
2702 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2703 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2705 else if (unop_user_defined_p (op
, arg1
))
2707 return value_x_unop (arg1
, op
, noside
);
2711 arg3
= value_non_lval (arg1
);
2713 if (ptrmath_type_p (exp
->language_defn
, value_type (arg1
)))
2714 arg2
= value_ptradd (arg1
, 1);
2717 struct value
*tmp
= arg1
;
2719 arg2
= value_one (value_type (arg1
));
2720 binop_promote (exp
->language_defn
, exp
->gdbarch
, &tmp
, &arg2
);
2721 arg2
= value_binop (tmp
, arg2
, BINOP_ADD
);
2724 value_assign (arg1
, arg2
);
2728 case UNOP_POSTDECREMENT
:
2729 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2730 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2732 else if (unop_user_defined_p (op
, arg1
))
2734 return value_x_unop (arg1
, op
, noside
);
2738 arg3
= value_non_lval (arg1
);
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_SUB
);
2751 value_assign (arg1
, arg2
);
2757 return value_of_this (exp
->language_defn
);
2760 /* The value is not supposed to be used. This is here to make it
2761 easier to accommodate expressions that contain types. */
2763 if (noside
== EVAL_SKIP
)
2765 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2767 struct type
*type
= exp
->elts
[pc
+ 1].type
;
2769 /* If this is a typedef, then find its immediate target. We
2770 use check_typedef to resolve stubs, but we ignore its
2771 result because we do not want to dig past all
2773 check_typedef (type
);
2774 if (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
2775 type
= TYPE_TARGET_TYPE (type
);
2776 return allocate_value (type
);
2779 error (_("Attempt to use a type name as an expression"));
2783 if (noside
== EVAL_SKIP
)
2785 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
2788 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2790 enum exp_opcode sub_op
= exp
->elts
[*pos
].opcode
;
2791 struct value
*result
;
2793 result
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
2794 EVAL_AVOID_SIDE_EFFECTS
);
2796 /* 'decltype' has special semantics for lvalues. */
2797 if (op
== OP_DECLTYPE
2798 && (sub_op
== BINOP_SUBSCRIPT
2799 || sub_op
== STRUCTOP_MEMBER
2800 || sub_op
== STRUCTOP_MPTR
2801 || sub_op
== UNOP_IND
2802 || sub_op
== STRUCTOP_STRUCT
2803 || sub_op
== STRUCTOP_PTR
2804 || sub_op
== OP_SCOPE
))
2806 struct type
*type
= value_type (result
);
2808 if (TYPE_CODE (check_typedef (type
)) != TYPE_CODE_REF
)
2810 type
= lookup_reference_type (type
);
2811 result
= allocate_value (type
);
2818 error (_("Attempt to use a type as an expression"));
2821 /* Removing this case and compiling with gcc -Wall reveals that
2822 a lot of cases are hitting this case. Some of these should
2823 probably be removed from expression.h; others are legitimate
2824 expressions which are (apparently) not fully implemented.
2826 If there are any cases landing here which mean a user error,
2827 then they should be separate cases, with more descriptive
2830 error (_("GDB does not (yet) know how to "
2831 "evaluate that kind of expression"));
2835 return value_from_longest (builtin_type (exp
->gdbarch
)->builtin_int
, 1);
2838 /* Evaluate a subexpression of EXP, at index *POS,
2839 and return the address of that subexpression.
2840 Advance *POS over the subexpression.
2841 If the subexpression isn't an lvalue, get an error.
2842 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
2843 then only the type of the result need be correct. */
2845 static struct value
*
2846 evaluate_subexp_for_address (struct expression
*exp
, int *pos
,
2856 op
= exp
->elts
[pc
].opcode
;
2862 x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2864 /* We can't optimize out "&*" if there's a user-defined operator*. */
2865 if (unop_user_defined_p (op
, x
))
2867 x
= value_x_unop (x
, op
, noside
);
2868 goto default_case_after_eval
;
2871 return coerce_array (x
);
2875 return value_cast (lookup_pointer_type (exp
->elts
[pc
+ 1].type
),
2876 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
2878 case UNOP_MEMVAL_TYPE
:
2883 x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2884 type
= value_type (x
);
2885 return value_cast (lookup_pointer_type (type
),
2886 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
2890 var
= exp
->elts
[pc
+ 2].symbol
;
2892 /* C++: The "address" of a reference should yield the address
2893 * of the object pointed to. Let value_addr() deal with it. */
2894 if (TYPE_CODE (SYMBOL_TYPE (var
)) == TYPE_CODE_REF
)
2898 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2901 lookup_pointer_type (SYMBOL_TYPE (var
));
2902 enum address_class sym_class
= SYMBOL_CLASS (var
);
2904 if (sym_class
== LOC_CONST
2905 || sym_class
== LOC_CONST_BYTES
2906 || sym_class
== LOC_REGISTER
)
2907 error (_("Attempt to take address of register or constant."));
2910 value_zero (type
, not_lval
);
2913 return address_of_variable (var
, exp
->elts
[pc
+ 1].block
);
2916 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
2917 (*pos
) += 5 + BYTES_TO_EXP_ELEM (tem
+ 1);
2918 x
= value_aggregate_elt (exp
->elts
[pc
+ 1].type
,
2919 &exp
->elts
[pc
+ 3].string
,
2922 error (_("There is no field named %s"), &exp
->elts
[pc
+ 3].string
);
2927 x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2928 default_case_after_eval
:
2929 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2931 struct type
*type
= check_typedef (value_type (x
));
2933 if (VALUE_LVAL (x
) == lval_memory
|| value_must_coerce_to_target (x
))
2934 return value_zero (lookup_pointer_type (value_type (x
)),
2936 else if (TYPE_CODE (type
) == TYPE_CODE_REF
)
2937 return value_zero (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
2940 error (_("Attempt to take address of "
2941 "value not located in memory."));
2943 return value_addr (x
);
2947 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
2948 When used in contexts where arrays will be coerced anyway, this is
2949 equivalent to `evaluate_subexp' but much faster because it avoids
2950 actually fetching array contents (perhaps obsolete now that we have
2953 Note that we currently only do the coercion for C expressions, where
2954 arrays are zero based and the coercion is correct. For other languages,
2955 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
2956 to decide if coercion is appropriate. */
2959 evaluate_subexp_with_coercion (struct expression
*exp
,
2960 int *pos
, enum noside noside
)
2969 op
= exp
->elts
[pc
].opcode
;
2974 var
= exp
->elts
[pc
+ 2].symbol
;
2975 type
= check_typedef (SYMBOL_TYPE (var
));
2976 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
2977 && !TYPE_VECTOR (type
)
2978 && CAST_IS_CONVERSION (exp
->language_defn
))
2981 val
= address_of_variable (var
, exp
->elts
[pc
+ 1].block
);
2982 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
2988 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2992 /* Evaluate a subexpression of EXP, at index *POS,
2993 and return a value for the size of that subexpression.
2994 Advance *POS over the subexpression. */
2996 static struct value
*
2997 evaluate_subexp_for_sizeof (struct expression
*exp
, int *pos
)
2999 /* FIXME: This should be size_t. */
3000 struct type
*size_type
= builtin_type (exp
->gdbarch
)->builtin_int
;
3007 op
= exp
->elts
[pc
].opcode
;
3011 /* This case is handled specially
3012 so that we avoid creating a value for the result type.
3013 If the result type is very big, it's desirable not to
3014 create a value unnecessarily. */
3017 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3018 type
= check_typedef (value_type (val
));
3019 if (TYPE_CODE (type
) != TYPE_CODE_PTR
3020 && TYPE_CODE (type
) != TYPE_CODE_REF
3021 && TYPE_CODE (type
) != TYPE_CODE_ARRAY
)
3022 error (_("Attempt to take contents of a non-pointer value."));
3023 type
= check_typedef (TYPE_TARGET_TYPE (type
));
3024 return value_from_longest (size_type
, (LONGEST
) TYPE_LENGTH (type
));
3028 type
= check_typedef (exp
->elts
[pc
+ 1].type
);
3029 return value_from_longest (size_type
, (LONGEST
) TYPE_LENGTH (type
));
3031 case UNOP_MEMVAL_TYPE
:
3033 val
= evaluate_subexp (NULL
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3034 type
= check_typedef (value_type (val
));
3035 return value_from_longest (size_type
, (LONGEST
) TYPE_LENGTH (type
));
3039 type
= check_typedef (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
));
3041 value_from_longest (size_type
, (LONGEST
) TYPE_LENGTH (type
));
3044 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
3045 return value_from_longest (size_type
,
3046 (LONGEST
) TYPE_LENGTH (value_type (val
)));
3050 /* Parse a type expression in the string [P..P+LENGTH). */
3053 parse_and_eval_type (char *p
, int length
)
3055 char *tmp
= (char *) alloca (length
+ 4);
3056 struct expression
*expr
;
3059 memcpy (tmp
+ 1, p
, length
);
3060 tmp
[length
+ 1] = ')';
3061 tmp
[length
+ 2] = '0';
3062 tmp
[length
+ 3] = '\0';
3063 expr
= parse_expression (tmp
);
3064 if (expr
->elts
[0].opcode
!= UNOP_CAST
)
3065 error (_("Internal error in eval_type."));
3066 return expr
->elts
[1].type
;
3070 calc_f77_array_dims (struct type
*array_type
)
3073 struct type
*tmp_type
;
3075 if ((TYPE_CODE (array_type
) != TYPE_CODE_ARRAY
))
3076 error (_("Can't get dimensions for a non-array type"));
3078 tmp_type
= array_type
;
3080 while ((tmp_type
= TYPE_TARGET_TYPE (tmp_type
)))
3082 if (TYPE_CODE (tmp_type
) == TYPE_CODE_ARRAY
)