This is the mail archive of the
mailing list for the GCC project.
Function parameter debug info at -O0
- From: Senthil Kumar Selvaraj <senthil_kumar dot selvaraj at atmel dot com>
- To: <gcc at gcc dot gnu dot org>
- Date: Mon, 6 Aug 2012 18:50:00 +0530
- Subject: Function parameter debug info at -O0
The following program, when compiled with -O0 -g3 (x86_64 target, but
doesn't seem to matter), shows wrong values for p (function parameter)
[saaadhu@jaguar scratch]$ cat test.c
int func(int p)
p = 20;
p = 30;
int local = 42;
The assembly generated looks like this
movq %rsp, %rbp
movl %edi, -20(%rbp)
movl $20, -4(%rbp)
movl $30, -4(%rbp)
I guess the DWARF debug information generated specifies -20(%rbp)
as the offset to look for p, and that's why the debugger keeps showing
the passed value (42) instead of 20 and 30 (see gdb session dump below).
The same behavior occurs for the avr target as well, and debugging
cc1 showed that the initial move happens from gimple_expand_cfg's
expand_function_start, when it eventually calls assign_parm_setup_stack.
That in itself is ok I guess, but the frame offset doesn't match other
reads from and writes to the same variable.
Debugging further, I found that that the offset is bumped up because
expand_vars, called earlier from gimple_expand_cfg, allocates space on
the frame for p as well. Specifically, expand_used_vars, when looping
through SA.map->num_partitions, sees that SA.partition_has_default_def
is false for the partition corresponding to p, and calls expand_one_var
to allocate space for it.
remove_ssa_form sets partition_has_default_def, but looping
over num_ssa_names does not include the tree node for the parameter.
Before investigating further, I wanted to know if this actually is a bug
and if I'm debugging it right. Shouldn't function parameters be defined by default
on entry into the function?
[saaadhu@jaguar scratch]$ gcc -g3 -O0 test.c
[saaadhu@jaguar scratch]$ gdb a.out
GNU gdb (GDB) 7.4.1
(gdb) b func
Breakpoint 1 at 0x4004b3: file test.c, line 3.
Temporary breakpoint 2 at 0x4004cb: file test.c, line 9.
Starting program: /home/saaadhu/scratch/a.out
Temporary breakpoint 2, main () at test.c:9
9 int local = 42;
Breakpoint 1, func (p=42) at test.c:3
3 p = 20;
4 p = 30;
(gdb) print p
$1 = 42