diff options
author | Simon Marchi <simon.marchi@ericsson.com> | 2015-07-28 11:01:50 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@ericsson.com> | 2015-07-28 11:01:50 -0400 |
commit | 3ae385afe150f2e001a1cc8fb14f4ba0ab94cdf2 (patch) | |
tree | 0984430c0197e8fb667866605cac82e050fd8ce5 /gdb/value.c | |
parent | e512cdbdffafefa63baeb835ba6636fcef56e17d (diff) | |
download | gdb-3ae385afe150f2e001a1cc8fb14f4ba0ab94cdf2.zip gdb-3ae385afe150f2e001a1cc8fb14f4ba0ab94cdf2.tar.gz gdb-3ae385afe150f2e001a1cc8fb14f4ba0ab94cdf2.tar.bz2 |
Consider addressable memory unit size in various value functions
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.
Diffstat (limited to 'gdb/value.c')
-rw-r--r-- | gdb/value.c | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/gdb/value.c b/gdb/value.c index 0d540d5..2f0b2cc 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -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) { |