[PATCH] Implement i386 register renumbering
Mark Kettenis
kettenis@wins.uva.nl
Sat Jul 28 10:24:00 GMT 2001
The attached patch implements the mapping from debug info register
numbers to GDB's internal register numbers. I chose reasonable
defaults for stabs, COFF, DWARF and DWARF2 based on the the GCC
configuration files:
* stabs, COFF: Use the "default" register map; probably based on what
was used by dbx on BSD and System V before release 4.
* DWARF, DWARF2: Use the Dwarf register map; Based on sdb on System V
release 4.
These defaults don't work for all targets. On most ELF targets, GCC
always uses the Dwarf map, which means that stabs-in-ELF (the default
for many of those systems) will have problems. The converse will be
true for COFF/a.out that support DWARF2. Overriding the right
_REG_TO_REGNUM define in your target's tm.h should be enough to get it
working. The attached patch does this for the targets that I
maintain.
If your target doesn't support floating-point registers, don't bother,
the defaults will work just fine. If you want me to fix your target,
just drop me a mail, and I'll fix things such that it works right with
GCC 3.0.
Mark
Index: ChangeLog
from Mark Kettenis <kettenis@gnu.org>
* config/i386/tm-i386.h (STAB_REG_TO_REGNUM, SDB_REG_TO_REGNUM,
DWARF_REG_TO_REGNUM, DWARF2_REG_TO_REGNUM): New defines.
(i386_stab_reg_to_regnum, i386_dwarf_reg_to_regnum): New
prototypes.
* config/i386/tm-fbsd.h, config/i386/tm-i386gnu.h,
config/i386/tm-linux.h (STAB_REG_TO_REGNUM): Redefine to call
i386_dwarf_reg_to_regnum.
* i386-tdep.c (i386_stab_reg_to_regnum, i386_dwarf_reg_to_regnum):
New functions.
Index: i386-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-tdep.c,v
retrieving revision 1.35
diff -u -p -r1.35 i386-tdep.c
--- i386-tdep.c 2001/07/28 16:48:59 1.35
+++ i386-tdep.c 2001/07/28 16:59:32
@@ -59,6 +59,68 @@ int i386_register_raw_size[MAX_NUM_REGS]
/* i386_register_virtual_size[i] is the size in bytes of the virtual
type of register i. */
int i386_register_virtual_size[MAX_NUM_REGS];
+
+/* Convert stabs register number REG to the appropriate register
+ number used by GDB. */
+
+int
+i386_stab_reg_to_regnum (int reg)
+{
+ /* This implements what GCC calls the "default" register map. */
+ if (reg >= 0 && reg <= 7)
+ {
+ /* General registers. */
+ return reg;
+ }
+ else if (reg >= 12 && reg <= 19)
+ {
+ /* Floating-point registers. */
+ return reg - 12 + FP0_REGNUM;
+ }
+ else if (reg >= 21 && reg <= 28)
+ {
+ /* SSE registers. */
+ return reg - 21 + XMM0_REGNUM;
+ }
+ else if (reg >= 29 && reg <= 36)
+ {
+ /* MMX registers. */
+ /* FIXME: kettenis/2001-07-28: Should we have the MMX registers
+ as pseudo-registers? */
+ return reg - 29 + FP0_REGNUM;
+ }
+
+ /* This will hopefully provoke a warning. */
+ return NUM_REGS + NUM_PSEUDO_REGS;
+}
+
+/* Convert Dwarf register number REG to the appropriate register
+ number used by GDB. */
+
+int
+i386_dwarf_reg_to_regnum (int reg)
+{
+ /* The DWARF register numbering includes %eip and %eflags, and
+ numbers the floating point registers differently. */
+ if (reg >= 0 && reg <= 9)
+ {
+ /* General registers. */
+ return reg;
+ }
+ else if (reg >= 11 && reg <= 18)
+ {
+ /* Floating-point registers. */
+ return reg - 11 + FP0_REGNUM;
+ }
+ else if (reg >= 21)
+ {
+ /* The SSE and MMX registers have identical numbers as in stabs. */
+ return i386_stab_reg_to_regnum (reg);
+ }
+
+ /* This will hopefully provoke a warning. */
+ return NUM_REGS + NUM_PSEUDO_REGS;
+}
/* This is the variable that is set with "set disassembly-flavor", and
Index: config/i386/tm-fbsd.h
===================================================================
RCS file: /cvs/src/src/gdb/config/i386/tm-fbsd.h,v
retrieving revision 1.4
diff -u -p -r1.4 tm-fbsd.h
--- config/i386/tm-fbsd.h 2001/07/13 18:27:21 1.4
+++ config/i386/tm-fbsd.h 2001/07/28 16:59:32
@@ -24,6 +24,14 @@
#define HAVE_I387_REGS
#include "i386/tm-i386.h"
+/* FreeBSD/ELF uses stabs-in-ELF with the DWARF register numbering
+ scheme by default, so we must redefine STAB_REG_TO_REGNUM. This
+ messes up the floating-point registers for a.out, but there is not
+ much we can do about that. */
+
+#undef STAB_REG_TO_REGNUM
+#define STAB_REG_TO_REGNUM(reg) i386_dwarf_reg_to_regnum ((reg))
+
/* FreeBSD uses the old gcc convention for struct returns. */
#define USE_STRUCT_CONVENTION(gcc_p, type) \
Index: config/i386/tm-i386gnu.h
===================================================================
RCS file: /cvs/src/src/gdb/config/i386/tm-i386gnu.h,v
retrieving revision 1.2
diff -u -p -r1.2 tm-i386gnu.h
--- config/i386/tm-i386gnu.h 2001/03/06 08:21:29 1.2
+++ config/i386/tm-i386gnu.h 2001/07/28 16:59:32
@@ -42,6 +42,11 @@
#define HAVE_I387_REGS
#include "i386/tm-i386.h"
+/* We use stabs-in-ELF with the DWARF register numbering scheme. */
+
+#undef STAB_REG_TO_REGNUM
+#define STAB_REG_TO_REGNUM(reg) i386_dwarf_reg_to_regnum ((reg))
+
/* Offset to saved PC in sigcontext. */
#define SIGCONTEXT_PC_OFFSET 68
More information about the Gdb-patches
mailing list