This is the mail archive of the binutils@sourceware.org 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]
Other format: [Raw text]

PATCH: Add functions to write core notes for i386/amd64


This adds the necessary backend functions to write proper core notes
like the ppc code already has.  This is necessary for GDB to generate
proper 32-bit core dumps on 64-bit systems.

ok?


2010-04-19  Mark Kettenis  <kettenis@gnu.org>

	* elf64-x86-64.c (elf64_x86_64_write_core_note): New function.
	(elf_backend_write_core_note): Define.
	* elf32-i386.c (elf_i386_write_core_note): New function.
	(elf_backend_write_core_note): Define.

Index: elf32-i386.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-i386.c,v
retrieving revision 1.232
diff -u -p -r1.232 elf32-i386.c
--- elf32-i386.c	9 Apr 2010 14:40:16 -0000	1.232
+++ elf32-i386.c	19 Apr 2010 15:59:28 -0000
@@ -20,6 +20,7 @@
    MA 02110-1301, USA.  */
 
 #include "sysdep.h"
+#include <stdarg.h>
 #include "bfd.h"
 #include "bfdlink.h"
 #include "libbfd.h"
@@ -495,6 +496,52 @@ elf_i386_grok_psinfo (bfd *abfd, Elf_Int
 
   return TRUE;
 }
+
+static char *
+elf_i386_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type, ...)
+{
+  switch (note_type)
+    {
+    default:
+      return NULL;
+
+    case NT_PRPSINFO:
+      {
+	char data[124];
+	va_list ap;
+
+	va_start (ap, note_type);
+	memset (data, 0, 28);
+	strncpy (data + 28, va_arg (ap, const char *), 16);
+	strncpy (data + 44, va_arg (ap, const char *), 80);
+	va_end (ap);
+	return elfcore_write_note (abfd, buf, bufsiz,
+				   "CORE", note_type, data, sizeof (data));
+      }
+
+    case NT_PRSTATUS:
+      {
+	char data[144];
+	va_list ap;
+	long pid;
+	int cursig;
+	const void *greg;
+
+	va_start (ap, note_type);
+	memset (data, 0, 32);
+	pid = va_arg (ap, long);
+	bfd_put_32 (abfd, pid, data + 24);
+	cursig = va_arg (ap, int);
+	bfd_put_16 (abfd, cursig, data + 12);
+	greg = va_arg (ap, const void *);
+	memcpy (data + 72, greg, 68);
+	memset (data + 140, 0, 4);
+	va_end (ap);
+	return elfcore_write_note (abfd, buf, bufsiz,
+				   "CORE", note_type, data, sizeof (data));
+      }
+    }
+}
 
 /* Functions for the i386 ELF linker.
 
@@ -4672,6 +4719,7 @@ elf_i386_add_symbol_hook (bfd * abfd,
 #define elf_backend_gc_sweep_hook	      elf_i386_gc_sweep_hook
 #define elf_backend_grok_prstatus	      elf_i386_grok_prstatus
 #define elf_backend_grok_psinfo		      elf_i386_grok_psinfo
+#define elf_backend_write_core_note	      elf_i386_write_core_note
 #define elf_backend_reloc_type_class	      elf_i386_reloc_type_class
 #define elf_backend_relocate_section	      elf_i386_relocate_section
 #define elf_backend_size_dynamic_sections     elf_i386_size_dynamic_sections
Index: elf64-x86-64.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-x86-64.c,v
retrieving revision 1.193
diff -u -p -r1.193 elf64-x86-64.c
--- elf64-x86-64.c	5 Mar 2010 19:48:55 -0000	1.193
+++ elf64-x86-64.c	19 Apr 2010 15:59:33 -0000
@@ -21,6 +21,7 @@
    MA 02110-1301, USA.  */
 
 #include "sysdep.h"
+#include <stdarg.h>
 #include "bfd.h"
 #include "bfdlink.h"
 #include "libbfd.h"
@@ -352,6 +353,53 @@ elf64_x86_64_grok_psinfo (bfd *abfd, Elf
 
   return TRUE;
 }
+
+static char *
+elf64_x86_64_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type,
+			      ...)
+{
+  switch (note_type)
+    {
+    default:
+      return NULL;
+
+    case NT_PRPSINFO:
+      {
+	char data[136];
+	va_list ap;
+
+	va_start (ap, note_type);
+	memset (data, 0, 40);
+	strncpy (data + 40, va_arg (ap, const char *), 16);
+	strncpy (data + 56, va_arg (ap, const char *), 80);
+	va_end (ap);
+	return elfcore_write_note (abfd, buf, bufsiz,
+				   "CORE", note_type, data, sizeof (data));
+      }
+
+    case NT_PRSTATUS:
+      {
+	char data[336];
+	va_list ap;
+	long pid;
+	int cursig;
+	const void *greg;
+
+	va_start (ap, note_type);
+	memset (data, 0, 112);
+	pid = va_arg (ap, long);
+	bfd_put_32 (abfd, pid, data + 32);
+	cursig = va_arg (ap, int);
+	bfd_put_16 (abfd, cursig, data + 12);
+	greg = va_arg (ap, const void *);
+	memcpy (data + 112, greg, 216);
+	memset (data + 328, 0, 8);
+	va_end (ap);
+	return elfcore_write_note (abfd, buf, bufsiz,
+				   "CORE", note_type, data, sizeof (data));
+      }
+    }
+}
 
 /* Functions for the x86-64 ELF linker.	 */
 
@@ -4457,6 +4505,7 @@ static const struct bfd_elf_special_sect
 #define elf_backend_gc_sweep_hook	    elf64_x86_64_gc_sweep_hook
 #define elf_backend_grok_prstatus	    elf64_x86_64_grok_prstatus
 #define elf_backend_grok_psinfo		    elf64_x86_64_grok_psinfo
+#define elf_backend_write_core_note	    elf64_x86_64_write_core_note
 #define elf_backend_reloc_type_class	    elf64_x86_64_reloc_type_class
 #define elf_backend_relocate_section	    elf64_x86_64_relocate_section
 #define elf_backend_size_dynamic_sections   elf64_x86_64_size_dynamic_sections


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