[PATCH] i386_stab_reg_to_regnum (4 <-> 5, ebp <-> esp)

Brian Ford
2004-04-01T00:11:09Z

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2195 bytes --]

I noticed this while tracking down another problem with adding DWARF2
support to Cygwin. (Jim Blandy knows which one. Thanks again Jim :^),
and this is not necessarily related to that.)

In gcc/config/i386/i386.c, we have:

/* The "default" register map used in 32bit mode. */

int const dbx_register_map[FIRST_PSEUDO_REGISTER] =
{
0, 2, 1, 3, 6, 7, 4, 5, /* general regs */
12, 13, 14, 15, 16, 17, 18, 19, /* fp regs */
-1, -1, -1, -1, -1, /* arg, flags, fpsr, dir, frame */
21, 22, 23, 24, 25, 26, 27, 28, /* SSE */
29, 30, 31, 32, 33, 34, 35, 36, /* MMX */
-1, -1, -1, -1, -1, -1, -1, -1, /* extended integer registers */
-1, -1, -1, -1, -1, -1, -1, -1, /* extended SSE registers */
};

and:

/* Define the register numbers to be used in Dwarf debugging information. */

int const svr4_dbx_register_map[FIRST_PSEUDO_REGISTER] =
{
0, 2, 1, 3, 6, 7, 5, 4, /* general regs */
11, 12, 13, 14, 15, 16, 17, 18, /* fp regs */
-1, 9, -1, -1, -1, /* arg, flags, fpsr, dir, frame */
21, 22, 23, 24, 25, 26, 27, 28, /* SSE registers */
29, 30, 31, 32, 33, 34, 35, 36, /* MMX registers */
-1, -1, -1, -1, -1, -1, -1, -1, /* extended integer registers */
-1, -1, -1, -1, -1, -1, -1, -1, /* extended SSE registers */
};

Notice that gcc regno 6 (ebp) and 7 (esp) map to regno 4 and 5
respectively in the "default" (aka dbx, stabs, sdb) table. But, in
the svr4 (aka dwarf, dwarf2, stabs-in-elf) table, they map to regno 5 and
4 respectively.

I'm not sure if/how this should affect i386_register_names. I also hope
that targets have not already coded around this bug so that fixing it will
break something else :-). Please do have a look at these issues before
applying the patch. I'm afraid they are over my head right now.

Thanks.

2004-03-31 Brian Ford <ford@vss.fsi.com>

* i386-tdep.c (i386_stab_reg_to_regnum): Reverse 4 and 5
(ebp and esp respectively) to match the gdb/DWARF regnums.

--
Brian Ford
Senior Realtime Software Engineer
VITAL - Visual Simulation Systems
FlightSafety International
Phone: 314-551-8460
Fax: 314-551-8444

[-- Attachment #2: Type: TEXT/PLAIN, Size: 721 bytes --]

Index: i386-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-tdep.c,v
retrieving revision 1.181
diff -u -p -r1.181 i386-tdep.c
--- i386-tdep.c 23 Mar 2004 14:47:56 -0000 1.181
+++ i386-tdep.c 31 Mar 2004 23:25:52 -0000
@@ -175,8 +175,10 @@ i386_stab_reg_to_regnum (int reg)
/* This implements what GCC calls the "default" register map. */
if (reg >= 0 && reg <= 7)
{
- /* General-purpose registers. */
- return reg;
+ /* General-purpose registers.
+ ebp and esp (4, 5) are reversed with respect to gdb and DWARF. */
+
+ return (reg & 6) == 4 ? reg ^ 1 : reg;
}
else if (reg >= 12 && reg <= 19)
{