http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53927
Bug #: 53927 Summary: wrong value for DW_AT_static_link Classification: Unclassified Product: gcc Version: 4.6.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: debug AssignedTo: unassig...@gcc.gnu.org ReportedBy: tro...@gcc.gnu.org Compile this program with -g: typedef int compute_function (int); int nestee (compute_function *computer, int arg, int self_call) { int nested (int nested_arg) { return nested_arg + 23 + self_call; /* Break here */ } if (self_call) arg = nestee (nested, arg + 5, 0); return computer (arg); } int misc (int arg) { return 0; } int main(int argc, char **argv) { nestee (misc, 5, 1); return 0; } .debug_info says: <2><8b>: Abbrev Number: 9 (DW_TAG_subprogram) <8c> DW_AT_name : (indirect string, offset: 0xe6): nested <90> DW_AT_decl_file : 1 <91> DW_AT_decl_line : 5 <92> DW_AT_prototyped : 1 <92> DW_AT_type : <0x47> <96> DW_AT_low_pc : 0x4004b4 <9e> DW_AT_high_pc : 0x4004ca <a6> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa) <a8> DW_AT_static_link : 1 byte block: 50 (DW_OP_reg0 (rax)) <aa> DW_AT_GNU_all_call_sites: 1 <aa> DW_AT_sibling : <0xcb> That is, the static link is $rax. In gdb I set a breakpoint at line 7 and ran the program. Then: (gdb) p/x $rax $8 = 0x7fffffffe400 Now I go up a couple of frames to the relevant (outermost) invocation of nestee: (gdb) p /x $pc $9 = 0x40052c And then from the frame info: 00000080 0000001c 00000084 FDE cie=00000000 pc=0040053c..0040054a LOC CFA rbp ra 000000000040053c rsp+8 u c-8 000000000040053d rsp+16 c-16 c-8 0000000000400540 rbp+16 c-16 c-8 0000000000400549 rsp+8 c-16 c-8 So I think the CFA in this frame is $rsp+8. But in gdb: (gdb) p /x $rsp+8 $10 = 0x7fffffffe3f8 ... which is different from the DW_AT_static_link. nestee does specify that its frame base is the CFA: <1><4e>: Abbrev Number: 6 (DW_TAG_subprogram) <4f> DW_AT_external : 1 <4f> DW_AT_name : (indirect string, offset: 0xed): nestee <53> DW_AT_decl_file : 1 <54> DW_AT_decl_line : 3 <55> DW_AT_prototyped : 1 <55> DW_AT_type : <0x47> <59> DW_AT_low_pc : 0x4004ca <61> DW_AT_high_pc : 0x40053c <69> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa) So, I think this is a GCC bug.