Clear upper bits during sign extension
Commit Message
Yao Qi <yao@codesourcery.com> writes:
>> + byte_order = gdbarch_byte_order (get_type_arch (type));
>
> How about getting gdbarch via get_frame_arch (frame)? How about
> removing gdb_sign_extend as it is no longer used?
>
> I'll post a full version on top of yours.
Here is the patch, what do you think?
Comments
On 01/08/2015 05:40 AM, Yao Qi wrote:
> Yao Qi <yao@codesourcery.com> writes:
>
>>> + byte_order = gdbarch_byte_order (get_type_arch (type));
>>
>> How about getting gdbarch via get_frame_arch (frame)? How about
>> removing gdb_sign_extend as it is no longer used?
>>
>> I'll post a full version on top of yours.
>
> Here is the patch, what do you think?
Looks good to me. Thanks.
Pedro Alves <palves@redhat.com> writes:
> Looks good to me. Thanks.
Patch is pushed in.
@@ -2012,6 +2012,7 @@ indirect_pieced_value (struct value *value)
int i, bit_offset, bit_length;
struct dwarf_expr_piece *piece = NULL;
LONGEST byte_offset;
+ enum bfd_endian byte_order;
type = check_typedef (value_type (value));
if (TYPE_CODE (type) != TYPE_CODE_PTR)
@@ -2056,11 +2057,16 @@ indirect_pieced_value (struct value *value)
/* This is an offset requested by GDB, such as value subscripts.
However, due to how synthetic pointers are implemented, this is
always presented to us as a pointer type. This means we have to
- sign-extend it manually as appropriate. */
- byte_offset = value_as_address (value);
- if (TYPE_LENGTH (value_type (value)) < sizeof (LONGEST))
- byte_offset = gdb_sign_extend (byte_offset,
- 8 * TYPE_LENGTH (value_type (value)));
+ sign-extend it manually as appropriate. Use raw
+ extract_signed_integer directly rather than value_as_address and
+ sign extend afterwards on architectures that would need it
+ (mostly everywhere except MIPS, which has signed addresses) as
+ the later would go through gdbarch_pointer_to_address and thus
+ return a CORE_ADDR with high bits set on architectures that
+ encode address spaces and other things in CORE_ADDR. */
+ byte_order = gdbarch_byte_order (get_frame_arch (frame));
+ byte_offset = extract_signed_integer (value_contents (value),
+ TYPE_LENGTH (type), byte_order);
byte_offset += piece->v.ptr.offset;
gdb_assert (piece);
@@ -3021,23 +3021,6 @@ align_down (ULONGEST v, int n)
return (v & -n);
}
-/* See utils.h. */
-
-LONGEST
-gdb_sign_extend (LONGEST value, int bit)
-{
- gdb_assert (bit >= 1 && bit <= 8 * sizeof (LONGEST));
-
- if (((value >> (bit - 1)) & 1) != 0)
- {
- LONGEST signbit = ((LONGEST) 1) << (bit - 1);
-
- value = (value ^ signbit) - signbit;
- }
-
- return value;
-}
-
/* Allocation function for the libiberty hash table which uses an
obstack. The obstack is passed as DATA. */
@@ -340,11 +340,6 @@ extern int myread (int, char *, int);
extern ULONGEST align_up (ULONGEST v, int n);
extern ULONGEST align_down (ULONGEST v, int n);
-/* Sign extend VALUE. BIT is the (1-based) index of the bit in VALUE
- to sign-extend. */
-
-extern LONGEST gdb_sign_extend (LONGEST value, int bit);
-
/* Resource limits used by getrlimit and setrlimit. */
enum resource_limit_kind