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]

[BUG] print_address_numeric


In printcmd.c (print_address_numeric), we find the lines:

      int ptr_bit = TARGET_PTR_BIT;
      if (ptr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
	addr &= ((CORE_ADDR) 1 << ptr_bit) - 1;
      print_longest (stream, 'x', use_local, (ULONGEST) addr);

This code has a bug, namely it assumes that addresses and pointers are
the same size.

[address == gdb representation; pointer == target representation]

For some processors they are different.  For the d10v and at least one
other processor, the size of a pointer is 2 bytes, but the size of an
address is 4 bytes.

I propose the creation of a new macro TARGET_ADDR_BIT, the addition of
the lines:

    #if !defined(TARGET_ADDR_BIT)
    #define TARGET_ADDR_BIT	TARGET_PTR_BIT
    #endif

to defs.h, and that the above lines of print_address_numeric be changed to:

    int addr_bit = TARGET_ADDR_BIT
    if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
      addr & ((CORE_ADDR) 1 << ptr_bit) - 1;
    print_longest (stream, 'x', use_local, (ULONGEST) addr);

Comments?

Andrew,

Is this:

taylor@texas 266: cvs diff -c gdbarch.sh
Index: gdbarch.sh
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/gdbarch.sh,v
retrieving revision 2.61
diff -c -r2.61 gdbarch.sh
*** gdbarch.sh  2000/07/24 15:26:48     2.61
--- gdbarch.sh  2000/07/31 14:43:23
***************
*** 276,281 ****
--- 276,282 ----
  #
  v:1:TARGET_BFD_VMA_BIT:int:bfd_vma_bit::::8 * sizeof (void*):TARGET_ARCHITECTURE->bits_per_address::0
  v:1:TARGET_PTR_BIT:int:ptr_bit::::8 * sizeof (void*):0
+ v:1:TARGET_ADDR_BIT:int:addr_bit::::8 * sizeof (void*):0:gdbarch->ptr_bit
  #v:1:TARGET_CHAR_BIT:int:char_bit::::8 * sizeof (char):0
  v:1:TARGET_SHORT_BIT:int:short_bit::::8 * sizeof (short):0
  v:1:TARGET_INT_BIT:int:int_bit::::8 * sizeof (int):0
***************
*** 471,483 ****
  
  /* This file was created with the aid of \`\`gdbarch.sh''.
  
!    The bourn shell script \`\`gdbarch.sh'' creates the files
     \`\`new-gdbarch.c'' and \`\`new-gdbarch.h and then compares them
     against the existing \`\`gdbarch.[hc]''.  Any differences found
     being reported.
  
     If editing this file, please also run gdbarch.sh and merge any
!    changes into that script. Conversely, when makeing sweeping changes
     to this file, modifying gdbarch.sh and using its output may prove
     easier. */
  
--- 472,484 ----
  
  /* This file was created with the aid of \`\`gdbarch.sh''.
  
!    The Bourne shell script \`\`gdbarch.sh'' creates the files
     \`\`new-gdbarch.c'' and \`\`new-gdbarch.h and then compares them
     against the existing \`\`gdbarch.[hc]''.  Any differences found
     being reported.
  
     If editing this file, please also run gdbarch.sh and merge any
!    changes into that script. Conversely, when making sweeping changes
     to this file, modifying gdbarch.sh and using its output may prove
     easier. */
 
the appropriate change to make to gdbarch.sh?

[The intent is to have the multi-arch default value be the same as the
non multi-arch default value -- namely, the value of TARGET_PTR_BIT.

So, it starts out as 0, and if the architecture specific code doesn't
change it to something else, then the multi-arch machinery changes it
to the value of gdbarch->ptr_bit (and does so AFTER the POSTDEFAULT
processing has already occurred for ptr_bit).]

David

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