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