PATCH: Add support for NetBSD ELF core files

Jason R Thorpe thorpej@wasabisystems.com
Thu Dec 13 11:45:00 GMT 2001
The following patch adds support for NetBSD ELF core files.

	[ for bfd/ChangeLog ]
2001-12-13  Jason Thorpe  <thorpej@wasabisystems.com>

	* elf.c (elfcore_netbsd_get_lwpid): New function.
	(elfcore_grok_netbsd_procinfo): New function.
	(elfcore_grok_netbsd_note): New function.
	(elfcore_read_notes): Call elfcore_grok_netbsd_note
	to process NetBSD ELF core file notes.

-- 
        -- Jason R. Thorpe <thorpej@wasabisystems.com>
-------------- next part --------------
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.111
diff -c -r1.111 elf.c
*** elf.c	2001/12/13 11:09:29	1.111
--- elf.c	2001/12/13 19:39:13
***************
*** 71,76 ****
--- 71,81 ----
  static boolean elfcore_grok_prxfpreg PARAMS ((bfd *, Elf_Internal_Note *));
  static boolean elfcore_grok_note PARAMS ((bfd *, Elf_Internal_Note *));
  
+ static boolean elfcore_netbsd_get_lwpid PARAMS ((Elf_Internal_Note *, int *));
+ static boolean elfcore_grok_netbsd_procinfo PARAMS ((bfd *,
+ 						     Elf_Internal_Note *));
+ static boolean elfcore_grok_netbsd_note PARAMS ((bfd *, Elf_Internal_Note *));
+ 
  /* 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.  */
***************
*** 6233,6238 ****
--- 6238,6346 ----
  }
  
  static boolean
+ elfcore_netbsd_get_lwpid (note, lwpidp)
+      Elf_Internal_Note *note;
+      int *lwpidp;
+ {
+   char *cp;
+ 
+   cp = strchr (note->namedata, '@');
+   if (cp != NULL)
+     {
+       *lwpidp = atoi(cp);
+       return true;
+     }
+   return false;
+ }
+ 
+ static boolean
+ elfcore_grok_netbsd_procinfo (abfd, note)
+      bfd *abfd;
+      Elf_Internal_Note *note;
+ {
+ 
+   /* Signal number at offset 0x08. */
+   elf_tdata (abfd)->core_signal
+     = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + 0x08);
+ 
+   /* Process ID at offset 0x50. */
+   elf_tdata (abfd)->core_pid
+     = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + 0x50);
+ 
+   /* Command name at 0x7c (max 32 bytes, including nul). */
+   elf_tdata (abfd)->core_command
+     = _bfd_elfcore_strndup (abfd, note->descdata + 0x7c, 31);
+ 
+   return true;
+ }
+ 
+ static boolean
+ elfcore_grok_netbsd_note (abfd, note)
+      bfd *abfd;
+      Elf_Internal_Note *note;
+ {
+   int lwp;
+ 
+   if (elfcore_netbsd_get_lwpid (note, &lwp))
+     elf_tdata (abfd)->core_lwpid = lwp;
+ 
+   if (note->type == 1)
+     {
+       /* NetBSD-specific core "procinfo".  Note that we expect to
+          find this note before any of the others, which is fine,
+          since the kernel writes this note out first when it
+          creates a core file.  */
+       
+       return elfcore_grok_netbsd_procinfo (abfd, note);
+     }
+ 
+   /* There are not currently any other machine-independent notes defined
+      for NetBSD ELF core files.  If the note type is less than the start
+      of the machine-dependent note types, we don't understand it.  */
+   
+   if (note->type < 32)
+     return true;
+ 
+ 
+   switch (bfd_get_arch (abfd))
+     {
+     /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0 and
+        PT_GETFPREGS == mach+2.  */
+ 
+     case bfd_arch_alpha:
+     case bfd_arch_sparc:
+       switch (note->type)
+         {
+         case 32+0:
+           return elfcore_make_note_pseudosection (abfd, ".reg", note);
+ 
+         case 32+2:
+           return elfcore_make_note_pseudosection (abfd, ".reg2", note);
+ 
+         default:
+           return true;
+         }
+ 
+     /* On all other arch's, PT_GETREGS == mach+1 and
+        PT_GETFPREGS == mach+3.  */
+ 
+     default:
+       switch (note->type)
+         {
+         case 32+1:
+           return elfcore_make_note_pseudosection (abfd, ".reg", note);
+ 
+         case 32+3:
+           return elfcore_make_note_pseudosection (abfd, ".reg2", note);
+ 
+         default:
+           return true;
+         }
+     }
+     /* NOTREACHED */
+ }
+ 
+ static boolean
  elfcore_read_notes (abfd, offset, size)
       bfd *abfd;
       file_ptr offset;
***************
*** 6274,6281 ****
        in.descdata = in.namedata + BFD_ALIGN (in.namesz, 4);
        in.descpos = offset + (in.descdata - buf);
  
!       if (! elfcore_grok_note (abfd, &in))
! 	goto error;
  
        p = in.descdata + BFD_ALIGN (in.descsz, 4);
      }
--- 6382,6397 ----
        in.descdata = in.namedata + BFD_ALIGN (in.namesz, 4);
        in.descpos = offset + (in.descdata - buf);
  
!       if (strncmp (in.namedata, "NetBSD-CORE", 11) == 0)
!         {
!           if (! elfcore_grok_netbsd_note (abfd, &in))
!             goto error;
!         }
!       else
!         {
!           if (! elfcore_grok_note (abfd, &in))
!             goto error;
!         }
  
        p = in.descdata + BFD_ALIGN (in.descsz, 4);
      }


More information about the Binutils mailing list