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