* symtab.h (GLOBAL_BLOCK, STATIC_BLOCK, FIRST_LOCAL_BLOCK): New
[binutils-gdb.git] / gdb / value.h
1 /* Definitions for values of C expressions, for GDB.
2 Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 GDB 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 1, or (at your option)
9 any later version.
10
11 GDB 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.
15
16 You should have received a copy of the GNU General Public License
17 along with GDB; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #if !defined (VALUE_H)
21 #define VALUE_H 1
22 /*
23 * The structure which defines the type of a value. It should never
24 * be possible for a program lval value to survive over a call to the inferior
25 * (ie to be put into the history list or an internal variable).
26 */
27 enum lval_type {
28 /* Not an lval. */
29 not_lval,
30 /* In memory. Could be a saved register. */
31 lval_memory,
32 /* In a register. */
33 lval_register,
34 /* In a gdb internal variable. */
35 lval_internalvar,
36 /* Part of a gdb internal variable (structure field). */
37 lval_internalvar_component,
38 /* In a register series in a frame not the current one, which may have been
39 partially saved or saved in different places (otherwise would be
40 lval_register or lval_memory). */
41 lval_reg_frame_relative,
42 };
43
44 struct value
45 {
46 /* Type of value; either not an lval, or one of the various
47 different possible kinds of lval. */
48 enum lval_type lval;
49 /* Location of value (if lval). */
50 union
51 {
52 /* Address in inferior or byte of registers structure. */
53 CORE_ADDR address;
54 /* Pointer to interrnal variable. */
55 struct internalvar *internalvar;
56 /* Number of register. Only used with
57 lval_reg_frame_relative. */
58 int regnum;
59 } location;
60 /* Describes offset of a value within lval a structure in bytes. */
61 int offset;
62 /* Only used for bitfields; number of bits contained in them. */
63 int bitsize;
64 /* Only used for bitfields; position of start of field. */
65 int bitpos;
66 /* Frame value is relative to. In practice, this address is only
67 used if the value is stored in several registers in other than
68 the current frame, and these registers have not all been saved
69 at the same place in memory. This will be described in the
70 lval enum above as "lval_reg_frame_relative". */
71 CORE_ADDR frame_addr;
72 /* Type of the value. */
73 struct type *type;
74 /* Values are stored in a chain, so that they can be deleted
75 easily over calls to the inferior. Values assigned to internal
76 variables or put into the value history are taken off this
77 list. */
78 struct value *next;
79 /* If an lval is forced to repeat, a new value is created with
80 these fields set. The new value is not an lval. */
81 short repeated;
82 short repetitions;
83 /* Register number if the value is from a register. Is not kept
84 if you take a field of a structure that is stored in a
85 register. Shouldn't it be? */
86 short regno;
87 /* If zero, contents of this value are in the contents field.
88 If nonzero, contents are in inferior memory at address
89 in the location.address field plus the offset field
90 (and the lval field should be lval_memory). */
91 char lazy;
92 /* If nonzero, this is the value of a variable which does not
93 actually exist in the program. */
94 char optimized_out;
95 /* Actual contents of the value. For use of this value; setting
96 it uses the stuff above. Not valid if lazy is nonzero.
97 Target byte-order. We force it to be aligned properly for any
98 possible value. */
99 union {
100 long contents[1];
101 double force_double_align;
102 #ifdef LONG_LONG
103 long long force_longlong_align;
104 #endif
105 } aligner;
106
107 };
108
109 typedef struct value *value;
110
111 #define VALUE_TYPE(val) (val)->type
112 #define VALUE_LAZY(val) (val)->lazy
113 /* VALUE_CONTENTS and VALUE_CONTENTS_RAW both return the address of
114 the gdb buffer used to hold a copy of the contents of the lval.
115 VALUE_CONTENTS is used when the contents of the buffer are needed --
116 it uses value_fetch_lazy() to load the buffer from the process being
117 debugged if it hasn't already been loaded. VALUE_CONTENTS_RAW is
118 used when data is being stored into the buffer, or when it is
119 certain that the contents of the buffer are valid. */
120 #define VALUE_CONTENTS_RAW(val) ((char *) (val)->aligner.contents)
121 #define VALUE_CONTENTS(val) ((void)(VALUE_LAZY(val) && value_fetch_lazy(val)),\
122 VALUE_CONTENTS_RAW(val))
123 extern int value_fetch_lazy ();
124 #define VALUE_LVAL(val) (val)->lval
125 #define VALUE_ADDRESS(val) (val)->location.address
126 #define VALUE_INTERNALVAR(val) (val)->location.internalvar
127 #define VALUE_FRAME_REGNUM(val) ((val)->location.regnum)
128 #define VALUE_FRAME(val) ((val)->frame_addr)
129 #define VALUE_OFFSET(val) (val)->offset
130 #define VALUE_BITSIZE(val) (val)->bitsize
131 #define VALUE_BITPOS(val) (val)->bitpos
132 #define VALUE_NEXT(val) (val)->next
133 #define VALUE_REPEATED(val) (val)->repeated
134 #define VALUE_REPETITIONS(val) (val)->repetitions
135 #define VALUE_REGNO(val) (val)->regno
136 #define VALUE_OPTIMIZED_OUT(val) ((val)->optimized_out)
137
138 /* Convert a REF to the object referenced. */
139
140 #define COERCE_REF(arg) \
141 { if (TYPE_CODE ( VALUE_TYPE (arg)) == TYPE_CODE_REF) \
142 arg = value_at_lazy (TYPE_TARGET_TYPE (VALUE_TYPE (arg)), \
143 unpack_long (VALUE_TYPE (arg), \
144 VALUE_CONTENTS (arg)));}
145
146 /* If ARG is an array, convert it to a pointer.
147 If ARG is an enum, convert it to an integer.
148 If ARG is a function, convert it to a function pointer.
149
150 References are dereferenced. */
151
152 #define COERCE_ARRAY(arg) \
153 { COERCE_REF(arg); \
154 if (VALUE_REPEATED (arg) \
155 || TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_ARRAY) \
156 arg = value_coerce_array (arg); \
157 if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_FUNC) \
158 arg = value_coerce_function (arg); \
159 if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_ENUM) \
160 arg = value_cast (builtin_type_unsigned_int, arg); \
161 }
162
163 /* If ARG is an enum, convert it to an integer. */
164
165 #define COERCE_ENUM(arg) \
166 { if (TYPE_CODE ( VALUE_TYPE (arg)) == TYPE_CODE_REF) \
167 arg = value_ind (arg); \
168 if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_ENUM) \
169 arg = value_cast (builtin_type_unsigned_int, arg); \
170 }
171
172 /* Internal variables (variables for convenience of use of debugger)
173 are recorded as a chain of these structures. */
174
175 struct internalvar
176 {
177 struct internalvar *next;
178 char *name;
179 value value;
180 };
181 \f
182 #include "symtab.h"
183 LONGEST value_as_long ();
184 double value_as_double ();
185 LONGEST unpack_long ();
186 double unpack_double ();
187 long unpack_field_as_long ();
188 value value_from_long ();
189 value value_from_double ();
190 value value_at ();
191 value value_at_lazy ();
192 value value_from_register ();
193 value value_of_variable ();
194 value value_of_register ();
195 value read_var_value ();
196 value locate_var_value ();
197 value allocate_value ();
198 value allocate_repeat_value ();
199 value value_string ();
200
201 value value_binop ();
202 value value_add ();
203 value value_sub ();
204 value value_coerce_array ();
205 value value_coerce_function ();
206 value value_ind ();
207 value value_addr ();
208 value value_assign ();
209 value value_neg ();
210 value value_lognot ();
211 value value_struct_elt (), value_struct_elt_for_address ();
212 value value_field (), value_primitive_field ();
213 value value_cast ();
214 value value_zero ();
215 value value_repeat ();
216 value value_subscript ();
217
218 value value_being_returned ();
219 int using_struct_return ();
220 void set_return_value ();
221
222 value evaluate_expression ();
223 value evaluate_type ();
224 value parse_and_eval ();
225 value parse_to_comma_and_eval ();
226 extern CORE_ADDR parse_and_eval_address ();
227 extern CORE_ADDR parse_and_eval_address_1 ();
228
229 value access_value_history ();
230 value value_of_internalvar ();
231 void set_internalvar ();
232 void set_internalvar_component ();
233 struct internalvar *lookup_internalvar ();
234
235 int value_equal ();
236 int value_less ();
237 int value_zerop ();
238
239 /* C++ */
240 value value_of_this ();
241 value value_static_field ();
242 value value_x_binop ();
243 value value_x_unop ();
244 value value_fn_field ();
245 value value_virtual_fn_field ();
246 value value_static_field ();
247 int binop_user_defined_p ();
248 int unop_user_defined_p ();
249 int typecmp ();
250 int fill_in_vptr_fieldno ();
251 int destructor_name_p ();
252
253 #define value_free(val) free (val)
254 void free_all_values ();
255 void release_value ();
256 int record_latest_value ();
257
258 void registers_changed ();
259 void read_register_bytes ();
260 void write_register_bytes ();
261 void read_register_gen ();
262 CORE_ADDR read_register ();
263 void write_register ();
264 void supply_register ();
265 void get_saved_register ();
266
267 void modify_field ();
268 void type_print ();
269 void type_print_1 ();
270
271 /* Possibilities for prettyprint parameters to routines which print
272 things. */
273 enum val_prettyprint {
274 Val_no_prettyprint = 0,
275 Val_prettyprint,
276 /* Use the default setting which the user has specified. */
277 Val_pretty_default
278 };
279
280 char *baseclass_addr ();
281 void print_floating ();
282 int value_print ();
283 int val_print ();
284 void print_variable_value ();
285 char *internalvar_name ();
286 void clear_value_history ();
287 void clear_internalvars ();
288
289 #endif /* value.h not already included. */