GDB (API)
/home/stan/gdb/src/gdb/value.c
Go to the documentation of this file.
00001 /* Low level packing and unpacking of values for GDB, the GNU Debugger.
00002 
00003    Copyright (C) 1986-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 #include "arch-utils.h"
00022 #include "gdb_string.h"
00023 #include "symtab.h"
00024 #include "gdbtypes.h"
00025 #include "value.h"
00026 #include "gdbcore.h"
00027 #include "command.h"
00028 #include "gdbcmd.h"
00029 #include "target.h"
00030 #include "language.h"
00031 #include "demangle.h"
00032 #include "doublest.h"
00033 #include "gdb_assert.h"
00034 #include "regcache.h"
00035 #include "block.h"
00036 #include "dfp.h"
00037 #include "objfiles.h"
00038 #include "valprint.h"
00039 #include "cli/cli-decode.h"
00040 #include "exceptions.h"
00041 #include "python/python.h"
00042 #include <ctype.h>
00043 #include "tracepoint.h"
00044 #include "cp-abi.h"
00045 #include "user-regs.h"
00046 
00047 /* Prototypes for exported functions.  */
00048 
00049 void _initialize_values (void);
00050 
00051 /* Definition of a user function.  */
00052 struct internal_function
00053 {
00054   /* The name of the function.  It is a bit odd to have this in the
00055      function itself -- the user might use a differently-named
00056      convenience variable to hold the function.  */
00057   char *name;
00058 
00059   /* The handler.  */
00060   internal_function_fn handler;
00061 
00062   /* User data for the handler.  */
00063   void *cookie;
00064 };
00065 
00066 /* Defines an [OFFSET, OFFSET + LENGTH) range.  */
00067 
00068 struct range
00069 {
00070   /* Lowest offset in the range.  */
00071   int offset;
00072 
00073   /* Length of the range.  */
00074   int length;
00075 };
00076 
00077 typedef struct range range_s;
00078 
00079 DEF_VEC_O(range_s);
00080 
00081 /* Returns true if the ranges defined by [offset1, offset1+len1) and
00082    [offset2, offset2+len2) overlap.  */
00083 
00084 static int
00085 ranges_overlap (int offset1, int len1,
00086                 int offset2, int len2)
00087 {
00088   ULONGEST h, l;
00089 
00090   l = max (offset1, offset2);
00091   h = min (offset1 + len1, offset2 + len2);
00092   return (l < h);
00093 }
00094 
00095 /* Returns true if the first argument is strictly less than the
00096    second, useful for VEC_lower_bound.  We keep ranges sorted by
00097    offset and coalesce overlapping and contiguous ranges, so this just
00098    compares the starting offset.  */
00099 
00100 static int
00101 range_lessthan (const range_s *r1, const range_s *r2)
00102 {
00103   return r1->offset < r2->offset;
00104 }
00105 
00106 /* Returns true if RANGES contains any range that overlaps [OFFSET,
00107    OFFSET+LENGTH).  */
00108 
00109 static int
00110 ranges_contain (VEC(range_s) *ranges, int offset, int length)
00111 {
00112   range_s what;
00113   int i;
00114 
00115   what.offset = offset;
00116   what.length = length;
00117 
00118   /* We keep ranges sorted by offset and coalesce overlapping and
00119      contiguous ranges, so to check if a range list contains a given
00120      range, we can do a binary search for the position the given range
00121      would be inserted if we only considered the starting OFFSET of
00122      ranges.  We call that position I.  Since we also have LENGTH to
00123      care for (this is a range afterall), we need to check if the
00124      _previous_ range overlaps the I range.  E.g.,
00125 
00126          R
00127          |---|
00128        |---|    |---|  |------| ... |--|
00129        0        1      2            N
00130 
00131        I=1
00132 
00133      In the case above, the binary search would return `I=1', meaning,
00134      this OFFSET should be inserted at position 1, and the current
00135      position 1 should be pushed further (and before 2).  But, `0'
00136      overlaps with R.
00137 
00138      Then we need to check if the I range overlaps the I range itself.
00139      E.g.,
00140 
00141               R
00142               |---|
00143        |---|    |---|  |-------| ... |--|
00144        0        1      2             N
00145 
00146        I=1
00147   */
00148 
00149   i = VEC_lower_bound (range_s, ranges, &what, range_lessthan);
00150 
00151   if (i > 0)
00152     {
00153       struct range *bef = VEC_index (range_s, ranges, i - 1);
00154 
00155       if (ranges_overlap (bef->offset, bef->length, offset, length))
00156         return 1;
00157     }
00158 
00159   if (i < VEC_length (range_s, ranges))
00160     {
00161       struct range *r = VEC_index (range_s, ranges, i);
00162 
00163       if (ranges_overlap (r->offset, r->length, offset, length))
00164         return 1;
00165     }
00166 
00167   return 0;
00168 }
00169 
00170 static struct cmd_list_element *functionlist;
00171 
00172 /* Note that the fields in this structure are arranged to save a bit
00173    of memory.  */
00174 
00175 struct value
00176 {
00177   /* Type of value; either not an lval, or one of the various
00178      different possible kinds of lval.  */
00179   enum lval_type lval;
00180 
00181   /* Is it modifiable?  Only relevant if lval != not_lval.  */
00182   unsigned int modifiable : 1;
00183 
00184   /* If zero, contents of this value are in the contents field.  If
00185      nonzero, contents are in inferior.  If the lval field is lval_memory,
00186      the contents are in inferior memory at location.address plus offset.
00187      The lval field may also be lval_register.
00188 
00189      WARNING: This field is used by the code which handles watchpoints
00190      (see breakpoint.c) to decide whether a particular value can be
00191      watched by hardware watchpoints.  If the lazy flag is set for
00192      some member of a value chain, it is assumed that this member of
00193      the chain doesn't need to be watched as part of watching the
00194      value itself.  This is how GDB avoids watching the entire struct
00195      or array when the user wants to watch a single struct member or
00196      array element.  If you ever change the way lazy flag is set and
00197      reset, be sure to consider this use as well!  */
00198   unsigned int lazy : 1;
00199 
00200   /* If nonzero, this is the value of a variable that does not
00201      actually exist in the program.  If nonzero, and LVAL is
00202      lval_register, this is a register ($pc, $sp, etc., never a
00203      program variable) that has not been saved in the frame.  All
00204      optimized-out values are treated pretty much the same, except
00205      registers have a different string representation and related
00206      error strings.  */
00207   unsigned int optimized_out : 1;
00208 
00209   /* If value is a variable, is it initialized or not.  */
00210   unsigned int initialized : 1;
00211 
00212   /* If value is from the stack.  If this is set, read_stack will be
00213      used instead of read_memory to enable extra caching.  */
00214   unsigned int stack : 1;
00215 
00216   /* If the value has been released.  */
00217   unsigned int released : 1;
00218 
00219   /* Location of value (if lval).  */
00220   union
00221   {
00222     /* If lval == lval_memory, this is the address in the inferior.
00223        If lval == lval_register, this is the byte offset into the
00224        registers structure.  */
00225     CORE_ADDR address;
00226 
00227     /* Pointer to internal variable.  */
00228     struct internalvar *internalvar;
00229 
00230     /* If lval == lval_computed, this is a set of function pointers
00231        to use to access and describe the value, and a closure pointer
00232        for them to use.  */
00233     struct
00234     {
00235       /* Functions to call.  */
00236       const struct lval_funcs *funcs;
00237 
00238       /* Closure for those functions to use.  */
00239       void *closure;
00240     } computed;
00241   } location;
00242 
00243   /* Describes offset of a value within lval of a structure in bytes.
00244      If lval == lval_memory, this is an offset to the address.  If
00245      lval == lval_register, this is a further offset from
00246      location.address within the registers structure.  Note also the
00247      member embedded_offset below.  */
00248   int offset;
00249 
00250   /* Only used for bitfields; number of bits contained in them.  */
00251   int bitsize;
00252 
00253   /* Only used for bitfields; position of start of field.  For
00254      gdbarch_bits_big_endian=0 targets, it is the position of the LSB.  For
00255      gdbarch_bits_big_endian=1 targets, it is the position of the MSB.  */
00256   int bitpos;
00257 
00258   /* The number of references to this value.  When a value is created,
00259      the value chain holds a reference, so REFERENCE_COUNT is 1.  If
00260      release_value is called, this value is removed from the chain but
00261      the caller of release_value now has a reference to this value.
00262      The caller must arrange for a call to value_free later.  */
00263   int reference_count;
00264 
00265   /* Only used for bitfields; the containing value.  This allows a
00266      single read from the target when displaying multiple
00267      bitfields.  */
00268   struct value *parent;
00269 
00270   /* Frame register value is relative to.  This will be described in
00271      the lval enum above as "lval_register".  */
00272   struct frame_id frame_id;
00273 
00274   /* Type of the value.  */
00275   struct type *type;
00276 
00277   /* If a value represents a C++ object, then the `type' field gives
00278      the object's compile-time type.  If the object actually belongs
00279      to some class derived from `type', perhaps with other base
00280      classes and additional members, then `type' is just a subobject
00281      of the real thing, and the full object is probably larger than
00282      `type' would suggest.
00283 
00284      If `type' is a dynamic class (i.e. one with a vtable), then GDB
00285      can actually determine the object's run-time type by looking at
00286      the run-time type information in the vtable.  When this
00287      information is available, we may elect to read in the entire
00288      object, for several reasons:
00289 
00290      - When printing the value, the user would probably rather see the
00291      full object, not just the limited portion apparent from the
00292      compile-time type.
00293 
00294      - If `type' has virtual base classes, then even printing `type'
00295      alone may require reaching outside the `type' portion of the
00296      object to wherever the virtual base class has been stored.
00297 
00298      When we store the entire object, `enclosing_type' is the run-time
00299      type -- the complete object -- and `embedded_offset' is the
00300      offset of `type' within that larger type, in bytes.  The
00301      value_contents() macro takes `embedded_offset' into account, so
00302      most GDB code continues to see the `type' portion of the value,
00303      just as the inferior would.
00304 
00305      If `type' is a pointer to an object, then `enclosing_type' is a
00306      pointer to the object's run-time type, and `pointed_to_offset' is
00307      the offset in bytes from the full object to the pointed-to object
00308      -- that is, the value `embedded_offset' would have if we followed
00309      the pointer and fetched the complete object.  (I don't really see
00310      the point.  Why not just determine the run-time type when you
00311      indirect, and avoid the special case?  The contents don't matter
00312      until you indirect anyway.)
00313 
00314      If we're not doing anything fancy, `enclosing_type' is equal to
00315      `type', and `embedded_offset' is zero, so everything works
00316      normally.  */
00317   struct type *enclosing_type;
00318   int embedded_offset;
00319   int pointed_to_offset;
00320 
00321   /* Values are stored in a chain, so that they can be deleted easily
00322      over calls to the inferior.  Values assigned to internal
00323      variables, put into the value history or exposed to Python are
00324      taken off this list.  */
00325   struct value *next;
00326 
00327   /* Register number if the value is from a register.  */
00328   short regnum;
00329 
00330   /* Actual contents of the value.  Target byte-order.  NULL or not
00331      valid if lazy is nonzero.  */
00332   gdb_byte *contents;
00333 
00334   /* Unavailable ranges in CONTENTS.  We mark unavailable ranges,
00335      rather than available, since the common and default case is for a
00336      value to be available.  This is filled in at value read time.  */
00337   VEC(range_s) *unavailable;
00338 };
00339 
00340 int
00341 value_bytes_available (const struct value *value, int offset, int length)
00342 {
00343   gdb_assert (!value->lazy);
00344 
00345   return !ranges_contain (value->unavailable, offset, length);
00346 }
00347 
00348 int
00349 value_entirely_available (struct value *value)
00350 {
00351   /* We can only tell whether the whole value is available when we try
00352      to read it.  */
00353   if (value->lazy)
00354     value_fetch_lazy (value);
00355 
00356   if (VEC_empty (range_s, value->unavailable))
00357     return 1;
00358   return 0;
00359 }
00360 
00361 int
00362 value_entirely_unavailable (struct value *value)
00363 {
00364   /* We can only tell whether the whole value is available when we try
00365      to read it.  */
00366   if (value->lazy)
00367     value_fetch_lazy (value);
00368 
00369   if (VEC_length (range_s, value->unavailable) == 1)
00370     {
00371       struct range *t = VEC_index (range_s, value->unavailable, 0);
00372 
00373       if (t->offset == 0
00374           && t->length == TYPE_LENGTH (value_enclosing_type (value)))
00375         return 1;
00376     }
00377 
00378   return 0;
00379 }
00380 
00381 void
00382 mark_value_bytes_unavailable (struct value *value, int offset, int length)
00383 {
00384   range_s newr;
00385   int i;
00386 
00387   /* Insert the range sorted.  If there's overlap or the new range
00388      would be contiguous with an existing range, merge.  */
00389 
00390   newr.offset = offset;
00391   newr.length = length;
00392 
00393   /* Do a binary search for the position the given range would be
00394      inserted if we only considered the starting OFFSET of ranges.
00395      Call that position I.  Since we also have LENGTH to care for
00396      (this is a range afterall), we need to check if the _previous_
00397      range overlaps the I range.  E.g., calling R the new range:
00398 
00399        #1 - overlaps with previous
00400 
00401            R
00402            |-...-|
00403          |---|     |---|  |------| ... |--|
00404          0         1      2            N
00405 
00406          I=1
00407 
00408      In the case #1 above, the binary search would return `I=1',
00409      meaning, this OFFSET should be inserted at position 1, and the
00410      current position 1 should be pushed further (and become 2).  But,
00411      note that `0' overlaps with R, so we want to merge them.
00412 
00413      A similar consideration needs to be taken if the new range would
00414      be contiguous with the previous range:
00415 
00416        #2 - contiguous with previous
00417 
00418             R
00419             |-...-|
00420          |--|       |---|  |------| ... |--|
00421          0          1      2            N
00422 
00423          I=1
00424 
00425      If there's no overlap with the previous range, as in:
00426 
00427        #3 - not overlapping and not contiguous
00428 
00429                R
00430                |-...-|
00431           |--|         |---|  |------| ... |--|
00432           0            1      2            N
00433 
00434          I=1
00435 
00436      or if I is 0:
00437 
00438        #4 - R is the range with lowest offset
00439 
00440           R
00441          |-...-|
00442                  |--|       |---|  |------| ... |--|
00443                  0          1      2            N
00444 
00445          I=0
00446 
00447      ... we just push the new range to I.
00448 
00449      All the 4 cases above need to consider that the new range may
00450      also overlap several of the ranges that follow, or that R may be
00451      contiguous with the following range, and merge.  E.g.,
00452 
00453        #5 - overlapping following ranges
00454 
00455           R
00456          |------------------------|
00457                  |--|       |---|  |------| ... |--|
00458                  0          1      2            N
00459 
00460          I=0
00461 
00462        or:
00463 
00464             R
00465             |-------|
00466          |--|       |---|  |------| ... |--|
00467          0          1      2            N
00468 
00469          I=1
00470 
00471   */
00472 
00473   i = VEC_lower_bound (range_s, value->unavailable, &newr, range_lessthan);
00474   if (i > 0)
00475     {
00476       struct range *bef = VEC_index (range_s, value->unavailable, i - 1);
00477 
00478       if (ranges_overlap (bef->offset, bef->length, offset, length))
00479         {
00480           /* #1 */
00481           ULONGEST l = min (bef->offset, offset);
00482           ULONGEST h = max (bef->offset + bef->length, offset + length);
00483 
00484           bef->offset = l;
00485           bef->length = h - l;
00486           i--;
00487         }
00488       else if (offset == bef->offset + bef->length)
00489         {
00490           /* #2 */
00491           bef->length += length;
00492           i--;
00493         }
00494       else
00495         {
00496           /* #3 */
00497           VEC_safe_insert (range_s, value->unavailable, i, &newr);
00498         }
00499     }
00500   else
00501     {
00502       /* #4 */
00503       VEC_safe_insert (range_s, value->unavailable, i, &newr);
00504     }
00505 
00506   /* Check whether the ranges following the one we've just added or
00507      touched can be folded in (#5 above).  */
00508   if (i + 1 < VEC_length (range_s, value->unavailable))
00509     {
00510       struct range *t;
00511       struct range *r;
00512       int removed = 0;
00513       int next = i + 1;
00514 
00515       /* Get the range we just touched.  */
00516       t = VEC_index (range_s, value->unavailable, i);
00517       removed = 0;
00518 
00519       i = next;
00520       for (; VEC_iterate (range_s, value->unavailable, i, r); i++)
00521         if (r->offset <= t->offset + t->length)
00522           {
00523             ULONGEST l, h;
00524 
00525             l = min (t->offset, r->offset);
00526             h = max (t->offset + t->length, r->offset + r->length);
00527 
00528             t->offset = l;
00529             t->length = h - l;
00530 
00531             removed++;
00532           }
00533         else
00534           {
00535             /* If we couldn't merge this one, we won't be able to
00536                merge following ones either, since the ranges are
00537                always sorted by OFFSET.  */
00538             break;
00539           }
00540 
00541       if (removed != 0)
00542         VEC_block_remove (range_s, value->unavailable, next, removed);
00543     }
00544 }
00545 
00546 /* Find the first range in RANGES that overlaps the range defined by
00547    OFFSET and LENGTH, starting at element POS in the RANGES vector,
00548    Returns the index into RANGES where such overlapping range was
00549    found, or -1 if none was found.  */
00550 
00551 static int
00552 find_first_range_overlap (VEC(range_s) *ranges, int pos,
00553                           int offset, int length)
00554 {
00555   range_s *r;
00556   int i;
00557 
00558   for (i = pos; VEC_iterate (range_s, ranges, i, r); i++)
00559     if (ranges_overlap (r->offset, r->length, offset, length))
00560       return i;
00561 
00562   return -1;
00563 }
00564 
00565 int
00566 value_available_contents_eq (const struct value *val1, int offset1,
00567                              const struct value *val2, int offset2,
00568                              int length)
00569 {
00570   int idx1 = 0, idx2 = 0;
00571 
00572   /* See function description in value.h.  */
00573   gdb_assert (!val1->lazy && !val2->lazy);
00574 
00575   while (length > 0)
00576     {
00577       range_s *r1, *r2;
00578       ULONGEST l1, h1;
00579       ULONGEST l2, h2;
00580 
00581       idx1 = find_first_range_overlap (val1->unavailable, idx1,
00582                                        offset1, length);
00583       idx2 = find_first_range_overlap (val2->unavailable, idx2,
00584                                        offset2, length);
00585 
00586       /* The usual case is for both values to be completely available.  */
00587       if (idx1 == -1 && idx2 == -1)
00588         return (memcmp (val1->contents + offset1,
00589                         val2->contents + offset2,
00590                         length) == 0);
00591       /* The contents only match equal if the available set matches as
00592          well.  */
00593       else if (idx1 == -1 || idx2 == -1)
00594         return 0;
00595 
00596       gdb_assert (idx1 != -1 && idx2 != -1);
00597 
00598       r1 = VEC_index (range_s, val1->unavailable, idx1);
00599       r2 = VEC_index (range_s, val2->unavailable, idx2);
00600 
00601       /* Get the unavailable windows intersected by the incoming
00602          ranges.  The first and last ranges that overlap the argument
00603          range may be wider than said incoming arguments ranges.  */
00604       l1 = max (offset1, r1->offset);
00605       h1 = min (offset1 + length, r1->offset + r1->length);
00606 
00607       l2 = max (offset2, r2->offset);
00608       h2 = min (offset2 + length, r2->offset + r2->length);
00609 
00610       /* Make them relative to the respective start offsets, so we can
00611          compare them for equality.  */
00612       l1 -= offset1;
00613       h1 -= offset1;
00614 
00615       l2 -= offset2;
00616       h2 -= offset2;
00617 
00618       /* Different availability, no match.  */
00619       if (l1 != l2 || h1 != h2)
00620         return 0;
00621 
00622       /* Compare the _available_ contents.  */
00623       if (memcmp (val1->contents + offset1,
00624                   val2->contents + offset2,
00625                   l1) != 0)
00626         return 0;
00627 
00628       length -= h1;
00629       offset1 += h1;
00630       offset2 += h1;
00631     }
00632 
00633   return 1;
00634 }
00635 
00636 /* Prototypes for local functions.  */
00637 
00638 static void show_values (char *, int);
00639 
00640 static void show_convenience (char *, int);
00641 
00642 
00643 /* The value-history records all the values printed
00644    by print commands during this session.  Each chunk
00645    records 60 consecutive values.  The first chunk on
00646    the chain records the most recent values.
00647    The total number of values is in value_history_count.  */
00648 
00649 #define VALUE_HISTORY_CHUNK 60
00650 
00651 struct value_history_chunk
00652   {
00653     struct value_history_chunk *next;
00654     struct value *values[VALUE_HISTORY_CHUNK];
00655   };
00656 
00657 /* Chain of chunks now in use.  */
00658 
00659 static struct value_history_chunk *value_history_chain;
00660 
00661 static int value_history_count; /* Abs number of last entry stored.  */
00662 
00663 
00664 /* List of all value objects currently allocated
00665    (except for those released by calls to release_value)
00666    This is so they can be freed after each command.  */
00667 
00668 static struct value *all_values;
00669 
00670 /* Allocate a lazy value for type TYPE.  Its actual content is
00671    "lazily" allocated too: the content field of the return value is
00672    NULL; it will be allocated when it is fetched from the target.  */
00673 
00674 struct value *
00675 allocate_value_lazy (struct type *type)
00676 {
00677   struct value *val;
00678 
00679   /* Call check_typedef on our type to make sure that, if TYPE
00680      is a TYPE_CODE_TYPEDEF, its length is set to the length
00681      of the target type instead of zero.  However, we do not
00682      replace the typedef type by the target type, because we want
00683      to keep the typedef in order to be able to set the VAL's type
00684      description correctly.  */
00685   check_typedef (type);
00686 
00687   val = (struct value *) xzalloc (sizeof (struct value));
00688   val->contents = NULL;
00689   val->next = all_values;
00690   all_values = val;
00691   val->type = type;
00692   val->enclosing_type = type;
00693   VALUE_LVAL (val) = not_lval;
00694   val->location.address = 0;
00695   VALUE_FRAME_ID (val) = null_frame_id;
00696   val->offset = 0;
00697   val->bitpos = 0;
00698   val->bitsize = 0;
00699   VALUE_REGNUM (val) = -1;
00700   val->lazy = 1;
00701   val->optimized_out = 0;
00702   val->embedded_offset = 0;
00703   val->pointed_to_offset = 0;
00704   val->modifiable = 1;
00705   val->initialized = 1;  /* Default to initialized.  */
00706 
00707   /* Values start out on the all_values chain.  */
00708   val->reference_count = 1;
00709 
00710   return val;
00711 }
00712 
00713 /* Allocate the contents of VAL if it has not been allocated yet.  */
00714 
00715 static void
00716 allocate_value_contents (struct value *val)
00717 {
00718   if (!val->contents)
00719     val->contents = (gdb_byte *) xzalloc (TYPE_LENGTH (val->enclosing_type));
00720 }
00721 
00722 /* Allocate a  value  and its contents for type TYPE.  */
00723 
00724 struct value *
00725 allocate_value (struct type *type)
00726 {
00727   struct value *val = allocate_value_lazy (type);
00728 
00729   allocate_value_contents (val);
00730   val->lazy = 0;
00731   return val;
00732 }
00733 
00734 /* Allocate a  value  that has the correct length
00735    for COUNT repetitions of type TYPE.  */
00736 
00737 struct value *
00738 allocate_repeat_value (struct type *type, int count)
00739 {
00740   int low_bound = current_language->string_lower_bound;         /* ??? */
00741   /* FIXME-type-allocation: need a way to free this type when we are
00742      done with it.  */
00743   struct type *array_type
00744     = lookup_array_range_type (type, low_bound, count + low_bound - 1);
00745 
00746   return allocate_value (array_type);
00747 }
00748 
00749 struct value *
00750 allocate_computed_value (struct type *type,
00751                          const struct lval_funcs *funcs,
00752                          void *closure)
00753 {
00754   struct value *v = allocate_value_lazy (type);
00755 
00756   VALUE_LVAL (v) = lval_computed;
00757   v->location.computed.funcs = funcs;
00758   v->location.computed.closure = closure;
00759 
00760   return v;
00761 }
00762 
00763 /* Allocate NOT_LVAL value for type TYPE being OPTIMIZED_OUT.  */
00764 
00765 struct value *
00766 allocate_optimized_out_value (struct type *type)
00767 {
00768   struct value *retval = allocate_value_lazy (type);
00769 
00770   set_value_optimized_out (retval, 1);
00771 
00772   return retval;
00773 }
00774 
00775 /* Accessor methods.  */
00776 
00777 struct value *
00778 value_next (struct value *value)
00779 {
00780   return value->next;
00781 }
00782 
00783 struct type *
00784 value_type (const struct value *value)
00785 {
00786   return value->type;
00787 }
00788 void
00789 deprecated_set_value_type (struct value *value, struct type *type)
00790 {
00791   value->type = type;
00792 }
00793 
00794 int
00795 value_offset (const struct value *value)
00796 {
00797   return value->offset;
00798 }
00799 void
00800 set_value_offset (struct value *value, int offset)
00801 {
00802   value->offset = offset;
00803 }
00804 
00805 int
00806 value_bitpos (const struct value *value)
00807 {
00808   return value->bitpos;
00809 }
00810 void
00811 set_value_bitpos (struct value *value, int bit)
00812 {
00813   value->bitpos = bit;
00814 }
00815 
00816 int
00817 value_bitsize (const struct value *value)
00818 {
00819   return value->bitsize;
00820 }
00821 void
00822 set_value_bitsize (struct value *value, int bit)
00823 {
00824   value->bitsize = bit;
00825 }
00826 
00827 struct value *
00828 value_parent (struct value *value)
00829 {
00830   return value->parent;
00831 }
00832 
00833 /* See value.h.  */
00834 
00835 void
00836 set_value_parent (struct value *value, struct value *parent)
00837 {
00838   struct value *old = value->parent;
00839 
00840   value->parent = parent;
00841   if (parent != NULL)
00842     value_incref (parent);
00843   value_free (old);
00844 }
00845 
00846 gdb_byte *
00847 value_contents_raw (struct value *value)
00848 {
00849   allocate_value_contents (value);
00850   return value->contents + value->embedded_offset;
00851 }
00852 
00853 gdb_byte *
00854 value_contents_all_raw (struct value *value)
00855 {
00856   allocate_value_contents (value);
00857   return value->contents;
00858 }
00859 
00860 struct type *
00861 value_enclosing_type (struct value *value)
00862 {
00863   return value->enclosing_type;
00864 }
00865 
00866 /* Look at value.h for description.  */
00867 
00868 struct type *
00869 value_actual_type (struct value *value, int resolve_simple_types,
00870                    int *real_type_found)
00871 {
00872   struct value_print_options opts;
00873   struct type *result;
00874 
00875   get_user_print_options (&opts);
00876 
00877   if (real_type_found)
00878     *real_type_found = 0;
00879   result = value_type (value);
00880   if (opts.objectprint)
00881     {
00882       /* If result's target type is TYPE_CODE_STRUCT, proceed to
00883          fetch its rtti type.  */
00884       if ((TYPE_CODE (result) == TYPE_CODE_PTR
00885           || TYPE_CODE (result) == TYPE_CODE_REF)
00886           && TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (result)))
00887              == TYPE_CODE_STRUCT)
00888         {
00889           struct type *real_type;
00890 
00891           real_type = value_rtti_indirect_type (value, NULL, NULL, NULL);
00892           if (real_type)
00893             {
00894               if (real_type_found)
00895                 *real_type_found = 1;
00896               result = real_type;
00897             }
00898         }
00899       else if (resolve_simple_types)
00900         {
00901           if (real_type_found)
00902             *real_type_found = 1;
00903           result = value_enclosing_type (value);
00904         }
00905     }
00906 
00907   return result;
00908 }
00909 
00910 void
00911 error_value_optimized_out (void)
00912 {
00913   error (_("value has been optimized out"));
00914 }
00915 
00916 static void
00917 require_not_optimized_out (const struct value *value)
00918 {
00919   if (value->optimized_out)
00920     {
00921       if (value->lval == lval_register)
00922         error (_("register has not been saved in frame"));
00923       else
00924         error_value_optimized_out ();
00925     }
00926 }
00927 
00928 static void
00929 require_available (const struct value *value)
00930 {
00931   if (!VEC_empty (range_s, value->unavailable))
00932     throw_error (NOT_AVAILABLE_ERROR, _("value is not available"));
00933 }
00934 
00935 const gdb_byte *
00936 value_contents_for_printing (struct value *value)
00937 {
00938   if (value->lazy)
00939     value_fetch_lazy (value);
00940   return value->contents;
00941 }
00942 
00943 const gdb_byte *
00944 value_contents_for_printing_const (const struct value *value)
00945 {
00946   gdb_assert (!value->lazy);
00947   return value->contents;
00948 }
00949 
00950 const gdb_byte *
00951 value_contents_all (struct value *value)
00952 {
00953   const gdb_byte *result = value_contents_for_printing (value);
00954   require_not_optimized_out (value);
00955   require_available (value);
00956   return result;
00957 }
00958 
00959 /* Copy LENGTH bytes of SRC value's (all) contents
00960    (value_contents_all) starting at SRC_OFFSET, into DST value's (all)
00961    contents, starting at DST_OFFSET.  If unavailable contents are
00962    being copied from SRC, the corresponding DST contents are marked
00963    unavailable accordingly.  Neither DST nor SRC may be lazy
00964    values.
00965 
00966    It is assumed the contents of DST in the [DST_OFFSET,
00967    DST_OFFSET+LENGTH) range are wholly available.  */
00968 
00969 void
00970 value_contents_copy_raw (struct value *dst, int dst_offset,
00971                          struct value *src, int src_offset, int length)
00972 {
00973   range_s *r;
00974   int i;
00975 
00976   /* A lazy DST would make that this copy operation useless, since as
00977      soon as DST's contents were un-lazied (by a later value_contents
00978      call, say), the contents would be overwritten.  A lazy SRC would
00979      mean we'd be copying garbage.  */
00980   gdb_assert (!dst->lazy && !src->lazy);
00981 
00982   /* The overwritten DST range gets unavailability ORed in, not
00983      replaced.  Make sure to remember to implement replacing if it
00984      turns out actually necessary.  */
00985   gdb_assert (value_bytes_available (dst, dst_offset, length));
00986 
00987   /* Copy the data.  */
00988   memcpy (value_contents_all_raw (dst) + dst_offset,
00989           value_contents_all_raw (src) + src_offset,
00990           length);
00991 
00992   /* Copy the meta-data, adjusted.  */
00993   for (i = 0; VEC_iterate (range_s, src->unavailable, i, r); i++)
00994     {
00995       ULONGEST h, l;
00996 
00997       l = max (r->offset, src_offset);
00998       h = min (r->offset + r->length, src_offset + length);
00999 
01000       if (l < h)
01001         mark_value_bytes_unavailable (dst,
01002                                       dst_offset + (l - src_offset),
01003                                       h - l);
01004     }
01005 }
01006 
01007 /* Copy LENGTH bytes of SRC value's (all) contents
01008    (value_contents_all) starting at SRC_OFFSET byte, into DST value's
01009    (all) contents, starting at DST_OFFSET.  If unavailable contents
01010    are being copied from SRC, the corresponding DST contents are
01011    marked unavailable accordingly.  DST must not be lazy.  If SRC is
01012    lazy, it will be fetched now.  If SRC is not valid (is optimized
01013    out), an error is thrown.
01014 
01015    It is assumed the contents of DST in the [DST_OFFSET,
01016    DST_OFFSET+LENGTH) range are wholly available.  */
01017 
01018 void
01019 value_contents_copy (struct value *dst, int dst_offset,
01020                      struct value *src, int src_offset, int length)
01021 {
01022   require_not_optimized_out (src);
01023 
01024   if (src->lazy)
01025     value_fetch_lazy (src);
01026 
01027   value_contents_copy_raw (dst, dst_offset, src, src_offset, length);
01028 }
01029 
01030 int
01031 value_lazy (struct value *value)
01032 {
01033   return value->lazy;
01034 }
01035 
01036 void
01037 set_value_lazy (struct value *value, int val)
01038 {
01039   value->lazy = val;
01040 }
01041 
01042 int
01043 value_stack (struct value *value)
01044 {
01045   return value->stack;
01046 }
01047 
01048 void
01049 set_value_stack (struct value *value, int val)
01050 {
01051   value->stack = val;
01052 }
01053 
01054 const gdb_byte *
01055 value_contents (struct value *value)
01056 {
01057   const gdb_byte *result = value_contents_writeable (value);
01058   require_not_optimized_out (value);
01059   require_available (value);
01060   return result;
01061 }
01062 
01063 gdb_byte *
01064 value_contents_writeable (struct value *value)
01065 {
01066   if (value->lazy)
01067     value_fetch_lazy (value);
01068   return value_contents_raw (value);
01069 }
01070 
01071 /* Return non-zero if VAL1 and VAL2 have the same contents.  Note that
01072    this function is different from value_equal; in C the operator ==
01073    can return 0 even if the two values being compared are equal.  */
01074 
01075 int
01076 value_contents_equal (struct value *val1, struct value *val2)
01077 {
01078   struct type *type1;
01079   struct type *type2;
01080 
01081   type1 = check_typedef (value_type (val1));
01082   type2 = check_typedef (value_type (val2));
01083   if (TYPE_LENGTH (type1) != TYPE_LENGTH (type2))
01084     return 0;
01085 
01086   return (memcmp (value_contents (val1), value_contents (val2),
01087                   TYPE_LENGTH (type1)) == 0);
01088 }
01089 
01090 int
01091 value_optimized_out (struct value *value)
01092 {
01093   /* We can only know if a value is optimized out once we have tried to
01094      fetch it.  */
01095   if (!value->optimized_out && value->lazy)
01096     value_fetch_lazy (value);
01097 
01098   return value->optimized_out;
01099 }
01100 
01101 int
01102 value_optimized_out_const (const struct value *value)
01103 {
01104   return value->optimized_out;
01105 }
01106 
01107 void
01108 set_value_optimized_out (struct value *value, int val)
01109 {
01110   value->optimized_out = val;
01111 }
01112 
01113 int
01114 value_entirely_optimized_out (const struct value *value)
01115 {
01116   if (!value->optimized_out)
01117     return 0;
01118   if (value->lval != lval_computed
01119       || !value->location.computed.funcs->check_any_valid)
01120     return 1;
01121   return !value->location.computed.funcs->check_any_valid (value);
01122 }
01123 
01124 int
01125 value_bits_valid (const struct value *value, int offset, int length)
01126 {
01127   if (!value->optimized_out)
01128     return 1;
01129   if (value->lval != lval_computed
01130       || !value->location.computed.funcs->check_validity)
01131     return 0;
01132   return value->location.computed.funcs->check_validity (value, offset,
01133                                                          length);
01134 }
01135 
01136 int
01137 value_bits_synthetic_pointer (const struct value *value,
01138                               int offset, int length)
01139 {
01140   if (value->lval != lval_computed
01141       || !value->location.computed.funcs->check_synthetic_pointer)
01142     return 0;
01143   return value->location.computed.funcs->check_synthetic_pointer (value,
01144                                                                   offset,
01145                                                                   length);
01146 }
01147 
01148 int
01149 value_embedded_offset (struct value *value)
01150 {
01151   return value->embedded_offset;
01152 }
01153 
01154 void
01155 set_value_embedded_offset (struct value *value, int val)
01156 {
01157   value->embedded_offset = val;
01158 }
01159 
01160 int
01161 value_pointed_to_offset (struct value *value)
01162 {
01163   return value->pointed_to_offset;
01164 }
01165 
01166 void
01167 set_value_pointed_to_offset (struct value *value, int val)
01168 {
01169   value->pointed_to_offset = val;
01170 }
01171 
01172 const struct lval_funcs *
01173 value_computed_funcs (const struct value *v)
01174 {
01175   gdb_assert (value_lval_const (v) == lval_computed);
01176 
01177   return v->location.computed.funcs;
01178 }
01179 
01180 void *
01181 value_computed_closure (const struct value *v)
01182 {
01183   gdb_assert (v->lval == lval_computed);
01184 
01185   return v->location.computed.closure;
01186 }
01187 
01188 enum lval_type *
01189 deprecated_value_lval_hack (struct value *value)
01190 {
01191   return &value->lval;
01192 }
01193 
01194 enum lval_type
01195 value_lval_const (const struct value *value)
01196 {
01197   return value->lval;
01198 }
01199 
01200 CORE_ADDR
01201 value_address (const struct value *value)
01202 {
01203   if (value->lval == lval_internalvar
01204       || value->lval == lval_internalvar_component)
01205     return 0;
01206   if (value->parent != NULL)
01207     return value_address (value->parent) + value->offset;
01208   else
01209     return value->location.address + value->offset;
01210 }
01211 
01212 CORE_ADDR
01213 value_raw_address (struct value *value)
01214 {
01215   if (value->lval == lval_internalvar
01216       || value->lval == lval_internalvar_component)
01217     return 0;
01218   return value->location.address;
01219 }
01220 
01221 void
01222 set_value_address (struct value *value, CORE_ADDR addr)
01223 {
01224   gdb_assert (value->lval != lval_internalvar
01225               && value->lval != lval_internalvar_component);
01226   value->location.address = addr;
01227 }
01228 
01229 struct internalvar **
01230 deprecated_value_internalvar_hack (struct value *value)
01231 {
01232   return &value->location.internalvar;
01233 }
01234 
01235 struct frame_id *
01236 deprecated_value_frame_id_hack (struct value *value)
01237 {
01238   return &value->frame_id;
01239 }
01240 
01241 short *
01242 deprecated_value_regnum_hack (struct value *value)
01243 {
01244   return &value->regnum;
01245 }
01246 
01247 int
01248 deprecated_value_modifiable (struct value *value)
01249 {
01250   return value->modifiable;
01251 }
01252 
01253 /* Return a mark in the value chain.  All values allocated after the
01254    mark is obtained (except for those released) are subject to being freed
01255    if a subsequent value_free_to_mark is passed the mark.  */
01256 struct value *
01257 value_mark (void)
01258 {
01259   return all_values;
01260 }
01261 
01262 /* Take a reference to VAL.  VAL will not be deallocated until all
01263    references are released.  */
01264 
01265 void
01266 value_incref (struct value *val)
01267 {
01268   val->reference_count++;
01269 }
01270 
01271 /* Release a reference to VAL, which was acquired with value_incref.
01272    This function is also called to deallocate values from the value
01273    chain.  */
01274 
01275 void
01276 value_free (struct value *val)
01277 {
01278   if (val)
01279     {
01280       gdb_assert (val->reference_count > 0);
01281       val->reference_count--;
01282       if (val->reference_count > 0)
01283         return;
01284 
01285       /* If there's an associated parent value, drop our reference to
01286          it.  */
01287       if (val->parent != NULL)
01288         value_free (val->parent);
01289 
01290       if (VALUE_LVAL (val) == lval_computed)
01291         {
01292           const struct lval_funcs *funcs = val->location.computed.funcs;
01293 
01294           if (funcs->free_closure)
01295             funcs->free_closure (val);
01296         }
01297 
01298       xfree (val->contents);
01299       VEC_free (range_s, val->unavailable);
01300     }
01301   xfree (val);
01302 }
01303 
01304 /* Free all values allocated since MARK was obtained by value_mark
01305    (except for those released).  */
01306 void
01307 value_free_to_mark (struct value *mark)
01308 {
01309   struct value *val;
01310   struct value *next;
01311 
01312   for (val = all_values; val && val != mark; val = next)
01313     {
01314       next = val->next;
01315       val->released = 1;
01316       value_free (val);
01317     }
01318   all_values = val;
01319 }
01320 
01321 /* Free all the values that have been allocated (except for those released).
01322    Call after each command, successful or not.
01323    In practice this is called before each command, which is sufficient.  */
01324 
01325 void
01326 free_all_values (void)
01327 {
01328   struct value *val;
01329   struct value *next;
01330 
01331   for (val = all_values; val; val = next)
01332     {
01333       next = val->next;
01334       val->released = 1;
01335       value_free (val);
01336     }
01337 
01338   all_values = 0;
01339 }
01340 
01341 /* Frees all the elements in a chain of values.  */
01342 
01343 void
01344 free_value_chain (struct value *v)
01345 {
01346   struct value *next;
01347 
01348   for (; v; v = next)
01349     {
01350       next = value_next (v);
01351       value_free (v);
01352     }
01353 }
01354 
01355 /* Remove VAL from the chain all_values
01356    so it will not be freed automatically.  */
01357 
01358 void
01359 release_value (struct value *val)
01360 {
01361   struct value *v;
01362 
01363   if (all_values == val)
01364     {
01365       all_values = val->next;
01366       val->next = NULL;
01367       val->released = 1;
01368       return;
01369     }
01370 
01371   for (v = all_values; v; v = v->next)
01372     {
01373       if (v->next == val)
01374         {
01375           v->next = val->next;
01376           val->next = NULL;
01377           val->released = 1;
01378           break;
01379         }
01380     }
01381 }
01382 
01383 /* If the value is not already released, release it.
01384    If the value is already released, increment its reference count.
01385    That is, this function ensures that the value is released from the
01386    value chain and that the caller owns a reference to it.  */
01387 
01388 void
01389 release_value_or_incref (struct value *val)
01390 {
01391   if (val->released)
01392     value_incref (val);
01393   else
01394     release_value (val);
01395 }
01396 
01397 /* Release all values up to mark  */
01398 struct value *
01399 value_release_to_mark (struct value *mark)
01400 {
01401   struct value *val;
01402   struct value *next;
01403 
01404   for (val = next = all_values; next; next = next->next)
01405     {
01406       if (next->next == mark)
01407         {
01408           all_values = next->next;
01409           next->next = NULL;
01410           return val;
01411         }
01412       next->released = 1;
01413     }
01414   all_values = 0;
01415   return val;
01416 }
01417 
01418 /* Return a copy of the value ARG.
01419    It contains the same contents, for same memory address,
01420    but it's a different block of storage.  */
01421 
01422 struct value *
01423 value_copy (struct value *arg)
01424 {
01425   struct type *encl_type = value_enclosing_type (arg);
01426   struct value *val;
01427 
01428   if (value_lazy (arg))
01429     val = allocate_value_lazy (encl_type);
01430   else
01431     val = allocate_value (encl_type);
01432   val->type = arg->type;
01433   VALUE_LVAL (val) = VALUE_LVAL (arg);
01434   val->location = arg->location;
01435   val->offset = arg->offset;
01436   val->bitpos = arg->bitpos;
01437   val->bitsize = arg->bitsize;
01438   VALUE_FRAME_ID (val) = VALUE_FRAME_ID (arg);
01439   VALUE_REGNUM (val) = VALUE_REGNUM (arg);
01440   val->lazy = arg->lazy;
01441   val->optimized_out = arg->optimized_out;
01442   val->embedded_offset = value_embedded_offset (arg);
01443   val->pointed_to_offset = arg->pointed_to_offset;
01444   val->modifiable = arg->modifiable;
01445   if (!value_lazy (val))
01446     {
01447       memcpy (value_contents_all_raw (val), value_contents_all_raw (arg),
01448               TYPE_LENGTH (value_enclosing_type (arg)));
01449 
01450     }
01451   val->unavailable = VEC_copy (range_s, arg->unavailable);
01452   set_value_parent (val, arg->parent);
01453   if (VALUE_LVAL (val) == lval_computed)
01454     {
01455       const struct lval_funcs *funcs = val->location.computed.funcs;
01456 
01457       if (funcs->copy_closure)
01458         val->location.computed.closure = funcs->copy_closure (val);
01459     }
01460   return val;
01461 }
01462 
01463 /* Return a version of ARG that is non-lvalue.  */
01464 
01465 struct value *
01466 value_non_lval (struct value *arg)
01467 {
01468   if (VALUE_LVAL (arg) != not_lval)
01469     {
01470       struct type *enc_type = value_enclosing_type (arg);
01471       struct value *val = allocate_value (enc_type);
01472 
01473       memcpy (value_contents_all_raw (val), value_contents_all (arg),
01474               TYPE_LENGTH (enc_type));
01475       val->type = arg->type;
01476       set_value_embedded_offset (val, value_embedded_offset (arg));
01477       set_value_pointed_to_offset (val, value_pointed_to_offset (arg));
01478       return val;
01479     }
01480    return arg;
01481 }
01482 
01483 void
01484 set_value_component_location (struct value *component,
01485                               const struct value *whole)
01486 {
01487   if (whole->lval == lval_internalvar)
01488     VALUE_LVAL (component) = lval_internalvar_component;
01489   else
01490     VALUE_LVAL (component) = whole->lval;
01491 
01492   component->location = whole->location;
01493   if (whole->lval == lval_computed)
01494     {
01495       const struct lval_funcs *funcs = whole->location.computed.funcs;
01496 
01497       if (funcs->copy_closure)
01498         component->location.computed.closure = funcs->copy_closure (whole);
01499     }
01500 }
01501 
01502 
01503 /* Access to the value history.  */
01504 
01505 /* Record a new value in the value history.
01506    Returns the absolute history index of the entry.
01507    Result of -1 indicates the value was not saved; otherwise it is the
01508    value history index of this new item.  */
01509 
01510 int
01511 record_latest_value (struct value *val)
01512 {
01513   int i;
01514 
01515   /* We don't want this value to have anything to do with the inferior anymore.
01516      In particular, "set $1 = 50" should not affect the variable from which
01517      the value was taken, and fast watchpoints should be able to assume that
01518      a value on the value history never changes.  */
01519   if (value_lazy (val))
01520     value_fetch_lazy (val);
01521   /* We preserve VALUE_LVAL so that the user can find out where it was fetched
01522      from.  This is a bit dubious, because then *&$1 does not just return $1
01523      but the current contents of that location.  c'est la vie...  */
01524   val->modifiable = 0;
01525   release_value (val);
01526 
01527   /* Here we treat value_history_count as origin-zero
01528      and applying to the value being stored now.  */
01529 
01530   i = value_history_count % VALUE_HISTORY_CHUNK;
01531   if (i == 0)
01532     {
01533       struct value_history_chunk *new
01534         = (struct value_history_chunk *)
01535 
01536       xmalloc (sizeof (struct value_history_chunk));
01537       memset (new->values, 0, sizeof new->values);
01538       new->next = value_history_chain;
01539       value_history_chain = new;
01540     }
01541 
01542   value_history_chain->values[i] = val;
01543 
01544   /* Now we regard value_history_count as origin-one
01545      and applying to the value just stored.  */
01546 
01547   return ++value_history_count;
01548 }
01549 
01550 /* Return a copy of the value in the history with sequence number NUM.  */
01551 
01552 struct value *
01553 access_value_history (int num)
01554 {
01555   struct value_history_chunk *chunk;
01556   int i;
01557   int absnum = num;
01558 
01559   if (absnum <= 0)
01560     absnum += value_history_count;
01561 
01562   if (absnum <= 0)
01563     {
01564       if (num == 0)
01565         error (_("The history is empty."));
01566       else if (num == 1)
01567         error (_("There is only one value in the history."));
01568       else
01569         error (_("History does not go back to $$%d."), -num);
01570     }
01571   if (absnum > value_history_count)
01572     error (_("History has not yet reached $%d."), absnum);
01573 
01574   absnum--;
01575 
01576   /* Now absnum is always absolute and origin zero.  */
01577 
01578   chunk = value_history_chain;
01579   for (i = (value_history_count - 1) / VALUE_HISTORY_CHUNK
01580          - absnum / VALUE_HISTORY_CHUNK;
01581        i > 0; i--)
01582     chunk = chunk->next;
01583 
01584   return value_copy (chunk->values[absnum % VALUE_HISTORY_CHUNK]);
01585 }
01586 
01587 static void
01588 show_values (char *num_exp, int from_tty)
01589 {
01590   int i;
01591   struct value *val;
01592   static int num = 1;
01593 
01594   if (num_exp)
01595     {
01596       /* "show values +" should print from the stored position.
01597          "show values <exp>" should print around value number <exp>.  */
01598       if (num_exp[0] != '+' || num_exp[1] != '\0')
01599         num = parse_and_eval_long (num_exp) - 5;
01600     }
01601   else
01602     {
01603       /* "show values" means print the last 10 values.  */
01604       num = value_history_count - 9;
01605     }
01606 
01607   if (num <= 0)
01608     num = 1;
01609 
01610   for (i = num; i < num + 10 && i <= value_history_count; i++)
01611     {
01612       struct value_print_options opts;
01613 
01614       val = access_value_history (i);
01615       printf_filtered (("$%d = "), i);
01616       get_user_print_options (&opts);
01617       value_print (val, gdb_stdout, &opts);
01618       printf_filtered (("\n"));
01619     }
01620 
01621   /* The next "show values +" should start after what we just printed.  */
01622   num += 10;
01623 
01624   /* Hitting just return after this command should do the same thing as
01625      "show values +".  If num_exp is null, this is unnecessary, since
01626      "show values +" is not useful after "show values".  */
01627   if (from_tty && num_exp)
01628     {
01629       num_exp[0] = '+';
01630       num_exp[1] = '\0';
01631     }
01632 }
01633 
01634 /* Internal variables.  These are variables within the debugger
01635    that hold values assigned by debugger commands.
01636    The user refers to them with a '$' prefix
01637    that does not appear in the variable names stored internally.  */
01638 
01639 struct internalvar
01640 {
01641   struct internalvar *next;
01642   char *name;
01643 
01644   /* We support various different kinds of content of an internal variable.
01645      enum internalvar_kind specifies the kind, and union internalvar_data
01646      provides the data associated with this particular kind.  */
01647 
01648   enum internalvar_kind
01649     {
01650       /* The internal variable is empty.  */
01651       INTERNALVAR_VOID,
01652 
01653       /* The value of the internal variable is provided directly as
01654          a GDB value object.  */
01655       INTERNALVAR_VALUE,
01656 
01657       /* A fresh value is computed via a call-back routine on every
01658          access to the internal variable.  */
01659       INTERNALVAR_MAKE_VALUE,
01660 
01661       /* The internal variable holds a GDB internal convenience function.  */
01662       INTERNALVAR_FUNCTION,
01663 
01664       /* The variable holds an integer value.  */
01665       INTERNALVAR_INTEGER,
01666 
01667       /* The variable holds a GDB-provided string.  */
01668       INTERNALVAR_STRING,
01669 
01670     } kind;
01671 
01672   union internalvar_data
01673     {
01674       /* A value object used with INTERNALVAR_VALUE.  */
01675       struct value *value;
01676 
01677       /* The call-back routine used with INTERNALVAR_MAKE_VALUE.  */
01678       struct
01679         {
01680           /* The functions to call.  */
01681           const struct internalvar_funcs *functions;
01682 
01683           /* The function's user-data.  */
01684           void *data;
01685         } make_value;
01686 
01687       /* The internal function used with INTERNALVAR_FUNCTION.  */
01688       struct
01689         {
01690           struct internal_function *function;
01691           /* True if this is the canonical name for the function.  */
01692           int canonical;
01693         } fn;
01694 
01695       /* An integer value used with INTERNALVAR_INTEGER.  */
01696       struct
01697         {
01698           /* If type is non-NULL, it will be used as the type to generate
01699              a value for this internal variable.  If type is NULL, a default
01700              integer type for the architecture is used.  */
01701           struct type *type;
01702           LONGEST val;
01703         } integer;
01704 
01705       /* A string value used with INTERNALVAR_STRING.  */
01706       char *string;
01707     } u;
01708 };
01709 
01710 static struct internalvar *internalvars;
01711 
01712 /* If the variable does not already exist create it and give it the
01713    value given.  If no value is given then the default is zero.  */
01714 static void
01715 init_if_undefined_command (char* args, int from_tty)
01716 {
01717   struct internalvar* intvar;
01718 
01719   /* Parse the expression - this is taken from set_command().  */
01720   struct expression *expr = parse_expression (args);
01721   register struct cleanup *old_chain =
01722     make_cleanup (free_current_contents, &expr);
01723 
01724   /* Validate the expression.
01725      Was the expression an assignment?
01726      Or even an expression at all?  */
01727   if (expr->nelts == 0 || expr->elts[0].opcode != BINOP_ASSIGN)
01728     error (_("Init-if-undefined requires an assignment expression."));
01729 
01730   /* Extract the variable from the parsed expression.
01731      In the case of an assign the lvalue will be in elts[1] and elts[2].  */
01732   if (expr->elts[1].opcode != OP_INTERNALVAR)
01733     error (_("The first parameter to init-if-undefined "
01734              "should be a GDB variable."));
01735   intvar = expr->elts[2].internalvar;
01736 
01737   /* Only evaluate the expression if the lvalue is void.
01738      This may still fail if the expresssion is invalid.  */
01739   if (intvar->kind == INTERNALVAR_VOID)
01740     evaluate_expression (expr);
01741 
01742   do_cleanups (old_chain);
01743 }
01744 
01745 
01746 /* Look up an internal variable with name NAME.  NAME should not
01747    normally include a dollar sign.
01748 
01749    If the specified internal variable does not exist,
01750    the return value is NULL.  */
01751 
01752 struct internalvar *
01753 lookup_only_internalvar (const char *name)
01754 {
01755   struct internalvar *var;
01756 
01757   for (var = internalvars; var; var = var->next)
01758     if (strcmp (var->name, name) == 0)
01759       return var;
01760 
01761   return NULL;
01762 }
01763 
01764 /* Complete NAME by comparing it to the names of internal variables.
01765    Returns a vector of newly allocated strings, or NULL if no matches
01766    were found.  */
01767 
01768 VEC (char_ptr) *
01769 complete_internalvar (const char *name)
01770 {
01771   VEC (char_ptr) *result = NULL;
01772   struct internalvar *var;
01773   int len;
01774 
01775   len = strlen (name);
01776 
01777   for (var = internalvars; var; var = var->next)
01778     if (strncmp (var->name, name, len) == 0)
01779       {
01780         char *r = xstrdup (var->name);
01781 
01782         VEC_safe_push (char_ptr, result, r);
01783       }
01784 
01785   return result;
01786 }
01787 
01788 /* Create an internal variable with name NAME and with a void value.
01789    NAME should not normally include a dollar sign.  */
01790 
01791 struct internalvar *
01792 create_internalvar (const char *name)
01793 {
01794   struct internalvar *var;
01795 
01796   var = (struct internalvar *) xmalloc (sizeof (struct internalvar));
01797   var->name = concat (name, (char *)NULL);
01798   var->kind = INTERNALVAR_VOID;
01799   var->next = internalvars;
01800   internalvars = var;
01801   return var;
01802 }
01803 
01804 /* Create an internal variable with name NAME and register FUN as the
01805    function that value_of_internalvar uses to create a value whenever
01806    this variable is referenced.  NAME should not normally include a
01807    dollar sign.  DATA is passed uninterpreted to FUN when it is
01808    called.  CLEANUP, if not NULL, is called when the internal variable
01809    is destroyed.  It is passed DATA as its only argument.  */
01810 
01811 struct internalvar *
01812 create_internalvar_type_lazy (const char *name,
01813                               const struct internalvar_funcs *funcs,
01814                               void *data)
01815 {
01816   struct internalvar *var = create_internalvar (name);
01817 
01818   var->kind = INTERNALVAR_MAKE_VALUE;
01819   var->u.make_value.functions = funcs;
01820   var->u.make_value.data = data;
01821   return var;
01822 }
01823 
01824 /* See documentation in value.h.  */
01825 
01826 int
01827 compile_internalvar_to_ax (struct internalvar *var,
01828                            struct agent_expr *expr,
01829                            struct axs_value *value)
01830 {
01831   if (var->kind != INTERNALVAR_MAKE_VALUE
01832       || var->u.make_value.functions->compile_to_ax == NULL)
01833     return 0;
01834 
01835   var->u.make_value.functions->compile_to_ax (var, expr, value,
01836                                               var->u.make_value.data);
01837   return 1;
01838 }
01839 
01840 /* Look up an internal variable with name NAME.  NAME should not
01841    normally include a dollar sign.
01842 
01843    If the specified internal variable does not exist,
01844    one is created, with a void value.  */
01845 
01846 struct internalvar *
01847 lookup_internalvar (const char *name)
01848 {
01849   struct internalvar *var;
01850 
01851   var = lookup_only_internalvar (name);
01852   if (var)
01853     return var;
01854 
01855   return create_internalvar (name);
01856 }
01857 
01858 /* Return current value of internal variable VAR.  For variables that
01859    are not inherently typed, use a value type appropriate for GDBARCH.  */
01860 
01861 struct value *
01862 value_of_internalvar (struct gdbarch *gdbarch, struct internalvar *var)
01863 {
01864   struct value *val;
01865   struct trace_state_variable *tsv;
01866 
01867   /* If there is a trace state variable of the same name, assume that
01868      is what we really want to see.  */
01869   tsv = find_trace_state_variable (var->name);
01870   if (tsv)
01871     {
01872       tsv->value_known = target_get_trace_state_variable_value (tsv->number,
01873                                                                 &(tsv->value));
01874       if (tsv->value_known)
01875         val = value_from_longest (builtin_type (gdbarch)->builtin_int64,
01876                                   tsv->value);
01877       else
01878         val = allocate_value (builtin_type (gdbarch)->builtin_void);
01879       return val;
01880     }
01881 
01882   switch (var->kind)
01883     {
01884     case INTERNALVAR_VOID:
01885       val = allocate_value (builtin_type (gdbarch)->builtin_void);
01886       break;
01887 
01888     case INTERNALVAR_FUNCTION:
01889       val = allocate_value (builtin_type (gdbarch)->internal_fn);
01890       break;
01891 
01892     case INTERNALVAR_INTEGER:
01893       if (!var->u.integer.type)
01894         val = value_from_longest (builtin_type (gdbarch)->builtin_int,
01895                                   var->u.integer.val);
01896       else
01897         val = value_from_longest (var->u.integer.type, var->u.integer.val);
01898       break;
01899 
01900     case INTERNALVAR_STRING:
01901       val = value_cstring (var->u.string, strlen (var->u.string),
01902                            builtin_type (gdbarch)->builtin_char);
01903       break;
01904 
01905     case INTERNALVAR_VALUE:
01906       val = value_copy (var->u.value);
01907       if (value_lazy (val))
01908         value_fetch_lazy (val);
01909       break;
01910 
01911     case INTERNALVAR_MAKE_VALUE:
01912       val = (*var->u.make_value.functions->make_value) (gdbarch, var,
01913                                                         var->u.make_value.data);
01914       break;
01915 
01916     default:
01917       internal_error (__FILE__, __LINE__, _("bad kind"));
01918     }
01919 
01920   /* Change the VALUE_LVAL to lval_internalvar so that future operations
01921      on this value go back to affect the original internal variable.
01922 
01923      Do not do this for INTERNALVAR_MAKE_VALUE variables, as those have
01924      no underlying modifyable state in the internal variable.
01925 
01926      Likewise, if the variable's value is a computed lvalue, we want
01927      references to it to produce another computed lvalue, where
01928      references and assignments actually operate through the
01929      computed value's functions.
01930 
01931      This means that internal variables with computed values
01932      behave a little differently from other internal variables:
01933      assignments to them don't just replace the previous value
01934      altogether.  At the moment, this seems like the behavior we
01935      want.  */
01936 
01937   if (var->kind != INTERNALVAR_MAKE_VALUE
01938       && val->lval != lval_computed)
01939     {
01940       VALUE_LVAL (val) = lval_internalvar;
01941       VALUE_INTERNALVAR (val) = var;
01942     }
01943 
01944   return val;
01945 }
01946 
01947 int
01948 get_internalvar_integer (struct internalvar *var, LONGEST *result)
01949 {
01950   if (var->kind == INTERNALVAR_INTEGER)
01951     {
01952       *result = var->u.integer.val;
01953       return 1;
01954     }
01955 
01956   if (var->kind == INTERNALVAR_VALUE)
01957     {
01958       struct type *type = check_typedef (value_type (var->u.value));
01959 
01960       if (TYPE_CODE (type) == TYPE_CODE_INT)
01961         {
01962           *result = value_as_long (var->u.value);
01963           return 1;
01964         }
01965     }
01966 
01967   return 0;
01968 }
01969 
01970 static int
01971 get_internalvar_function (struct internalvar *var,
01972                           struct internal_function **result)
01973 {
01974   switch (var->kind)
01975     {
01976     case INTERNALVAR_FUNCTION:
01977       *result = var->u.fn.function;
01978       return 1;
01979 
01980     default:
01981       return 0;
01982     }
01983 }
01984 
01985 void
01986 set_internalvar_component (struct internalvar *var, int offset, int bitpos,
01987                            int bitsize, struct value *newval)
01988 {
01989   gdb_byte *addr;
01990 
01991   switch (var->kind)
01992     {
01993     case INTERNALVAR_VALUE:
01994       addr = value_contents_writeable (var->u.value);
01995 
01996       if (bitsize)
01997         modify_field (value_type (var->u.value), addr + offset,
01998                       value_as_long (newval), bitpos, bitsize);
01999       else
02000         memcpy (addr + offset, value_contents (newval),
02001                 TYPE_LENGTH (value_type (newval)));
02002       break;
02003 
02004     default:
02005       /* We can never get a component of any other kind.  */
02006       internal_error (__FILE__, __LINE__, _("set_internalvar_component"));
02007     }
02008 }
02009 
02010 void
02011 set_internalvar (struct internalvar *var, struct value *val)
02012 {
02013   enum internalvar_kind new_kind;
02014   union internalvar_data new_data = { 0 };
02015 
02016   if (var->kind == INTERNALVAR_FUNCTION && var->u.fn.canonical)
02017     error (_("Cannot overwrite convenience function %s"), var->name);
02018 
02019   /* Prepare new contents.  */
02020   switch (TYPE_CODE (check_typedef (value_type (val))))
02021     {
02022     case TYPE_CODE_VOID:
02023       new_kind = INTERNALVAR_VOID;
02024       break;
02025 
02026     case TYPE_CODE_INTERNAL_FUNCTION:
02027       gdb_assert (VALUE_LVAL (val) == lval_internalvar);
02028       new_kind = INTERNALVAR_FUNCTION;
02029       get_internalvar_function (VALUE_INTERNALVAR (val),
02030                                 &new_data.fn.function);
02031       /* Copies created here are never canonical.  */
02032       break;
02033 
02034     default:
02035       new_kind = INTERNALVAR_VALUE;
02036       new_data.value = value_copy (val);
02037       new_data.value->modifiable = 1;
02038 
02039       /* Force the value to be fetched from the target now, to avoid problems
02040          later when this internalvar is referenced and the target is gone or
02041          has changed.  */
02042       if (value_lazy (new_data.value))
02043        value_fetch_lazy (new_data.value);
02044 
02045       /* Release the value from the value chain to prevent it from being
02046          deleted by free_all_values.  From here on this function should not
02047          call error () until new_data is installed into the var->u to avoid
02048          leaking memory.  */
02049       release_value (new_data.value);
02050       break;
02051     }
02052 
02053   /* Clean up old contents.  */
02054   clear_internalvar (var);
02055 
02056   /* Switch over.  */
02057   var->kind = new_kind;
02058   var->u = new_data;
02059   /* End code which must not call error().  */
02060 }
02061 
02062 void
02063 set_internalvar_integer (struct internalvar *var, LONGEST l)
02064 {
02065   /* Clean up old contents.  */
02066   clear_internalvar (var);
02067 
02068   var->kind = INTERNALVAR_INTEGER;
02069   var->u.integer.type = NULL;
02070   var->u.integer.val = l;
02071 }
02072 
02073 void
02074 set_internalvar_string (struct internalvar *var, const char *string)
02075 {
02076   /* Clean up old contents.  */
02077   clear_internalvar (var);
02078 
02079   var->kind = INTERNALVAR_STRING;
02080   var->u.string = xstrdup (string);
02081 }
02082 
02083 static void
02084 set_internalvar_function (struct internalvar *var, struct internal_function *f)
02085 {
02086   /* Clean up old contents.  */
02087   clear_internalvar (var);
02088 
02089   var->kind = INTERNALVAR_FUNCTION;
02090   var->u.fn.function = f;
02091   var->u.fn.canonical = 1;
02092   /* Variables installed here are always the canonical version.  */
02093 }
02094 
02095 void
02096 clear_internalvar (struct internalvar *var)
02097 {
02098   /* Clean up old contents.  */
02099   switch (var->kind)
02100     {
02101     case INTERNALVAR_VALUE:
02102       value_free (var->u.value);
02103       break;
02104 
02105     case INTERNALVAR_STRING:
02106       xfree (var->u.string);
02107       break;
02108 
02109     case INTERNALVAR_MAKE_VALUE:
02110       if (var->u.make_value.functions->destroy != NULL)
02111         var->u.make_value.functions->destroy (var->u.make_value.data);
02112       break;
02113 
02114     default:
02115       break;
02116     }
02117 
02118   /* Reset to void kind.  */
02119   var->kind = INTERNALVAR_VOID;
02120 }
02121 
02122 char *
02123 internalvar_name (struct internalvar *var)
02124 {
02125   return var->name;
02126 }
02127 
02128 static struct internal_function *
02129 create_internal_function (const char *name,
02130                           internal_function_fn handler, void *cookie)
02131 {
02132   struct internal_function *ifn = XNEW (struct internal_function);
02133 
02134   ifn->name = xstrdup (name);
02135   ifn->handler = handler;
02136   ifn->cookie = cookie;
02137   return ifn;
02138 }
02139 
02140 char *
02141 value_internal_function_name (struct value *val)
02142 {
02143   struct internal_function *ifn;
02144   int result;
02145 
02146   gdb_assert (VALUE_LVAL (val) == lval_internalvar);
02147   result = get_internalvar_function (VALUE_INTERNALVAR (val), &ifn);
02148   gdb_assert (result);
02149 
02150   return ifn->name;
02151 }
02152 
02153 struct value *
02154 call_internal_function (struct gdbarch *gdbarch,
02155                         const struct language_defn *language,
02156                         struct value *func, int argc, struct value **argv)
02157 {
02158   struct internal_function *ifn;
02159   int result;
02160 
02161   gdb_assert (VALUE_LVAL (func) == lval_internalvar);
02162   result = get_internalvar_function (VALUE_INTERNALVAR (func), &ifn);
02163   gdb_assert (result);
02164 
02165   return (*ifn->handler) (gdbarch, language, ifn->cookie, argc, argv);
02166 }
02167 
02168 /* The 'function' command.  This does nothing -- it is just a
02169    placeholder to let "help function NAME" work.  This is also used as
02170    the implementation of the sub-command that is created when
02171    registering an internal function.  */
02172 static void
02173 function_command (char *command, int from_tty)
02174 {
02175   /* Do nothing.  */
02176 }
02177 
02178 /* Clean up if an internal function's command is destroyed.  */
02179 static void
02180 function_destroyer (struct cmd_list_element *self, void *ignore)
02181 {
02182   xfree ((char *) self->name);
02183   xfree (self->doc);
02184 }
02185 
02186 /* Add a new internal function.  NAME is the name of the function; DOC
02187    is a documentation string describing the function.  HANDLER is
02188    called when the function is invoked.  COOKIE is an arbitrary
02189    pointer which is passed to HANDLER and is intended for "user
02190    data".  */
02191 void
02192 add_internal_function (const char *name, const char *doc,
02193                        internal_function_fn handler, void *cookie)
02194 {
02195   struct cmd_list_element *cmd;
02196   struct internal_function *ifn;
02197   struct internalvar *var = lookup_internalvar (name);
02198 
02199   ifn = create_internal_function (name, handler, cookie);
02200   set_internalvar_function (var, ifn);
02201 
02202   cmd = add_cmd (xstrdup (name), no_class, function_command, (char *) doc,
02203                  &functionlist);
02204   cmd->destroyer = function_destroyer;
02205 }
02206 
02207 /* Update VALUE before discarding OBJFILE.  COPIED_TYPES is used to
02208    prevent cycles / duplicates.  */
02209 
02210 void
02211 preserve_one_value (struct value *value, struct objfile *objfile,
02212                     htab_t copied_types)
02213 {
02214   if (TYPE_OBJFILE (value->type) == objfile)
02215     value->type = copy_type_recursive (objfile, value->type, copied_types);
02216 
02217   if (TYPE_OBJFILE (value->enclosing_type) == objfile)
02218     value->enclosing_type = copy_type_recursive (objfile,
02219                                                  value->enclosing_type,
02220                                                  copied_types);
02221 }
02222 
02223 /* Likewise for internal variable VAR.  */
02224 
02225 static void
02226 preserve_one_internalvar (struct internalvar *var, struct objfile *objfile,
02227                           htab_t copied_types)
02228 {
02229   switch (var->kind)
02230     {
02231     case INTERNALVAR_INTEGER:
02232       if (var->u.integer.type && TYPE_OBJFILE (var->u.integer.type) == objfile)
02233         var->u.integer.type
02234           = copy_type_recursive (objfile, var->u.integer.type, copied_types);
02235       break;
02236 
02237     case INTERNALVAR_VALUE:
02238       preserve_one_value (var->u.value, objfile, copied_types);
02239       break;
02240     }
02241 }
02242 
02243 /* Update the internal variables and value history when OBJFILE is
02244    discarded; we must copy the types out of the objfile.  New global types
02245    will be created for every convenience variable which currently points to
02246    this objfile's types, and the convenience variables will be adjusted to
02247    use the new global types.  */
02248 
02249 void
02250 preserve_values (struct objfile *objfile)
02251 {
02252   htab_t copied_types;
02253   struct value_history_chunk *cur;
02254   struct internalvar *var;
02255   int i;
02256 
02257   /* Create the hash table.  We allocate on the objfile's obstack, since
02258      it is soon to be deleted.  */
02259   copied_types = create_copied_types_hash (objfile);
02260 
02261   for (cur = value_history_chain; cur; cur = cur->next)
02262     for (i = 0; i < VALUE_HISTORY_CHUNK; i++)
02263       if (cur->values[i])
02264         preserve_one_value (cur->values[i], objfile, copied_types);
02265 
02266   for (var = internalvars; var; var = var->next)
02267     preserve_one_internalvar (var, objfile, copied_types);
02268 
02269   preserve_python_values (objfile, copied_types);
02270 
02271   htab_delete (copied_types);
02272 }
02273 
02274 static void
02275 show_convenience (char *ignore, int from_tty)
02276 {
02277   struct gdbarch *gdbarch = get_current_arch ();
02278   struct internalvar *var;
02279   int varseen = 0;
02280   struct value_print_options opts;
02281 
02282   get_user_print_options (&opts);
02283   for (var = internalvars; var; var = var->next)
02284     {
02285       volatile struct gdb_exception ex;
02286 
02287       if (!varseen)
02288         {
02289           varseen = 1;
02290         }
02291       printf_filtered (("$%s = "), var->name);
02292 
02293       TRY_CATCH (ex, RETURN_MASK_ERROR)
02294         {
02295           struct value *val;
02296 
02297           val = value_of_internalvar (gdbarch, var);
02298           value_print (val, gdb_stdout, &opts);
02299         }
02300       if (ex.reason < 0)
02301         fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.message);
02302       printf_filtered (("\n"));
02303     }
02304   if (!varseen)
02305     {
02306       /* This text does not mention convenience functions on purpose.
02307          The user can't create them except via Python, and if Python support
02308          is installed this message will never be printed ($_streq will
02309          exist).  */
02310       printf_unfiltered (_("No debugger convenience variables now defined.\n"
02311                            "Convenience variables have "
02312                            "names starting with \"$\";\n"
02313                            "use \"set\" as in \"set "
02314                            "$foo = 5\" to define them.\n"));
02315     }
02316 }
02317 
02318 /* Extract a value as a C number (either long or double).
02319    Knows how to convert fixed values to double, or
02320    floating values to long.
02321    Does not deallocate the value.  */
02322 
02323 LONGEST
02324 value_as_long (struct value *val)
02325 {
02326   /* This coerces arrays and functions, which is necessary (e.g.
02327      in disassemble_command).  It also dereferences references, which
02328      I suspect is the most logical thing to do.  */
02329   val = coerce_array (val);
02330   return unpack_long (value_type (val), value_contents (val));
02331 }
02332 
02333 DOUBLEST
02334 value_as_double (struct value *val)
02335 {
02336   DOUBLEST foo;
02337   int inv;
02338 
02339   foo = unpack_double (value_type (val), value_contents (val), &inv);
02340   if (inv)
02341     error (_("Invalid floating value found in program."));
02342   return foo;
02343 }
02344 
02345 /* Extract a value as a C pointer.  Does not deallocate the value.
02346    Note that val's type may not actually be a pointer; value_as_long
02347    handles all the cases.  */
02348 CORE_ADDR
02349 value_as_address (struct value *val)
02350 {
02351   struct gdbarch *gdbarch = get_type_arch (value_type (val));
02352 
02353   /* Assume a CORE_ADDR can fit in a LONGEST (for now).  Not sure
02354      whether we want this to be true eventually.  */
02355 #if 0
02356   /* gdbarch_addr_bits_remove is wrong if we are being called for a
02357      non-address (e.g. argument to "signal", "info break", etc.), or
02358      for pointers to char, in which the low bits *are* significant.  */
02359   return gdbarch_addr_bits_remove (gdbarch, value_as_long (val));
02360 #else
02361 
02362   /* There are several targets (IA-64, PowerPC, and others) which
02363      don't represent pointers to functions as simply the address of
02364      the function's entry point.  For example, on the IA-64, a
02365      function pointer points to a two-word descriptor, generated by
02366      the linker, which contains the function's entry point, and the
02367      value the IA-64 "global pointer" register should have --- to
02368      support position-independent code.  The linker generates
02369      descriptors only for those functions whose addresses are taken.
02370 
02371      On such targets, it's difficult for GDB to convert an arbitrary
02372      function address into a function pointer; it has to either find
02373      an existing descriptor for that function, or call malloc and
02374      build its own.  On some targets, it is impossible for GDB to
02375      build a descriptor at all: the descriptor must contain a jump
02376      instruction; data memory cannot be executed; and code memory
02377      cannot be modified.
02378 
02379      Upon entry to this function, if VAL is a value of type `function'
02380      (that is, TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FUNC), then
02381      value_address (val) is the address of the function.  This is what
02382      you'll get if you evaluate an expression like `main'.  The call
02383      to COERCE_ARRAY below actually does all the usual unary
02384      conversions, which includes converting values of type `function'
02385      to `pointer to function'.  This is the challenging conversion
02386      discussed above.  Then, `unpack_long' will convert that pointer
02387      back into an address.
02388 
02389      So, suppose the user types `disassemble foo' on an architecture
02390      with a strange function pointer representation, on which GDB
02391      cannot build its own descriptors, and suppose further that `foo'
02392      has no linker-built descriptor.  The address->pointer conversion
02393      will signal an error and prevent the command from running, even
02394      though the next step would have been to convert the pointer
02395      directly back into the same address.
02396 
02397      The following shortcut avoids this whole mess.  If VAL is a
02398      function, just return its address directly.  */
02399   if (TYPE_CODE (value_type (val)) == TYPE_CODE_FUNC
02400       || TYPE_CODE (value_type (val)) == TYPE_CODE_METHOD)
02401     return value_address (val);
02402 
02403   val = coerce_array (val);
02404 
02405   /* Some architectures (e.g. Harvard), map instruction and data
02406      addresses onto a single large unified address space.  For
02407      instance: An architecture may consider a large integer in the
02408      range 0x10000000 .. 0x1000ffff to already represent a data
02409      addresses (hence not need a pointer to address conversion) while
02410      a small integer would still need to be converted integer to
02411      pointer to address.  Just assume such architectures handle all
02412      integer conversions in a single function.  */
02413 
02414   /* JimB writes:
02415 
02416      I think INTEGER_TO_ADDRESS is a good idea as proposed --- but we
02417      must admonish GDB hackers to make sure its behavior matches the
02418      compiler's, whenever possible.
02419 
02420      In general, I think GDB should evaluate expressions the same way
02421      the compiler does.  When the user copies an expression out of
02422      their source code and hands it to a `print' command, they should
02423      get the same value the compiler would have computed.  Any
02424      deviation from this rule can cause major confusion and annoyance,
02425      and needs to be justified carefully.  In other words, GDB doesn't
02426      really have the freedom to do these conversions in clever and
02427      useful ways.
02428 
02429      AndrewC pointed out that users aren't complaining about how GDB
02430      casts integers to pointers; they are complaining that they can't
02431      take an address from a disassembly listing and give it to `x/i'.
02432      This is certainly important.
02433 
02434      Adding an architecture method like integer_to_address() certainly
02435      makes it possible for GDB to "get it right" in all circumstances
02436      --- the target has complete control over how things get done, so
02437      people can Do The Right Thing for their target without breaking
02438      anyone else.  The standard doesn't specify how integers get
02439      converted to pointers; usually, the ABI doesn't either, but
02440      ABI-specific code is a more reasonable place to handle it.  */
02441 
02442   if (TYPE_CODE (value_type (val)) != TYPE_CODE_PTR
02443       && TYPE_CODE (value_type (val)) != TYPE_CODE_REF
02444       && gdbarch_integer_to_address_p (gdbarch))
02445     return gdbarch_integer_to_address (gdbarch, value_type (val),
02446                                        value_contents (val));
02447 
02448   return unpack_long (value_type (val), value_contents (val));
02449 #endif
02450 }
02451 
02452 /* Unpack raw data (copied from debugee, target byte order) at VALADDR
02453    as a long, or as a double, assuming the raw data is described
02454    by type TYPE.  Knows how to convert different sizes of values
02455    and can convert between fixed and floating point.  We don't assume
02456    any alignment for the raw data.  Return value is in host byte order.
02457 
02458    If you want functions and arrays to be coerced to pointers, and
02459    references to be dereferenced, call value_as_long() instead.
02460 
02461    C++: It is assumed that the front-end has taken care of
02462    all matters concerning pointers to members.  A pointer
02463    to member which reaches here is considered to be equivalent
02464    to an INT (or some size).  After all, it is only an offset.  */
02465 
02466 LONGEST
02467 unpack_long (struct type *type, const gdb_byte *valaddr)
02468 {
02469   enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
02470   enum type_code code = TYPE_CODE (type);
02471   int len = TYPE_LENGTH (type);
02472   int nosign = TYPE_UNSIGNED (type);
02473 
02474   switch (code)
02475     {
02476     case TYPE_CODE_TYPEDEF:
02477       return unpack_long (check_typedef (type), valaddr);
02478     case TYPE_CODE_ENUM:
02479     case TYPE_CODE_FLAGS:
02480     case TYPE_CODE_BOOL:
02481     case TYPE_CODE_INT:
02482     case TYPE_CODE_CHAR:
02483     case TYPE_CODE_RANGE:
02484     case TYPE_CODE_MEMBERPTR:
02485       if (nosign)
02486         return extract_unsigned_integer (valaddr, len, byte_order);
02487       else
02488         return extract_signed_integer (valaddr, len, byte_order);
02489 
02490     case TYPE_CODE_FLT:
02491       return extract_typed_floating (valaddr, type);
02492 
02493     case TYPE_CODE_DECFLOAT:
02494       /* libdecnumber has a function to convert from decimal to integer, but
02495          it doesn't work when the decimal number has a fractional part.  */
02496       return decimal_to_doublest (valaddr, len, byte_order);
02497 
02498     case TYPE_CODE_PTR:
02499     case TYPE_CODE_REF:
02500       /* Assume a CORE_ADDR can fit in a LONGEST (for now).  Not sure
02501          whether we want this to be true eventually.  */
02502       return extract_typed_address (valaddr, type);
02503 
02504     default:
02505       error (_("Value can't be converted to integer."));
02506     }
02507   return 0;                     /* Placate lint.  */
02508 }
02509 
02510 /* Return a double value from the specified type and address.
02511    INVP points to an int which is set to 0 for valid value,
02512    1 for invalid value (bad float format).  In either case,
02513    the returned double is OK to use.  Argument is in target
02514    format, result is in host format.  */
02515 
02516 DOUBLEST
02517 unpack_double (struct type *type, const gdb_byte *valaddr, int *invp)
02518 {
02519   enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
02520   enum type_code code;
02521   int len;
02522   int nosign;
02523 
02524   *invp = 0;                    /* Assume valid.  */
02525   CHECK_TYPEDEF (type);
02526   code = TYPE_CODE (type);
02527   len = TYPE_LENGTH (type);
02528   nosign = TYPE_UNSIGNED (type);
02529   if (code == TYPE_CODE_FLT)
02530     {
02531       /* NOTE: cagney/2002-02-19: There was a test here to see if the
02532          floating-point value was valid (using the macro
02533          INVALID_FLOAT).  That test/macro have been removed.
02534 
02535          It turns out that only the VAX defined this macro and then
02536          only in a non-portable way.  Fixing the portability problem
02537          wouldn't help since the VAX floating-point code is also badly
02538          bit-rotten.  The target needs to add definitions for the
02539          methods gdbarch_float_format and gdbarch_double_format - these
02540          exactly describe the target floating-point format.  The
02541          problem here is that the corresponding floatformat_vax_f and
02542          floatformat_vax_d values these methods should be set to are
02543          also not defined either.  Oops!
02544 
02545          Hopefully someone will add both the missing floatformat
02546          definitions and the new cases for floatformat_is_valid ().  */
02547 
02548       if (!floatformat_is_valid (floatformat_from_type (type), valaddr))
02549         {
02550           *invp = 1;
02551           return 0.0;
02552         }
02553 
02554       return extract_typed_floating (valaddr, type);
02555     }
02556   else if (code == TYPE_CODE_DECFLOAT)
02557     return decimal_to_doublest (valaddr, len, byte_order);
02558   else if (nosign)
02559     {
02560       /* Unsigned -- be sure we compensate for signed LONGEST.  */
02561       return (ULONGEST) unpack_long (type, valaddr);
02562     }
02563   else
02564     {
02565       /* Signed -- we are OK with unpack_long.  */
02566       return unpack_long (type, valaddr);
02567     }
02568 }
02569 
02570 /* Unpack raw data (copied from debugee, target byte order) at VALADDR
02571    as a CORE_ADDR, assuming the raw data is described by type TYPE.
02572    We don't assume any alignment for the raw data.  Return value is in
02573    host byte order.
02574 
02575    If you want functions and arrays to be coerced to pointers, and
02576    references to be dereferenced, call value_as_address() instead.
02577 
02578    C++: It is assumed that the front-end has taken care of
02579    all matters concerning pointers to members.  A pointer
02580    to member which reaches here is considered to be equivalent
02581    to an INT (or some size).  After all, it is only an offset.  */
02582 
02583 CORE_ADDR
02584 unpack_pointer (struct type *type, const gdb_byte *valaddr)
02585 {
02586   /* Assume a CORE_ADDR can fit in a LONGEST (for now).  Not sure
02587      whether we want this to be true eventually.  */
02588   return unpack_long (type, valaddr);
02589 }
02590 
02591 
02592 /* Get the value of the FIELDNO'th field (which must be static) of
02593    TYPE.  Return NULL if the field doesn't exist or has been
02594    optimized out.  */
02595 
02596 struct value *
02597 value_static_field (struct type *type, int fieldno)
02598 {
02599   struct value *retval;
02600 
02601   switch (TYPE_FIELD_LOC_KIND (type, fieldno))
02602     {
02603     case FIELD_LOC_KIND_PHYSADDR:
02604       retval = value_at_lazy (TYPE_FIELD_TYPE (type, fieldno),
02605                               TYPE_FIELD_STATIC_PHYSADDR (type, fieldno));
02606       break;
02607     case FIELD_LOC_KIND_PHYSNAME:
02608     {
02609       const char *phys_name = TYPE_FIELD_STATIC_PHYSNAME (type, fieldno);
02610       /* TYPE_FIELD_NAME (type, fieldno); */
02611       struct symbol *sym = lookup_symbol (phys_name, 0, VAR_DOMAIN, 0);
02612 
02613       if (sym == NULL)
02614         {
02615           /* With some compilers, e.g. HP aCC, static data members are
02616              reported as non-debuggable symbols.  */
02617           struct minimal_symbol *msym = lookup_minimal_symbol (phys_name,
02618                                                                NULL, NULL);
02619 
02620           if (!msym)
02621             return NULL;
02622           else
02623             {
02624               retval = value_at_lazy (TYPE_FIELD_TYPE (type, fieldno),
02625                                       SYMBOL_VALUE_ADDRESS (msym));
02626             }
02627         }
02628       else
02629         retval = value_of_variable (sym, NULL);
02630       break;
02631     }
02632     default:
02633       gdb_assert_not_reached ("unexpected field location kind");
02634     }
02635 
02636   return retval;
02637 }
02638 
02639 /* Change the enclosing type of a value object VAL to NEW_ENCL_TYPE.
02640    You have to be careful here, since the size of the data area for the value
02641    is set by the length of the enclosing type.  So if NEW_ENCL_TYPE is bigger
02642    than the old enclosing type, you have to allocate more space for the
02643    data.  */
02644 
02645 void
02646 set_value_enclosing_type (struct value *val, struct type *new_encl_type)
02647 {
02648   if (TYPE_LENGTH (new_encl_type) > TYPE_LENGTH (value_enclosing_type (val))) 
02649     val->contents =
02650       (gdb_byte *) xrealloc (val->contents, TYPE_LENGTH (new_encl_type));
02651 
02652   val->enclosing_type = new_encl_type;
02653 }
02654 
02655 /* Given a value ARG1 (offset by OFFSET bytes)
02656    of a struct or union type ARG_TYPE,
02657    extract and return the value of one of its (non-static) fields.
02658    FIELDNO says which field.  */
02659 
02660 struct value *
02661 value_primitive_field (struct value *arg1, int offset,
02662                        int fieldno, struct type *arg_type)
02663 {
02664   struct value *v;
02665   struct type *type;
02666 
02667   CHECK_TYPEDEF (arg_type);
02668   type = TYPE_FIELD_TYPE (arg_type, fieldno);
02669 
02670   /* Call check_typedef on our type to make sure that, if TYPE
02671      is a TYPE_CODE_TYPEDEF, its length is set to the length
02672      of the target type instead of zero.  However, we do not
02673      replace the typedef type by the target type, because we want
02674      to keep the typedef in order to be able to print the type
02675      description correctly.  */
02676   check_typedef (type);
02677 
02678   if (TYPE_FIELD_BITSIZE (arg_type, fieldno))
02679     {
02680       /* Handle packed fields.
02681 
02682          Create a new value for the bitfield, with bitpos and bitsize
02683          set.  If possible, arrange offset and bitpos so that we can
02684          do a single aligned read of the size of the containing type.
02685          Otherwise, adjust offset to the byte containing the first
02686          bit.  Assume that the address, offset, and embedded offset
02687          are sufficiently aligned.  */
02688 
02689       int bitpos = TYPE_FIELD_BITPOS (arg_type, fieldno);
02690       int container_bitsize = TYPE_LENGTH (type) * 8;
02691 
02692       if (arg1->optimized_out)
02693         v = allocate_optimized_out_value (type);
02694       else
02695         {
02696           v = allocate_value_lazy (type);
02697           v->bitsize = TYPE_FIELD_BITSIZE (arg_type, fieldno);
02698           if ((bitpos % container_bitsize) + v->bitsize <= container_bitsize
02699               && TYPE_LENGTH (type) <= (int) sizeof (LONGEST))
02700             v->bitpos = bitpos % container_bitsize;
02701           else
02702             v->bitpos = bitpos % 8;
02703           v->offset = (value_embedded_offset (arg1)
02704                        + offset
02705                        + (bitpos - v->bitpos) / 8);
02706           set_value_parent (v, arg1);
02707           if (!value_lazy (arg1))
02708             value_fetch_lazy (v);
02709         }
02710     }
02711   else if (fieldno < TYPE_N_BASECLASSES (arg_type))
02712     {
02713       /* This field is actually a base subobject, so preserve the
02714          entire object's contents for later references to virtual
02715          bases, etc.  */
02716       int boffset;
02717 
02718       /* Lazy register values with offsets are not supported.  */
02719       if (VALUE_LVAL (arg1) == lval_register && value_lazy (arg1))
02720         value_fetch_lazy (arg1);
02721 
02722       /* The optimized_out flag is only set correctly once a lazy value is
02723          loaded, having just loaded some lazy values we should check the
02724          optimized out case now.  */
02725       if (arg1->optimized_out)
02726         v = allocate_optimized_out_value (type);
02727       else
02728         {
02729           /* We special case virtual inheritance here because this
02730              requires access to the contents, which we would rather avoid
02731              for references to ordinary fields of unavailable values.  */
02732           if (BASETYPE_VIA_VIRTUAL (arg_type, fieldno))
02733             boffset = baseclass_offset (arg_type, fieldno,
02734                                         value_contents (arg1),
02735                                         value_embedded_offset (arg1),
02736                                         value_address (arg1),
02737                                         arg1);
02738           else
02739             boffset = TYPE_FIELD_BITPOS (arg_type, fieldno) / 8;
02740 
02741           if (value_lazy (arg1))
02742             v = allocate_value_lazy (value_enclosing_type (arg1));
02743           else
02744             {
02745               v = allocate_value (value_enclosing_type (arg1));
02746               value_contents_copy_raw (v, 0, arg1, 0,
02747                                        TYPE_LENGTH (value_enclosing_type (arg1)));
02748             }
02749           v->type = type;
02750           v->offset = value_offset (arg1);
02751           v->embedded_offset = offset + value_embedded_offset (arg1) + boffset;
02752         }
02753     }
02754   else
02755     {
02756       /* Plain old data member */
02757       offset += TYPE_FIELD_BITPOS (arg_type, fieldno) / 8;
02758 
02759       /* Lazy register values with offsets are not supported.  */
02760       if (VALUE_LVAL (arg1) == lval_register && value_lazy (arg1))
02761         value_fetch_lazy (arg1);
02762 
02763       /* The optimized_out flag is only set correctly once a lazy value is
02764          loaded, having just loaded some lazy values we should check for
02765          the optimized out case now.  */
02766       if (arg1->optimized_out)
02767         v = allocate_optimized_out_value (type);
02768       else if (value_lazy (arg1))
02769         v = allocate_value_lazy (type);
02770       else
02771         {
02772           v = allocate_value (type);
02773           value_contents_copy_raw (v, value_embedded_offset (v),
02774                                    arg1, value_embedded_offset (arg1) + offset,
02775                                    TYPE_LENGTH (type));
02776         }
02777       v->offset = (value_offset (arg1) + offset
02778                    + value_embedded_offset (arg1));
02779     }
02780   set_value_component_location (v, arg1);
02781   VALUE_REGNUM (v) = VALUE_REGNUM (arg1);
02782   VALUE_FRAME_ID (v) = VALUE_FRAME_ID (arg1);
02783   return v;
02784 }
02785 
02786 /* Given a value ARG1 of a struct or union type,
02787    extract and return the value of one of its (non-static) fields.
02788    FIELDNO says which field.  */
02789 
02790 struct value *
02791 value_field (struct value *arg1, int fieldno)
02792 {
02793   return value_primitive_field (arg1, 0, fieldno, value_type (arg1));
02794 }
02795 
02796 /* Return a non-virtual function as a value.
02797    F is the list of member functions which contains the desired method.
02798    J is an index into F which provides the desired method.
02799 
02800    We only use the symbol for its address, so be happy with either a
02801    full symbol or a minimal symbol.  */
02802 
02803 struct value *
02804 value_fn_field (struct value **arg1p, struct fn_field *f,
02805                 int j, struct type *type,
02806                 int offset)
02807 {
02808   struct value *v;
02809   struct type *ftype = TYPE_FN_FIELD_TYPE (f, j);
02810   const char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
02811   struct symbol *sym;
02812   struct bound_minimal_symbol msym;
02813 
02814   sym = lookup_symbol (physname, 0, VAR_DOMAIN, 0);
02815   if (sym != NULL)
02816     {
02817       memset (&msym, 0, sizeof (msym));
02818     }
02819   else
02820     {
02821       gdb_assert (sym == NULL);
02822       msym = lookup_bound_minimal_symbol (physname);
02823       if (msym.minsym == NULL)
02824         return NULL;
02825     }
02826 
02827   v = allocate_value (ftype);
02828   if (sym)
02829     {
02830       set_value_address (v, BLOCK_START (SYMBOL_BLOCK_VALUE (sym)));
02831     }
02832   else
02833     {
02834       /* The minimal symbol might point to a function descriptor;
02835          resolve it to the actual code address instead.  */
02836       struct objfile *objfile = msym.objfile;
02837       struct gdbarch *gdbarch = get_objfile_arch (objfile);
02838 
02839       set_value_address (v,
02840         gdbarch_convert_from_func_ptr_addr
02841            (gdbarch, SYMBOL_VALUE_ADDRESS (msym.minsym), &current_target));
02842     }
02843 
02844   if (arg1p)
02845     {
02846       if (type != value_type (*arg1p))
02847         *arg1p = value_ind (value_cast (lookup_pointer_type (type),
02848                                         value_addr (*arg1p)));
02849 
02850       /* Move the `this' pointer according to the offset.
02851          VALUE_OFFSET (*arg1p) += offset; */
02852     }
02853 
02854   return v;
02855 }
02856 
02857 
02858 
02859 /* Helper function for both unpack_value_bits_as_long and
02860    unpack_bits_as_long.  See those functions for more details on the
02861    interface; the only difference is that this function accepts either
02862    a NULL or a non-NULL ORIGINAL_VALUE.  */
02863 
02864 static int
02865 unpack_value_bits_as_long_1 (struct type *field_type, const gdb_byte *valaddr,
02866                              int embedded_offset, int bitpos, int bitsize,
02867                              const struct value *original_value,
02868                              LONGEST *result)
02869 {
02870   enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (field_type));
02871   ULONGEST val;
02872   ULONGEST valmask;
02873   int lsbcount;
02874   int bytes_read;
02875   int read_offset;
02876 
02877   /* Read the minimum number of bytes required; there may not be
02878      enough bytes to read an entire ULONGEST.  */
02879   CHECK_TYPEDEF (field_type);
02880   if (bitsize)
02881     bytes_read = ((bitpos % 8) + bitsize + 7) / 8;
02882   else
02883     bytes_read = TYPE_LENGTH (field_type);
02884 
02885   read_offset = bitpos / 8;
02886 
02887   if (original_value != NULL
02888       && !value_bytes_available (original_value, embedded_offset + read_offset,
02889                                  bytes_read))
02890     return 0;
02891 
02892   val = extract_unsigned_integer (valaddr + embedded_offset + read_offset,
02893                                   bytes_read, byte_order);
02894 
02895   /* Extract bits.  See comment above.  */
02896 
02897   if (gdbarch_bits_big_endian (get_type_arch (field_type)))
02898     lsbcount = (bytes_read * 8 - bitpos % 8 - bitsize);
02899   else
02900     lsbcount = (bitpos % 8);
02901   val >>= lsbcount;
02902 
02903   /* If the field does not entirely fill a LONGEST, then zero the sign bits.
02904      If the field is signed, and is negative, then sign extend.  */
02905 
02906   if ((bitsize > 0) && (bitsize < 8 * (int) sizeof (val)))
02907     {
02908       valmask = (((ULONGEST) 1) << bitsize) - 1;
02909       val &= valmask;
02910       if (!TYPE_UNSIGNED (field_type))
02911         {
02912           if (val & (valmask ^ (valmask >> 1)))
02913             {
02914               val |= ~valmask;
02915             }
02916         }
02917     }
02918 
02919   *result = val;
02920   return 1;
02921 }
02922 
02923 /* Unpack a bitfield of the specified FIELD_TYPE, from the object at
02924    VALADDR + EMBEDDED_OFFSET, and store the result in *RESULT.
02925    VALADDR points to the contents of ORIGINAL_VALUE, which must not be
02926    NULL.  The bitfield starts at BITPOS bits and contains BITSIZE
02927    bits.
02928 
02929    Returns false if the value contents are unavailable, otherwise
02930    returns true, indicating a valid value has been stored in *RESULT.
02931 
02932    Extracting bits depends on endianness of the machine.  Compute the
02933    number of least significant bits to discard.  For big endian machines,
02934    we compute the total number of bits in the anonymous object, subtract
02935    off the bit count from the MSB of the object to the MSB of the
02936    bitfield, then the size of the bitfield, which leaves the LSB discard
02937    count.  For little endian machines, the discard count is simply the
02938    number of bits from the LSB of the anonymous object to the LSB of the
02939    bitfield.
02940 
02941    If the field is signed, we also do sign extension.  */
02942 
02943 int
02944 unpack_value_bits_as_long (struct type *field_type, const gdb_byte *valaddr,
02945                            int embedded_offset, int bitpos, int bitsize,
02946                            const struct value *original_value,
02947                            LONGEST *result)
02948 {
02949   gdb_assert (original_value != NULL);
02950 
02951   return unpack_value_bits_as_long_1 (field_type, valaddr, embedded_offset,
02952                                       bitpos, bitsize, original_value, result);
02953 
02954 }
02955 
02956 /* Unpack a field FIELDNO of the specified TYPE, from the object at
02957    VALADDR + EMBEDDED_OFFSET.  VALADDR points to the contents of
02958    ORIGINAL_VALUE.  See unpack_value_bits_as_long for more
02959    details.  */
02960 
02961 static int
02962 unpack_value_field_as_long_1 (struct type *type, const gdb_byte *valaddr,
02963                               int embedded_offset, int fieldno,
02964                               const struct value *val, LONGEST *result)
02965 {
02966   int bitpos = TYPE_FIELD_BITPOS (type, fieldno);
02967   int bitsize = TYPE_FIELD_BITSIZE (type, fieldno);
02968   struct type *field_type = TYPE_FIELD_TYPE (type, fieldno);
02969 
02970   return unpack_value_bits_as_long_1 (field_type, valaddr, embedded_offset,
02971                                       bitpos, bitsize, val,
02972                                       result);
02973 }
02974 
02975 /* Unpack a field FIELDNO of the specified TYPE, from the object at
02976    VALADDR + EMBEDDED_OFFSET.  VALADDR points to the contents of
02977    ORIGINAL_VALUE, which must not be NULL.  See
02978    unpack_value_bits_as_long for more details.  */
02979 
02980 int
02981 unpack_value_field_as_long (struct type *type, const gdb_byte *valaddr,
02982                             int embedded_offset, int fieldno,
02983                             const struct value *val, LONGEST *result)
02984 {
02985   gdb_assert (val != NULL);
02986 
02987   return unpack_value_field_as_long_1 (type, valaddr, embedded_offset,
02988                                        fieldno, val, result);
02989 }
02990 
02991 /* Unpack a field FIELDNO of the specified TYPE, from the anonymous
02992    object at VALADDR.  See unpack_value_bits_as_long for more details.
02993    This function differs from unpack_value_field_as_long in that it
02994    operates without a struct value object.  */
02995 
02996 LONGEST
02997 unpack_field_as_long (struct type *type, const gdb_byte *valaddr, int fieldno)
02998 {
02999   LONGEST result;
03000 
03001   unpack_value_field_as_long_1 (type, valaddr, 0, fieldno, NULL, &result);
03002   return result;
03003 }
03004 
03005 /* Return a new value with type TYPE, which is FIELDNO field of the
03006    object at VALADDR + EMBEDDEDOFFSET.  VALADDR points to the contents
03007    of VAL.  If the VAL's contents required to extract the bitfield
03008    from are unavailable, the new value is correspondingly marked as
03009    unavailable.  */
03010 
03011 struct value *
03012 value_field_bitfield (struct type *type, int fieldno,
03013                       const gdb_byte *valaddr,
03014                       int embedded_offset, const struct value *val)
03015 {
03016   LONGEST l;
03017 
03018   if (!unpack_value_field_as_long (type, valaddr, embedded_offset, fieldno,
03019                                    val, &l))
03020     {
03021       struct type *field_type = TYPE_FIELD_TYPE (type, fieldno);
03022       struct value *retval = allocate_value (field_type);
03023       mark_value_bytes_unavailable (retval, 0, TYPE_LENGTH (field_type));
03024       return retval;
03025     }
03026   else
03027     {
03028       return value_from_longest (TYPE_FIELD_TYPE (type, fieldno), l);
03029     }
03030 }
03031 
03032 /* Modify the value of a bitfield.  ADDR points to a block of memory in
03033    target byte order; the bitfield starts in the byte pointed to.  FIELDVAL
03034    is the desired value of the field, in host byte order.  BITPOS and BITSIZE
03035    indicate which bits (in target bit order) comprise the bitfield.
03036    Requires 0 < BITSIZE <= lbits, 0 <= BITPOS % 8 + BITSIZE <= lbits, and
03037    0 <= BITPOS, where lbits is the size of a LONGEST in bits.  */
03038 
03039 void
03040 modify_field (struct type *type, gdb_byte *addr,
03041               LONGEST fieldval, int bitpos, int bitsize)
03042 {
03043   enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
03044   ULONGEST oword;
03045   ULONGEST mask = (ULONGEST) -1 >> (8 * sizeof (ULONGEST) - bitsize);
03046   int bytesize;
03047 
03048   /* Normalize BITPOS.  */
03049   addr += bitpos / 8;
03050   bitpos %= 8;
03051 
03052   /* If a negative fieldval fits in the field in question, chop
03053      off the sign extension bits.  */
03054   if ((~fieldval & ~(mask >> 1)) == 0)
03055     fieldval &= mask;
03056 
03057   /* Warn if value is too big to fit in the field in question.  */
03058   if (0 != (fieldval & ~mask))
03059     {
03060       /* FIXME: would like to include fieldval in the message, but
03061          we don't have a sprintf_longest.  */
03062       warning (_("Value does not fit in %d bits."), bitsize);
03063 
03064       /* Truncate it, otherwise adjoining fields may be corrupted.  */
03065       fieldval &= mask;
03066     }
03067 
03068   /* Ensure no bytes outside of the modified ones get accessed as it may cause
03069      false valgrind reports.  */
03070 
03071   bytesize = (bitpos + bitsize + 7) / 8;
03072   oword = extract_unsigned_integer (addr, bytesize, byte_order);
03073 
03074   /* Shifting for bit field depends on endianness of the target machine.  */
03075   if (gdbarch_bits_big_endian (get_type_arch (type)))
03076     bitpos = bytesize * 8 - bitpos - bitsize;
03077 
03078   oword &= ~(mask << bitpos);
03079   oword |= fieldval << bitpos;
03080 
03081   store_unsigned_integer (addr, bytesize, byte_order, oword);
03082 }
03083 
03084 /* Pack NUM into BUF using a target format of TYPE.  */
03085 
03086 void
03087 pack_long (gdb_byte *buf, struct type *type, LONGEST num)
03088 {
03089   enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
03090   int len;
03091 
03092   type = check_typedef (type);
03093   len = TYPE_LENGTH (type);
03094 
03095   switch (TYPE_CODE (type))
03096     {
03097     case TYPE_CODE_INT:
03098     case TYPE_CODE_CHAR:
03099     case TYPE_CODE_ENUM:
03100     case TYPE_CODE_FLAGS:
03101     case TYPE_CODE_BOOL:
03102     case TYPE_CODE_RANGE:
03103     case TYPE_CODE_MEMBERPTR:
03104       store_signed_integer (buf, len, byte_order, num);
03105       break;
03106 
03107     case TYPE_CODE_REF:
03108     case TYPE_CODE_PTR:
03109       store_typed_address (buf, type, (CORE_ADDR) num);
03110       break;
03111 
03112     default:
03113       error (_("Unexpected type (%d) encountered for integer constant."),
03114              TYPE_CODE (type));
03115     }
03116 }
03117 
03118 
03119 /* Pack NUM into BUF using a target format of TYPE.  */
03120 
03121 static void
03122 pack_unsigned_long (gdb_byte *buf, struct type *type, ULONGEST num)
03123 {
03124   int len;
03125   enum bfd_endian byte_order;
03126 
03127   type = check_typedef (type);
03128   len = TYPE_LENGTH (type);
03129   byte_order = gdbarch_byte_order (get_type_arch (type));
03130 
03131   switch (TYPE_CODE (type))
03132     {
03133     case TYPE_CODE_INT:
03134     case TYPE_CODE_CHAR:
03135     case TYPE_CODE_ENUM:
03136     case TYPE_CODE_FLAGS:
03137     case TYPE_CODE_BOOL:
03138     case TYPE_CODE_RANGE:
03139     case TYPE_CODE_MEMBERPTR:
03140       store_unsigned_integer (buf, len, byte_order, num);
03141       break;
03142 
03143     case TYPE_CODE_REF:
03144     case TYPE_CODE_PTR:
03145       store_typed_address (buf, type, (CORE_ADDR) num);
03146       break;
03147 
03148     default:
03149       error (_("Unexpected type (%d) encountered "
03150                "for unsigned integer constant."),
03151              TYPE_CODE (type));
03152     }
03153 }
03154 
03155 
03156 /* Convert C numbers into newly allocated values.  */
03157 
03158 struct value *
03159 value_from_longest (struct type *type, LONGEST num)
03160 {
03161   struct value *val = allocate_value (type);
03162 
03163   pack_long (value_contents_raw (val), type, num);
03164   return val;
03165 }
03166 
03167 
03168 /* Convert C unsigned numbers into newly allocated values.  */
03169 
03170 struct value *
03171 value_from_ulongest (struct type *type, ULONGEST num)
03172 {
03173   struct value *val = allocate_value (type);
03174 
03175   pack_unsigned_long (value_contents_raw (val), type, num);
03176 
03177   return val;
03178 }
03179 
03180 
03181 /* Create a value representing a pointer of type TYPE to the address
03182    ADDR.  */
03183 struct value *
03184 value_from_pointer (struct type *type, CORE_ADDR addr)
03185 {
03186   struct value *val = allocate_value (type);
03187 
03188   store_typed_address (value_contents_raw (val), check_typedef (type), addr);
03189   return val;
03190 }
03191 
03192 
03193 /* Create a value of type TYPE whose contents come from VALADDR, if it
03194    is non-null, and whose memory address (in the inferior) is
03195    ADDRESS.  */
03196 
03197 struct value *
03198 value_from_contents_and_address (struct type *type,
03199                                  const gdb_byte *valaddr,
03200                                  CORE_ADDR address)
03201 {
03202   struct value *v;
03203 
03204   if (valaddr == NULL)
03205     v = allocate_value_lazy (type);
03206   else
03207     v = value_from_contents (type, valaddr);
03208   set_value_address (v, address);
03209   VALUE_LVAL (v) = lval_memory;
03210   return v;
03211 }
03212 
03213 /* Create a value of type TYPE holding the contents CONTENTS.
03214    The new value is `not_lval'.  */
03215 
03216 struct value *
03217 value_from_contents (struct type *type, const gdb_byte *contents)
03218 {
03219   struct value *result;
03220 
03221   result = allocate_value (type);
03222   memcpy (value_contents_raw (result), contents, TYPE_LENGTH (type));
03223   return result;
03224 }
03225 
03226 struct value *
03227 value_from_double (struct type *type, DOUBLEST num)
03228 {
03229   struct value *val = allocate_value (type);
03230   struct type *base_type = check_typedef (type);
03231   enum type_code code = TYPE_CODE (base_type);
03232 
03233   if (code == TYPE_CODE_FLT)
03234     {
03235       store_typed_floating (value_contents_raw (val), base_type, num);
03236     }
03237   else
03238     error (_("Unexpected type encountered for floating constant."));
03239 
03240   return val;
03241 }
03242 
03243 struct value *
03244 value_from_decfloat (struct type *type, const gdb_byte *dec)
03245 {
03246   struct value *val = allocate_value (type);
03247 
03248   memcpy (value_contents_raw (val), dec, TYPE_LENGTH (type));
03249   return val;
03250 }
03251 
03252 /* Extract a value from the history file.  Input will be of the form
03253    $digits or $$digits.  See block comment above 'write_dollar_variable'
03254    for details.  */
03255 
03256 struct value *
03257 value_from_history_ref (char *h, char **endp)
03258 {
03259   int index, len;
03260 
03261   if (h[0] == '$')
03262     len = 1;
03263   else
03264     return NULL;
03265 
03266   if (h[1] == '$')
03267     len = 2;
03268 
03269   /* Find length of numeral string.  */
03270   for (; isdigit (h[len]); len++)
03271     ;
03272 
03273   /* Make sure numeral string is not part of an identifier.  */
03274   if (h[len] == '_' || isalpha (h[len]))
03275     return NULL;
03276 
03277   /* Now collect the index value.  */
03278   if (h[1] == '$')
03279     {
03280       if (len == 2)
03281         {
03282           /* For some bizarre reason, "$$" is equivalent to "$$1", 
03283              rather than to "$$0" as it ought to be!  */
03284           index = -1;
03285           *endp += len;
03286         }
03287       else
03288         index = -strtol (&h[2], endp, 10);
03289     }
03290   else
03291     {
03292       if (len == 1)
03293         {
03294           /* "$" is equivalent to "$0".  */
03295           index = 0;
03296           *endp += len;
03297         }
03298       else
03299         index = strtol (&h[1], endp, 10);
03300     }
03301 
03302   return access_value_history (index);
03303 }
03304 
03305 struct value *
03306 coerce_ref_if_computed (const struct value *arg)
03307 {
03308   const struct lval_funcs *funcs;
03309 
03310   if (TYPE_CODE (check_typedef (value_type (arg))) != TYPE_CODE_REF)
03311     return NULL;
03312 
03313   if (value_lval_const (arg) != lval_computed)
03314     return NULL;
03315 
03316   funcs = value_computed_funcs (arg);
03317   if (funcs->coerce_ref == NULL)
03318     return NULL;
03319 
03320   return funcs->coerce_ref (arg);
03321 }
03322 
03323 /* Look at value.h for description.  */
03324 
03325 struct value *
03326 readjust_indirect_value_type (struct value *value, struct type *enc_type,
03327                               struct type *original_type,
03328                               struct value *original_value)
03329 {
03330   /* Re-adjust type.  */
03331   deprecated_set_value_type (value, TYPE_TARGET_TYPE (original_type));
03332 
03333   /* Add embedding info.  */
03334   set_value_enclosing_type (value, enc_type);
03335   set_value_embedded_offset (value, value_pointed_to_offset (original_value));
03336 
03337   /* We may be pointing to an object of some derived type.  */
03338   return value_full_object (value, NULL, 0, 0, 0);
03339 }
03340 
03341 struct value *
03342 coerce_ref (struct value *arg)
03343 {
03344   struct type *value_type_arg_tmp = check_typedef (value_type (arg));
03345   struct value *retval;
03346   struct type *enc_type;
03347 
03348   retval = coerce_ref_if_computed (arg);
03349   if (retval)
03350     return retval;
03351 
03352   if (TYPE_CODE (value_type_arg_tmp) != TYPE_CODE_REF)
03353     return arg;
03354 
03355   enc_type = check_typedef (value_enclosing_type (arg));
03356   enc_type = TYPE_TARGET_TYPE (enc_type);
03357 
03358   retval = value_at_lazy (enc_type,
03359                           unpack_pointer (value_type (arg),
03360                                           value_contents (arg)));
03361   return readjust_indirect_value_type (retval, enc_type,
03362                                        value_type_arg_tmp, arg);
03363 }
03364 
03365 struct value *
03366 coerce_array (struct value *arg)
03367 {
03368   struct type *type;
03369 
03370   arg = coerce_ref (arg);
03371   type = check_typedef (value_type (arg));
03372 
03373   switch (TYPE_CODE (type))
03374     {
03375     case TYPE_CODE_ARRAY:
03376       if (!TYPE_VECTOR (type) && current_language->c_style_arrays)
03377         arg = value_coerce_array (arg);
03378       break;
03379     case TYPE_CODE_FUNC:
03380       arg = value_coerce_function (arg);
03381       break;
03382     }
03383   return arg;
03384 }
03385 
03386 
03387 /* Return the return value convention that will be used for the
03388    specified type.  */
03389 
03390 enum return_value_convention
03391 struct_return_convention (struct gdbarch *gdbarch,
03392                           struct value *function, struct type *value_type)
03393 {
03394   enum type_code code = TYPE_CODE (value_type);
03395 
03396   if (code == TYPE_CODE_ERROR)
03397     error (_("Function return type unknown."));
03398 
03399   /* Probe the architecture for the return-value convention.  */
03400   return gdbarch_return_value (gdbarch, function, value_type,
03401                                NULL, NULL, NULL);
03402 }
03403 
03404 /* Return true if the function returning the specified type is using
03405    the convention of returning structures in memory (passing in the
03406    address as a hidden first parameter).  */
03407 
03408 int
03409 using_struct_return (struct gdbarch *gdbarch,
03410                      struct value *function, struct type *value_type)
03411 {
03412   if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
03413     /* A void return value is never in memory.  See also corresponding
03414        code in "print_return_value".  */
03415     return 0;
03416 
03417   return (struct_return_convention (gdbarch, function, value_type)
03418           != RETURN_VALUE_REGISTER_CONVENTION);
03419 }
03420 
03421 /* Set the initialized field in a value struct.  */
03422 
03423 void
03424 set_value_initialized (struct value *val, int status)
03425 {
03426   val->initialized = status;
03427 }
03428 
03429 /* Return the initialized field in a value struct.  */
03430 
03431 int
03432 value_initialized (struct value *val)
03433 {
03434   return val->initialized;
03435 }
03436 
03437 /* Called only from the value_contents and value_contents_all()
03438    macros, if the current data for a variable needs to be loaded into
03439    value_contents(VAL).  Fetches the data from the user's process, and
03440    clears the lazy flag to indicate that the data in the buffer is
03441    valid.
03442 
03443    If the value is zero-length, we avoid calling read_memory, which
03444    would abort.  We mark the value as fetched anyway -- all 0 bytes of
03445    it.
03446 
03447    This function returns a value because it is used in the
03448    value_contents macro as part of an expression, where a void would
03449    not work.  The value is ignored.  */
03450 
03451 int
03452 value_fetch_lazy (struct value *val)
03453 {
03454   gdb_assert (value_lazy (val));
03455   allocate_value_contents (val);
03456   if (value_bitsize (val))
03457     {
03458       /* To read a lazy bitfield, read the entire enclosing value.  This
03459          prevents reading the same block of (possibly volatile) memory once
03460          per bitfield.  It would be even better to read only the containing
03461          word, but we have no way to record that just specific bits of a
03462          value have been fetched.  */
03463       struct type *type = check_typedef (value_type (val));
03464       enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
03465       struct value *parent = value_parent (val);
03466       LONGEST offset = value_offset (val);
03467       LONGEST num;
03468 
03469       if (value_lazy (parent))
03470         value_fetch_lazy (parent);
03471 
03472       if (!value_bits_valid (parent,
03473                              TARGET_CHAR_BIT * offset + value_bitpos (val),
03474                              value_bitsize (val)))
03475         set_value_optimized_out (val, 1);
03476       else if (!unpack_value_bits_as_long (value_type (val),
03477                                       value_contents_for_printing (parent),
03478                                       offset,
03479                                       value_bitpos (val),
03480                                       value_bitsize (val), parent, &num))
03481         mark_value_bytes_unavailable (val,
03482                                       value_embedded_offset (val),
03483                                       TYPE_LENGTH (type));
03484       else
03485         store_signed_integer (value_contents_raw (val), TYPE_LENGTH (type),
03486                               byte_order, num);
03487     }
03488   else if (VALUE_LVAL (val) == lval_memory)
03489     {
03490       CORE_ADDR addr = value_address (val);
03491       struct type *type = check_typedef (value_enclosing_type (val));
03492 
03493       if (TYPE_LENGTH (type))
03494         read_value_memory (val, 0, value_stack (val),
03495                            addr, value_contents_all_raw (val),
03496                            TYPE_LENGTH (type));
03497     }
03498   else if (VALUE_LVAL (val) == lval_register)
03499     {
03500       struct frame_info *frame;
03501       int regnum;
03502       struct type *type = check_typedef (value_type (val));
03503       struct value *new_val = val, *mark = value_mark ();
03504 
03505       /* Offsets are not supported here; lazy register values must
03506          refer to the entire register.  */
03507       gdb_assert (value_offset (val) == 0);
03508 
03509       while (VALUE_LVAL (new_val) == lval_register && value_lazy (new_val))
03510         {
03511           frame = frame_find_by_id (VALUE_FRAME_ID (new_val));
03512           regnum = VALUE_REGNUM (new_val);
03513 
03514           gdb_assert (frame != NULL);
03515 
03516           /* Convertible register routines are used for multi-register
03517              values and for interpretation in different types
03518              (e.g. float or int from a double register).  Lazy
03519              register values should have the register's natural type,
03520              so they do not apply.  */
03521           gdb_assert (!gdbarch_convert_register_p (get_frame_arch (frame),
03522                                                    regnum, type));
03523 
03524           new_val = get_frame_register_value (frame, regnum);
03525         }
03526 
03527       /* If it's still lazy (for instance, a saved register on the
03528          stack), fetch it.  */
03529       if (value_lazy (new_val))
03530         value_fetch_lazy (new_val);
03531 
03532       /* If the register was not saved, mark it optimized out.  */
03533       if (value_optimized_out (new_val))
03534         set_value_optimized_out (val, 1);
03535       else
03536         {
03537           set_value_lazy (val, 0);
03538           value_contents_copy (val, value_embedded_offset (val),
03539                                new_val, value_embedded_offset (new_val),
03540                                TYPE_LENGTH (type));
03541         }
03542 
03543       if (frame_debug)
03544         {
03545           struct gdbarch *gdbarch;
03546           frame = frame_find_by_id (VALUE_FRAME_ID (val));
03547           regnum = VALUE_REGNUM (val);
03548           gdbarch = get_frame_arch (frame);
03549 
03550           fprintf_unfiltered (gdb_stdlog,
03551                               "{ value_fetch_lazy "
03552                               "(frame=%d,regnum=%d(%s),...) ",
03553                               frame_relative_level (frame), regnum,
03554                               user_reg_map_regnum_to_name (gdbarch, regnum));
03555 
03556           fprintf_unfiltered (gdb_stdlog, "->");
03557           if (value_optimized_out (new_val))
03558             fprintf_unfiltered (gdb_stdlog, " optimized out");
03559           else
03560             {
03561               int i;
03562               const gdb_byte *buf = value_contents (new_val);
03563 
03564               if (VALUE_LVAL (new_val) == lval_register)
03565                 fprintf_unfiltered (gdb_stdlog, " register=%d",
03566                                     VALUE_REGNUM (new_val));
03567               else if (VALUE_LVAL (new_val) == lval_memory)
03568                 fprintf_unfiltered (gdb_stdlog, " address=%s",
03569                                     paddress (gdbarch,
03570                                               value_address (new_val)));
03571               else
03572                 fprintf_unfiltered (gdb_stdlog, " computed");
03573 
03574               fprintf_unfiltered (gdb_stdlog, " bytes=");
03575               fprintf_unfiltered (gdb_stdlog, "[");
03576               for (i = 0; i < register_size (gdbarch, regnum); i++)
03577                 fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
03578               fprintf_unfiltered (gdb_stdlog, "]");
03579             }
03580 
03581           fprintf_unfiltered (gdb_stdlog, " }\n");
03582         }
03583 
03584       /* Dispose of the intermediate values.  This prevents
03585          watchpoints from trying to watch the saved frame pointer.  */
03586       value_free_to_mark (mark);
03587     }
03588   else if (VALUE_LVAL (val) == lval_computed
03589            && value_computed_funcs (val)->read != NULL)
03590     value_computed_funcs (val)->read (val);
03591   /* Don't call value_optimized_out on val, doing so would result in a
03592      recursive call back to value_fetch_lazy, instead check the
03593      optimized_out flag directly.  */
03594   else if (val->optimized_out)
03595     /* Keep it optimized out.  */;
03596   else
03597     internal_error (__FILE__, __LINE__, _("Unexpected lazy value type."));
03598 
03599   set_value_lazy (val, 0);
03600   return 0;
03601 }
03602 
03603 /* Implementation of the convenience function $_isvoid.  */
03604 
03605 static struct value *
03606 isvoid_internal_fn (struct gdbarch *gdbarch,
03607                     const struct language_defn *language,
03608                     void *cookie, int argc, struct value **argv)
03609 {
03610   int ret;
03611 
03612   if (argc != 1)
03613     error (_("You must provide one argument for $_isvoid."));
03614 
03615   ret = TYPE_CODE (value_type (argv[0])) == TYPE_CODE_VOID;
03616 
03617   return value_from_longest (builtin_type (gdbarch)->builtin_int, ret);
03618 }
03619 
03620 void
03621 _initialize_values (void)
03622 {
03623   add_cmd ("convenience", no_class, show_convenience, _("\
03624 Debugger convenience (\"$foo\") variables and functions.\n\
03625 Convenience variables are created when you assign them values;\n\
03626 thus, \"set $foo=1\" gives \"$foo\" the value 1.  Values may be any type.\n\
03627 \n\
03628 A few convenience variables are given values automatically:\n\
03629 \"$_\"holds the last address examined with \"x\" or \"info lines\",\n\
03630 \"$__\" holds the contents of the last address examined with \"x\"."
03631 #ifdef HAVE_PYTHON
03632 "\n\n\
03633 Convenience functions are defined via the Python API."
03634 #endif
03635            ), &showlist);
03636   add_alias_cmd ("conv", "convenience", no_class, 1, &showlist);
03637 
03638   add_cmd ("values", no_set_class, show_values, _("\
03639 Elements of value history around item number IDX (or last ten)."),
03640            &showlist);
03641 
03642   add_com ("init-if-undefined", class_vars, init_if_undefined_command, _("\
03643 Initialize a convenience variable if necessary.\n\
03644 init-if-undefined VARIABLE = EXPRESSION\n\
03645 Set an internal VARIABLE to the result of the EXPRESSION if it does not\n\
03646 exist or does not contain a value.  The EXPRESSION is not evaluated if the\n\
03647 VARIABLE is already initialized."));
03648 
03649   add_prefix_cmd ("function", no_class, function_command, _("\
03650 Placeholder command for showing help on convenience functions."),
03651                   &functionlist, "function ", 0, &cmdlist);
03652 
03653   add_internal_function ("_isvoid", _("\
03654 Check whether an expression is void.\n\
03655 Usage: $_isvoid (expression)\n\
03656 Return 1 if the expression is void, zero otherwise."),
03657                          isvoid_internal_fn, NULL);
03658 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines