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