diff options
author | Jason Molenda <jmolenda@apple.com> | 2000-01-25 02:40:50 +0000 |
---|---|---|
committer | Jason Molenda <jmolenda@apple.com> | 2000-01-25 02:40:50 +0000 |
commit | 0fda6bd286fe931a998c4d5322ad12a4ed610f87 (patch) | |
tree | d26808089bd54c9de4bf565a6cf7a34be7d320b9 /gdb/utils.c | |
parent | b5f303f092e873d88d2b9459deb105e20ff5222c (diff) | |
download | gdb-0fda6bd286fe931a998c4d5322ad12a4ed610f87.zip gdb-0fda6bd286fe931a998c4d5322ad12a4ed610f87.tar.gz gdb-0fda6bd286fe931a998c4d5322ad12a4ed610f87.tar.bz2 |
import gdb-2000-01-24 snapshot
Diffstat (limited to 'gdb/utils.c')
-rw-r--r-- | gdb/utils.c | 70 |
1 files changed, 49 insertions, 21 deletions
diff --git a/gdb/utils.c b/gdb/utils.c index 596c0ae..ab790d9 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -3203,12 +3203,31 @@ get_field (data, order, total_len, start, len) int cur_bitshift; /* Start at the least significant part of the field. */ - cur_byte = (start + len) / FLOATFORMAT_CHAR_BIT; if (order == floatformat_little || order == floatformat_littlebyte_bigword) - cur_byte = (total_len / FLOATFORMAT_CHAR_BIT) - cur_byte - 1; - cur_bitshift = - ((start + len) % FLOATFORMAT_CHAR_BIT) - FLOATFORMAT_CHAR_BIT; - result = *(data + cur_byte) >> (-cur_bitshift); + { + /* We start counting from the other end (i.e, from the high bytes + rather than the low bytes). As such, we need to be concerned + with what happens if bit 0 doesn't start on a byte boundary. + I.e, we need to properly handle the case where total_len is + not evenly divisible by 8. So we compute ``excess'' which + represents the number of bits from the end of our starting + byte needed to get to bit 0. */ + int excess = FLOATFORMAT_CHAR_BIT - (total_len % FLOATFORMAT_CHAR_BIT); + cur_byte = (total_len / FLOATFORMAT_CHAR_BIT) + - ((start + len + excess) / FLOATFORMAT_CHAR_BIT); + cur_bitshift = ((start + len + excess) % FLOATFORMAT_CHAR_BIT) + - FLOATFORMAT_CHAR_BIT; + } + else + { + cur_byte = (start + len) / FLOATFORMAT_CHAR_BIT; + cur_bitshift = + ((start + len) % FLOATFORMAT_CHAR_BIT) - FLOATFORMAT_CHAR_BIT; + } + if (cur_bitshift > -FLOATFORMAT_CHAR_BIT) + result = *(data + cur_byte) >> (-cur_bitshift); + else + result = 0; cur_bitshift += FLOATFORMAT_CHAR_BIT; if (order == floatformat_little || order == floatformat_littlebyte_bigword) ++cur_byte; @@ -3218,20 +3237,16 @@ get_field (data, order, total_len, start, len) /* Move towards the most significant part of the field. */ while (cur_bitshift < len) { - if (len - cur_bitshift < FLOATFORMAT_CHAR_BIT) - /* This is the last byte; zero out the bits which are not part of - this field. */ - result |= - (*(data + cur_byte) & ((1 << (len - cur_bitshift)) - 1)) - << cur_bitshift; - else - result |= *(data + cur_byte) << cur_bitshift; + result |= (unsigned long)*(data + cur_byte) << cur_bitshift; cur_bitshift += FLOATFORMAT_CHAR_BIT; if (order == floatformat_little || order == floatformat_littlebyte_bigword) ++cur_byte; else --cur_byte; } + if (len < sizeof(result) * FLOATFORMAT_CHAR_BIT) + /* Mask out bits which are not part of the field */ + result &= ((1UL << len) - 1); return result; } @@ -3368,15 +3383,28 @@ put_field (data, order, total_len, start, len, stuff_to_put) int cur_bitshift; /* Start at the least significant part of the field. */ - cur_byte = (start + len) / FLOATFORMAT_CHAR_BIT; if (order == floatformat_little || order == floatformat_littlebyte_bigword) - cur_byte = (total_len / FLOATFORMAT_CHAR_BIT) - cur_byte - 1; - cur_bitshift = - ((start + len) % FLOATFORMAT_CHAR_BIT) - FLOATFORMAT_CHAR_BIT; - *(data + cur_byte) &= - ~(((1 << ((start + len) % FLOATFORMAT_CHAR_BIT)) - 1) << (-cur_bitshift)); - *(data + cur_byte) |= - (stuff_to_put & ((1 << FLOATFORMAT_CHAR_BIT) - 1)) << (-cur_bitshift); + { + int excess = FLOATFORMAT_CHAR_BIT - (total_len % FLOATFORMAT_CHAR_BIT); + cur_byte = (total_len / FLOATFORMAT_CHAR_BIT) + - ((start + len + excess) / FLOATFORMAT_CHAR_BIT); + cur_bitshift = ((start + len + excess) % FLOATFORMAT_CHAR_BIT) + - FLOATFORMAT_CHAR_BIT; + } + else + { + cur_byte = (start + len) / FLOATFORMAT_CHAR_BIT; + cur_bitshift = + ((start + len) % FLOATFORMAT_CHAR_BIT) - FLOATFORMAT_CHAR_BIT; + } + if (cur_bitshift > -FLOATFORMAT_CHAR_BIT) + { + *(data + cur_byte) &= + ~(((1 << ((start + len) % FLOATFORMAT_CHAR_BIT)) - 1) + << (-cur_bitshift)); + *(data + cur_byte) |= + (stuff_to_put & ((1 << FLOATFORMAT_CHAR_BIT) - 1)) << (-cur_bitshift); + } cur_bitshift += FLOATFORMAT_CHAR_BIT; if (order == floatformat_little || order == floatformat_littlebyte_bigword) ++cur_byte; |