This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[patch] cast ints->pointers; Was: 0xa.... and signed addresses
FYI,
I've committed the attatched.
Andrew
Mon Jul 17 13:08:10 2000 Andrew Cagney <cagney@b1.cygnus.com>
* values.c (value_as_pointer): When VAL is an integer, explictly
cast to a pointer before converting to a CORE_ADDR.
* gdbtypes.c (build_gdbtypes): For builtin_type_ptr, construct a
real void pointer instead of an integer.
Index: gdbtypes.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.c,v
retrieving revision 1.10
diff -p -r1.10 gdbtypes.c
*** gdbtypes.c 2000/07/09 05:15:50 1.10
--- gdbtypes.c 2000/07/17 03:34:26
*************** make_pointer_type (type, typeptr)
*** 179,185 ****
TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
TYPE_CODE (ntype) = TYPE_CODE_PTR;
! /* pointers are unsigned */
TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
--- 179,187 ----
TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
TYPE_CODE (ntype) = TYPE_CODE_PTR;
! /* Mark pointers as unsigned. The target converts between pointers
! and addresses (CORE_ADDRs) using POINTER_TO_ADDRESS() and
! ADDRESS_TO_POINTER(). */
TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
*************** build_gdbtypes ()
*** 3034,3043 ****
/* NOTE: At present there is no way of differentiating between at
target address and the target C language pointer type type even
though the two can be different (cf d10v) */
! builtin_type_ptr =
! init_type (TYPE_CODE_INT, TARGET_PTR_BIT / 8,
! TYPE_FLAG_UNSIGNED,
! "__ptr", (struct objfile *) NULL);
builtin_type_CORE_ADDR =
init_type (TYPE_CODE_INT, TARGET_PTR_BIT / 8,
TYPE_FLAG_UNSIGNED,
--- 3036,3042 ----
/* NOTE: At present there is no way of differentiating between at
target address and the target C language pointer type type even
though the two can be different (cf d10v) */
! builtin_type_ptr = make_pointer_type (builtin_type_void, NULL);
builtin_type_CORE_ADDR =
init_type (TYPE_CODE_INT, TARGET_PTR_BIT / 8,
TYPE_FLAG_UNSIGNED,
Index: values.c
===================================================================
RCS file: /cvs/src/src/gdb/values.c,v
retrieving revision 1.7
diff -p -r1.7 values.c
*** values.c 2000/06/09 00:51:55 1.7
--- values.c 2000/07/17 03:34:34
*************** value_as_pointer (val)
*** 594,600 ****
for pointers to char, in which the low bits *are* significant. */
return ADDR_BITS_REMOVE (value_as_long (val));
#else
! return value_as_long (val);
#endif
}
--- 594,629 ----
for pointers to char, in which the low bits *are* significant. */
return ADDR_BITS_REMOVE (value_as_long (val));
#else
! COERCE_ARRAY (val);
! /* In converting VAL to an address (CORE_ADDR), any small integers
! are first cast to a generic pointer. The function unpack_long
! will then correctly convert that pointer into a canonical address
! (using POINTER_TO_ADDRESS).
!
! Without the cast, the MIPS gets: 0xa0000000 -> (unsigned int)
! 0xa0000000 -> (LONGEST) 0x00000000a0000000
!
! With the cast, the MIPS gets: 0xa0000000 -> (unsigned int)
! 0xa0000000 -> (void*) 0xa0000000 -> (LONGEST) 0xffffffffa0000000.
!
! If the user specifies an integer that is larger than the target
! pointer type, it is assumed that it was intentional and the value
! is converted directly into an ADDRESS. This ensures that no
! information is discarded.
!
! NOTE: The cast operation may eventualy be converted into a TARGET
! method (see POINTER_TO_ADDRESS() and ADDRESS_TO_POINTER()) so
! that the TARGET ISA/ABI can apply an arbitrary conversion.
!
! NOTE: In pure harvard architectures function and data pointers
! can be different and may require different integer to pointer
! conversions. */
! if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT
! && TYPE_LENGTH (VALUE_TYPE (val)) <= TYPE_LENGTH (builtin_type_ptr))
! {
! val = value_cast (builtin_type_ptr, val);
! }
! return unpack_long (VALUE_TYPE (val), VALUE_CONTENTS (val));
#endif
}