http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51358
--- Comment #1 from Jan Kratochvil <jan.kratochvil at redhat dot com>
2011-11-30 20:46:54 UTC ---
(In reply to comment #0)
> Compiling the following with g++ -gdwarf-4 -o length length.cxx
[...]
> <aa5> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
[...]
> <ab6> DW_AT_location : 2 byte block: 91 58 (DW_OP_fbreg: -40)
>
> Which seems to suggest that the formal_parameter "str" can always be accessed
> through fbreg -40. But this isn't true as you can see by looking at the
> generated code:
>
> Dump of assembler code for function length(std::string const&):
> 0x000000000040088c <+0>: push %rbp
> 0x000000000040088d <+1>: mov %rsp,%rbp
> 0x0000000000400890 <+4>: sub $0x20,%rsp
> 0x0000000000400894 <+8>: mov %rdi,-0x18(%rbp)
[...]
> The argument was actually in %rdi, which isn't pushed on the stack till
> 400894, so when we probe at the start of the function (40088c) we will see
> garbage when trying to extract the str parameter.
>
> Is there a way a dwarf consumer could have known that?
This is AFAIK correct. With -O0 there is no location tracking and the consumer
must skip the prologue first before considering DW_AT_location content.
See GDB symtab->locations_valid detection so that GDB at least knows the cases
when it does not have to skip the prologue.
locations_valid detection should be further extended by detecting -O>=1 in
DW_AT_producer for some rare cases where the current GDB detection would not
work. But -grecord-gcc-switches is not default in FSF GCC so the
DW_AT_producer may not be so useful for FSF GCC builds.
> GCC also doesn't seem to produce line table prologue markers, so it also
> doesn't help trying to search for the end of prologue.
(a) GDB reliably detects the prologue end by skipping the first source line.
GCC even supports this by producing 0-line advance in some cases.
(b) I cannot find the Bug now but my request for DW_LNS_set_prologue_end has
been declined as the current source-line based detection works correctly
and DW_LNS_set_prologue_end would just needlessly increase the debug info
size.