This is the mail archive of the gdb-patches@sourceware.cygnus.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]

[rfa/symtab] Sign extend dwarf2 addresses (sometimes)


Hello,

[This depends on a BFD patch, so the final form may change slightly]

The attatched patch modifies the dwarf2 reader so that it sign extends
addresses read from the object file (if that is correct for the ISA). 
MIPS is probably the best example of this.

Without this patch GDB gets very confused when trying to match addresses
and symbols (and doesn't always find them).  With this patch, GDB
internally does pretty well.  Externally, the user may be confused as
GDB occasionally prints 0xffffffff87654321 instead of 0x87654321 as an
address.  I'm fixing cases of that as I find them (the testsuite isn't
very helpful :-).

Ok?
	Andrew
Fri Jun 23 18:30:58 2000  Andrew Cagney  <cagney@b1.cygnus.com>

	* dwarf2read.c (address_signed_p): New variable.
	(dwarf2_build_psymtabs_hard): Set according to
 	bfd_elf_get_sign_extend_vma.
	(read_address): Sign extend the address when necessary.

Index: dwarf2read.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/dwarf2read.c,v
retrieving revision 2.46
diff -p -r2.46 dwarf2read.c
*** dwarf2read.c	2000/06/19 22:19:53	2.46
--- dwarf2read.c	2000/06/23 08:33:29
*************** static struct complaint dwarf2_unsupport
*** 551,556 ****
--- 551,563 ----
     whatever scope is currently getting read. */
  static int address_size;
  
+ /* Remember the signess of addresses read from the dwarf.
+    Some BFD targets expect addresses to implicitly be sign extended.
+    GDB needs to be sure that such addresses have been converted to
+    their canonical (sign extended) form. */
+ static int address_signed_p;
+ 
+ 
  /* Externals references.  */
  extern int info_verbose;	/* From main.c; nonzero => verbose */
  
*************** dwarf2_build_psymtabs_hard (objfile, mai
*** 924,929 ****
--- 931,940 ----
    obstack_init (&dwarf2_tmp_obstack);
    back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL);
  
+   address_signed_p = bfd_elf_get_sign_extend_vma (objfile->obfd);
+   if (address_signed_p < 0)
+     internal_error ("dwarf2_build_psymtabs_hard: dwarf from non elf file");
+ 
    while ((unsigned int) (info_ptr - dwarf_info_buffer)
  	 + ((info_ptr - dwarf_info_buffer) % 4) < dwarf_info_size)
      {
*************** read_address (abfd, buf)
*** 3467,3486 ****
  {
    CORE_ADDR retval = 0;
  
!   switch (address_size)
      {
!     case 2:
!       retval = bfd_get_16 (abfd, (bfd_byte *) buf);
!       break;
!     case 4:
!       retval = bfd_get_32 (abfd, (bfd_byte *) buf);
!       break;
!     case 8:
!       retval = bfd_get_64 (abfd, (bfd_byte *) buf);
!       break;
!     default:
!       /* *THE* alternative is 8, right? */
!       abort ();
      }
  
   return retval;
--- 3478,3518 ----
  {
    CORE_ADDR retval = 0;
  
!   if (address_signed_p)
      {
!       switch (address_size)
! 	{
! 	case 2:
! 	  retval = bfd_get_signed_16 (abfd, (bfd_byte *) buf);
! 	  break;
! 	case 4:
! 	  retval = bfd_get_signed_32 (abfd, (bfd_byte *) buf);
! 	  break;
! 	case 8:
! 	  retval = bfd_get_signed_64 (abfd, (bfd_byte *) buf);
! 	  break;
! 	default:
! 	  /* *THE* alternative is 8, right? */
! 	  internal_error ("read_address: bad switch, signed");
! 	}
!     }
!   else
!     {
!       switch (address_size)
! 	{
! 	case 2:
! 	  retval = bfd_get_16 (abfd, (bfd_byte *) buf);
! 	  break;
! 	case 4:
! 	  retval = bfd_get_32 (abfd, (bfd_byte *) buf);
! 	  break;
! 	case 8:
! 	  retval = bfd_get_64 (abfd, (bfd_byte *) buf);
! 	  break;
! 	default:
! 	  /* *THE* alternative is 8, right? */
! 	  internal_error ("read_address: bad switch, unsigned");
! 	}
      }
  
   return retval;

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