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

Jim Blandy
2004-04-05T18:18:03Z

[-- Attachment #1: Type: text/plain, Size: 938 bytes --]

Eli, here is a program you can use to see whether DJGPP's GCC and
the current GDB disagree on how to number %ebp and %esp.

One of the reasons people would tend not to notice if %ebp and %esp
are misnumbered in STABS is that they almost never occur. Dwarf 2
emits explicit location expressions to specify the "frame base" for a
function; these expressions usually refer to %esp or %ebp. In STABS,
however, stack-based variables are simply marked as "LSYMS" or
"PSYMS", whose locations are given as offsets relative to some
implicit base that the debugger just has to know.

So the only way to get those register numbers to appear at all is to
get a variable allocated to them. You'll never get a variable
allocated to %esp. And you'll never get a varable allocated to %ebp
unless you compile with -fomit-frame-pointer. So, if I compile the
attached program with GCC 3.3 passing -O -fomit-frame-pointer, 'n'
gets allocated to %ebp.

[-- Attachment #2: test program to get a variable in %ebp --]
[-- Type: text/plain, Size: 609 bytes --]

#include <stdio.h>
#include <stdlib.h>

int
foo (register int n)
{
register int i;
register int a = n * 1;
register int b = n * 2;
register int c = n * 3;
register int d = n * 4;
register int e = n * 5;

for (i = 0; i < n; i++)
{
if (i & 1) a = b + c; else a = c + e;
if (i & 2) b = c + d; else b = d + a;
if (i & 4) c = d + e; else c = e + b;
if (i & 8) d = e + a; else d = a + c;
if (i & 16) e = a + b; else e = b + d;
}

return a + b + c + d + e;
}

int
main (int argc, char **argv)
{
if (argc == 2)
printf ("%d\n", foo (atoi (argv[1])));
}