This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[PATCH] gdb/valops.c


[The following is motivated by a port of gdb to target a new Harvard
architecture processor; for this port, pointers are 2 bytes long, but
addresses are 4 bytes long.  For most targets, addresses and pointers
are identical and for them this change is a no-op.]

I will shortly be committing the following patch to gdb/valops.c:

ChangeLog entry:

	* valops.c (value_cast): If casting a scalar (int, enum, range) to
 	"a pointer", do not truncate it to the length of a pointer, but
 	rather to the length of an address as we are dealing here with
 	gdb's representation, not the target's representation.  That is,
 	we are really dealing with addresses, not pointers.  This allows
 	things like "print *(int *)0x01000234" to work when dealing with
 	a target having two byte pointers and four byte addresses.

Index: valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.29
diff -c -r1.29 valops.c
*** valops.c	2001/01/04 19:58:31	1.29
--- valops.c	2001/02/05 15:32:15
***************
*** 287,298 ****
  				      code2 == TYPE_CODE_ENUM ||
  				      code2 == TYPE_CODE_RANGE))
      {
!       int ptr_bit = HOST_CHAR_BIT * TYPE_LENGTH (type);
        LONGEST longest = value_as_long (arg2);
!       if (ptr_bit < sizeof (LONGEST) * HOST_CHAR_BIT)
  	{
! 	  if (longest >= ((LONGEST) 1 << ptr_bit)
! 	      || longest <= -((LONGEST) 1 << ptr_bit))
  	    warning ("value truncated");
  	}
        return value_from_longest (type, longest);
--- 287,305 ----
  				      code2 == TYPE_CODE_ENUM ||
  				      code2 == TYPE_CODE_RANGE))
      {
!       /* TYPE_LENGTH (type) is the length of a pointer, but we really
! 	 want the length of an address! -- we are really dealing with
! 	 addresses (i.e., gdb representations) not pointers (i.e.,
! 	 target representations) here.  This allows things like "print
! 	 *(int *)0x01000234" to work when dealing with a target having
! 	 two byte pointers and four byte addresses.  */
!       int addr_bit = TARGET_ADDR_BIT;
! 
        LONGEST longest = value_as_long (arg2);
!       if (addr_bit < sizeof (LONGEST) * HOST_CHAR_BIT)
  	{
! 	  if (longest >= ((LONGEST) 1 << addr_bit)
! 	      || longest <= -((LONGEST) 1 << addr_bit))
  	    warning ("value truncated");
  	}
        return value_from_longest (type, longest);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]