@@ -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);
}
}
@@ -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. */
@@ -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))
@@ -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);
@@ -379,6 +379,7 @@ generic_val_print (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);
unsigned int i = 0; /* Number of characters printed. */
unsigned len;
struct type *elttype, *unresolved_elttype;
@@ -431,7 +432,7 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
unresolved_elttype = TYPE_TARGET_TYPE (type);
elttype = check_typedef (unresolved_elttype);
{
- addr = unpack_pointer (type, valaddr + embedded_offset);
+ addr = unpack_pointer (type, valaddr + embedded_offset * unit_size);
print_unpacked_pointer:
if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
@@ -495,7 +496,7 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
break;
}
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;
@@ -583,7 +584,7 @@ generic_val_print (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)
@@ -615,7 +616,8 @@ generic_val_print (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);
break;
case TYPE_CODE_CHAR:
@@ -630,7 +632,7 @@ generic_val_print (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 (TYPE_UNSIGNED (type))
fprintf_filtered (stream, "%u", (unsigned int) val);
else
@@ -648,7 +650,7 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
}
else
{
- print_floating (valaddr + embedded_offset, type, stream);
+ print_floating (valaddr + embedded_offset * unit_size, type, stream);
}
break;
@@ -657,8 +659,8 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
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);
break;
case TYPE_CODE_VOID:
@@ -684,19 +686,19 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
valaddr, embedded_offset,
original_value, options, 0, stream);
else
- print_floating (valaddr + embedded_offset,
+ 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
+ embedded_offset * unit_size
+ TYPE_LENGTH (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);
@@ -964,6 +966,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));
@@ -989,7 +994,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);
}
@@ -1637,7 +1642,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))
@@ -1089,8 +1089,10 @@ 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 *
@@ -1240,7 +1242,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 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
@@ -1255,8 +1257,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
@@ -1273,14 +1276,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 * CHAR_BIT;
+ dst_bit_offset = dst_offset * unit_size * CHAR_BIT;
+ bit_length = length * unit_size * CHAR_BIT;
value_ranges_copy_adjusted (dst, dst_bit_offset,
src, src_bit_offset,
@@ -2277,17 +2280,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;
@@ -2998,6 +3005,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);
@@ -3076,7 +3085,7 @@ 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) / (CHAR_BIT * unit_size);
/* Lazy register values with offsets are not supported. */
if (VALUE_LVAL (arg1) == lval_register && value_lazy (arg1))
@@ -3089,7 +3098,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));
@@ -3831,7 +3840,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)
{
@@ -3890,7 +3899,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)
{
@@ -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