Consider addressable memory unit size in various value functions
authorSimon Marchi <simon.marchi@ericsson.com>
Tue, 28 Jul 2015 15:01:50 +0000 (11:01 -0400)
committerSimon Marchi <simon.marchi@ericsson.com>
Tue, 28 Jul 2015 15:01:50 +0000 (11:01 -0400)
This patch updates various value handling functions to make them
consider the addressable memory unit size of the current architecture.
This allows to correctly extract and print values on architectures whose
addressable memory unit is not 8 bits.

The patch doesn't cover all the code that would ideally need to be
adjusted, only the code paths that we happen to use, plus a few obvious
ones.  Specifically, those areas are not covered by this patch:

 - Management of unavailable bits
 - Bitfields
 - C++ stuff

Regression-tested on x86-64 Ubuntu 14.04.  I saw no related test result
change.

gdb/ChangeLog:

* c-valprint.c (c_val_print_array): Consider addressable memory
unit size.
(c_val_print_ptr): Likewise.
(c_val_print_int): Likewise.
* findvar.c (read_frame_register_value): Likewise.
* valarith.c (find_size_for_pointer_math): Likewise.
(value_ptrdiff): Likewise.
(value_subscripted_rvalue): Likewise.
* valops.c (read_value_memory): Likewise (and rename variables).
(value_assign): Likewise.
(value_repeat): Likewise.
(value_array): Likewise.
(value_slice): Likewise.
* valprint.c (generic_val_print_ptr): Likewise.
(generic_val_print_enum): Likewise.
(generic_val_print_bool): Likewise.
(generic_val_print_int): Likewise.
(generic_val_print_char): Likewise.
(generic_val_print_float): Likewise.
(generic_val_print_decfloat): Likewise.
(generic_val_print_complex): Likewise.
(val_print_scalar_formatted): Likewise.
(val_print_array_elements): Likewise.
* value.c (set_value_parent): Likewise.
(value_contents_copy_raw): Likewise.
(set_internalvar_component): Likewise.
(value_primitive_field): Likewise.
(value_fetch_lazy): Likewise.
* value.h (read_value_memory): Update comment.

gdb/ChangeLog
gdb/c-valprint.c
gdb/findvar.c
gdb/valarith.c
gdb/valops.c
gdb/valprint.c
gdb/value.c
gdb/value.h

index 93e054bcb400c8b55a193693c4bc93712e37336d..f0220f5275d7c8bba9743b78e42addeeef9ff5e2 100644 (file)
@@ -1,3 +1,35 @@
+2015-07-28  Simon Marchi  <simon.marchi@ericsson.com>
+
+       * c-valprint.c (c_val_print_array): Consider addressable memory
+       unit size.
+       (c_val_print_ptr): Likewise.
+       (c_val_print_int): Likewise.
+       * findvar.c (read_frame_register_value): Likewise.
+       * valarith.c (find_size_for_pointer_math): Likewise.
+       (value_ptrdiff): Likewise.
+       (value_subscripted_rvalue): Likewise.
+       * valops.c (read_value_memory): Likewise (and rename variables).
+       (value_assign): Likewise.
+       (value_repeat): Likewise.
+       (value_array): Likewise.
+       (value_slice): Likewise.
+       * valprint.c (generic_val_print_ptr): Likewise.
+       (generic_val_print_enum): Likewise.
+       (generic_val_print_bool): Likewise.
+       (generic_val_print_int): Likewise.
+       (generic_val_print_char): Likewise.
+       (generic_val_print_float): Likewise.
+       (generic_val_print_decfloat): Likewise.
+       (generic_val_print_complex): Likewise.
+       (val_print_scalar_formatted): Likewise.
+       (val_print_array_elements): Likewise.
+       * value.c (set_value_parent): Likewise.
+       (value_contents_copy_raw): Likewise.
+       (set_internalvar_component): Likewise.
+       (value_primitive_field): Likewise.
+       (value_fetch_lazy): Likewise.
+       * value.h (read_value_memory): Update comment.
+
 2015-07-28  Simon Marchi  <simon.marchi@ericsson.com>
 
        * value.c (get_value_arch): New function.
index 2009e953a95eaad9914a36495c508c6bb9cbc514..0cf2d7d972d812f284de27ef7314e418419aefe1 100644 (file)
@@ -236,6 +236,8 @@ c_val_print_array (struct type *type, const gdb_byte *valaddr,
 {
   struct type *unresolved_elttype = TYPE_TARGET_TYPE (type);
   struct type *elttype = check_typedef (unresolved_elttype);
+  struct gdbarch *arch = get_type_arch (type);
+  int unit_size = gdbarch_addressable_memory_unit_size (arch);
 
   if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0)
     {
@@ -276,7 +278,8 @@ c_val_print_array (struct type *type, const gdb_byte *valaddr,
              for (temp_len = 0;
                   (temp_len < len
                    && temp_len < options->print_max
-                   && extract_unsigned_integer (valaddr + embedded_offset
+                   && extract_unsigned_integer (valaddr
+                                                + embedded_offset * unit_size
                                                 + temp_len * eltlen,
                                                 eltlen, byte_order) != 0);
                   ++temp_len)
@@ -288,7 +291,8 @@ c_val_print_array (struct type *type, const gdb_byte *valaddr,
              if (temp_len == options->print_max && temp_len < len)
                {
                  ULONGEST val
-                   = extract_unsigned_integer (valaddr + embedded_offset
+                   = extract_unsigned_integer (valaddr
+                                               + embedded_offset * unit_size
                                                + temp_len * eltlen,
                                                eltlen, byte_order);
                  if (val != 0)
@@ -299,7 +303,7 @@ c_val_print_array (struct type *type, const gdb_byte *valaddr,
            }
 
          LA_PRINT_STRING (stream, unresolved_elttype,
-                          valaddr + embedded_offset, len,
+                          valaddr + embedded_offset * unit_size, len,
                           NULL, force_ellipses, options);
          i = len;
        }
@@ -342,6 +346,9 @@ c_val_print_ptr (struct type *type, const gdb_byte *valaddr,
                 const struct value *original_value,
                 const struct value_print_options *options)
 {
+  struct gdbarch *arch = get_type_arch (type);
+  int unit_size = gdbarch_addressable_memory_unit_size (arch);
+
   if (options->format && options->format != 's')
     {
       val_print_scalar_formatted (type, valaddr, embedded_offset,
@@ -363,7 +370,8 @@ c_val_print_ptr (struct type *type, const gdb_byte *valaddr,
     {
       struct type *unresolved_elttype = TYPE_TARGET_TYPE (type);
       struct type *elttype = check_typedef (unresolved_elttype);
-      CORE_ADDR addr = unpack_pointer (type, valaddr + embedded_offset);
+      CORE_ADDR addr = unpack_pointer (type,
+                                      valaddr + embedded_offset * unit_size);
 
       print_unpacked_pointer (type, elttype, unresolved_elttype, valaddr,
                              embedded_offset, addr, stream, recurse, options);
@@ -430,6 +438,9 @@ c_val_print_int (struct type *type, struct type *unresolved_type,
                 struct ui_file *stream, const struct value *original_value,
                 const struct value_print_options *options)
 {
+  struct gdbarch *arch = get_type_arch (type);
+  int unit_size = gdbarch_addressable_memory_unit_size (arch);
+
   if (options->format || options->output_format)
     {
       struct value_print_options opts = *options;
@@ -441,7 +452,7 @@ c_val_print_int (struct type *type, struct type *unresolved_type,
     }
   else
     {
-      val_print_type_code_int (type, valaddr + embedded_offset,
+      val_print_type_code_int (type, valaddr + embedded_offset * unit_size,
                               stream);
       /* C and C++ has no single byte int type, char is used
         instead.  Since we don't know whether the value is really
@@ -450,7 +461,8 @@ c_val_print_int (struct type *type, struct type *unresolved_type,
       if (c_textual_element_type (unresolved_type, options->format))
        {
          fputs_filtered (" ", stream);
-         LA_PRINT_CHAR (unpack_long (type, valaddr + embedded_offset),
+         LA_PRINT_CHAR (unpack_long (type,
+                                     valaddr + embedded_offset * unit_size),
                         unresolved_type, stream);
        }
     }
index 2079b4b2b183f14a2ff0b6027a25fdeba1b97bdb..83b4fca500af32c3f43847a8828d50f5c30d6f3f 100644 (file)
@@ -662,7 +662,7 @@ read_frame_register_value (struct value *value, struct frame_info *frame)
   int offset = 0;
   int reg_offset = value_offset (value);
   int regnum = VALUE_REGNUM (value);
-  int len = TYPE_LENGTH (check_typedef (value_type (value)));
+  int len = type_length_units (check_typedef (value_type (value)));
 
   gdb_assert (VALUE_LVAL (value) == lval_register);
 
@@ -677,7 +677,7 @@ read_frame_register_value (struct value *value, struct frame_info *frame)
   while (len > 0)
     {
       struct value *regval = get_frame_register_value (frame, regnum);
-      int reg_len = TYPE_LENGTH (value_type (regval)) - reg_offset;
+      int reg_len = type_length_units (value_type (regval)) - reg_offset;
 
       /* If the register length is larger than the number of bytes
          remaining to copy, then only copy the appropriate bytes.  */
index 0162c10681aeadade85f3ec68f8115c9547be5b4..3e349f23f5b8720a133530fb75fc0af5cda714f8 100644 (file)
@@ -54,7 +54,7 @@ find_size_for_pointer_math (struct type *ptr_type)
   gdb_assert (TYPE_CODE (ptr_type) == TYPE_CODE_PTR);
   ptr_target = check_typedef (TYPE_TARGET_TYPE (ptr_type));
 
-  sz = TYPE_LENGTH (ptr_target);
+  sz = type_length_units (ptr_target);
   if (sz == 0)
     {
       if (TYPE_CODE (ptr_type) == TYPE_CODE_VOID)
@@ -121,7 +121,7 @@ value_ptrdiff (struct value *arg1, struct value *arg2)
             "second argument is neither\n"
             "an integer nor a pointer of the same type."));
 
-  sz = TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type1)));
+  sz = type_length_units (check_typedef (TYPE_TARGET_TYPE (type1)));
   if (sz == 0) 
     {
       warning (_("Type size unknown, assuming 1. "
@@ -192,12 +192,12 @@ value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
 {
   struct type *array_type = check_typedef (value_type (array));
   struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
-  unsigned int elt_size = TYPE_LENGTH (elt_type);
+  unsigned int elt_size = type_length_units (elt_type);
   unsigned int elt_offs = elt_size * longest_to_int (index - lowerbound);
   struct value *v;
 
   if (index < lowerbound || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
-                            && elt_offs >= TYPE_LENGTH (array_type)))
+                            && elt_offs >= type_length_units (array_type)))
     error (_("no such vector element"));
 
   if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
index d68e9f3e59727fc250773b4c5513a58cf2c24af9..dac0274e474dfb72f2869683435a8e8629cec8d0 100644 (file)
@@ -958,30 +958,33 @@ read_value_memory (struct value *val, int embedded_offset,
                   int stack, CORE_ADDR memaddr,
                   gdb_byte *buffer, size_t length)
 {
-  ULONGEST xfered = 0;
+  ULONGEST xfered_total = 0;
+  struct gdbarch *arch = get_value_arch (val);
+  int unit_size = gdbarch_addressable_memory_unit_size (arch);
 
-  while (xfered < length)
+  while (xfered_total < length)
     {
       enum target_xfer_status status;
-      ULONGEST xfered_len;
+      ULONGEST xfered_partial;
 
       status = target_xfer_partial (current_target.beneath,
                                    TARGET_OBJECT_MEMORY, NULL,
-                                   buffer + xfered, NULL,
-                                   memaddr + xfered, length - xfered,
-                                   &xfered_len);
+                                   buffer + xfered_total * unit_size, NULL,
+                                   memaddr + xfered_total,
+                                   length - xfered_total,
+                                   &xfered_partial);
 
       if (status == TARGET_XFER_OK)
        /* nothing */;
       else if (status == TARGET_XFER_UNAVAILABLE)
-       mark_value_bytes_unavailable (val, embedded_offset + xfered,
-                                     xfered_len);
+       mark_value_bytes_unavailable (val, embedded_offset + xfered_total,
+                                     xfered_partial);
       else if (status == TARGET_XFER_EOF)
-       memory_error (TARGET_XFER_E_IO, memaddr + xfered);
+       memory_error (TARGET_XFER_E_IO, memaddr + xfered_total);
       else
-       memory_error (status, memaddr + xfered);
+       memory_error (status, memaddr + xfered_total);
 
-      xfered += xfered_len;
+      xfered_total += xfered_partial;
       QUIT;
     }
 }
@@ -1089,7 +1092,7 @@ value_assign (struct value *toval, struct value *fromval)
        else
          {
            changed_addr = value_address (toval);
-           changed_len = TYPE_LENGTH (type);
+           changed_len = type_length_units (type);
            dest_buffer = value_contents (fromval);
          }
 
@@ -1280,7 +1283,7 @@ value_repeat (struct value *arg1, int count)
 
   read_value_memory (val, 0, value_stack (val), value_address (val),
                     value_contents_all_raw (val),
-                    TYPE_LENGTH (value_enclosing_type (val)));
+                    type_length_units (value_enclosing_type (val)));
 
   return val;
 }
@@ -1606,10 +1609,11 @@ value_array (int lowbound, int highbound, struct value **elemvec)
     {
       error (_("bad array bounds (%d, %d)"), lowbound, highbound);
     }
-  typelength = TYPE_LENGTH (value_enclosing_type (elemvec[0]));
+  typelength = type_length_units (value_enclosing_type (elemvec[0]));
   for (idx = 1; idx < nelem; idx++)
     {
-      if (TYPE_LENGTH (value_enclosing_type (elemvec[idx])) != typelength)
+      if (type_length_units (value_enclosing_type (elemvec[idx]))
+         != typelength)
        {
          error (_("array elements must all be the same size"));
        }
@@ -3812,7 +3816,7 @@ value_slice (struct value *array, int lowbound, int length)
       {
        slice = allocate_value (slice_type);
        value_contents_copy (slice, 0, array, offset,
-                            TYPE_LENGTH (slice_type));
+                            type_length_units (slice_type));
       }
 
     set_value_component_location (slice, array);
index 8893830ff3d063b5dce9876a61dc0abd7a340483..713998cc7a068b75cd0d1d72fdee40cd4d3d5731 100644 (file)
@@ -433,6 +433,9 @@ generic_val_print_ptr (struct type *type, const gdb_byte *valaddr,
                       const struct value *original_value,
                       const struct value_print_options *options)
 {
+  struct gdbarch *gdbarch = get_type_arch (type);
+  int unit_size = gdbarch_addressable_memory_unit_size (gdbarch);
+
   if (options->format && options->format != 's')
     {
       val_print_scalar_formatted (type, valaddr, embedded_offset,
@@ -442,7 +445,8 @@ generic_val_print_ptr (struct type *type, const gdb_byte *valaddr,
     {
       struct type *unresolved_elttype = TYPE_TARGET_TYPE(type);
       struct type *elttype = check_typedef (unresolved_elttype);
-      CORE_ADDR addr = unpack_pointer (type, valaddr + embedded_offset);
+      CORE_ADDR addr = unpack_pointer (type,
+                                      valaddr + embedded_offset * unit_size);
 
       print_unpacked_pointer (type, elttype, addr, stream, options);
     }
@@ -520,6 +524,8 @@ generic_val_print_enum (struct type *type, const gdb_byte *valaddr,
   unsigned int i;
   unsigned int len;
   LONGEST val;
+  struct gdbarch *gdbarch = get_type_arch (type);
+  int unit_size = gdbarch_addressable_memory_unit_size (gdbarch);
 
   if (options->format)
     {
@@ -528,7 +534,7 @@ generic_val_print_enum (struct type *type, const gdb_byte *valaddr,
       return;
     }
   len = TYPE_NFIELDS (type);
-  val = unpack_long (type, valaddr + embedded_offset);
+  val = unpack_long (type, valaddr + embedded_offset * unit_size);
   for (i = 0; i < len; i++)
     {
       QUIT;
@@ -633,6 +639,8 @@ generic_val_print_bool (struct type *type, const gdb_byte *valaddr,
                        const struct generic_val_print_decorations *decorations)
 {
   LONGEST val;
+  struct gdbarch *gdbarch = get_type_arch (type);
+  int unit_size = gdbarch_addressable_memory_unit_size (gdbarch);
 
   if (options->format || options->output_format)
     {
@@ -644,7 +652,7 @@ generic_val_print_bool (struct type *type, const gdb_byte *valaddr,
     }
   else
     {
-      val = unpack_long (type, valaddr + embedded_offset);
+      val = unpack_long (type, valaddr + embedded_offset * unit_size);
       if (val == 0)
        fputs_filtered (decorations->false_name, stream);
       else if (val == 1)
@@ -662,6 +670,9 @@ generic_val_print_int (struct type *type, const gdb_byte *valaddr,
                       const struct value *original_value,
                       const struct value_print_options *options)
 {
+  struct gdbarch *gdbarch = get_type_arch (type);
+  int unit_size = gdbarch_addressable_memory_unit_size (gdbarch);
+
   if (options->format || options->output_format)
     {
       struct value_print_options opts = *options;
@@ -672,7 +683,8 @@ generic_val_print_int (struct type *type, const gdb_byte *valaddr,
                                  original_value, &opts, 0, stream);
     }
   else
-    val_print_type_code_int (type, valaddr + embedded_offset, stream);
+    val_print_type_code_int (type, valaddr + embedded_offset * unit_size,
+                            stream);
 }
 
 /* generic_val_print helper for TYPE_CODE_CHAR.  */
@@ -685,6 +697,8 @@ generic_val_print_char (struct type *type, struct type *unresolved_type,
                        const struct value_print_options *options)
 {
   LONGEST val;
+  struct gdbarch *gdbarch = get_type_arch (type);
+  int unit_size = gdbarch_addressable_memory_unit_size (gdbarch);
 
   if (options->format || options->output_format)
     {
@@ -697,7 +711,7 @@ generic_val_print_char (struct type *type, struct type *unresolved_type,
     }
   else
     {
-      val = unpack_long (type, valaddr + embedded_offset);
+      val = unpack_long (type, valaddr + embedded_offset * unit_size);
       if (TYPE_UNSIGNED (type))
        fprintf_filtered (stream, "%u", (unsigned int) val);
       else
@@ -715,6 +729,9 @@ generic_val_print_float (struct type *type, const gdb_byte *valaddr,
                         const struct value *original_value,
                         const struct value_print_options *options)
 {
+  struct gdbarch *gdbarch = get_type_arch (type);
+  int unit_size = gdbarch_addressable_memory_unit_size (gdbarch);
+
   if (options->format)
     {
       val_print_scalar_formatted (type, valaddr, embedded_offset,
@@ -722,7 +739,7 @@ generic_val_print_float (struct type *type, const gdb_byte *valaddr,
     }
   else
     {
-      print_floating (valaddr + embedded_offset, type, stream);
+      print_floating (valaddr + embedded_offset * unit_size, type, stream);
     }
 }
 
@@ -734,11 +751,15 @@ generic_val_print_decfloat (struct type *type, const gdb_byte *valaddr,
                            const struct value *original_value,
                            const struct value_print_options *options)
 {
+  struct gdbarch *gdbarch = get_type_arch (type);
+  int unit_size = gdbarch_addressable_memory_unit_size (gdbarch);
+
   if (options->format)
     val_print_scalar_formatted (type, valaddr, embedded_offset, original_value,
                                options, 0, stream);
   else
-    print_decimal_floating (valaddr + embedded_offset, type, stream);
+    print_decimal_floating (valaddr + embedded_offset * unit_size, type,
+                           stream);
 }
 
 /* generic_val_print helper for TYPE_CODE_COMPLEX.  */
@@ -751,22 +772,25 @@ generic_val_print_complex (struct type *type, const gdb_byte *valaddr,
                           const struct generic_val_print_decorations
                             *decorations)
 {
+  struct gdbarch *gdbarch = get_type_arch (type);
+  int unit_size = gdbarch_addressable_memory_unit_size (gdbarch);
+
   fprintf_filtered (stream, "%s", decorations->complex_prefix);
   if (options->format)
     val_print_scalar_formatted (TYPE_TARGET_TYPE (type), valaddr,
                                embedded_offset, original_value, options, 0,
                                stream);
   else
-    print_floating (valaddr + embedded_offset, TYPE_TARGET_TYPE (type),
-                   stream);
+    print_floating (valaddr + embedded_offset * unit_size,
+                   TYPE_TARGET_TYPE (type), stream);
   fprintf_filtered (stream, "%s", decorations->complex_infix);
   if (options->format)
     val_print_scalar_formatted (TYPE_TARGET_TYPE (type), valaddr,
                                embedded_offset
-                               + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
+                               + type_length_units (TYPE_TARGET_TYPE (type)),
                                original_value, options, 0, stream);
   else
-    print_floating (valaddr + embedded_offset
+    print_floating (valaddr + embedded_offset * unit_size
                    + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
                    TYPE_TARGET_TYPE (type), stream);
   fprintf_filtered (stream, "%s", decorations->complex_suffix);
@@ -1150,6 +1174,9 @@ val_print_scalar_formatted (struct type *type,
                            int size,
                            struct ui_file *stream)
 {
+  struct gdbarch *arch = get_type_arch (type);
+  int unit_size = gdbarch_addressable_memory_unit_size (arch);
+
   gdb_assert (val != NULL);
   gdb_assert (valaddr == value_contents_for_printing_const (val));
 
@@ -1175,7 +1202,7 @@ val_print_scalar_formatted (struct type *type,
   else if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type)))
     val_print_unavailable (stream);
   else
-    print_scalar_formatted (valaddr + embedded_offset, type,
+    print_scalar_formatted (valaddr + embedded_offset * unit_size, type,
                            options, size, stream);
 }
 
@@ -1823,7 +1850,7 @@ val_print_array_elements (struct type *type,
   LONGEST low_pos, high_pos;
 
   elttype = TYPE_TARGET_TYPE (type);
-  eltlen = TYPE_LENGTH (check_typedef (elttype));
+  eltlen = type_length_units (check_typedef (elttype));
   index_type = TYPE_INDEX_TYPE (type);
 
   if (get_array_bounds (type, &low_bound, &high_bound))
index 0d540d5762df0efc0d3f2c77c5fea51f85b63ccf..2f0b2cc5cbcebb764350451e2ef878fc46263ffb 100644 (file)
@@ -1091,8 +1091,11 @@ set_value_parent (struct value *value, struct value *parent)
 gdb_byte *
 value_contents_raw (struct value *value)
 {
+  struct gdbarch *arch = get_value_arch (value);
+  int unit_size = gdbarch_addressable_memory_unit_size (arch);
+
   allocate_value_contents (value);
-  return value->contents + value->embedded_offset;
+  return value->contents + value->embedded_offset * unit_size;
 }
 
 gdb_byte *
@@ -1242,7 +1245,7 @@ value_ranges_copy_adjusted (struct value *dst, int dst_bit_offset,
                        bit_length);
 }
 
-/* Copy LENGTH bytes of SRC value's (all) contents
+/* Copy LENGTH target addressable memory units of SRC value's (all) contents
    (value_contents_all) starting at SRC_OFFSET, into DST value's (all)
    contents, starting at DST_OFFSET.  If unavailable contents are
    being copied from SRC, the corresponding DST contents are marked
@@ -1257,8 +1260,9 @@ value_contents_copy_raw (struct value *dst, int dst_offset,
                         struct value *src, int src_offset, int length)
 {
   range_s *r;
-  int i;
   int src_bit_offset, dst_bit_offset, bit_length;
+  struct gdbarch *arch = get_value_arch (src);
+  int unit_size = gdbarch_addressable_memory_unit_size (arch);
 
   /* A lazy DST would make that this copy operation useless, since as
      soon as DST's contents were un-lazied (by a later value_contents
@@ -1275,14 +1279,14 @@ value_contents_copy_raw (struct value *dst, int dst_offset,
                                             TARGET_CHAR_BIT * length));
 
   /* Copy the data.  */
-  memcpy (value_contents_all_raw (dst) + dst_offset,
-         value_contents_all_raw (src) + src_offset,
-         length);
+  memcpy (value_contents_all_raw (dst) + dst_offset * unit_size,
+         value_contents_all_raw (src) + src_offset * unit_size,
+         length * unit_size);
 
   /* Copy the meta-data, adjusted.  */
-  src_bit_offset = src_offset * TARGET_CHAR_BIT;
-  dst_bit_offset = dst_offset * TARGET_CHAR_BIT;
-  bit_length = length * TARGET_CHAR_BIT;
+  src_bit_offset = src_offset * unit_size * HOST_CHAR_BIT;
+  dst_bit_offset = dst_offset * unit_size * HOST_CHAR_BIT;
+  bit_length = length * unit_size * HOST_CHAR_BIT;
 
   value_ranges_copy_adjusted (dst, dst_bit_offset,
                              src, src_bit_offset,
@@ -2279,17 +2283,21 @@ set_internalvar_component (struct internalvar *var, int offset, int bitpos,
                           int bitsize, struct value *newval)
 {
   gdb_byte *addr;
+  struct gdbarch *arch;
+  int unit_size;
 
   switch (var->kind)
     {
     case INTERNALVAR_VALUE:
       addr = value_contents_writeable (var->u.value);
+      arch = get_value_arch (var->u.value);
+      unit_size = gdbarch_addressable_memory_unit_size (arch);
 
       if (bitsize)
        modify_field (value_type (var->u.value), addr + offset,
                      value_as_long (newval), bitpos, bitsize);
       else
-       memcpy (addr + offset, value_contents (newval),
+       memcpy (addr + offset * unit_size, value_contents (newval),
                TYPE_LENGTH (value_type (newval)));
       break;
 
@@ -3000,6 +3008,8 @@ value_primitive_field (struct value *arg1, int offset,
 {
   struct value *v;
   struct type *type;
+  struct gdbarch *arch = get_value_arch (arg1);
+  int unit_size = gdbarch_addressable_memory_unit_size (arch);
 
   arg_type = check_typedef (arg_type);
   type = TYPE_FIELD_TYPE (arg_type, fieldno);
@@ -3078,7 +3088,8 @@ value_primitive_field (struct value *arg1, int offset,
   else
     {
       /* Plain old data member */
-      offset += TYPE_FIELD_BITPOS (arg_type, fieldno) / 8;
+      offset += (TYPE_FIELD_BITPOS (arg_type, fieldno)
+                / (HOST_CHAR_BIT * unit_size));
 
       /* Lazy register values with offsets are not supported.  */
       if (VALUE_LVAL (arg1) == lval_register && value_lazy (arg1))
@@ -3091,7 +3102,7 @@ value_primitive_field (struct value *arg1, int offset,
          v = allocate_value (type);
          value_contents_copy_raw (v, value_embedded_offset (v),
                                   arg1, value_embedded_offset (arg1) + offset,
-                                  TYPE_LENGTH (type));
+                                  type_length_units (type));
        }
       v->offset = (value_offset (arg1) + offset
                   + value_embedded_offset (arg1));
@@ -3833,7 +3844,7 @@ value_fetch_lazy (struct value *val)
       if (TYPE_LENGTH (type))
        read_value_memory (val, 0, value_stack (val),
                           addr, value_contents_all_raw (val),
-                          TYPE_LENGTH (type));
+                          type_length_units (type));
     }
   else if (VALUE_LVAL (val) == lval_register)
     {
@@ -3892,7 +3903,7 @@ value_fetch_lazy (struct value *val)
       set_value_lazy (val, 0);
       value_contents_copy (val, value_embedded_offset (val),
                           new_val, value_embedded_offset (new_val),
-                          TYPE_LENGTH (type));
+                          type_length_units (type));
 
       if (frame_debug)
        {
index e25f52bffca0416f58ffa01210792288f12ee3c0..82deaf21688749ddc816f276e693b55850d80c36 100644 (file)
@@ -571,8 +571,8 @@ extern int value_contents_eq (const struct value *val1, int offset1,
                              const struct value *val2, int offset2,
                              int length);
 
-/* Read LENGTH bytes of memory starting at MEMADDR into BUFFER, which
-   is (or will be copied to) VAL's contents buffer offset by
+/* Read LENGTH addressable memory units starting at MEMADDR into BUFFER,
+   which is (or will be copied to) VAL's contents buffer offset by
    EMBEDDED_OFFSET (that is, to &VAL->contents[EMBEDDED_OFFSET]).
    Marks value contents ranges as unavailable if the corresponding
    memory is likewise unavailable.  STACK indicates whether the memory
This page took 0.048887 seconds and 4 git commands to generate.