This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


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

[Fwd: [PATCH]: enable bfd to read 32-bit corefile on 64-bit host]





Hi, 

These changes will allow a Sparc64 Solaris bfd client (eg. gdb)
to read a Sparc32 corefile.  This is important since sparc64
solaris hosts can run both 64-bit and 32-bit apps.

2000-05-26  Michael Snyder  <msnyder@seadog.cygnus.com>

	* elf.c (elfcore_grok_prstatus, elfcore_grok_pstatus, 
	elfcore_grok_psinfo): Add code to allow debugging a 32-bit
	corefile on a 64-bit (Sparc Solaris) host.

Index: elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.31
diff -p -r1.31 elf.c
*** elf.c	2000/05/09 00:43:44	1.31
--- elf.c	2000/05/26 20:34:19
*************** SECTION
*** 31,36 ****
--- 31,38 ----
  	haven't bothered yet.
   */
  
+ #define _SYSCALL32
+ 
  #include "bfd.h"
  #include "sysdep.h"
  #include "bfdlink.h"
*************** static INLINE int sym_is_global PARAMS (
*** 54,60 ****
--- 56,74 ----
  static boolean elf_map_symbols PARAMS ((bfd *));
  static bfd_size_type get_program_header_size PARAMS ((bfd *));
  static boolean elfcore_read_notes PARAMS ((bfd *, bfd_vma, bfd_vma));
+ static int elfcore_make_pid PARAMS ((bfd *abfd));
+ static boolean elfcore_maybe_make_sect PARAMS ((bfd *abfd, 
+ 						char *name, 
+ 						asection *sect));
+ static char* elfcore_strndup PARAMS ((bfd *abfd, char *start, int max));
+ 
+ /* Define offsetof for those systems which lack it. */
+ 
+ #ifndef offsetof
+ # define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
+ #endif
  
+ 
  /* Swap version information in and out.  The version information is
     currently size independent.  If that ever changes, this code will
     need to move into elfcode.h.  */
*************** _bfd_elf_rel_vtable_reloc_fn (abfd, re, 
*** 5036,5048 ****
  #endif
  
  
- /* Define offsetof for those systems which lack it. */
- 
- #ifndef offsetof
- # define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
- #endif
- 
- 
  /* FIXME: this is kinda wrong, but it's what gdb wants. */
  
  static int
--- 5050,5055 ----
*************** elfcore_grok_prstatus (abfd, note)
*** 5094,5122 ****
       bfd* abfd;
       Elf_Internal_Note* note;
  {
-   prstatus_t prstat;
    char buf[100];
    char* name;
    asection* sect;
  
!   if (note->descsz != sizeof (prstat))
!     return true;
  
!   memcpy (&prstat, note->descdata, sizeof (prstat));
  
!   elf_tdata (abfd)->core_signal = prstat.pr_cursig;
!   elf_tdata (abfd)->core_pid = prstat.pr_pid;
  
!   /* pr_who exists on:
!        solaris 2.[567]
!        unixware 4.2
!      pr_who doesn't exist on:
!        linux 2.[01]
!   */
  #if defined (HAVE_PRSTATUS_T_PR_WHO)
!   elf_tdata (abfd)->core_lwpid = prstat.pr_who;
  #endif
  
    /* Make a ".reg/999" section. */
  
    sprintf (buf, ".reg/%d", elfcore_make_pid (abfd));
--- 5101,5154 ----
       bfd* abfd;
       Elf_Internal_Note* note;
  {
    char buf[100];
    char* name;
    asection* sect;
  
!   if (note->descsz == sizeof (prstatus_t))
!     {
!       prstatus_t prstat;
  
!       memcpy (&prstat, note->descdata, sizeof (prstat));
  
!       elf_tdata (abfd)->core_signal = prstat.pr_cursig;
!       elf_tdata (abfd)->core_pid = prstat.pr_pid;
  
!       /* pr_who exists on:
! 	 solaris 2.[567]
! 	 unixware 4.2
! 	 pr_who doesn't exist on:
! 	 linux 2.[01]
! 	 */
  #if defined (HAVE_PRSTATUS_T_PR_WHO)
!       elf_tdata (abfd)->core_lwpid = prstat.pr_who;
  #endif
+     }
+ #if defined (__sparcv9)
+   else if (note->descsz == sizeof (prstatus32_t))
+     {
+       /* 64-bit host, 32-bit corefile */
+       prstatus32_t prstat;
+ 
+       memcpy (&prstat, note->descdata, sizeof (prstat));
  
+       elf_tdata (abfd)->core_signal = prstat.pr_cursig;
+       elf_tdata (abfd)->core_pid = prstat.pr_pid;
+ 
+       /* pr_who exists on:
+ 	 solaris 2.[567]
+ 	 unixware 4.2
+ 	 pr_who doesn't exist on:
+ 	 linux 2.[01]
+ 	 */
+ #if defined (HAVE_PRSTATUS_T_PR_WHO)
+       elf_tdata (abfd)->core_lwpid = prstat.pr_who;
+ #endif
+     }
+ #endif /* __sparcv9 */
+   else
+     return true;	/* bad size */
+ 
    /* Make a ".reg/999" section. */
  
    sprintf (buf, ".reg/%d", elfcore_make_pid (abfd));
*************** elfcore_grok_prstatus (abfd, note)
*** 5128,5135 ****
    sect = bfd_make_section (abfd, name);
    if (sect == NULL)
      return false;
!   sect->_raw_size = sizeof (prstat.pr_reg);
!   sect->filepos = note->descpos + offsetof (prstatus_t, pr_reg);
    sect->flags = SEC_HAS_CONTENTS;
    sect->alignment_power = 2;
  
--- 5160,5179 ----
    sect = bfd_make_section (abfd, name);
    if (sect == NULL)
      return false;
! 
!   if (note->descsz == sizeof (prstatus_t))
!     {
!       sect->_raw_size = sizeof (prgregset_t);
!       sect->filepos = note->descpos + offsetof (prstatus_t, pr_reg);
!     }
! #if defined (__sparcv9)
!   else if (note->descsz == sizeof (prstatus32_t))
!     {
!       sect->_raw_size = sizeof (prgregset32_t);
!       sect->filepos = note->descpos + offsetof (prstatus32_t, pr_reg);
!     }
! #endif
! 
    sect->flags = SEC_HAS_CONTENTS;
    sect->alignment_power = 2;
  
*************** elfcore_grok_prxfpreg (abfd, note)
*** 5207,5218 ****
  
  
  #if defined (HAVE_PRPSINFO_T)
! # define elfcore_psinfo_t prpsinfo_t
  #endif
  
  #if defined (HAVE_PSINFO_T)
! # define elfcore_psinfo_t psinfo_t
  #endif
  
  
  #if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T)
--- 5251,5268 ----
  
  
  #if defined (HAVE_PRPSINFO_T)
! typedef prpsinfo_t   elfcore_psinfo_t;
! #if defined (__sparcv9)
! typedef prpsinfo32_t elfcore_psinfo32_t;
! #endif
  #endif
  
  #if defined (HAVE_PSINFO_T)
! typedef psinfo_t   elfcore_psinfo_t;
! #if defined (__sparcv9)
! typedef psinfo32_t elfcore_psinfo32_t;
  #endif
+ #endif
  
  
  #if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T)
*************** elfcore_grok_psinfo (abfd, note)
*** 5251,5269 ****
       bfd* abfd;
       Elf_Internal_Note* note;
  {
!   elfcore_psinfo_t psinfo;
  
!   if (note->descsz != sizeof (elfcore_psinfo_t))
!     return true;
  
!   memcpy (&psinfo, note->descdata, note->descsz);
  
!   elf_tdata (abfd)->core_program
!     = elfcore_strndup (abfd, psinfo.pr_fname, sizeof (psinfo.pr_fname));
  
!   elf_tdata (abfd)->core_command
!     = elfcore_strndup (abfd, psinfo.pr_psargs, sizeof (psinfo.pr_psargs));
  
    /* Note that for some reason, a spurious space is tacked
       onto the end of the args in some (at least one anyway)
       implementations, so strip it off if it exists. */
--- 5301,5337 ----
       bfd* abfd;
       Elf_Internal_Note* note;
  {
!   if (note->descsz == sizeof (elfcore_psinfo_t))
!     {
!       elfcore_psinfo_t psinfo;
  
!       memcpy (&psinfo, note->descdata, note->descsz);
! 
!       elf_tdata (abfd)->core_program
! 	= elfcore_strndup (abfd, psinfo.pr_fname, sizeof (psinfo.pr_fname));
! 
!       elf_tdata (abfd)->core_command
! 	= elfcore_strndup (abfd, psinfo.pr_psargs, sizeof (psinfo.pr_psargs));
!     }
! #if defined (__sparcv9)
!   else if (note->descsz == sizeof (elfcore_psinfo32_t))
!     {
!       /* 64-bit host, 32-bit corefile */
!       elfcore_psinfo32_t psinfo;
  
!       memcpy (&psinfo, note->descdata, note->descsz);
  
!       elf_tdata (abfd)->core_program
! 	= elfcore_strndup (abfd, psinfo.pr_fname, sizeof (psinfo.pr_fname));
  
!       elf_tdata (abfd)->core_command
! 	= elfcore_strndup (abfd, psinfo.pr_psargs, sizeof (psinfo.pr_psargs));
!     }
! #endif
  
+   else
+     return true;	/* bad size */
+ 
    /* Note that for some reason, a spurious space is tacked
       onto the end of the args in some (at least one anyway)
       implementations, so strip it off if it exists. */
*************** elfcore_grok_pstatus (abfd, note)
*** 5287,5304 ****
       bfd* abfd;
       Elf_Internal_Note* note;
  {
!   pstatus_t pstat;
  
!   if (note->descsz != sizeof (pstat))
!     return true;
  
!   memcpy (&pstat, note->descdata, sizeof (pstat));
  
!   elf_tdata (abfd)->core_pid = pstat.pr_pid;
  
!   /* Could grab some more details from the "representative"
!      lwpstatus_t in pstat.pr_lwp, but we'll catch it all in an
!      NT_LWPSTATUS note, presumably. */
  
    return true;
  }
--- 5355,5387 ----
       bfd* abfd;
       Elf_Internal_Note* note;
  {
!   if (note->descsz == sizeof (pstatus_t))
!     {
!       pstatus_t pstat;
  
!       memcpy (&pstat, note->descdata, sizeof (pstat));
  
!       elf_tdata (abfd)->core_pid = pstat.pr_pid;
  
!       /* Could grab some more details from the "representative"
! 	 lwpstatus_t in pstat.pr_lwp, but we'll catch it all in an
! 	 NT_LWPSTATUS note, presumably. */
!     }
! #if defined (__sparcv9)
!   else if (note->descsz == sizeof (pstatus32_t))
!     {
!       /* 64-bit host, 32-bit corefile */
!       pstatus32_t pstat;
! 
!       memcpy (&pstat, note->descdata, sizeof (pstat));
  
!       elf_tdata (abfd)->core_pid = pstat.pr_pid;
! 
!       /* Could grab some more details from the "representative"
! 	 lwpstatus_t in pstat.pr_lwp, but we'll catch it all in an
! 	 NT_LWPSTATUS note, presumably. */
!     }
! #endif
  
    return true;
  }




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