Turn value_arch into method
[binutils-gdb.git] / gdb / value.h
1 /* Definitions for values of C expressions, for GDB.
2
3 Copyright (C) 1986-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20 #if !defined (VALUE_H)
21 #define VALUE_H 1
22
23 #include "frame.h" /* For struct frame_id. */
24 #include "extension.h"
25 #include "gdbsupport/gdb_ref_ptr.h"
26 #include "gmp-utils.h"
27
28 struct block;
29 struct expression;
30 struct regcache;
31 struct symbol;
32 struct type;
33 struct ui_file;
34 struct language_defn;
35 struct value_print_options;
36
37 /* Values can be partially 'optimized out' and/or 'unavailable'.
38 These are distinct states and have different string representations
39 and related error strings.
40
41 'unavailable' has a specific meaning in this context. It means the
42 value exists in the program (at the machine level), but GDB has no
43 means to get to it. Such a value is normally printed as
44 <unavailable>. Examples of how to end up with an unavailable value
45 would be:
46
47 - We're inspecting a traceframe, and the memory or registers the
48 debug information says the value lives on haven't been collected.
49
50 - We're inspecting a core dump, the memory or registers the debug
51 information says the value lives aren't present in the dump
52 (that is, we have a partial/trimmed core dump, or we don't fully
53 understand/handle the core dump's format).
54
55 - We're doing live debugging, but the debug API has no means to
56 get at where the value lives in the machine, like e.g., ptrace
57 not having access to some register or register set.
58
59 - Any other similar scenario.
60
61 OTOH, "optimized out" is about what the compiler decided to generate
62 (or not generate). A chunk of a value that was optimized out does
63 not actually exist in the program. There's no way to get at it
64 short of compiling the program differently.
65
66 A register that has not been saved in a frame is likewise considered
67 optimized out, except not-saved registers have a different string
68 representation and related error strings. E.g., we'll print them as
69 <not-saved> instead of <optimized out>, as in:
70
71 (gdb) p/x $rax
72 $1 = <not saved>
73 (gdb) info registers rax
74 rax <not saved>
75
76 If the debug info describes a variable as being in such a register,
77 we'll still print the variable as <optimized out>. IOW, <not saved>
78 is reserved for inspecting registers at the machine level.
79
80 When comparing value contents, optimized out chunks, unavailable
81 chunks, and valid contents data are all considered different. See
82 value_contents_eq for more info.
83 */
84
85 extern bool overload_resolution;
86
87 /* Defines an [OFFSET, OFFSET + LENGTH) range. */
88
89 struct range
90 {
91 /* Lowest offset in the range. */
92 LONGEST offset;
93
94 /* Length of the range. */
95 ULONGEST length;
96
97 /* Returns true if THIS is strictly less than OTHER, useful for
98 searching. We keep ranges sorted by offset and coalesce
99 overlapping and contiguous ranges, so this just compares the
100 starting offset. */
101
102 bool operator< (const range &other) const
103 {
104 return offset < other.offset;
105 }
106
107 /* Returns true if THIS is equal to OTHER. */
108 bool operator== (const range &other) const
109 {
110 return offset == other.offset && length == other.length;
111 }
112 };
113
114 /* Increase VAL's reference count. */
115
116 extern void value_incref (struct value *val);
117
118 /* Decrease VAL's reference count. When the reference count drops to
119 0, VAL will be freed. */
120
121 extern void value_decref (struct value *val);
122
123 /* A policy class to interface gdb::ref_ptr with struct value. */
124
125 struct value_ref_policy
126 {
127 static void incref (struct value *ptr)
128 {
129 value_incref (ptr);
130 }
131
132 static void decref (struct value *ptr)
133 {
134 value_decref (ptr);
135 }
136 };
137
138 /* A gdb:;ref_ptr pointer to a struct value. */
139
140 typedef gdb::ref_ptr<struct value, value_ref_policy> value_ref_ptr;
141
142 /* Note that the fields in this structure are arranged to save a bit
143 of memory. */
144
145 struct value
146 {
147 explicit value (struct type *type_)
148 : m_modifiable (1),
149 m_lazy (1),
150 m_initialized (1),
151 m_stack (0),
152 m_is_zero (false),
153 m_in_history (false),
154 m_type (type_),
155 m_enclosing_type (type_)
156 {
157 }
158
159 ~value ();
160
161 DISABLE_COPY_AND_ASSIGN (value);
162
163 /* Type of the value. */
164 struct type *type () const
165 { return m_type; }
166
167 /* This is being used to change the type of an existing value, that
168 code should instead be creating a new value with the changed type
169 (but possibly shared content). */
170 void deprecated_set_type (struct type *type)
171 { m_type = type; }
172
173 /* Return the gdbarch associated with the value. */
174 struct gdbarch *arch () const;
175
176
177 /* Type of value; either not an lval, or one of the various
178 different possible kinds of lval. */
179 enum lval_type m_lval = not_lval;
180
181 /* Is it modifiable? Only relevant if lval != not_lval. */
182 unsigned int m_modifiable : 1;
183
184 /* If zero, contents of this value are in the contents field. If
185 nonzero, contents are in inferior. If the lval field is lval_memory,
186 the contents are in inferior memory at location.address plus offset.
187 The lval field may also be lval_register.
188
189 WARNING: This field is used by the code which handles watchpoints
190 (see breakpoint.c) to decide whether a particular value can be
191 watched by hardware watchpoints. If the lazy flag is set for
192 some member of a value chain, it is assumed that this member of
193 the chain doesn't need to be watched as part of watching the
194 value itself. This is how GDB avoids watching the entire struct
195 or array when the user wants to watch a single struct member or
196 array element. If you ever change the way lazy flag is set and
197 reset, be sure to consider this use as well! */
198 unsigned int m_lazy : 1;
199
200 /* If value is a variable, is it initialized or not. */
201 unsigned int m_initialized : 1;
202
203 /* If value is from the stack. If this is set, read_stack will be
204 used instead of read_memory to enable extra caching. */
205 unsigned int m_stack : 1;
206
207 /* True if this is a zero value, created by 'value_zero'; false
208 otherwise. */
209 bool m_is_zero : 1;
210
211 /* True if this a value recorded in value history; false otherwise. */
212 bool m_in_history : 1;
213
214 /* Location of value (if lval). */
215 union
216 {
217 /* If lval == lval_memory, this is the address in the inferior */
218 CORE_ADDR address;
219
220 /*If lval == lval_register, the value is from a register. */
221 struct
222 {
223 /* Register number. */
224 int regnum;
225 /* Frame ID of "next" frame to which a register value is relative.
226 If the register value is found relative to frame F, then the
227 frame id of F->next will be stored in next_frame_id. */
228 struct frame_id next_frame_id;
229 } reg;
230
231 /* Pointer to internal variable. */
232 struct internalvar *internalvar;
233
234 /* Pointer to xmethod worker. */
235 struct xmethod_worker *xm_worker;
236
237 /* If lval == lval_computed, this is a set of function pointers
238 to use to access and describe the value, and a closure pointer
239 for them to use. */
240 struct
241 {
242 /* Functions to call. */
243 const struct lval_funcs *funcs;
244
245 /* Closure for those functions to use. */
246 void *closure;
247 } computed;
248 } m_location {};
249
250 /* Describes offset of a value within lval of a structure in target
251 addressable memory units. Note also the member embedded_offset
252 below. */
253 LONGEST m_offset = 0;
254
255 /* Only used for bitfields; number of bits contained in them. */
256 LONGEST m_bitsize = 0;
257
258 /* Only used for bitfields; position of start of field. For
259 little-endian targets, it is the position of the LSB. For
260 big-endian targets, it is the position of the MSB. */
261 LONGEST m_bitpos = 0;
262
263 /* The number of references to this value. When a value is created,
264 the value chain holds a reference, so REFERENCE_COUNT is 1. If
265 release_value is called, this value is removed from the chain but
266 the caller of release_value now has a reference to this value.
267 The caller must arrange for a call to value_free later. */
268 int m_reference_count = 1;
269
270 /* Only used for bitfields; the containing value. This allows a
271 single read from the target when displaying multiple
272 bitfields. */
273 value_ref_ptr m_parent;
274
275 /* Type of the value. */
276 struct type *m_type;
277
278 /* If a value represents a C++ object, then the `type' field gives
279 the object's compile-time type. If the object actually belongs
280 to some class derived from `type', perhaps with other base
281 classes and additional members, then `type' is just a subobject
282 of the real thing, and the full object is probably larger than
283 `type' would suggest.
284
285 If `type' is a dynamic class (i.e. one with a vtable), then GDB
286 can actually determine the object's run-time type by looking at
287 the run-time type information in the vtable. When this
288 information is available, we may elect to read in the entire
289 object, for several reasons:
290
291 - When printing the value, the user would probably rather see the
292 full object, not just the limited portion apparent from the
293 compile-time type.
294
295 - If `type' has virtual base classes, then even printing `type'
296 alone may require reaching outside the `type' portion of the
297 object to wherever the virtual base class has been stored.
298
299 When we store the entire object, `enclosing_type' is the run-time
300 type -- the complete object -- and `embedded_offset' is the
301 offset of `type' within that larger type, in target addressable memory
302 units. The value_contents() macro takes `embedded_offset' into account,
303 so most GDB code continues to see the `type' portion of the value, just
304 as the inferior would.
305
306 If `type' is a pointer to an object, then `enclosing_type' is a
307 pointer to the object's run-time type, and `pointed_to_offset' is
308 the offset in target addressable memory units from the full object
309 to the pointed-to object -- that is, the value `embedded_offset' would
310 have if we followed the pointer and fetched the complete object.
311 (I don't really see the point. Why not just determine the
312 run-time type when you indirect, and avoid the special case? The
313 contents don't matter until you indirect anyway.)
314
315 If we're not doing anything fancy, `enclosing_type' is equal to
316 `type', and `embedded_offset' is zero, so everything works
317 normally. */
318 struct type *m_enclosing_type;
319 LONGEST m_embedded_offset = 0;
320 LONGEST m_pointed_to_offset = 0;
321
322 /* Actual contents of the value. Target byte-order.
323
324 May be nullptr if the value is lazy or is entirely optimized out.
325 Guaranteed to be non-nullptr otherwise. */
326 gdb::unique_xmalloc_ptr<gdb_byte> m_contents;
327
328 /* Unavailable ranges in CONTENTS. We mark unavailable ranges,
329 rather than available, since the common and default case is for a
330 value to be available. This is filled in at value read time.
331 The unavailable ranges are tracked in bits. Note that a contents
332 bit that has been optimized out doesn't really exist in the
333 program, so it can't be marked unavailable either. */
334 std::vector<range> m_unavailable;
335
336 /* Likewise, but for optimized out contents (a chunk of the value of
337 a variable that does not actually exist in the program). If LVAL
338 is lval_register, this is a register ($pc, $sp, etc., never a
339 program variable) that has not been saved in the frame. Not
340 saved registers and optimized-out program variables values are
341 treated pretty much the same, except not-saved registers have a
342 different string representation and related error strings. */
343 std::vector<range> m_optimized_out;
344
345 /* This is only non-zero for values of TYPE_CODE_ARRAY and if the size of
346 the array in inferior memory is greater than max_value_size. If these
347 conditions are met then, when the value is loaded from the inferior
348 GDB will only load a portion of the array into memory, and
349 limited_length will be set to indicate the length in octets that were
350 loaded from the inferior. */
351 ULONGEST m_limited_length = 0;
352 };
353
354 /* Only used for bitfields; number of bits contained in them. */
355
356 extern LONGEST value_bitsize (const struct value *);
357 extern void set_value_bitsize (struct value *, LONGEST bit);
358
359 /* Only used for bitfields; position of start of field. For
360 little-endian targets, it is the position of the LSB. For
361 big-endian targets, it is the position of the MSB. */
362
363 extern LONGEST value_bitpos (const struct value *);
364 extern void set_value_bitpos (struct value *, LONGEST bit);
365
366 /* Only used for bitfields; the containing value. This allows a
367 single read from the target when displaying multiple
368 bitfields. */
369
370 struct value *value_parent (const struct value *);
371 extern void set_value_parent (struct value *value, struct value *parent);
372
373 /* Describes offset of a value within lval of a structure in bytes.
374 If lval == lval_memory, this is an offset to the address. If lval
375 == lval_register, this is a further offset from location.address
376 within the registers structure. Note also the member
377 embedded_offset below. */
378
379 extern LONGEST value_offset (const struct value *);
380 extern void set_value_offset (struct value *, LONGEST offset);
381
382 /* The comment from "struct value" reads: ``Is it modifiable? Only
383 relevant if lval != not_lval.''. Shouldn't the value instead be
384 not_lval and be done with it? */
385
386 extern int deprecated_value_modifiable (const struct value *value);
387
388 /* If a value represents a C++ object, then the `type' field gives the
389 object's compile-time type. If the object actually belongs to some
390 class derived from `type', perhaps with other base classes and
391 additional members, then `type' is just a subobject of the real
392 thing, and the full object is probably larger than `type' would
393 suggest.
394
395 If `type' is a dynamic class (i.e. one with a vtable), then GDB can
396 actually determine the object's run-time type by looking at the
397 run-time type information in the vtable. When this information is
398 available, we may elect to read in the entire object, for several
399 reasons:
400
401 - When printing the value, the user would probably rather see the
402 full object, not just the limited portion apparent from the
403 compile-time type.
404
405 - If `type' has virtual base classes, then even printing `type'
406 alone may require reaching outside the `type' portion of the
407 object to wherever the virtual base class has been stored.
408
409 When we store the entire object, `enclosing_type' is the run-time
410 type -- the complete object -- and `embedded_offset' is the offset
411 of `type' within that larger type, in bytes. The value_contents()
412 macro takes `embedded_offset' into account, so most GDB code
413 continues to see the `type' portion of the value, just as the
414 inferior would.
415
416 If `type' is a pointer to an object, then `enclosing_type' is a
417 pointer to the object's run-time type, and `pointed_to_offset' is
418 the offset in bytes from the full object to the pointed-to object
419 -- that is, the value `embedded_offset' would have if we followed
420 the pointer and fetched the complete object. (I don't really see
421 the point. Why not just determine the run-time type when you
422 indirect, and avoid the special case? The contents don't matter
423 until you indirect anyway.)
424
425 If we're not doing anything fancy, `enclosing_type' is equal to
426 `type', and `embedded_offset' is zero, so everything works
427 normally. */
428
429 extern struct type *value_enclosing_type (const struct value *);
430 extern void set_value_enclosing_type (struct value *val,
431 struct type *new_type);
432
433 /* Returns value_type or value_enclosing_type depending on
434 value_print_options.objectprint.
435
436 If RESOLVE_SIMPLE_TYPES is 0 the enclosing type will be resolved
437 only for pointers and references, else it will be returned
438 for all the types (e.g. structures). This option is useful
439 to prevent retrieving enclosing type for the base classes fields.
440
441 REAL_TYPE_FOUND is used to inform whether the real type was found
442 (or just static type was used). The NULL may be passed if it is not
443 necessary. */
444
445 extern struct type *value_actual_type (struct value *value,
446 int resolve_simple_types,
447 int *real_type_found);
448
449 extern LONGEST value_pointed_to_offset (const struct value *value);
450 extern void set_value_pointed_to_offset (struct value *value, LONGEST val);
451 extern LONGEST value_embedded_offset (const struct value *value);
452 extern void set_value_embedded_offset (struct value *value, LONGEST val);
453
454 /* For lval_computed values, this structure holds functions used to
455 retrieve and set the value (or portions of the value).
456
457 For each function, 'V' is the 'this' pointer: an lval_funcs
458 function F may always assume that the V it receives is an
459 lval_computed value, and has F in the appropriate slot of its
460 lval_funcs structure. */
461
462 struct lval_funcs
463 {
464 /* Fill in VALUE's contents. This is used to "un-lazy" values. If
465 a problem arises in obtaining VALUE's bits, this function should
466 call 'error'. If it is NULL value_fetch_lazy on "un-lazy"
467 non-optimized-out value is an internal error. */
468 void (*read) (struct value *v);
469
470 /* Handle an assignment TOVAL = FROMVAL by writing the value of
471 FROMVAL to TOVAL's location. The contents of TOVAL have not yet
472 been updated. If a problem arises in doing so, this function
473 should call 'error'. If it is NULL such TOVAL assignment is an error as
474 TOVAL is not considered as an lvalue. */
475 void (*write) (struct value *toval, struct value *fromval);
476
477 /* Return true if any part of V is optimized out, false otherwise.
478 This will only be called for lazy values -- if the value has been
479 fetched, then the value's optimized-out bits are consulted
480 instead. */
481 bool (*is_optimized_out) (struct value *v);
482
483 /* If non-NULL, this is used to implement pointer indirection for
484 this value. This method may return NULL, in which case value_ind
485 will fall back to ordinary indirection. */
486 struct value *(*indirect) (struct value *value);
487
488 /* If non-NULL, this is used to implement reference resolving for
489 this value. This method may return NULL, in which case coerce_ref
490 will fall back to ordinary references resolving. */
491 struct value *(*coerce_ref) (const struct value *value);
492
493 /* If non-NULL, this is used to determine whether the indicated bits
494 of VALUE are a synthetic pointer. */
495 int (*check_synthetic_pointer) (const struct value *value,
496 LONGEST offset, int length);
497
498 /* Return a duplicate of VALUE's closure, for use in a new value.
499 This may simply return the same closure, if VALUE's is
500 reference-counted or statically allocated.
501
502 This may be NULL, in which case VALUE's closure is re-used in the
503 new value. */
504 void *(*copy_closure) (const struct value *v);
505
506 /* Drop VALUE's reference to its closure. Maybe this frees the
507 closure; maybe this decrements a reference count; maybe the
508 closure is statically allocated and this does nothing.
509
510 This may be NULL, in which case no action is taken to free
511 VALUE's closure. */
512 void (*free_closure) (struct value *v);
513 };
514
515 /* Create a computed lvalue, with type TYPE, function pointers FUNCS,
516 and closure CLOSURE. */
517
518 extern struct value *allocate_computed_value (struct type *type,
519 const struct lval_funcs *funcs,
520 void *closure);
521
522 extern struct value *allocate_optimized_out_value (struct type *type);
523
524 /* If VALUE is lval_computed, return its lval_funcs structure. */
525
526 extern const struct lval_funcs *value_computed_funcs (const struct value *);
527
528 /* If VALUE is lval_computed, return its closure. The meaning of the
529 returned value depends on the functions VALUE uses. */
530
531 extern void *value_computed_closure (const struct value *value);
532
533 /* If zero, contents of this value are in the contents field. If
534 nonzero, contents are in inferior. If the lval field is lval_memory,
535 the contents are in inferior memory at location.address plus offset.
536 The lval field may also be lval_register.
537
538 WARNING: This field is used by the code which handles watchpoints
539 (see breakpoint.c) to decide whether a particular value can be
540 watched by hardware watchpoints. If the lazy flag is set for some
541 member of a value chain, it is assumed that this member of the
542 chain doesn't need to be watched as part of watching the value
543 itself. This is how GDB avoids watching the entire struct or array
544 when the user wants to watch a single struct member or array
545 element. If you ever change the way lazy flag is set and reset, be
546 sure to consider this use as well! */
547
548 extern int value_lazy (const struct value *);
549 extern void set_value_lazy (struct value *value, int val);
550
551 extern int value_stack (const struct value *);
552 extern void set_value_stack (struct value *value, int val);
553
554 /* Throw an error complaining that the value has been optimized
555 out. */
556
557 extern void error_value_optimized_out (void);
558
559 /* value_contents() and value_contents_raw() both return the address
560 of the gdb buffer used to hold a copy of the contents of the lval.
561 value_contents() is used when the contents of the buffer are needed
562 -- it uses value_fetch_lazy() to load the buffer from the process
563 being debugged if it hasn't already been loaded
564 (value_contents_writeable() is used when a writeable but fetched
565 buffer is required).. value_contents_raw() is used when data is
566 being stored into the buffer, or when it is certain that the
567 contents of the buffer are valid.
568
569 Note: The contents pointer is adjusted by the offset required to
570 get to the real subobject, if the value happens to represent
571 something embedded in a larger run-time object. */
572
573 extern gdb::array_view<gdb_byte> value_contents_raw (struct value *);
574
575 /* Actual contents of the value. For use of this value; setting it
576 uses the stuff above. Not valid if lazy is nonzero. Target
577 byte-order. We force it to be aligned properly for any possible
578 value. Note that a value therefore extends beyond what is
579 declared here. */
580
581 extern gdb::array_view<const gdb_byte> value_contents (struct value *);
582 extern gdb::array_view<gdb_byte> value_contents_writeable (struct value *);
583
584 /* The ALL variants of the above two macros do not adjust the returned
585 pointer by the embedded_offset value. */
586
587 extern gdb::array_view<gdb_byte> value_contents_all_raw (struct value *);
588 extern gdb::array_view<const gdb_byte> value_contents_all (struct value *);
589
590 /* Like value_contents_all, but does not require that the returned
591 bits be valid. This should only be used in situations where you
592 plan to check the validity manually. */
593 extern gdb::array_view<const gdb_byte> value_contents_for_printing (struct value *value);
594
595 /* Like value_contents_for_printing, but accepts a constant value
596 pointer. Unlike value_contents_for_printing however, the pointed
597 value must _not_ be lazy. */
598 extern gdb::array_view<const gdb_byte>
599 value_contents_for_printing_const (const struct value *value);
600
601 extern void value_fetch_lazy (struct value *val);
602
603 /* If nonzero, this is the value of a variable which does not actually
604 exist in the program, at least partially. If the value is lazy,
605 this may fetch it now. */
606 extern int value_optimized_out (struct value *value);
607
608 /* Given a value, return true if any of the contents bits starting at
609 OFFSET and extending for LENGTH bits is optimized out, false
610 otherwise. */
611
612 extern int value_bits_any_optimized_out (const struct value *value,
613 int bit_offset, int bit_length);
614
615 /* Like value_optimized_out, but return true iff the whole value is
616 optimized out. */
617 extern int value_entirely_optimized_out (struct value *value);
618
619 /* Mark VALUE's content bytes starting at OFFSET and extending for
620 LENGTH bytes as optimized out. */
621
622 extern void mark_value_bytes_optimized_out (struct value *value,
623 int offset, int length);
624
625 /* Mark VALUE's content bits starting at OFFSET and extending for
626 LENGTH bits as optimized out. */
627
628 extern void mark_value_bits_optimized_out (struct value *value,
629 LONGEST offset, LONGEST length);
630
631 /* Set or return field indicating whether a variable is initialized or
632 not, based on debugging information supplied by the compiler.
633 1 = initialized; 0 = uninitialized. */
634 extern int value_initialized (const struct value *);
635 extern void set_value_initialized (struct value *, int);
636
637 /* Set COMPONENT's location as appropriate for a component of WHOLE
638 --- regardless of what kind of lvalue WHOLE is. */
639 extern void set_value_component_location (struct value *component,
640 const struct value *whole);
641
642 /* While the following fields are per- VALUE .CONTENT .PIECE (i.e., a
643 single value might have multiple LVALs), this hacked interface is
644 limited to just the first PIECE. Expect further change. */
645 /* Type of value; either not an lval, or one of the various different
646 possible kinds of lval. */
647 extern enum lval_type *deprecated_value_lval_hack (struct value *);
648 #define VALUE_LVAL(val) (*deprecated_value_lval_hack (val))
649
650 /* Like VALUE_LVAL, except the parameter can be const. */
651 extern enum lval_type value_lval_const (const struct value *value);
652
653 /* If lval == lval_memory, return the address in the inferior. If
654 lval == lval_register, return the byte offset into the registers
655 structure. Otherwise, return 0. The returned address
656 includes the offset, if any. */
657 extern CORE_ADDR value_address (const struct value *);
658
659 /* Like value_address, except the result does not include value's
660 offset. */
661 extern CORE_ADDR value_raw_address (const struct value *);
662
663 /* Set the address of a value. */
664 extern void set_value_address (struct value *, CORE_ADDR);
665
666 /* Pointer to internal variable. */
667 extern struct internalvar **deprecated_value_internalvar_hack (struct value *);
668 #define VALUE_INTERNALVAR(val) (*deprecated_value_internalvar_hack (val))
669
670 /* Frame ID of "next" frame to which a register value is relative. A
671 register value is indicated by VALUE_LVAL being set to lval_register.
672 So, if the register value is found relative to frame F, then the
673 frame id of F->next will be stored in VALUE_NEXT_FRAME_ID. */
674 extern struct frame_id *deprecated_value_next_frame_id_hack (struct value *);
675 #define VALUE_NEXT_FRAME_ID(val) (*deprecated_value_next_frame_id_hack (val))
676
677 /* Register number if the value is from a register. */
678 extern int *deprecated_value_regnum_hack (struct value *);
679 #define VALUE_REGNUM(val) (*deprecated_value_regnum_hack (val))
680
681 /* Return value after lval_funcs->coerce_ref (after check_typedef). Return
682 NULL if lval_funcs->coerce_ref is not applicable for whatever reason. */
683
684 extern struct value *coerce_ref_if_computed (const struct value *arg);
685
686 /* Setup a new value type and enclosing value type for dereferenced value VALUE.
687 ENC_TYPE is the new enclosing type that should be set. ORIGINAL_TYPE and
688 ORIGINAL_VAL are the type and value of the original reference or
689 pointer. ORIGINAL_VALUE_ADDRESS is the address within VALUE, that is
690 the address that was dereferenced.
691
692 Note, that VALUE is modified by this function.
693
694 It is a common implementation for coerce_ref and value_ind. */
695
696 extern struct value * readjust_indirect_value_type (struct value *value,
697 struct type *enc_type,
698 const struct type *original_type,
699 struct value *original_val,
700 CORE_ADDR original_value_address);
701
702 /* Convert a REF to the object referenced. */
703
704 extern struct value *coerce_ref (struct value *value);
705
706 /* If ARG is an array, convert it to a pointer.
707 If ARG is a function, convert it to a function pointer.
708
709 References are dereferenced. */
710
711 extern struct value *coerce_array (struct value *value);
712
713 /* Given a value, determine whether the bits starting at OFFSET and
714 extending for LENGTH bits are a synthetic pointer. */
715
716 extern int value_bits_synthetic_pointer (const struct value *value,
717 LONGEST offset, LONGEST length);
718
719 /* Given a value, determine whether the contents bytes starting at
720 OFFSET and extending for LENGTH bytes are available. This returns
721 nonzero if all bytes in the given range are available, zero if any
722 byte is unavailable. */
723
724 extern int value_bytes_available (const struct value *value,
725 LONGEST offset, ULONGEST length);
726
727 /* Given a value, determine whether the contents bits starting at
728 OFFSET and extending for LENGTH bits are available. This returns
729 nonzero if all bits in the given range are available, zero if any
730 bit is unavailable. */
731
732 extern int value_bits_available (const struct value *value,
733 LONGEST offset, ULONGEST length);
734
735 /* Like value_bytes_available, but return false if any byte in the
736 whole object is unavailable. */
737 extern int value_entirely_available (struct value *value);
738
739 /* Like value_entirely_available, but return false if any byte in the
740 whole object is available. */
741 extern int value_entirely_unavailable (struct value *value);
742
743 /* Mark VALUE's content bytes starting at OFFSET and extending for
744 LENGTH bytes as unavailable. */
745
746 extern void mark_value_bytes_unavailable (struct value *value,
747 LONGEST offset, ULONGEST length);
748
749 /* Mark VALUE's content bits starting at OFFSET and extending for
750 LENGTH bits as unavailable. */
751
752 extern void mark_value_bits_unavailable (struct value *value,
753 LONGEST offset, ULONGEST length);
754
755 /* Compare LENGTH bytes of VAL1's contents starting at OFFSET1 with
756 LENGTH bytes of VAL2's contents starting at OFFSET2.
757
758 Note that "contents" refers to the whole value's contents
759 (value_contents_all), without any embedded offset adjustment. For
760 example, to compare a complete object value with itself, including
761 its enclosing type chunk, you'd do:
762
763 int len = check_typedef (value_enclosing_type (val))->length ();
764 value_contents_eq (val, 0, val, 0, len);
765
766 Returns true iff the set of available/valid contents match.
767
768 Optimized-out contents are equal to optimized-out contents, and are
769 not equal to non-optimized-out contents.
770
771 Unavailable contents are equal to unavailable contents, and are not
772 equal to non-unavailable contents.
773
774 For example, if 'x's represent an unavailable byte, and 'V' and 'Z'
775 represent different available/valid bytes, in a value with length
776 16:
777
778 offset: 0 4 8 12 16
779 contents: xxxxVVVVxxxxVVZZ
780
781 then:
782
783 value_contents_eq(val, 0, val, 8, 6) => true
784 value_contents_eq(val, 0, val, 4, 4) => false
785 value_contents_eq(val, 0, val, 8, 8) => false
786 value_contents_eq(val, 4, val, 12, 2) => true
787 value_contents_eq(val, 4, val, 12, 4) => true
788 value_contents_eq(val, 3, val, 4, 4) => true
789
790 If 'x's represent an unavailable byte, 'o' represents an optimized
791 out byte, in a value with length 8:
792
793 offset: 0 4 8
794 contents: xxxxoooo
795
796 then:
797
798 value_contents_eq(val, 0, val, 2, 2) => true
799 value_contents_eq(val, 4, val, 6, 2) => true
800 value_contents_eq(val, 0, val, 4, 4) => true
801
802 We only know whether a value chunk is unavailable or optimized out
803 if we've tried to read it. As this routine is used by printing
804 routines, which may be printing values in the value history, long
805 after the inferior is gone, it works with const values. Therefore,
806 this routine must not be called with lazy values. */
807
808 extern bool value_contents_eq (const struct value *val1, LONGEST offset1,
809 const struct value *val2, LONGEST offset2,
810 LONGEST length);
811
812 /* An overload of value_contents_eq that compares the entirety of both
813 values. */
814
815 extern bool value_contents_eq (const struct value *val1,
816 const struct value *val2);
817
818 /* Read LENGTH addressable memory units starting at MEMADDR into BUFFER,
819 which is (or will be copied to) VAL's contents buffer offset by
820 BIT_OFFSET bits. Marks value contents ranges as unavailable if
821 the corresponding memory is likewise unavailable. STACK indicates
822 whether the memory is known to be stack memory. */
823
824 extern void read_value_memory (struct value *val, LONGEST bit_offset,
825 int stack, CORE_ADDR memaddr,
826 gdb_byte *buffer, size_t length);
827
828 /* Cast SCALAR_VALUE to the element type of VECTOR_TYPE, then replicate
829 into each element of a new vector value with VECTOR_TYPE. */
830
831 struct value *value_vector_widen (struct value *scalar_value,
832 struct type *vector_type);
833
834 \f
835
836 #include "symtab.h"
837 #include "gdbtypes.h"
838 #include "expression.h"
839
840 class frame_info_ptr;
841 struct fn_field;
842
843 extern int print_address_demangle (const struct value_print_options *,
844 struct gdbarch *, CORE_ADDR,
845 struct ui_file *, int);
846
847 /* Returns true if VAL is of floating-point type. In addition,
848 throws an error if the value is an invalid floating-point value. */
849 extern bool is_floating_value (struct value *val);
850
851 extern LONGEST value_as_long (struct value *val);
852 extern CORE_ADDR value_as_address (struct value *val);
853
854 extern LONGEST unpack_long (struct type *type, const gdb_byte *valaddr);
855 extern CORE_ADDR unpack_pointer (struct type *type, const gdb_byte *valaddr);
856
857 extern LONGEST unpack_field_as_long (struct type *type,
858 const gdb_byte *valaddr,
859 int fieldno);
860
861 /* Unpack a bitfield of the specified FIELD_TYPE, from the object at
862 VALADDR, and store the result in *RESULT.
863 The bitfield starts at BITPOS bits and contains BITSIZE bits; if
864 BITSIZE is zero, then the length is taken from FIELD_TYPE.
865
866 Extracting bits depends on endianness of the machine. Compute the
867 number of least significant bits to discard. For big endian machines,
868 we compute the total number of bits in the anonymous object, subtract
869 off the bit count from the MSB of the object to the MSB of the
870 bitfield, then the size of the bitfield, which leaves the LSB discard
871 count. For little endian machines, the discard count is simply the
872 number of bits from the LSB of the anonymous object to the LSB of the
873 bitfield.
874
875 If the field is signed, we also do sign extension. */
876
877 extern LONGEST unpack_bits_as_long (struct type *field_type,
878 const gdb_byte *valaddr,
879 LONGEST bitpos, LONGEST bitsize);
880
881 extern int unpack_value_field_as_long (struct type *type, const gdb_byte *valaddr,
882 LONGEST embedded_offset, int fieldno,
883 const struct value *val, LONGEST *result);
884
885 extern void unpack_value_bitfield (struct value *dest_val,
886 LONGEST bitpos, LONGEST bitsize,
887 const gdb_byte *valaddr,
888 LONGEST embedded_offset,
889 const struct value *val);
890
891 extern struct value *value_field_bitfield (struct type *type, int fieldno,
892 const gdb_byte *valaddr,
893 LONGEST embedded_offset,
894 const struct value *val);
895
896 extern void pack_long (gdb_byte *buf, struct type *type, LONGEST num);
897
898 extern struct value *value_from_longest (struct type *type, LONGEST num);
899 extern struct value *value_from_ulongest (struct type *type, ULONGEST num);
900 extern struct value *value_from_pointer (struct type *type, CORE_ADDR addr);
901 extern struct value *value_from_host_double (struct type *type, double d);
902 extern struct value *value_from_history_ref (const char *, const char **);
903 extern struct value *value_from_component (struct value *, struct type *,
904 LONGEST);
905
906
907 /* Create a new value by extracting it from WHOLE. TYPE is the type
908 of the new value. BIT_OFFSET and BIT_LENGTH describe the offset
909 and field width of the value to extract from WHOLE -- BIT_LENGTH
910 may differ from TYPE's length in the case where WHOLE's type is
911 packed.
912
913 When the value does come from a non-byte-aligned offset or field
914 width, it will be marked non_lval. */
915
916 extern struct value *value_from_component_bitsize (struct value *whole,
917 struct type *type,
918 LONGEST bit_offset,
919 LONGEST bit_length);
920
921 extern struct value *value_at (struct type *type, CORE_ADDR addr);
922 extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr);
923
924 /* Like value_at, but ensures that the result is marked not_lval.
925 This can be important if the memory is "volatile". */
926 extern struct value *value_at_non_lval (struct type *type, CORE_ADDR addr);
927
928 extern struct value *value_from_contents_and_address_unresolved
929 (struct type *, const gdb_byte *, CORE_ADDR);
930 extern struct value *value_from_contents_and_address (struct type *,
931 const gdb_byte *,
932 CORE_ADDR);
933 extern struct value *value_from_contents (struct type *, const gdb_byte *);
934
935 extern struct value *default_value_from_register (struct gdbarch *gdbarch,
936 struct type *type,
937 int regnum,
938 struct frame_id frame_id);
939
940 extern void read_frame_register_value (struct value *value,
941 frame_info_ptr frame);
942
943 extern struct value *value_from_register (struct type *type, int regnum,
944 frame_info_ptr frame);
945
946 extern CORE_ADDR address_from_register (int regnum,
947 frame_info_ptr frame);
948
949 extern struct value *value_of_variable (struct symbol *var,
950 const struct block *b);
951
952 extern struct value *address_of_variable (struct symbol *var,
953 const struct block *b);
954
955 extern struct value *value_of_register (int regnum, frame_info_ptr frame);
956
957 struct value *value_of_register_lazy (frame_info_ptr frame, int regnum);
958
959 /* Return the symbol's reading requirement. */
960
961 extern enum symbol_needs_kind symbol_read_needs (struct symbol *);
962
963 /* Return true if the symbol needs a frame. This is a wrapper for
964 symbol_read_needs that simply checks for SYMBOL_NEEDS_FRAME. */
965
966 extern int symbol_read_needs_frame (struct symbol *);
967
968 extern struct value *read_var_value (struct symbol *var,
969 const struct block *var_block,
970 frame_info_ptr frame);
971
972 extern struct value *allocate_value (struct type *type);
973 extern struct value *allocate_value_lazy (struct type *type);
974 extern void value_contents_copy (struct value *dst, LONGEST dst_offset,
975 struct value *src, LONGEST src_offset,
976 LONGEST length);
977
978 extern struct value *allocate_repeat_value (struct type *type, int count);
979
980 extern struct value *value_mark (void);
981
982 extern void value_free_to_mark (const struct value *mark);
983
984 /* A helper class that uses value_mark at construction time and calls
985 value_free_to_mark in the destructor. This is used to clear out
986 temporary values created during the lifetime of this object. */
987 class scoped_value_mark
988 {
989 public:
990
991 scoped_value_mark ()
992 : m_value (value_mark ())
993 {
994 }
995
996 ~scoped_value_mark ()
997 {
998 free_to_mark ();
999 }
1000
1001 scoped_value_mark (scoped_value_mark &&other) = default;
1002
1003 DISABLE_COPY_AND_ASSIGN (scoped_value_mark);
1004
1005 /* Free the values currently on the value stack. */
1006 void free_to_mark ()
1007 {
1008 if (m_value != NULL)
1009 {
1010 value_free_to_mark (m_value);
1011 m_value = NULL;
1012 }
1013 }
1014
1015 private:
1016
1017 const struct value *m_value;
1018 };
1019
1020 extern struct value *value_cstring (const char *ptr, ssize_t len,
1021 struct type *char_type);
1022 extern struct value *value_string (const char *ptr, ssize_t len,
1023 struct type *char_type);
1024
1025 extern struct value *value_array (int lowbound, int highbound,
1026 struct value **elemvec);
1027
1028 extern struct value *value_concat (struct value *arg1, struct value *arg2);
1029
1030 extern struct value *value_binop (struct value *arg1, struct value *arg2,
1031 enum exp_opcode op);
1032
1033 extern struct value *value_ptradd (struct value *arg1, LONGEST arg2);
1034
1035 extern LONGEST value_ptrdiff (struct value *arg1, struct value *arg2);
1036
1037 /* Return true if VAL does not live in target memory, but should in order
1038 to operate on it. Otherwise return false. */
1039
1040 extern bool value_must_coerce_to_target (struct value *arg1);
1041
1042 extern struct value *value_coerce_to_target (struct value *arg1);
1043
1044 extern struct value *value_coerce_array (struct value *arg1);
1045
1046 extern struct value *value_coerce_function (struct value *arg1);
1047
1048 extern struct value *value_ind (struct value *arg1);
1049
1050 extern struct value *value_addr (struct value *arg1);
1051
1052 extern struct value *value_ref (struct value *arg1, enum type_code refcode);
1053
1054 extern struct value *value_assign (struct value *toval,
1055 struct value *fromval);
1056
1057 extern struct value *value_pos (struct value *arg1);
1058
1059 extern struct value *value_neg (struct value *arg1);
1060
1061 extern struct value *value_complement (struct value *arg1);
1062
1063 extern struct value *value_struct_elt (struct value **argp,
1064 gdb::optional<gdb::array_view <value *>> args,
1065 const char *name, int *static_memfuncp,
1066 const char *err);
1067
1068 extern struct value *value_struct_elt_bitpos (struct value **argp,
1069 int bitpos,
1070 struct type *field_type,
1071 const char *err);
1072
1073 extern struct value *value_aggregate_elt (struct type *curtype,
1074 const char *name,
1075 struct type *expect_type,
1076 int want_address,
1077 enum noside noside);
1078
1079 extern struct value *value_static_field (struct type *type, int fieldno);
1080
1081 enum oload_search_type { NON_METHOD, METHOD, BOTH };
1082
1083 extern int find_overload_match (gdb::array_view<value *> args,
1084 const char *name,
1085 enum oload_search_type method,
1086 struct value **objp, struct symbol *fsym,
1087 struct value **valp, struct symbol **symp,
1088 int *staticp, const int no_adl,
1089 enum noside noside);
1090
1091 extern struct value *value_field (struct value *arg1, int fieldno);
1092
1093 extern struct value *value_primitive_field (struct value *arg1, LONGEST offset,
1094 int fieldno,
1095 struct type *arg_type);
1096
1097
1098 extern struct type *value_rtti_indirect_type (struct value *, int *, LONGEST *,
1099 int *);
1100
1101 extern struct value *value_full_object (struct value *, struct type *, int,
1102 int, int);
1103
1104 extern struct value *value_cast_pointers (struct type *, struct value *, int);
1105
1106 extern struct value *value_cast (struct type *type, struct value *arg2);
1107
1108 extern struct value *value_reinterpret_cast (struct type *type,
1109 struct value *arg);
1110
1111 extern struct value *value_dynamic_cast (struct type *type, struct value *arg);
1112
1113 extern struct value *value_zero (struct type *type, enum lval_type lv);
1114
1115 extern struct value *value_one (struct type *type);
1116
1117 extern struct value *value_repeat (struct value *arg1, int count);
1118
1119 extern struct value *value_subscript (struct value *array, LONGEST index);
1120
1121 extern struct value *value_bitstring_subscript (struct type *type,
1122 struct value *bitstring,
1123 LONGEST index);
1124
1125 extern struct value *register_value_being_returned (struct type *valtype,
1126 struct regcache *retbuf);
1127
1128 extern int value_in (struct value *element, struct value *set);
1129
1130 extern int value_bit_index (struct type *type, const gdb_byte *addr,
1131 int index);
1132
1133 extern enum return_value_convention
1134 struct_return_convention (struct gdbarch *gdbarch, struct value *function,
1135 struct type *value_type);
1136
1137 extern int using_struct_return (struct gdbarch *gdbarch,
1138 struct value *function,
1139 struct type *value_type);
1140
1141 /* Evaluate the expression EXP. If set, EXPECT_TYPE is passed to the
1142 outermost operation's evaluation. This is ignored by most
1143 operations, but may be used, e.g., to determine the type of an
1144 otherwise untyped symbol. The caller should not assume that the
1145 returned value has this type. */
1146
1147 extern struct value *evaluate_expression (struct expression *exp,
1148 struct type *expect_type = nullptr);
1149
1150 extern struct value *evaluate_type (struct expression *exp);
1151
1152 extern value *evaluate_var_value (enum noside noside, const block *blk,
1153 symbol *var);
1154
1155 extern value *evaluate_var_msym_value (enum noside noside,
1156 struct objfile *objfile,
1157 minimal_symbol *msymbol);
1158
1159 namespace expr { class operation; };
1160 extern void fetch_subexp_value (struct expression *exp,
1161 expr::operation *op,
1162 struct value **valp, struct value **resultp,
1163 std::vector<value_ref_ptr> *val_chain,
1164 bool preserve_errors);
1165
1166 extern struct value *parse_and_eval (const char *exp);
1167
1168 extern struct value *parse_to_comma_and_eval (const char **expp);
1169
1170 extern struct type *parse_and_eval_type (const char *p, int length);
1171
1172 extern CORE_ADDR parse_and_eval_address (const char *exp);
1173
1174 extern LONGEST parse_and_eval_long (const char *exp);
1175
1176 extern void unop_promote (const struct language_defn *language,
1177 struct gdbarch *gdbarch,
1178 struct value **arg1);
1179
1180 extern void binop_promote (const struct language_defn *language,
1181 struct gdbarch *gdbarch,
1182 struct value **arg1, struct value **arg2);
1183
1184 extern struct value *access_value_history (int num);
1185
1186 /* Return the number of items in the value history. */
1187
1188 extern ULONGEST value_history_count ();
1189
1190 extern struct value *value_of_internalvar (struct gdbarch *gdbarch,
1191 struct internalvar *var);
1192
1193 extern int get_internalvar_integer (struct internalvar *var, LONGEST *l);
1194
1195 extern void set_internalvar (struct internalvar *var, struct value *val);
1196
1197 extern void set_internalvar_integer (struct internalvar *var, LONGEST l);
1198
1199 extern void set_internalvar_string (struct internalvar *var,
1200 const char *string);
1201
1202 extern void clear_internalvar (struct internalvar *var);
1203
1204 extern void set_internalvar_component (struct internalvar *var,
1205 LONGEST offset,
1206 LONGEST bitpos, LONGEST bitsize,
1207 struct value *newvalue);
1208
1209 extern struct internalvar *lookup_only_internalvar (const char *name);
1210
1211 extern struct internalvar *create_internalvar (const char *name);
1212
1213 extern void complete_internalvar (completion_tracker &tracker,
1214 const char *name);
1215
1216 /* An internalvar can be dynamically computed by supplying a vector of
1217 function pointers to perform various operations. */
1218
1219 struct internalvar_funcs
1220 {
1221 /* Compute the value of the variable. The DATA argument passed to
1222 the function is the same argument that was passed to
1223 `create_internalvar_type_lazy'. */
1224
1225 struct value *(*make_value) (struct gdbarch *arch,
1226 struct internalvar *var,
1227 void *data);
1228
1229 /* Update the agent expression EXPR with bytecode to compute the
1230 value. VALUE is the agent value we are updating. The DATA
1231 argument passed to this function is the same argument that was
1232 passed to `create_internalvar_type_lazy'. If this pointer is
1233 NULL, then the internalvar cannot be compiled to an agent
1234 expression. */
1235
1236 void (*compile_to_ax) (struct internalvar *var,
1237 struct agent_expr *expr,
1238 struct axs_value *value,
1239 void *data);
1240 };
1241
1242 extern struct internalvar *create_internalvar_type_lazy (const char *name,
1243 const struct internalvar_funcs *funcs,
1244 void *data);
1245
1246 /* Compile an internal variable to an agent expression. VAR is the
1247 variable to compile; EXPR and VALUE are the agent expression we are
1248 updating. This will return 0 if there is no known way to compile
1249 VAR, and 1 if VAR was successfully compiled. It may also throw an
1250 exception on error. */
1251
1252 extern int compile_internalvar_to_ax (struct internalvar *var,
1253 struct agent_expr *expr,
1254 struct axs_value *value);
1255
1256 extern struct internalvar *lookup_internalvar (const char *name);
1257
1258 extern int value_equal (struct value *arg1, struct value *arg2);
1259
1260 extern int value_equal_contents (struct value *arg1, struct value *arg2);
1261
1262 extern int value_less (struct value *arg1, struct value *arg2);
1263
1264 /* Simulate the C operator ! -- return true if ARG1 contains zero. */
1265 extern bool value_logical_not (struct value *arg1);
1266
1267 /* Returns true if the value VAL represents a true value. */
1268 static inline bool
1269 value_true (struct value *val)
1270 {
1271 return !value_logical_not (val);
1272 }
1273
1274 /* C++ */
1275
1276 extern struct value *value_of_this (const struct language_defn *lang);
1277
1278 extern struct value *value_of_this_silent (const struct language_defn *lang);
1279
1280 extern struct value *value_x_binop (struct value *arg1, struct value *arg2,
1281 enum exp_opcode op,
1282 enum exp_opcode otherop,
1283 enum noside noside);
1284
1285 extern struct value *value_x_unop (struct value *arg1, enum exp_opcode op,
1286 enum noside noside);
1287
1288 extern struct value *value_fn_field (struct value **arg1p, struct fn_field *f,
1289 int j, struct type *type, LONGEST offset);
1290
1291 extern int binop_types_user_defined_p (enum exp_opcode op,
1292 struct type *type1,
1293 struct type *type2);
1294
1295 extern int binop_user_defined_p (enum exp_opcode op, struct value *arg1,
1296 struct value *arg2);
1297
1298 extern int unop_user_defined_p (enum exp_opcode op, struct value *arg1);
1299
1300 extern int destructor_name_p (const char *name, struct type *type);
1301
1302 extern value_ref_ptr release_value (struct value *val);
1303
1304 extern int record_latest_value (struct value *val);
1305
1306 extern void modify_field (struct type *type, gdb_byte *addr,
1307 LONGEST fieldval, LONGEST bitpos, LONGEST bitsize);
1308
1309 extern void type_print (struct type *type, const char *varstring,
1310 struct ui_file *stream, int show);
1311
1312 extern std::string type_to_string (struct type *type);
1313
1314 extern gdb_byte *baseclass_addr (struct type *type, int index,
1315 gdb_byte *valaddr,
1316 struct value **valuep, int *errp);
1317
1318 extern void print_longest (struct ui_file *stream, int format,
1319 int use_local, LONGEST val);
1320
1321 extern void print_floating (const gdb_byte *valaddr, struct type *type,
1322 struct ui_file *stream);
1323
1324 extern void value_print (struct value *val, struct ui_file *stream,
1325 const struct value_print_options *options);
1326
1327 /* Release values from the value chain and return them. Values
1328 created after MARK are released. If MARK is nullptr, or if MARK is
1329 not found on the value chain, then all values are released. Values
1330 are returned in reverse order of creation; that is, newest
1331 first. */
1332
1333 extern std::vector<value_ref_ptr> value_release_to_mark
1334 (const struct value *mark);
1335
1336 extern void common_val_print (struct value *val,
1337 struct ui_file *stream, int recurse,
1338 const struct value_print_options *options,
1339 const struct language_defn *language);
1340
1341 extern int val_print_string (struct type *elttype, const char *encoding,
1342 CORE_ADDR addr, int len,
1343 struct ui_file *stream,
1344 const struct value_print_options *options);
1345
1346 extern void print_variable_and_value (const char *name,
1347 struct symbol *var,
1348 frame_info_ptr frame,
1349 struct ui_file *stream,
1350 int indent);
1351
1352 extern void typedef_print (struct type *type, struct symbol *news,
1353 struct ui_file *stream);
1354
1355 extern const char *internalvar_name (const struct internalvar *var);
1356
1357 extern void preserve_values (struct objfile *);
1358
1359 /* From values.c */
1360
1361 extern struct value *value_copy (const value *);
1362
1363 extern struct value *value_non_lval (struct value *);
1364
1365 extern void value_force_lval (struct value *, CORE_ADDR);
1366
1367 extern struct value *make_cv_value (int, int, struct value *);
1368
1369 extern void preserve_one_value (struct value *, struct objfile *, htab_t);
1370
1371 /* From valops.c */
1372
1373 extern struct value *varying_to_slice (struct value *);
1374
1375 extern struct value *value_slice (struct value *, int, int);
1376
1377 /* Create a complex number. The type is the complex type; the values
1378 are cast to the underlying scalar type before the complex number is
1379 created. */
1380
1381 extern struct value *value_literal_complex (struct value *, struct value *,
1382 struct type *);
1383
1384 /* Return the real part of a complex value. */
1385
1386 extern struct value *value_real_part (struct value *value);
1387
1388 /* Return the imaginary part of a complex value. */
1389
1390 extern struct value *value_imaginary_part (struct value *value);
1391
1392 extern struct value *find_function_in_inferior (const char *,
1393 struct objfile **);
1394
1395 extern struct value *value_allocate_space_in_inferior (int);
1396
1397 /* User function handler. */
1398
1399 typedef struct value *(*internal_function_fn) (struct gdbarch *gdbarch,
1400 const struct language_defn *language,
1401 void *cookie,
1402 int argc,
1403 struct value **argv);
1404
1405 /* Add a new internal function. NAME is the name of the function; DOC
1406 is a documentation string describing the function. HANDLER is
1407 called when the function is invoked. COOKIE is an arbitrary
1408 pointer which is passed to HANDLER and is intended for "user
1409 data". */
1410
1411 extern void add_internal_function (const char *name, const char *doc,
1412 internal_function_fn handler,
1413 void *cookie);
1414
1415 /* This overload takes an allocated documentation string. */
1416
1417 extern void add_internal_function (gdb::unique_xmalloc_ptr<char> &&name,
1418 gdb::unique_xmalloc_ptr<char> &&doc,
1419 internal_function_fn handler,
1420 void *cookie);
1421
1422 struct value *call_internal_function (struct gdbarch *gdbarch,
1423 const struct language_defn *language,
1424 struct value *function,
1425 int argc, struct value **argv);
1426
1427 const char *value_internal_function_name (struct value *);
1428
1429 /* Build a value wrapping and representing WORKER. The value takes ownership
1430 of the xmethod_worker object. */
1431
1432 extern struct value *value_from_xmethod (xmethod_worker_up &&worker);
1433
1434 extern struct type *result_type_of_xmethod (struct value *method,
1435 gdb::array_view<value *> argv);
1436
1437 extern struct value *call_xmethod (struct value *method,
1438 gdb::array_view<value *> argv);
1439
1440 /* Destroy the values currently allocated. This is called when GDB is
1441 exiting (e.g., on quit_force). */
1442 extern void finalize_values ();
1443
1444 /* Convert VALUE to a gdb_mpq. The caller must ensure that VALUE is
1445 of floating-point, fixed-point, or integer type. */
1446 extern gdb_mpq value_to_gdb_mpq (struct value *value);
1447
1448 /* While an instance of this class is live, and array values that are
1449 created, that are larger than max_value_size, will be restricted in size
1450 to a particular number of elements. */
1451
1452 struct scoped_array_length_limiting
1453 {
1454 /* Limit any large array values to only contain ELEMENTS elements. */
1455 scoped_array_length_limiting (int elements);
1456
1457 /* Restore the previous array value limit. */
1458 ~scoped_array_length_limiting ();
1459
1460 private:
1461 /* Used to hold the previous array value element limit. */
1462 gdb::optional<int> m_old_value;
1463 };
1464
1465 #endif /* !defined (VALUE_H) */