http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51358
Bug #: 51358 Summary: missing location Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: debug AssignedTo: unassig...@gcc.gnu.org ReportedBy: m...@gcc.gnu.org CC: do...@gcc.gnu.org, tro...@redhat.com This is related to the following systemtap bug report: http://sourceware.org/bugzilla/show_bug.cgi?id=13420 This is using g++ (GCC) 4.7.0 20111130 (experimental), but can be reproduced with other versions (g++ (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4) in particular). Compiling the following with g++ -gdwarf-4 -o length length.cxx #include <string> size_t length(const std::string& str) { int res = str.length(); return res; } int main() { std::string hello = "Hello World!"; return 12 != length(hello); } Produces: 00000000 00000014 00000000 CIE Version: 1 Augmentation: "zR" Code alignment factor: 1 Data alignment factor: -8 Return address column: 16 Augmentation data: 1b DW_CFA_def_cfa: r7 (rsp) ofs 8 DW_CFA_offset: r16 (rip) at cfa-8 DW_CFA_nop DW_CFA_nop 00000018 0000001c 0000001c FDE cie=00000000 pc=0040088c..004008ae DW_CFA_advance_loc: 1 to 0040088d DW_CFA_def_cfa_offset: 16 DW_CFA_offset: r6 (rbp) at cfa-16 DW_CFA_advance_loc: 3 to 00400890 DW_CFA_def_cfa_register: r6 (rbp) DW_CFA_advance_loc: 29 to 004008ad DW_CFA_def_cfa: r7 (rsp) ofs 8 DW_CFA_nop DW_CFA_nop DW_CFA_nop and <1><a86>: Abbrev Number: 95 (DW_TAG_subprogram) <a87> DW_AT_external : 1 <a87> DW_AT_name : (indirect string, offset: 0x1aec): length <a8b> DW_AT_decl_file : 1 <a8c> DW_AT_decl_line : 4 <a8d> DW_AT_linkage_name: (indirect string, offset: 0x293): _Z6lengthRKSs <a91> DW_AT_type : <0x2e2> <a95> DW_AT_low_pc : 0x40088c <a9d> DW_AT_high_pc : 0x4008ae <aa5> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa) <aa7> Unknown AT value: 2116: 1 <aa7> DW_AT_sibling : <0xada> <2><aab>: Abbrev Number: 96 (DW_TAG_formal_parameter) <aac> DW_AT_name : str <ab0> DW_AT_decl_file : 1 <ab1> DW_AT_decl_line : 4 <ab2> DW_AT_type : <0xada> <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) 0x0000000000400898 <+12>: mov -0x18(%rbp),%rax 0x000000000040089c <+16>: mov %rax,%rdi 0x000000000040089f <+19>: callq 0x4006c0 <_ZNKSs6lengthEv@plt> 0x00000000004008a4 <+24>: mov %eax,-0x4(%rbp) 0x00000000004008a7 <+27>: mov -0x4(%rbp),%eax 0x00000000004008aa <+30>: cltq 0x00000000004008ac <+32>: leaveq 0x00000000004008ad <+33>: retq End of assembler dump. 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? 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.