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