Commit | Line | Data |
---|---|---|
bd5635a1 | 1 | /* Definitions for values of C expressions, for GDB. |
e17960fb | 2 | Copyright 1986, 1987, 1989, 1992 Free Software Foundation, Inc. |
bd5635a1 RP |
3 | |
4 | This file is part of GDB. | |
5 | ||
e17960fb | 6 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 7 | it under the terms of the GNU General Public License as published by |
e17960fb JG |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | |
bd5635a1 | 10 | |
e17960fb | 11 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
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 | |
e17960fb JG |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
bd5635a1 RP |
19 | |
20 | #if !defined (VALUE_H) | |
21 | #define VALUE_H 1 | |
01be6913 | 22 | |
bd5635a1 RP |
23 | /* |
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). | |
27 | */ | |
28 | enum lval_type { | |
29 | /* Not an lval. */ | |
30 | not_lval, | |
31 | /* In memory. Could be a saved register. */ | |
32 | lval_memory, | |
33 | /* In a register. */ | |
34 | lval_register, | |
35 | /* In a gdb internal variable. */ | |
36 | lval_internalvar, | |
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). */ | |
e17960fb | 42 | lval_reg_frame_relative |
bd5635a1 RP |
43 | }; |
44 | ||
45 | struct value | |
46 | { | |
47 | /* Type of value; either not an lval, or one of the various | |
48 | different possible kinds of lval. */ | |
49 | enum lval_type lval; | |
50 | /* Location of value (if lval). */ | |
51 | union | |
52 | { | |
53 | /* Address in inferior or byte of registers structure. */ | |
54 | CORE_ADDR address; | |
35fcebce | 55 | /* Pointer to internal variable. */ |
bd5635a1 RP |
56 | struct internalvar *internalvar; |
57 | /* Number of register. Only used with | |
58 | lval_reg_frame_relative. */ | |
59 | int regnum; | |
60 | } location; | |
61 | /* Describes offset of a value within lval a structure in bytes. */ | |
62 | int offset; | |
63 | /* Only used for bitfields; number of bits contained in them. */ | |
64 | int bitsize; | |
35fcebce PB |
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. */ | |
bd5635a1 RP |
68 | int bitpos; |
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". */ | |
74 | CORE_ADDR frame_addr; | |
75 | /* Type of the value. */ | |
76 | struct type *type; | |
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 | |
80 | list. */ | |
81 | struct value *next; | |
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. */ | |
84 | short repeated; | |
85 | short repetitions; | |
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? */ | |
89 | short regno; | |
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). */ | |
94 | char lazy; | |
95 | /* If nonzero, this is the value of a variable which does not | |
96 | actually exist in the program. */ | |
97 | char optimized_out; | |
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 | |
101 | possible value. */ | |
102 | union { | |
103 | long contents[1]; | |
104 | double force_double_align; | |
105 | #ifdef LONG_LONG | |
106 | long long force_longlong_align; | |
107 | #endif | |
108 | } aligner; | |
109 | ||
110 | }; | |
111 | ||
112 | typedef struct value *value; | |
113 | ||
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)) | |
01be6913 PB |
126 | extern int |
127 | value_fetch_lazy PARAMS ((value val)); | |
128 | ||
bd5635a1 RP |
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) | |
142 | ||
143 | /* Convert a REF to the object referenced. */ | |
144 | ||
145 | #define COERCE_REF(arg) \ | |
e17960fb | 146 | { if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_REF) \ |
bd5635a1 RP |
147 | arg = value_at_lazy (TYPE_TARGET_TYPE (VALUE_TYPE (arg)), \ |
148 | unpack_long (VALUE_TYPE (arg), \ | |
149 | VALUE_CONTENTS (arg)));} | |
150 | ||
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. | |
154 | ||
155 | References are dereferenced. */ | |
156 | ||
157 | #define COERCE_ARRAY(arg) \ | |
158 | { COERCE_REF(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); \ | |
166 | } | |
167 | ||
168 | /* If ARG is an enum, convert it to an integer. */ | |
169 | ||
170 | #define COERCE_ENUM(arg) \ | |
e17960fb | 171 | { if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_REF) \ |
bd5635a1 RP |
172 | arg = value_ind (arg); \ |
173 | if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_ENUM) \ | |
174 | arg = value_cast (builtin_type_unsigned_int, arg); \ | |
175 | } | |
176 | ||
177 | /* Internal variables (variables for convenience of use of debugger) | |
178 | are recorded as a chain of these structures. */ | |
179 | ||
180 | struct internalvar | |
181 | { | |
182 | struct internalvar *next; | |
183 | char *name; | |
184 | value value; | |
185 | }; | |
01be6913 | 186 | |
35fcebce PB |
187 | /* Pointer to member function. Depends on compiler implementation. */ |
188 | ||
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)) | |
192 | ||
bd5635a1 RP |
193 | \f |
194 | #include "symtab.h" | |
01be6913 PB |
195 | #include "gdbtypes.h" |
196 | #include "expression.h" | |
197 | ||
e17960fb | 198 | #ifdef __STDC__ |
01be6913 | 199 | struct frame_info; |
e17960fb | 200 | #endif |
01be6913 PB |
201 | |
202 | extern void | |
203 | print_address_demangle PARAMS ((CORE_ADDR, FILE *, int)); | |
204 | ||
205 | extern LONGEST | |
206 | value_as_long PARAMS ((value val)); | |
207 | ||
208 | extern double | |
209 | value_as_double PARAMS ((value val)); | |
210 | ||
211 | extern CORE_ADDR | |
212 | value_as_pointer PARAMS ((value val)); | |
213 | ||
214 | extern LONGEST | |
215 | unpack_long PARAMS ((struct type *type, char *valaddr)); | |
216 | ||
217 | extern double | |
218 | unpack_double PARAMS ((struct type *type, char *valaddr, int *invp)); | |
219 | ||
220 | extern CORE_ADDR | |
221 | unpack_pointer PARAMS ((struct type *type, char *valaddr)); | |
222 | ||
35fcebce | 223 | extern LONGEST |
01be6913 PB |
224 | unpack_field_as_long PARAMS ((struct type *type, char *valaddr, |
225 | int fieldno)); | |
226 | ||
227 | extern value | |
228 | value_from_longest PARAMS ((struct type *type, LONGEST num)); | |
229 | ||
230 | extern value | |
231 | value_from_double PARAMS ((struct type *type, double num)); | |
232 | ||
233 | extern value | |
234 | value_at PARAMS ((struct type *type, CORE_ADDR addr)); | |
235 | ||
236 | extern value | |
237 | value_at_lazy PARAMS ((struct type *type, CORE_ADDR addr)); | |
238 | ||
239 | /* FIXME: Assumes equivalence of "struct frame_info *" and "FRAME" */ | |
240 | extern value | |
241 | value_from_register PARAMS ((struct type *type, int regnum, | |
242 | struct frame_info * frame)); | |
243 | ||
244 | extern value | |
245 | value_of_variable PARAMS ((struct symbol *var)); | |
246 | ||
247 | extern value | |
248 | value_of_register PARAMS ((int regnum)); | |
249 | ||
250 | /* FIXME: Assumes equivalence of "struct frame_info *" and "FRAME" */ | |
251 | extern value | |
252 | read_var_value PARAMS ((struct symbol *var, struct frame_info *frame)); | |
253 | ||
254 | /* FIXME: Assumes equivalence of "struct frame_info *" and "FRAME" */ | |
255 | extern value | |
256 | locate_var_value PARAMS ((struct symbol *var, struct frame_info *frame)); | |
257 | ||
258 | extern value | |
259 | allocate_value PARAMS ((struct type *type)); | |
260 | ||
261 | extern value | |
262 | allocate_repeat_value PARAMS ((struct type *type, int count)); | |
263 | ||
264 | extern value | |
265 | value_mark PARAMS ((void)); | |
266 | ||
267 | extern void | |
268 | value_free_to_mark PARAMS ((value mark)); | |
269 | ||
270 | extern value | |
271 | value_string PARAMS ((char *ptr, int len)); | |
272 | ||
273 | extern value | |
274 | value_binop PARAMS ((value arg1, value arg2, enum exp_opcode op)); | |
275 | ||
276 | extern value | |
277 | value_add PARAMS ((value arg1, value arg2)); | |
278 | ||
279 | extern value | |
280 | value_sub PARAMS ((value arg1, value arg2)); | |
281 | ||
282 | extern value | |
283 | value_coerce_array PARAMS ((value arg1)); | |
284 | ||
285 | extern value | |
286 | value_coerce_function PARAMS ((value arg1)); | |
287 | ||
288 | extern value | |
289 | value_ind PARAMS ((value arg1)); | |
290 | ||
291 | extern value | |
292 | value_addr PARAMS ((value arg1)); | |
293 | ||
294 | extern value | |
295 | value_assign PARAMS ((value toval, value fromval)); | |
296 | ||
297 | extern value | |
298 | value_neg PARAMS ((value arg1)); | |
299 | ||
300 | extern value | |
301 | value_lognot PARAMS ((value arg1)); | |
302 | ||
303 | extern value | |
304 | value_struct_elt PARAMS ((value *argp, value *args, char *name, | |
305 | int *static_memfuncp, char *err)); | |
306 | ||
307 | extern value | |
308 | value_struct_elt_for_reference PARAMS ((struct type *domain, | |
35fcebce | 309 | int offset, |
01be6913 PB |
310 | struct type *curtype, |
311 | char *name, | |
312 | struct type *intype)); | |
313 | ||
314 | extern value | |
315 | value_field PARAMS ((value arg1, int fieldno)); | |
316 | ||
317 | extern value | |
318 | value_primitive_field PARAMS ((value arg1, int offset, int fieldno, | |
319 | struct type *arg_type)); | |
320 | ||
321 | extern value | |
322 | value_cast PARAMS ((struct type *type, value arg2)); | |
323 | ||
324 | extern value | |
325 | value_zero PARAMS ((struct type *type, enum lval_type lv)); | |
326 | ||
327 | extern value | |
328 | value_repeat PARAMS ((value arg1, int count)); | |
329 | ||
330 | extern value | |
331 | value_subscript PARAMS ((value array, value idx)); | |
332 | ||
333 | extern value | |
334 | value_from_vtable_info PARAMS ((value arg, struct type *type)); | |
335 | ||
336 | extern value | |
337 | value_being_returned PARAMS ((struct type *valtype, | |
338 | char retbuf[REGISTER_BYTES], | |
339 | int struct_return)); | |
340 | ||
341 | extern int | |
342 | using_struct_return PARAMS ((value function, CORE_ADDR funcaddr, | |
343 | struct type *value_type, int gcc_p)); | |
344 | ||
345 | extern void | |
346 | set_return_value PARAMS ((value val)); | |
347 | ||
348 | extern value | |
349 | evaluate_expression PARAMS ((struct expression *exp)); | |
350 | ||
351 | extern value | |
352 | evaluate_type PARAMS ((struct expression *exp)); | |
353 | ||
354 | extern value | |
355 | parse_and_eval PARAMS ((char *exp)); | |
356 | ||
357 | extern value | |
358 | parse_to_comma_and_eval PARAMS ((char **expp)); | |
359 | ||
360 | extern struct type * | |
361 | parse_and_eval_type PARAMS ((char *p, int length)); | |
362 | ||
363 | extern CORE_ADDR | |
364 | parse_and_eval_address PARAMS ((char *exp)); | |
365 | ||
366 | extern CORE_ADDR | |
367 | parse_and_eval_address_1 PARAMS ((char **expptr)); | |
368 | ||
369 | extern value | |
370 | access_value_history PARAMS ((int num)); | |
371 | ||
372 | extern value | |
373 | value_of_internalvar PARAMS ((struct internalvar *var)); | |
374 | ||
375 | extern void | |
376 | set_internalvar PARAMS ((struct internalvar *var, value val)); | |
377 | ||
378 | extern void | |
379 | set_internalvar_component PARAMS ((struct internalvar *var, int offset, | |
380 | int bitpos, int bitsize, | |
381 | value newvalue)); | |
382 | ||
383 | extern struct internalvar * | |
384 | lookup_internalvar PARAMS ((char *name)); | |
385 | ||
386 | extern int | |
387 | value_equal PARAMS ((value arg1, value arg2)); | |
388 | ||
389 | extern int | |
390 | value_less PARAMS ((value arg1, value arg2)); | |
391 | ||
392 | extern int | |
393 | value_zerop PARAMS ((value arg1)); | |
bd5635a1 RP |
394 | |
395 | /* C++ */ | |
01be6913 PB |
396 | |
397 | extern value | |
398 | value_of_this PARAMS ((int complain)); | |
399 | ||
400 | extern value | |
401 | value_x_binop PARAMS ((value arg1, value arg2, enum exp_opcode op, | |
402 | enum exp_opcode otherop)); | |
403 | ||
404 | extern value | |
405 | value_x_unop PARAMS ((value arg1, enum exp_opcode op)); | |
406 | ||
407 | extern value | |
35fcebce PB |
408 | value_fn_field PARAMS ((value *arg1p, struct fn_field *f, int j, |
409 | struct type* type, int offset)); | |
01be6913 PB |
410 | |
411 | extern value | |
35fcebce PB |
412 | value_virtual_fn_field PARAMS ((value *arg1p, struct fn_field *f, int j, |
413 | struct type *type, int offset)); | |
01be6913 PB |
414 | |
415 | extern int | |
416 | binop_user_defined_p PARAMS ((enum exp_opcode op, value arg1, value arg2)); | |
417 | ||
418 | extern int | |
419 | unop_user_defined_p PARAMS ((enum exp_opcode op, value arg1)); | |
420 | ||
421 | extern int | |
422 | typecmp PARAMS ((int staticp, struct type *t1[], value t2[])); | |
423 | ||
424 | extern int | |
425 | destructor_name_p PARAMS ((const char *name, const struct type *type)); | |
bd5635a1 | 426 | |
35fcebce | 427 | #define value_free(val) free ((PTR)val) |
01be6913 PB |
428 | |
429 | extern void | |
430 | free_all_values PARAMS ((void)); | |
431 | ||
432 | extern void | |
433 | release_value PARAMS ((value val)); | |
434 | ||
435 | extern int | |
436 | record_latest_value PARAMS ((value val)); | |
437 | ||
438 | extern void | |
439 | registers_changed PARAMS ((void)); | |
440 | ||
441 | extern void | |
442 | read_register_bytes PARAMS ((int regbyte, char *myaddr, int len)); | |
443 | ||
444 | extern void | |
445 | write_register_bytes PARAMS ((int regbyte, char *myaddr, int len)); | |
446 | ||
447 | extern void | |
448 | read_register_gen PARAMS ((int regno, char *myaddr)); | |
449 | ||
450 | extern CORE_ADDR | |
451 | read_register PARAMS ((int regno)); | |
452 | ||
453 | extern void | |
454 | write_register PARAMS ((int regno, int val)); | |
455 | ||
456 | extern void | |
457 | supply_register PARAMS ((int regno, char *val)); | |
458 | ||
459 | /* FIXME: Assumes equivalence of "struct frame_info *" and "FRAME" */ | |
460 | extern void | |
461 | get_saved_register PARAMS ((char *raw_buffer, int *optimized, | |
462 | CORE_ADDR *addrp, struct frame_info *frame, | |
463 | int regnum, enum lval_type *lval)); | |
464 | ||
465 | extern void | |
466 | modify_field PARAMS ((char *addr, int fieldval, int bitpos, int bitsize)); | |
467 | ||
468 | extern void | |
469 | type_print PARAMS ((struct type *type, char *varstring, FILE *stream, | |
470 | int show)); | |
471 | ||
472 | extern void | |
473 | type_print_1 PARAMS ((struct type *type, char *varstring, FILE *stream, | |
474 | int show, int level)); | |
bd5635a1 RP |
475 | |
476 | /* Possibilities for prettyprint parameters to routines which print | |
477 | things. */ | |
478 | enum val_prettyprint { | |
479 | Val_no_prettyprint = 0, | |
480 | Val_prettyprint, | |
481 | /* Use the default setting which the user has specified. */ | |
482 | Val_pretty_default | |
483 | }; | |
484 | ||
01be6913 PB |
485 | extern char * |
486 | baseclass_addr PARAMS ((struct type *type, int index, char *valaddr, | |
487 | value *valuep, int *errp)); | |
488 | ||
489 | extern void | |
490 | print_floating PARAMS ((char *valaddr, struct type *type, FILE *stream)); | |
491 | ||
492 | extern int | |
493 | value_print PARAMS ((value val, FILE *stream, int format, | |
494 | enum val_prettyprint pretty)); | |
495 | ||
496 | extern int | |
497 | val_print PARAMS ((struct type *type, char *valaddr, CORE_ADDR address, | |
498 | FILE *stream, int format, int deref_ref, | |
499 | int recurse, enum val_prettyprint pretty)); | |
500 | ||
501 | /* FIXME: Assumes equivalence of "struct frame_info *" and "FRAME" */ | |
502 | extern void | |
503 | print_variable_value PARAMS ((struct symbol *var, struct frame_info *frame, | |
504 | FILE *stream)); | |
505 | ||
506 | extern value | |
507 | value_arg_coerce PARAMS ((value)); | |
508 | ||
509 | extern int | |
510 | check_field PARAMS ((value, const char *)); | |
511 | ||
512 | extern void | |
513 | typedef_print PARAMS ((struct type *type, struct symbol *new, FILE *stream)); | |
514 | ||
515 | extern char * | |
516 | internalvar_name PARAMS ((struct internalvar *var)); | |
517 | ||
518 | extern void | |
519 | clear_value_history PARAMS ((void)); | |
520 | ||
521 | extern void | |
522 | clear_internalvars PARAMS ((void)); | |
523 | ||
524 | /* From values.c */ | |
525 | ||
526 | extern value | |
527 | value_copy PARAMS ((value)); | |
528 | ||
529 | /* From valops.c */ | |
bd5635a1 | 530 | |
e17960fb | 531 | extern value |
01be6913 | 532 | call_function_by_hand PARAMS ((value, int, value *)); |
e17960fb | 533 | |
01be6913 | 534 | #endif /* !defined (VALUE_H) */ |