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] Use register sets for OpenBSD/i386


This adds register set support for OpenBSD/i386.  Tested on
i386-unknown-openbsd3.0.

Committed,

Mark


Index: ChangeLog
from  Mark Kettenis  <kettenis@gnu.org>
 
	* i386obsd-tdep.c: Include "regset.h", "gdb_assert.h" and
	"gdb_string.h".
	(i386obsd_r_reg_offset): New variable.
	(i386obsd_aout_supply_regset)
	(i386obsd_aout_regset_from_core_section): New functions.
	(i386obsd_supply_reg, fetch_core_registers): Remove functions.
	(i286obsd_core_fns): Remove variable.
	(i386obsd_init_abi): Initialize TDEP->gregset_reg_offset,
	TDEP->gregset_num_regs and TDEP->sizeof_gregset.  Set
	regset_from_core_section.  Use ARRAY_SIZE to initialize
	TDEP->sc_num_regs.
	(_initialize_i386obsd_tdep): Don't call add_core_fns.

 
Index: i386obsd-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386obsd-tdep.c,v
retrieving revision 1.6
diff -u -p -r1.6 i386obsd-tdep.c
--- i386obsd-tdep.c 28 Sep 2003 13:35:44 -0000 1.6
+++ i386obsd-tdep.c 26 Dec 2003 18:05:01 -0000
@@ -1,4 +1,5 @@
 /* Target-dependent code for OpenBSD/i386.
+
    Copyright 1988, 1989, 1991, 1992, 1994, 1996, 2000, 2001, 2002, 2003
    Free Software Foundation, Inc.
 
@@ -23,60 +24,74 @@
 #include "arch-utils.h"
 #include "gdbcore.h"
 #include "regcache.h"
+#include "regset.h"
 #include "osabi.h"
 
+#include "gdb_assert.h"
+#include "gdb_string.h"
+
 #include "i386-tdep.h"
 #include "i387-tdep.h"
 
-/* Provide a prototype to silence -Wmissing-prototypes.  */
-void _initialize_i386obsd_tdep (void);
-
-#define SIZEOF_STRUCT_REG	(16 * 4)
+/* From <machine/reg.h>.  */
+static int i386obsd_r_reg_offset[] =
+{
+  0 * 4,			/* %eax */
+  1 * 4,			/* %ecx */
+  2 * 4,			/* %edx */
+  3 * 4,			/* %ebx */
+  4 * 4,			/* %esp */
+  5 * 4,			/* %ebp */
+  6 * 4,			/* %esi */
+  7 * 4,			/* %edi */
+  8 * 4,			/* %eip */
+  9 * 4,			/* %eflags */
+  10 * 4,			/* %cs */
+  11 * 4,			/* %ss */
+  12 * 4,			/* %ds */
+  13 * 4,			/* %es */
+  14 * 4,			/* %fs */
+  15 * 4			/* %gs */
+};
 
 static void
-i386obsd_supply_reg (char *regs, int regno)
+i386obsd_aout_supply_regset (const struct regset *regset,
+			     struct regcache *regcache, int regnum,
+			     const void *regs, size_t len)
 {
-  int i;
+  const struct gdbarch_tdep *tdep = regset->descr;
+
+  gdb_assert (len >= tdep->sizeof_gregset + I387_SIZEOF_FSAVE);
 
-  for (i = 0; i <= 15; i++)
-    if (regno == i || regno == -1)
-      supply_register (i, regs + i * 4);
+  i386_supply_gregset (regset, regcache, regnum, regs, tdep->sizeof_gregset);
+  i387_supply_fsave (regcache, regnum, (char *) regs + tdep->sizeof_gregset);
 }
 
-static void
-fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which,
-                      CORE_ADDR ignore)
+const struct regset *
+i386obsd_aout_regset_from_core_section (struct gdbarch *gdbarch,
+					const char *sect_name,
+					size_t sect_size)
 {
-  char *regs, *fsave;
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
-  /* We get everything from one section.  */
-  if (which != 0)
-    return;
+  /* OpenBSD a.out core dumps don't use seperate register sets for the
+     general-purpose and floating-point registers.  */
 
-  if (core_reg_size < (SIZEOF_STRUCT_REG + 108))
+  if (strcmp (sect_name, ".reg") == 0
+      && sect_size >= tdep->sizeof_gregset + I387_SIZEOF_FSAVE)
     {
-      warning ("Wrong size register set in core file.");
-      return;
+      if (tdep->gregset == NULL)
+	{
+	  tdep->gregset = XMALLOC (struct regset);
+	  tdep->gregset->descr = tdep;
+	  tdep->gregset->supply_regset = i386obsd_aout_supply_regset;
+	}
+      return tdep->gregset;
     }
 
-  regs = core_reg_sect;
-  fsave = core_reg_sect + SIZEOF_STRUCT_REG;
-
-  /* Integer registers.  */
-  i386obsd_supply_reg (regs, -1);
-
-  /* Floating point registers.  */
-  i387_supply_fsave (current_regcache, -1, fsave);
+  return NULL;
 }
 
-static struct core_fns i386obsd_core_fns =
-{
-  bfd_target_unknown_flavour,		/* core_flavour */
-  default_check_format,			/* check_format */
-  default_core_sniffer,			/* core_sniffer */
-  fetch_core_registers,			/* core_read_registers */
-  NULL					/* next */
-};
 
 
 CORE_ADDR i386obsd_sigtramp_start = 0xbfbfdf20;
@@ -111,6 +126,15 @@ i386obsd_init_abi (struct gdbarch_info i
   /* Obviously OpenBSD is BSD-based.  */
   i386bsd_init_abi (info, gdbarch);
 
+  /* OpenBSD has a different `struct reg'.  */
+  tdep->gregset_reg_offset = i386obsd_r_reg_offset;
+  tdep->gregset_num_regs = ARRAY_SIZE (i386obsd_r_reg_offset);
+  tdep->sizeof_gregset = 16 * 4;
+
+  /* OpenBSD has a single register set.  */
+  set_gdbarch_regset_from_core_section
+    (gdbarch, i386obsd_aout_regset_from_core_section);
+
   /* OpenBSD uses -freg-struct-return by default.  */
   tdep->struct_return = reg_struct_return;
 
@@ -121,14 +145,16 @@ i386obsd_init_abi (struct gdbarch_info i
   /* OpenBSD has a `struct sigcontext' that's different from the
      origional 4.3 BSD.  */
   tdep->sc_reg_offset = i386obsd_sc_reg_offset;
-  tdep->sc_num_regs = I386_NUM_GREGS;
+  tdep->sc_num_regs = ARRAY_SIZE (i386obsd_sc_reg_offset);
 }
+
+
+/* Provide a prototype to silence -Wmissing-prototypes.  */
+void _initialize_i386obsd_tdep (void);
 
 void
 _initialize_i386obsd_tdep (void)
 {
-  add_core_fns (&i386obsd_core_fns);
-
   /* FIXME: kettenis/20021020: Since OpenBSD/i386 binaries are
      indistingushable from NetBSD/i386 a.out binaries, building a GDB
      that should support both these targets will probably not work as


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