Implement demangling for rvalue reference type names
[deliverable/binutils-gdb.git] / gdb / value.c
index cd59f43f01f3eeb5c5fb8eb4455a6a3e921ed3ef..8c3b3f6d71fc92378af33e1e6a3c15bfbe019657 100644 (file)
@@ -1,6 +1,6 @@
 /* Low level packing and unpacking of values for GDB, the GNU Debugger.
 
-   Copyright (C) 1986-2016 Free Software Foundation, Inc.
+   Copyright (C) 1986-2017 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -40,6 +40,7 @@
 #include "tracepoint.h"
 #include "cp-abi.h"
 #include "user-regs.h"
+#include <algorithm>
 
 /* Prototypes for exported functions.  */
 
@@ -84,8 +85,8 @@ ranges_overlap (LONGEST offset1, LONGEST len1,
 {
   ULONGEST h, l;
 
-  l = max (offset1, offset2);
-  h = min (offset1 + len1, offset2 + len2);
+  l = std::max (offset1, offset2);
+  h = std::min (offset1 + len1, offset2 + len2);
   return (l < h);
 }
 
@@ -204,17 +205,23 @@ struct value
   /* If the value has been released.  */
   unsigned int released : 1;
 
-  /* Register number if the value is from a register.  */
-  short regnum;
-
   /* Location of value (if lval).  */
   union
   {
-    /* If lval == lval_memory, this is the address in the inferior.
-       If lval == lval_register, this is the byte offset into the
-       registers structure.  */
+    /* If lval == lval_memory, this is the address in the inferior  */
     CORE_ADDR address;
 
+    /*If lval == lval_register, the value is from a register.  */
+    struct
+    {
+      /* Register number.  */
+      int regnum;
+      /* Frame ID of "next" frame to which a register value is relative.
+        If the register value is found relative to frame F, then the
+        frame id of F->next will be stored in next_frame_id.  */
+      struct frame_id next_frame_id;
+    } reg;
+
     /* Pointer to internal variable.  */
     struct internalvar *internalvar;
 
@@ -235,10 +242,8 @@ struct value
   } location;
 
   /* Describes offset of a value within lval of a structure in target
-     addressable memory units.  If lval == lval_memory, this is an offset to
-     the address.  If lval == lval_register, this is a further offset from
-     location.address within the registers structure.  Note also the member
-     embedded_offset below.  */
+     addressable memory units.  Note also the member embedded_offset
+     below.  */
   LONGEST offset;
 
   /* Only used for bitfields; number of bits contained in them.  */
@@ -261,10 +266,6 @@ struct value
      bitfields.  */
   struct value *parent;
 
-  /* Frame register value is relative to.  This will be described in
-     the lval enum above as "lval_register".  */
-  struct frame_id frame_id;
-
   /* Type of the value.  */
   struct type *type;
 
@@ -528,8 +529,8 @@ insert_into_bit_range_vector (VEC(range_s) **vectorp,
       if (ranges_overlap (bef->offset, bef->length, offset, length))
        {
          /* #1 */
-         ULONGEST l = min (bef->offset, offset);
-         ULONGEST h = max (bef->offset + bef->length, offset + length);
+         ULONGEST l = std::min (bef->offset, offset);
+         ULONGEST h = std::max (bef->offset + bef->length, offset + length);
 
          bef->offset = l;
          bef->length = h - l;
@@ -572,8 +573,8 @@ insert_into_bit_range_vector (VEC(range_s) **vectorp,
          {
            ULONGEST l, h;
 
-           l = min (t->offset, r->offset);
-           h = max (t->offset + t->length, r->offset + r->length);
+           l = std::min (t->offset, r->offset);
+           h = std::max (t->offset + t->length, r->offset + r->length);
 
            t->offset = l;
            t->length = h - l;
@@ -780,11 +781,11 @@ find_first_range_overlap_and_match (struct ranges_and_idx *rp1,
       /* Get the unavailable windows intersected by the incoming
         ranges.  The first and last ranges that overlap the argument
         range may be wider than said incoming arguments ranges.  */
-      l1 = max (offset1, r1->offset);
-      h1 = min (offset1 + length, r1->offset + r1->length);
+      l1 = std::max (offset1, r1->offset);
+      h1 = std::min (offset1 + length, r1->offset + r1->length);
 
-      l2 = max (offset2, r2->offset);
-      h2 = min (offset2 + length, offset2 + r2->length);
+      l2 = std::max (offset2, r2->offset);
+      h2 = std::min (offset2 + length, offset2 + r2->length);
 
       /* Make them relative to the respective start offsets, so we can
         compare them for equality.  */
@@ -942,11 +943,9 @@ allocate_value_lazy (struct type *type)
   val->enclosing_type = type;
   VALUE_LVAL (val) = not_lval;
   val->location.address = 0;
-  VALUE_FRAME_ID (val) = null_frame_id;
   val->offset = 0;
   val->bitpos = 0;
   val->bitsize = 0;
-  VALUE_REGNUM (val) = -1;
   val->lazy = 1;
   val->embedded_offset = 0;
   val->pointed_to_offset = 0;
@@ -1297,8 +1296,9 @@ ranges_copy_adjusted (VEC (range_s) **dst_range, int dst_bit_offset,
     {
       ULONGEST h, l;
 
-      l = max (r->offset, src_bit_offset);
-      h = min (r->offset + r->length, src_bit_offset + bit_length);
+      l = std::max (r->offset, (LONGEST) src_bit_offset);
+      h = std::min (r->offset + r->length,
+                   (LONGEST) src_bit_offset + bit_length);
 
       if (l < h)
        insert_into_bit_range_vector (dst_range,
@@ -1539,9 +1539,7 @@ value_lval_const (const struct value *value)
 CORE_ADDR
 value_address (const struct value *value)
 {
-  if (value->lval == lval_internalvar
-      || value->lval == lval_internalvar_component
-      || value->lval == lval_xcallable)
+  if (value->lval != lval_memory)
     return 0;
   if (value->parent != NULL)
     return value_address (value->parent) + value->offset;
@@ -1557,9 +1555,7 @@ value_address (const struct value *value)
 CORE_ADDR
 value_raw_address (const struct value *value)
 {
-  if (value->lval == lval_internalvar
-      || value->lval == lval_internalvar_component
-      || value->lval == lval_xcallable)
+  if (value->lval != lval_memory)
     return 0;
   return value->location.address;
 }
@@ -1567,9 +1563,7 @@ value_raw_address (const struct value *value)
 void
 set_value_address (struct value *value, CORE_ADDR addr)
 {
-  gdb_assert (value->lval != lval_internalvar
-             && value->lval != lval_internalvar_component
-             && value->lval != lval_xcallable);
+  gdb_assert (value->lval == lval_memory);
   value->location.address = addr;
 }
 
@@ -1580,15 +1574,17 @@ deprecated_value_internalvar_hack (struct value *value)
 }
 
 struct frame_id *
-deprecated_value_frame_id_hack (struct value *value)
+deprecated_value_next_frame_id_hack (struct value *value)
 {
-  return &value->frame_id;
+  gdb_assert (value->lval == lval_register);
+  return &value->location.reg.next_frame_id;
 }
 
-short *
+int *
 deprecated_value_regnum_hack (struct value *value)
 {
-  return &value->regnum;
+  gdb_assert (value->lval == lval_register);
+  return &value->location.reg.regnum;
 }
 
 int
@@ -1784,8 +1780,6 @@ value_copy (struct value *arg)
   val->offset = arg->offset;
   val->bitpos = arg->bitpos;
   val->bitsize = arg->bitsize;
-  VALUE_FRAME_ID (val) = VALUE_FRAME_ID (arg);
-  VALUE_REGNUM (val) = VALUE_REGNUM (arg);
   val->lazy = arg->lazy;
   val->embedded_offset = value_embedded_offset (arg);
   val->pointed_to_offset = arg->pointed_to_offset;
@@ -2111,9 +2105,7 @@ init_if_undefined_command (char* args, int from_tty)
   struct internalvar* intvar;
 
   /* Parse the expression - this is taken from set_command().  */
-  struct expression *expr = parse_expression (args);
-  register struct cleanup *old_chain =
-    make_cleanup (free_current_contents, &expr);
+  expression_up expr = parse_expression (args);
 
   /* Validate the expression.
      Was the expression an assignment?
@@ -2131,9 +2123,7 @@ init_if_undefined_command (char* args, int from_tty)
   /* Only evaluate the expression if the lvalue is void.
      This may still fail if the expresssion is invalid.  */
   if (intvar->kind == INTERNALVAR_VOID)
-    evaluate_expression (expr);
-
-  do_cleanups (old_chain);
+    evaluate_expression (expr.get ());
 }
 
 
@@ -3229,8 +3219,6 @@ value_primitive_field (struct value *arg1, LONGEST offset,
                   + value_embedded_offset (arg1));
     }
   set_value_component_location (v, arg1);
-  VALUE_REGNUM (v) = VALUE_REGNUM (arg1);
-  VALUE_FRAME_ID (v) = VALUE_FRAME_ID (arg1);
   return v;
 }
 
@@ -3276,6 +3264,7 @@ value_fn_field (struct value **arg1p, struct fn_field *f,
     }
 
   v = allocate_value (ftype);
+  VALUE_LVAL (v) = lval_memory;
   if (sym)
     {
       set_value_address (v, BLOCK_START (SYMBOL_BLOCK_VALUE (sym)));
@@ -3430,17 +3419,24 @@ unpack_value_bitfield (struct value *dest_val,
   enum bfd_endian byte_order;
   int src_bit_offset;
   int dst_bit_offset;
-  LONGEST num;
   struct type *field_type = value_type (dest_val);
 
-  /* First, unpack and sign extend the bitfield as if it was wholly
-     available.  Invalid/unavailable bits are read as zero, but that's
-     OK, as they'll end up marked below.  */
   byte_order = gdbarch_byte_order (get_type_arch (field_type));
-  num = unpack_bits_as_long (field_type, valaddr + embedded_offset,
-                            bitpos, bitsize);
-  store_signed_integer (value_contents_raw (dest_val),
-                       TYPE_LENGTH (field_type), byte_order, num);
+
+  /* First, unpack and sign extend the bitfield as if it was wholly
+     valid.  Optimized out/unavailable bits are read as zero, but
+     that's OK, as they'll end up marked below.  If the VAL is
+     wholly-invalid we may have skipped allocating its contents,
+     though.  See allocate_optimized_out_value.  */
+  if (valaddr != NULL)
+    {
+      LONGEST num;
+
+      num = unpack_bits_as_long (field_type, valaddr + embedded_offset,
+                                bitpos, bitsize);
+      store_signed_integer (value_contents_raw (dest_val),
+                           TYPE_LENGTH (field_type), byte_order, num);
+    }
 
   /* Now copy the optimized out / unavailability ranges to the right
      bits.  */
@@ -3655,8 +3651,8 @@ value_from_contents_and_address_unresolved (struct type *type,
     v = allocate_value_lazy (type);
   else
     v = value_from_contents (type, valaddr);
-  set_value_address (v, address);
   VALUE_LVAL (v) = lval_memory;
+  set_value_address (v, address);
   return v;
 }
 
@@ -3681,8 +3677,8 @@ value_from_contents_and_address (struct type *type,
   if (TYPE_DATA_LOCATION (resolved_type_no_typedef) != NULL
       && TYPE_DATA_LOCATION_KIND (resolved_type_no_typedef) == PROP_CONST)
     address = TYPE_DATA_LOCATION_ADDR (resolved_type_no_typedef);
-  set_value_address (v, address);
   VALUE_LVAL (v) = lval_memory;
+  set_value_address (v, address);
   return v;
 }
 
@@ -3788,6 +3784,29 @@ value_from_history_ref (const char *h, const char **endp)
   return access_value_history (index);
 }
 
+/* Get the component value (offset by OFFSET bytes) of a struct or
+   union WHOLE.  Component's type is TYPE.  */
+
+struct value *
+value_from_component (struct value *whole, struct type *type, LONGEST offset)
+{
+  struct value *v;
+
+  if (VALUE_LVAL (whole) == lval_memory && value_lazy (whole))
+    v = allocate_value_lazy (type);
+  else
+    {
+      v = allocate_value (type);
+      value_contents_copy (v, value_embedded_offset (v),
+                          whole, value_embedded_offset (whole) + offset,
+                          type_length_units (type));
+    }
+  v->offset = value_offset (whole) + offset + value_embedded_offset (whole);
+  set_value_component_location (v, whole);
+
+  return v;
+}
+
 struct value *
 coerce_ref_if_computed (const struct value *arg)
 {
@@ -3969,7 +3988,7 @@ value_fetch_lazy (struct value *val)
     }
   else if (VALUE_LVAL (val) == lval_register)
     {
-      struct frame_info *frame;
+      struct frame_info *next_frame;
       int regnum;
       struct type *type = check_typedef (value_type (val));
       struct value *new_val = val, *mark = value_mark ();
@@ -3980,27 +3999,33 @@ value_fetch_lazy (struct value *val)
 
       while (VALUE_LVAL (new_val) == lval_register && value_lazy (new_val))
        {
-         struct frame_id frame_id = VALUE_FRAME_ID (new_val);
+         struct frame_id next_frame_id = VALUE_NEXT_FRAME_ID (new_val);
 
-         frame = frame_find_by_id (frame_id);
+         next_frame = frame_find_by_id (next_frame_id);
          regnum = VALUE_REGNUM (new_val);
 
-         gdb_assert (frame != NULL);
+         gdb_assert (next_frame != NULL);
 
          /* Convertible register routines are used for multi-register
             values and for interpretation in different types
             (e.g. float or int from a double register).  Lazy
             register values should have the register's natural type,
             so they do not apply.  */
-         gdb_assert (!gdbarch_convert_register_p (get_frame_arch (frame),
+         gdb_assert (!gdbarch_convert_register_p (get_frame_arch (next_frame),
                                                   regnum, type));
 
-         new_val = get_frame_register_value (frame, regnum);
+         /* FRAME was obtained, above, via VALUE_NEXT_FRAME_ID. 
+            Since a "->next" operation was performed when setting
+            this field, we do not need to perform a "next" operation
+            again when unwinding the register.  That's why
+            frame_unwind_register_value() is called here instead of
+            get_frame_register_value().  */
+         new_val = frame_unwind_register_value (next_frame, regnum);
 
          /* If we get another lazy lval_register value, it means the
-            register is found by reading it from the next frame.
-            get_frame_register_value should never return a value with
-            the frame id pointing to FRAME.  If it does, it means we
+            register is found by reading it from NEXT_FRAME's next frame.
+            frame_unwind_register_value should never return a value with
+            the frame id pointing to NEXT_FRAME.  If it does, it means we
             either have two consecutive frames with the same frame id
             in the frame chain, or some code is trying to unwind
             behind get_prev_frame's back (e.g., a frame unwind
@@ -4009,7 +4034,7 @@ value_fetch_lazy (struct value *val)
             in this situation.  */
          if (VALUE_LVAL (new_val) == lval_register
              && value_lazy (new_val)
-             && frame_id_eq (VALUE_FRAME_ID (new_val), frame_id))
+             && frame_id_eq (VALUE_NEXT_FRAME_ID (new_val), next_frame_id))
            internal_error (__FILE__, __LINE__,
                            _("infinite loop while fetching a register"));
        }
@@ -4029,6 +4054,9 @@ value_fetch_lazy (struct value *val)
       if (frame_debug)
        {
          struct gdbarch *gdbarch;
+         struct frame_info *frame;
+         /* VALUE_FRAME_ID is used here, instead of VALUE_NEXT_FRAME_ID,
+            so that the frame level will be shown correctly.  */
          frame = frame_find_by_id (VALUE_FRAME_ID (val));
          regnum = VALUE_REGNUM (val);
          gdbarch = get_frame_arch (frame);
This page took 0.046232 seconds and 4 git commands to generate.