delete ada-lang.c::move_bits, sharing and re-using copy_bitwise instead
This patch deletes ada-lang.c's move_bits function entirely, and replaces all calls to it by calls to copy_bitwise instead. Because the latter function was declared locally inside dwarf2loc.c, this patch also move the function to a common area, and makes it non-static. gdb/ChangeLog: * ada-lang.c (move_bits): Delete. Update all callers to use copy_bitwise instead. * dwarf2loc.c (copy_bitwise, bits_to_str::bits_to_str) (selftests::check_copy_bitwise, selftests::copy_bitwise_tests): Move from here to utils.c. (_initialize_dwarf2loc): Remove call to register copy_bitwise selftests. * utils.h (copy_bitwise): Add declaration. * utils.c (copy_bitwise, bits_to_str::bits_to_str) (selftests::check_copy_bitwise, selftests::copy_bitwise_tests): Moved here from dwarf2loc.c. (_initialize_utils): Register copy_bitwise selftests. Tested on x86_64-linux, no regression. Also tested using AdaCore's testsuite on a collection of small endian and big endian platforms.
This commit is contained in:
parent
8b2d40cbba
commit
a99bc3d23c
5 changed files with 262 additions and 312 deletions
|
@ -190,8 +190,6 @@ static int ada_is_unconstrained_packed_array_type (struct type *);
|
|||
static struct value *value_subscript_packed (struct value *, int,
|
||||
struct value **);
|
||||
|
||||
static void move_bits (gdb_byte *, int, const gdb_byte *, int, int, int);
|
||||
|
||||
static struct value *coerce_unspec_val_to_type (struct value *,
|
||||
struct type *);
|
||||
|
||||
|
@ -2669,72 +2667,6 @@ ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr,
|
|||
return v;
|
||||
}
|
||||
|
||||
/* Move N bits from SOURCE, starting at bit offset SRC_OFFSET to
|
||||
TARGET, starting at bit offset TARG_OFFSET. SOURCE and TARGET must
|
||||
not overlap. */
|
||||
static void
|
||||
move_bits (gdb_byte *target, int targ_offset, const gdb_byte *source,
|
||||
int src_offset, int n, int bits_big_endian_p)
|
||||
{
|
||||
unsigned int accum, mask;
|
||||
int accum_bits, chunk_size;
|
||||
|
||||
target += targ_offset / HOST_CHAR_BIT;
|
||||
targ_offset %= HOST_CHAR_BIT;
|
||||
source += src_offset / HOST_CHAR_BIT;
|
||||
src_offset %= HOST_CHAR_BIT;
|
||||
if (bits_big_endian_p)
|
||||
{
|
||||
accum = (unsigned char) *source;
|
||||
source += 1;
|
||||
accum_bits = HOST_CHAR_BIT - src_offset;
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
int unused_right;
|
||||
|
||||
accum = (accum << HOST_CHAR_BIT) + (unsigned char) *source;
|
||||
accum_bits += HOST_CHAR_BIT;
|
||||
source += 1;
|
||||
chunk_size = HOST_CHAR_BIT - targ_offset;
|
||||
if (chunk_size > n)
|
||||
chunk_size = n;
|
||||
unused_right = HOST_CHAR_BIT - (chunk_size + targ_offset);
|
||||
mask = ((1 << chunk_size) - 1) << unused_right;
|
||||
*target =
|
||||
(*target & ~mask)
|
||||
| ((accum >> (accum_bits - chunk_size - unused_right)) & mask);
|
||||
n -= chunk_size;
|
||||
accum_bits -= chunk_size;
|
||||
target += 1;
|
||||
targ_offset = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
accum = (unsigned char) *source >> src_offset;
|
||||
source += 1;
|
||||
accum_bits = HOST_CHAR_BIT - src_offset;
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
accum = accum + ((unsigned char) *source << accum_bits);
|
||||
accum_bits += HOST_CHAR_BIT;
|
||||
source += 1;
|
||||
chunk_size = HOST_CHAR_BIT - targ_offset;
|
||||
if (chunk_size > n)
|
||||
chunk_size = n;
|
||||
mask = ((1 << chunk_size) - 1) << targ_offset;
|
||||
*target = (*target & ~mask) | ((accum << targ_offset) & mask);
|
||||
n -= chunk_size;
|
||||
accum_bits -= chunk_size;
|
||||
accum >>= chunk_size;
|
||||
target += 1;
|
||||
targ_offset = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Store the contents of FROMVAL into the location of TOVAL.
|
||||
Return a new value with the location of TOVAL and contents of
|
||||
FROMVAL. Handles assignment into packed fields that have
|
||||
|
@ -2777,11 +2709,11 @@ ada_value_assign (struct value *toval, struct value *fromval)
|
|||
if (from_size == 0)
|
||||
from_size = TYPE_LENGTH (value_type (fromval)) * TARGET_CHAR_BIT;
|
||||
if (gdbarch_bits_big_endian (get_type_arch (type)))
|
||||
move_bits (buffer, value_bitpos (toval),
|
||||
value_contents (fromval), from_size - bits, bits, 1);
|
||||
copy_bitwise (buffer, value_bitpos (toval),
|
||||
value_contents (fromval), from_size - bits, bits, 1);
|
||||
else
|
||||
move_bits (buffer, value_bitpos (toval),
|
||||
value_contents (fromval), 0, bits, 0);
|
||||
copy_bitwise (buffer, value_bitpos (toval),
|
||||
value_contents (fromval), 0, bits, 0);
|
||||
write_memory_with_notification (to_addr, buffer, len);
|
||||
|
||||
val = value_copy (toval);
|
||||
|
@ -2833,14 +2765,14 @@ value_assign_to_component (struct value *container, struct value *component,
|
|||
= TYPE_LENGTH (value_type (component)) * TARGET_CHAR_BIT - bits;
|
||||
else
|
||||
src_offset = 0;
|
||||
move_bits (value_contents_writeable (container) + offset_in_container,
|
||||
value_bitpos (container) + bit_offset_in_container,
|
||||
value_contents (val), src_offset, bits, 1);
|
||||
copy_bitwise (value_contents_writeable (container) + offset_in_container,
|
||||
value_bitpos (container) + bit_offset_in_container,
|
||||
value_contents (val), src_offset, bits, 1);
|
||||
}
|
||||
else
|
||||
move_bits (value_contents_writeable (container) + offset_in_container,
|
||||
value_bitpos (container) + bit_offset_in_container,
|
||||
value_contents (val), 0, bits, 0);
|
||||
copy_bitwise (value_contents_writeable (container) + offset_in_container,
|
||||
value_bitpos (container) + bit_offset_in_container,
|
||||
value_contents (val), 0, bits, 0);
|
||||
}
|
||||
|
||||
/* Determine if TYPE is an access to an unconstrained array. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue