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]
Other format: [Raw text]

[PATCH] OpenBSD/amd64 core dump support


I must have been terribly confused when I wrote the comment that
OpenBSD/amd64 doesn't use `struct reg' format for the registers in its
core files.  Fortunately I unconfused myself and came up with this
patch to actually support the core dumps.  This probably doesn't work
yet since there are some pending BFD patches that are needed to
actually select the correct OS ABI for core files.

Committed,

Mark

Index: ChangeLog
from  Mark Kettenis  <kettenis@gnu.org>
 
	* amd64obsd-tdep.c: Include "regset.h" and "i387-tdep.h".  Fix
	comments.
	(amd64obsd_supply_regset, amd64obsd_regset_from_core_section): New
	functions.
	(amd64obsd_init_abi): Reorder initializations.  Use
	amd64obsd_r_reg_offset to initialize the general-purpose register
	set details.  Set regset_from_core_section.
	(_initialize_amd64obsd_tdep): Rename from
	_initialize_amd64obsd_ndep.  Add OS ABI handler for core dumps.
	* Makefile.in (amd64obsd-tdep.o): Update dependencies.
	* config/i386/obsd64.mt (TDEPFILES): Add i386-tdep.o.

Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.510
diff -u -p -r1.510 Makefile.in
--- Makefile.in 18 Feb 2004 19:01:33 -0000 1.510
+++ Makefile.in 20 Feb 2004 19:01:45 -0000
@@ -1535,7 +1535,8 @@ amd64nbsd-tdep.o: amd64nbsd-tdep.c $(def
 amd64obsd-nat.o: amd64nbsd-nat.c $(defs_h) $(gdb_assert_h) $(x86_64_tdep_h) \
 	$(amd64_nat_h)
 amd64obsd-tdep.o: amd64nbsd-tdep.c $(defs_h) $(arch_utils_h) $(frame_h) \
-	$(gdbcore_h) $(osabi_h) $(gdb_assert_h) $(x86_64_tdep_h)
+	$(gdbcore_h) $(osabi_h) $(regset_h) $(target_h) $(gdb_assert_h) \
+	$(gdb_string_h) $(x86_64_tdep_h) $(i387_tdep_h)
 annotate.o: annotate.c $(defs_h) $(annotate_h) $(value_h) $(target_h) \
 	$(gdbtypes_h) $(breakpoint_h)
 arch-utils.o: arch-utils.c $(defs_h) $(arch_utils_h) $(buildsym_h) \
Index: amd64obsd-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/amd64obsd-tdep.c,v
retrieving revision 1.1
diff -u -p -r1.1 amd64obsd-tdep.c
--- amd64obsd-tdep.c 18 Feb 2004 17:44:51 -0000 1.1
+++ amd64obsd-tdep.c 20 Feb 2004 19:01:45 -0000
@@ -23,12 +23,54 @@
 #include "frame.h"
 #include "gdbcore.h"
 #include "osabi.h"
+#include "regset.h"
 #include "target.h"
 
 #include "gdb_assert.h"
 #include "gdb_string.h"
 
 #include "x86-64-tdep.h"
+#include "i387-tdep.h"
+
+/* Support for core dumps.  */
+
+static void
+amd64obsd_supply_regset (const struct regset *regset,
+			 struct regcache *regcache, int regnum,
+			 const void *regs, size_t len)
+{
+  const struct gdbarch_tdep *tdep = regset->descr;
+
+  gdb_assert (len >= tdep->sizeof_gregset + I387_SIZEOF_FXSAVE);
+
+  i386_supply_gregset (regset, regcache, regnum, regs, tdep->sizeof_gregset);
+  x86_64_supply_fxsave (regcache, regnum, (char *)regs + tdep->sizeof_gregset);
+}
+
+static const struct regset *
+amd64obsd_regset_from_core_section (struct gdbarch *gdbarch,
+				    const char *sect_name, size_t sect_size)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  /* OpenBSD core dumps don't use seperate register sets for the
+     general-purpose and floating-point registers.  */
+
+  if (strcmp (sect_name, ".reg") == 0
+      && sect_size >= tdep->sizeof_gregset + I387_SIZEOF_FXSAVE)
+    {
+      if (tdep->gregset == NULL)
+	{
+	  tdep->gregset = XMALLOC (struct regset);
+	  tdep->gregset->descr = tdep;
+	  tdep->gregset->supply_regset = amd64obsd_supply_regset;
+	}
+      return tdep->gregset;
+    }
+
+  return NULL;
+}
+
 
 /* Support for signal handlers.  */
 
@@ -77,7 +119,7 @@ amd64obsd_sigcontext_addr (struct frame_
 /* Mapping between the general-purpose registers in `struct reg'
    format and GDB's register cache layout.  */
 
-/* From <machine/reg.h>.  Used for ptrace(2), but not for core dumps.  */
+/* From <machine/reg.h>.  */
 int amd64obsd_r_reg_offset[] =
 {
   14 * 8,			/* %rax */
@@ -106,7 +148,7 @@ int amd64obsd_r_reg_offset[] =
   23 * 8			/* %gs */
 };
 
-/* From <machine/signal.h>.  Also used for core dumps.  */
+/* From <machine/signal.h>.  */
 static int amd64obsd_sc_reg_offset[] =
 {
   14 * 8,			/* %rax */
@@ -140,13 +182,16 @@ amd64obsd_init_abi (struct gdbarch_info 
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
-  /* Initialize general-purpose register set details first.  */
-  tdep->gregset_reg_offset = amd64obsd_sc_reg_offset;
-  tdep->gregset_num_regs = ARRAY_SIZE (amd64obsd_sc_reg_offset);
-  tdep->sizeof_gregset = 26 * 8;
-
   x86_64_init_abi (info, gdbarch);
 
+  /* Initialize general-purpose register set details.  */
+  tdep->gregset_reg_offset = amd64obsd_r_reg_offset;
+  tdep->gregset_num_regs = ARRAY_SIZE (amd64obsd_r_reg_offset);
+  tdep->sizeof_gregset = 24 * 8;
+
+  set_gdbarch_regset_from_core_section (gdbarch,
+					amd64obsd_regset_from_core_section);
+
   tdep->jb_pc_offset = 7 * 8;
 
   set_gdbarch_pc_in_sigtramp (gdbarch, amd64obsd_pc_in_sigtramp);
@@ -160,11 +205,15 @@ amd64obsd_init_abi (struct gdbarch_info 
 void _initialize_amd64obsd_tdep (void);
 
 void
-_initialize_amd64obsd_ndep (void)
+_initialize_amd64obsd_tdep (void)
 {
   /* The OpenBSD/amd64 native dependent code makes this assumption.  */
   gdb_assert (ARRAY_SIZE (amd64obsd_r_reg_offset) == X86_64_NUM_GREGS);
 
   gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
 			  GDB_OSABI_OPENBSD_ELF, amd64obsd_init_abi);
+
+  /* OpenBSD uses traditional (a.out) NetBSD-style core dumps.  */
+  gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
+			  GDB_OSABI_NETBSD_AOUT, amd64obsd_init_abi);
 }
Index: config/i386/obsd64.mt
===================================================================
RCS file: /cvs/src/src/gdb/config/i386/obsd64.mt,v
retrieving revision 1.1
diff -u -p -r1.1 obsd64.mt
--- config/i386/obsd64.mt 18 Feb 2004 17:44:52 -0000 1.1
+++ config/i386/obsd64.mt 20 Feb 2004 19:01:45 -0000
@@ -1,2 +1,3 @@
 # Target: OpenBSD/amd64
-TDEPFILES= x86-64-tdep.o amd64obsd-tdep.o i386-tdep.o i387-tdep.o
+TDEPFILES= x86-64-tdep.o amd64obsd-tdep.o \
+	i386-tdep.o i387-tdep.o i386bsd-tdep.o


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