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