This is the mail archive of the gdb@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]

Problem with location lists and variables on stack


Hello,

I writing a better pass (variable tracking) for GCC which finally emits
location lists for variables. (If you are insterested it is at
http://artax.karlin.mff.cuni.cz/~zlomj9am/download/vt-main.patch
It still contains many debugging checks and (disabled) prints.)

Let the local variables and (some) arguments be addressed using stack pointer,
for example x86-64 architecture with variables addressed using %rsp.
The address emitted for variables located on stack by my new patch is always
DW_OP_fbreg + constant.

When I was testing the emitted debug info with mainline GDB I found that
GDB probably does not adjust addresses of variables when stack pointer changes
(like because of "pushq" instruction) if using location lists.
I think GDB should adjust the address of %rsp addressed variables according to
change of %rsp (probably DWARF2 sais so for DW_OP_fbreg). I think it is a
better solution than emitting new locations to location list for all variables
located on stack after each "push" and "pop" which would cause too large debug
info.

When I looked to gdb/dwarf2loc.c I see there:
 /* FIXME: cagney/2003-03-26: This code should be using
     get_frame_base_address(), and then implement a dwarf2 specific
     this_base method.  */
Probably this is related to my problem.

I tested it on attached C file, assembler with debug info and x86-64 binary
is attached too.

GDB's output:

# g is the first argument on stack, the first 6 arguments are in registers

Breakpoint 1, func1 (a=10, b=20, c=30, d=40, e=50, f=60, g=70, seq=0) at m.c:5
5       {
2: x/i $pc  0x400400 <func1>:   push   %r12
1: g = 70
(gdb) ni
0x0000000000400402      5       {
2: x/i $pc  0x400402 <func1+2>: mov    %rcx,%r12

# here it looks GDB did not recompute address

1: g = 4195497
(gdb) 
0x0000000000400405      5       {
2: x/i $pc  0x400405 <func1+5>: mov    %r8,%rcx
1: g = 4195497
(gdb)
0x0000000000400408      5       { 
2: x/i $pc  0x400408 <func1+8>: mov    %rdx,%r10
1: g = 4195497
(gdb)
0x000000000040040b      5       {
2: x/i $pc  0x40040b <func1+11>:        push   %rbp
1: g = 4195497
(gdb) 
0x000000000040040c      5       {
2: x/i $pc  0x40040c <func1+12>:        mov    %rdi,%rbp
1: g = 4195520
(gdb) 
0x000000000040040f      5       {
2: x/i $pc  0x40040f <func1+15>:        push   %rbx
1: g = 4195520
(gdb) 
0x0000000000400410      5       {
2: x/i $pc  0x400410 <func1+16>:        mov    0x20(%rsp,1),%r8
1: g = 548682067112

# here g was loaded from stack to %r8

(gdb)
0x0000000000400415      5       {
2: x/i $pc  0x400415 <func1+21>:        mov    %rsi,%rbx
1: g = 70
(gdb)


Josef
long volatile vol;

long
func1 (long a, long b, long c, long d, long e, long f, long g, int seq)
{
	vol = a + b + c + d + e + f + g;
	
	if (seq == 3)
		return vol;
	
	return func1 (g, f, e, d, c, b, a, seq + 1);
}

int
main ()
{
	vol = func1 (10, 20, 30, 40, 50, 60, 70, 0);
	return (int) vol;
}

Attachment: m.s
Description: Text document

Attachment: a.out
Description: Binary data


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