Still problems with gdb and nested functions.
Eli Zaretskii
eliz@gnu.org
Tue Feb 22 20:50:00 GMT 2005
> Date: Tue, 22 Feb 2005 14:17:42 -0500
> From: tj <999alfred@comcast.net>
>
> Breakpoint 1, inside.0 () at test.c:12
> 12 printf("inside, k = %d, l = %d\n", k,l);
> (gdb) p k
> No symbol "k" in current context.
> (gdb) continue
> Continuing.
> inside, k = 1, l = 1
I can confirm this, but it looks like this is either a GCC problem, or
perhaps GCC generates DWARF-2 debug info that confuses GDB. Observe:
$ gcc -O0 -ggdb3 -o test test.c
$ gdb ./test
...
(gdb) break 12
Breakpoint 1 at 0x16de: file test.c, line 12.
(gdb) info address k
No symbol "k" in current context.
(gdb) disassemble
Dump of assembler code for function inside.0:
0x000016c8 <inside.0+0>: push %ebp
0x000016c9 <inside.0+1>: mov %esp,%ebp
0x000016cb <inside.0+3>: sub $0x18,%esp
0x000016ce <inside.0+6>: mov %ecx,0xfffffffc(%ebp)
0x000016d1 <inside.0+9>: movl $0x1,0xfffffff8(%ebp)
0x000016d8 <inside.0+16>: mov 0xfffffff8(%ebp),%eax
0x000016db <inside.0+19>: mov %eax,0xfffffff4(%ebp)
0x000016de <inside.0+22>: sub $0x4,%esp
0x000016e1 <inside.0+25>: pushl 0xfffffff4(%ebp)
0x000016e4 <inside.0+28>: pushl 0xfffffff8(%ebp)
0x000016e7 <inside.0+31>: push $0x16b0
0x000016ec <inside.0+36>: call 0x3360 <printf>
0x000016f1 <inside.0+41>: add $0x10,%esp
0x000016f4 <inside.0+44>: mov $0x0,%eax
0x000016f9 <inside.0+49>: leave
0x000016fa <inside.0+50>: ret
End of assembler dump.
(gdb) info locals
No locals.
The disassembly clearly shows that GDB is wrong: the variable k is
stored at 0xfffffff8(%ebp).
Now watch what happens with stabs debug info:
gcc -O0 -gstabs3 -o test test.c
$ gdb ./test
...
(gdb) break 12
Breakpoint 1 at 0x160e: file test.c, line 12.
(gdb) info address k
Symbol "k" is a local variable at frame offset -8.
(gdb) print k
$1 = 1
(gdb) info locals
k = 1
l = 1
(gdb)
So with stabs debug info, GDB works correctly, but with the default
DWARF-2 debug info, it gets confused.
(Strangely, the code location corresponding to breakpoint at line 12
is also different in these two builds: 0x160e vs 0x16de. Why would
debug info affect code locations? anyone?)
More information about the Gdb
mailing list