RFA: print addresses that are longer than pointers

Jim Blandy jimb@zwingli.cygnus.com
Wed Apr 26 17:25:00 GMT 2000


This is yet a third amendment to address printing in printcmd.c.

I recently made changes which allow GDB to handle architectures on
which addresses are larger than pointers.  However, the code which
Peter Schauer added to printcmd.c to handle unwanted sign extension
assumes that addresses and pointers are the same size.

As it turns out, this masking is unnecessary when the value being
printed is a genuine pointer; the sign extension won't occur, and the
masking is unneeded.

This also rewrites the mask generation in a way which I think is
overflow-free, without needing to pull the wool over the compiler's
eyes.



2000-04-26  Jim Blandy  <jimb@redhat.com>

	* printcmd.c (print_scalar_formatted): Addresses may be longer
	than pointers.  If the value we're printing is a genuine pointer,
	assume that unpack_pointer will do the right thing.
	
Index: gdb/printcmd.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/printcmd.c,v
retrieving revision 1.163
diff -c -r1.163 printcmd.c
*** gdb/printcmd.c	2000/04/16 14:53:33	1.163
--- gdb/printcmd.c	2000/04/27 00:20:36
***************
*** 444,457 ****
  
      case 'a':
        {
! 	/* Truncate address to the size of a target pointer, avoiding
! 	   shifts larger or equal than the width of a CORE_ADDR.  The
! 	   local variable PTR_BIT stops the compiler reporting a shift
! 	   overflow when it won't occure. */
  	CORE_ADDR addr = unpack_pointer (type, valaddr);
! 	int ptr_bit = TARGET_PTR_BIT;
! 	if (ptr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
! 	  addr &= ((CORE_ADDR) 1 << ptr_bit) - 1;
  	print_address (addr, stream);
        }
        break;
--- 444,459 ----
  
      case 'a':
        {
! 	/* If the value is actually a pointer, then unpack_pointer
! 	   will do the right thing.  If the value is not a pointer,
! 	   but happens to be a signed type, then unpack_pointer may
! 	   sign-extend it; in this case, we trim it to the size of a
! 	   pointer.  */
  	CORE_ADDR addr = unpack_pointer (type, valaddr);
! 	if (TYPE_CODE (type) != TYPE_CODE_PTR)
! 	  /* When building the mask, avoid shifts larger or equal than
! 	       the width of a CORE_ADDR.  */
! 	  addr &= (((CORE_ADDR) 1 << (TARGET_PTR_BIT - 1)) << 1) + 1;
  	print_address (addr, stream);
        }
        break;


More information about the Gdb-patches mailing list