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