1 /* Definitions for values of C expressions, for GDB.
2 Copyright 1986, 1987, 1989, 1992 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20 #if !defined (VALUE_H)
24 * The structure which defines the type of a value. It should never
25 * be possible for a program lval value to survive over a call to the inferior
26 * (ie to be put into the history list or an internal variable).
31 /* In memory. Could be a saved register. */
35 /* In a gdb internal variable. */
37 /* Part of a gdb internal variable (structure field). */
38 lval_internalvar_component,
39 /* In a register series in a frame not the current one, which may have been
40 partially saved or saved in different places (otherwise would be
41 lval_register or lval_memory). */
42 lval_reg_frame_relative
47 /* Type of value; either not an lval, or one of the various
48 different possible kinds of lval. */
50 /* Location of value (if lval). */
53 /* Address in inferior or byte of registers structure. */
55 /* Pointer to internal variable. */
56 struct internalvar *internalvar;
57 /* Number of register. Only used with
58 lval_reg_frame_relative. */
61 /* Describes offset of a value within lval a structure in bytes. */
63 /* Only used for bitfields; number of bits contained in them. */
65 /* Only used for bitfields; position of start of field.
66 For BITS_BIG_ENDIAN=0 targets, it is the position of the LSB.
67 For BITS_BIG_ENDIAN=1 targets, it is the position of the MSB. */
69 /* Frame value is relative to. In practice, this address is only
70 used if the value is stored in several registers in other than
71 the current frame, and these registers have not all been saved
72 at the same place in memory. This will be described in the
73 lval enum above as "lval_reg_frame_relative". */
75 /* Type of the value. */
77 /* Values are stored in a chain, so that they can be deleted
78 easily over calls to the inferior. Values assigned to internal
79 variables or put into the value history are taken off this
82 /* If an lval is forced to repeat, a new value is created with
83 these fields set. The new value is not an lval. */
86 /* Register number if the value is from a register. Is not kept
87 if you take a field of a structure that is stored in a
88 register. Shouldn't it be? */
90 /* If zero, contents of this value are in the contents field.
91 If nonzero, contents are in inferior memory at address
92 in the location.address field plus the offset field
93 (and the lval field should be lval_memory). */
95 /* If nonzero, this is the value of a variable which does not
96 actually exist in the program. */
98 /* Actual contents of the value. For use of this value; setting
99 it uses the stuff above. Not valid if lazy is nonzero.
100 Target byte-order. We force it to be aligned properly for any
104 double force_double_align;
106 long long force_longlong_align;
112 typedef struct value *value;
114 #define VALUE_TYPE(val) (val)->type
115 #define VALUE_LAZY(val) (val)->lazy
116 /* VALUE_CONTENTS and VALUE_CONTENTS_RAW both return the address of
117 the gdb buffer used to hold a copy of the contents of the lval.
118 VALUE_CONTENTS is used when the contents of the buffer are needed --
119 it uses value_fetch_lazy() to load the buffer from the process being
120 debugged if it hasn't already been loaded. VALUE_CONTENTS_RAW is
121 used when data is being stored into the buffer, or when it is
122 certain that the contents of the buffer are valid. */
123 #define VALUE_CONTENTS_RAW(val) ((char *) (val)->aligner.contents)
124 #define VALUE_CONTENTS(val) ((void)(VALUE_LAZY(val) && value_fetch_lazy(val)),\
125 VALUE_CONTENTS_RAW(val))
127 value_fetch_lazy PARAMS ((value val));
129 #define VALUE_LVAL(val) (val)->lval
130 #define VALUE_ADDRESS(val) (val)->location.address
131 #define VALUE_INTERNALVAR(val) (val)->location.internalvar
132 #define VALUE_FRAME_REGNUM(val) ((val)->location.regnum)
133 #define VALUE_FRAME(val) ((val)->frame_addr)
134 #define VALUE_OFFSET(val) (val)->offset
135 #define VALUE_BITSIZE(val) (val)->bitsize
136 #define VALUE_BITPOS(val) (val)->bitpos
137 #define VALUE_NEXT(val) (val)->next
138 #define VALUE_REPEATED(val) (val)->repeated
139 #define VALUE_REPETITIONS(val) (val)->repetitions
140 #define VALUE_REGNO(val) (val)->regno
141 #define VALUE_OPTIMIZED_OUT(val) ((val)->optimized_out)
143 /* Convert a REF to the object referenced. */
145 #define COERCE_REF(arg) \
146 { if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_REF) \
147 arg = value_at_lazy (TYPE_TARGET_TYPE (VALUE_TYPE (arg)), \
148 unpack_long (VALUE_TYPE (arg), \
149 VALUE_CONTENTS (arg)));}
151 /* If ARG is an array, convert it to a pointer.
152 If ARG is an enum, convert it to an integer.
153 If ARG is a function, convert it to a function pointer.
155 References are dereferenced. */
157 #define COERCE_ARRAY(arg) \
159 if (VALUE_REPEATED (arg) \
160 || TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_ARRAY) \
161 arg = value_coerce_array (arg); \
162 if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_FUNC) \
163 arg = value_coerce_function (arg); \
164 if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_ENUM) \
165 arg = value_cast (builtin_type_unsigned_int, arg); \
168 /* If ARG is an enum, convert it to an integer. */
170 #define COERCE_ENUM(arg) \
171 { if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_REF) \
172 arg = value_ind (arg); \
173 if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_ENUM) \
174 arg = value_cast (builtin_type_unsigned_int, arg); \
177 /* Internal variables (variables for convenience of use of debugger)
178 are recorded as a chain of these structures. */
182 struct internalvar *next;
187 /* Pointer to member function. Depends on compiler implementation. */
189 #define METHOD_PTR_IS_VIRTUAL(ADDR) ((ADDR) & 0x80000000)
190 #define METHOD_PTR_FROM_VOFFSET(OFFSET) (0x80000000 + (OFFSET))
191 #define METHOD_PTR_TO_VOFFSET(ADDR) (~0x80000000 & (ADDR))
195 #include "gdbtypes.h"
196 #include "expression.h"
204 print_address_demangle PARAMS ((CORE_ADDR, FILE *, int));
207 value_as_long PARAMS ((value val));
210 value_as_double PARAMS ((value val));
213 value_as_pointer PARAMS ((value val));
216 unpack_long PARAMS ((struct type *type, char *valaddr));
219 unpack_double PARAMS ((struct type *type, char *valaddr, int *invp));
222 unpack_pointer PARAMS ((struct type *type, char *valaddr));
225 unpack_field_as_long PARAMS ((struct type *type, char *valaddr,
229 value_from_longest PARAMS ((struct type *type, LONGEST num));
232 value_from_double PARAMS ((struct type *type, double num));
235 value_at PARAMS ((struct type *type, CORE_ADDR addr));
238 value_at_lazy PARAMS ((struct type *type, CORE_ADDR addr));
240 /* FIXME: Assumes equivalence of "struct frame_info *" and "FRAME" */
242 value_from_register PARAMS ((struct type *type, int regnum,
243 struct frame_info * frame));
246 value_of_variable PARAMS ((struct symbol *var));
249 value_of_register PARAMS ((int regnum));
251 /* FIXME: Assumes equivalence of "struct frame_info *" and "FRAME" */
253 read_var_value PARAMS ((struct symbol *var, struct frame_info *frame));
255 /* FIXME: Assumes equivalence of "struct frame_info *" and "FRAME" */
257 locate_var_value PARAMS ((struct symbol *var, struct frame_info *frame));
260 allocate_value PARAMS ((struct type *type));
263 allocate_repeat_value PARAMS ((struct type *type, int count));
266 value_mark PARAMS ((void));
269 value_free_to_mark PARAMS ((value mark));
272 value_string PARAMS ((char *ptr, int len));
275 value_binop PARAMS ((value arg1, value arg2, enum exp_opcode op));
278 value_add PARAMS ((value arg1, value arg2));
281 value_sub PARAMS ((value arg1, value arg2));
284 value_coerce_array PARAMS ((value arg1));
287 value_coerce_function PARAMS ((value arg1));
290 value_ind PARAMS ((value arg1));
293 value_addr PARAMS ((value arg1));
296 value_assign PARAMS ((value toval, value fromval));
299 value_neg PARAMS ((value arg1));
302 value_complement PARAMS ((value arg1));
305 value_struct_elt PARAMS ((value *argp, value *args, char *name,
306 int *static_memfuncp, char *err));
309 value_struct_elt_for_reference PARAMS ((struct type *domain,
311 struct type *curtype,
313 struct type *intype));
316 value_field PARAMS ((value arg1, int fieldno));
319 value_primitive_field PARAMS ((value arg1, int offset, int fieldno,
320 struct type *arg_type));
323 value_cast PARAMS ((struct type *type, value arg2));
326 value_zero PARAMS ((struct type *type, enum lval_type lv));
329 value_repeat PARAMS ((value arg1, int count));
332 value_subscript PARAMS ((value array, value idx));
335 value_from_vtable_info PARAMS ((value arg, struct type *type));
338 value_being_returned PARAMS ((struct type *valtype,
339 char retbuf[REGISTER_BYTES],
343 using_struct_return PARAMS ((value function, CORE_ADDR funcaddr,
344 struct type *value_type, int gcc_p));
347 set_return_value PARAMS ((value val));
350 evaluate_expression PARAMS ((struct expression *exp));
353 evaluate_type PARAMS ((struct expression *exp));
356 parse_and_eval PARAMS ((char *exp));
359 parse_to_comma_and_eval PARAMS ((char **expp));
362 parse_and_eval_type PARAMS ((char *p, int length));
365 parse_and_eval_address PARAMS ((char *exp));
368 parse_and_eval_address_1 PARAMS ((char **expptr));
371 access_value_history PARAMS ((int num));
374 value_of_internalvar PARAMS ((struct internalvar *var));
377 set_internalvar PARAMS ((struct internalvar *var, value val));
380 set_internalvar_component PARAMS ((struct internalvar *var, int offset,
381 int bitpos, int bitsize,
384 extern struct internalvar *
385 lookup_internalvar PARAMS ((char *name));
388 value_equal PARAMS ((value arg1, value arg2));
391 value_less PARAMS ((value arg1, value arg2));
394 value_logical_not PARAMS ((value arg1));
399 value_of_this PARAMS ((int complain));
402 value_x_binop PARAMS ((value arg1, value arg2, enum exp_opcode op,
403 enum exp_opcode otherop));
406 value_x_unop PARAMS ((value arg1, enum exp_opcode op));
409 value_fn_field PARAMS ((value *arg1p, struct fn_field *f, int j,
410 struct type* type, int offset));
413 value_virtual_fn_field PARAMS ((value *arg1p, struct fn_field *f, int j,
414 struct type *type, int offset));
417 binop_user_defined_p PARAMS ((enum exp_opcode op, value arg1, value arg2));
420 unop_user_defined_p PARAMS ((enum exp_opcode op, value arg1));
423 typecmp PARAMS ((int staticp, struct type *t1[], value t2[]));
426 destructor_name_p PARAMS ((const char *name, const struct type *type));
428 #define value_free(val) free ((PTR)val)
431 free_all_values PARAMS ((void));
434 release_value PARAMS ((value val));
437 record_latest_value PARAMS ((value val));
440 registers_changed PARAMS ((void));
443 read_register_bytes PARAMS ((int regbyte, char *myaddr, int len));
446 write_register_bytes PARAMS ((int regbyte, char *myaddr, int len));
449 read_register_gen PARAMS ((int regno, char *myaddr));
452 read_register PARAMS ((int regno));
455 write_register PARAMS ((int regno, int val));
458 supply_register PARAMS ((int regno, char *val));
460 /* FIXME: Assumes equivalence of "struct frame_info *" and "FRAME" */
462 get_saved_register PARAMS ((char *raw_buffer, int *optimized,
463 CORE_ADDR *addrp, struct frame_info *frame,
464 int regnum, enum lval_type *lval));
467 modify_field PARAMS ((char *addr, int fieldval, int bitpos, int bitsize));
470 type_print PARAMS ((struct type *type, char *varstring, FILE *stream,
474 baseclass_addr PARAMS ((struct type *type, int index, char *valaddr,
475 value *valuep, int *errp));
478 print_floating PARAMS ((char *valaddr, struct type *type, FILE *stream));
481 value_print PARAMS ((value val, FILE *stream, int format,
482 enum val_prettyprint pretty));
485 val_print PARAMS ((struct type *type, char *valaddr, CORE_ADDR address,
486 FILE *stream, int format, int deref_ref,
487 int recurse, enum val_prettyprint pretty));
490 val_print_string PARAMS ((CORE_ADDR addr, FILE *stream));
492 /* FIXME: Assumes equivalence of "struct frame_info *" and "FRAME" */
494 print_variable_value PARAMS ((struct symbol *var, struct frame_info *frame,
498 value_arg_coerce PARAMS ((value));
501 check_field PARAMS ((value, const char *));
504 c_typedef_print PARAMS ((struct type *type, struct symbol *new, FILE *stream));
507 internalvar_name PARAMS ((struct internalvar *var));
510 clear_value_history PARAMS ((void));
513 clear_internalvars PARAMS ((void));
518 value_copy PARAMS ((value));
521 baseclass_offset PARAMS ((struct type *, int, value, int));
526 call_function_by_hand PARAMS ((value, int, value *));
528 #endif /* !defined (VALUE_H) */