https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87440
Bug ID: 87440 Summary: GCC creates debug that confuses gdb Product: gcc Version: 8.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: debug Assignee: unassigned at gcc dot gnu.org Reporter: rguenth at gcc dot gnu.org Target Milestone: --- static int foo (int i) { volatile int j = i + 3; return j - 2; } int main() { volatile int z = foo (-1); return z; } > gcc t.c -O -g > gdb ./a,out (gdb) start (gdb) s foo (i=-1) at t.c:7 7 { (gdb) info locals j = 0 j = <optimized out> we get 'j' two times (this is with gdb 8.2) because we emit a stray lexical block for the DW_TAG_inlined_subroutine: <2><128>: Abbrev Number: 4 (DW_TAG_inlined_subroutine) <129> DW_AT_abstract_origin: <0x170> <12d> DW_AT_low_pc : 0x4004d7 <135> DW_AT_high_pc : 0xf <13d> DW_AT_call_file : 1 <13e> DW_AT_call_line : 8 <3><13f>: Abbrev Number: 5 (DW_TAG_formal_parameter) <140> DW_AT_abstract_origin: <0x17c> <144> DW_AT_location : 0x0 (location list) <3><148>: Abbrev Number: 6 (DW_TAG_lexical_block) <149> DW_AT_low_pc : 0x4004d7 <151> DW_AT_high_pc : 0xf <4><159>: Abbrev Number: 7 (DW_TAG_variable) <15a> DW_AT_abstract_origin: <0x185> <15e> DW_AT_location : 2 byte block: 91 70 (DW_OP_fbreg: -16) vs. the abstract origin which has: <1><170>: Abbrev Number: 10 (DW_TAG_subprogram) <171> DW_AT_name : foo <175> DW_AT_decl_file : 1 <176> DW_AT_decl_line : 1 <177> DW_AT_prototyped : 1 <177> DW_AT_type : <0x164> <17b> DW_AT_inline : 1 (inlined) <2><17c>: Abbrev Number: 11 (DW_TAG_formal_parameter) <17d> DW_AT_name : i <17f> DW_AT_decl_file : 1 <180> DW_AT_decl_line : 1 <181> DW_AT_type : <0x164> <2><185>: Abbrev Number: 12 (DW_TAG_variable) <186> DW_AT_name : j <188> DW_AT_decl_file : 1 <189> DW_AT_decl_line : 3 <18a> DW_AT_type : <0x16b> note how there's no outermost lexical block there. This is because gen_subprogram_die calls decls_for_scope on DECL_INITIAL rather than gen_lexical_block_die. gen_inlined_subroutine_die tries to do the same but fails to merge the "fake" block the inliner generates for the parameter replacements with the actual outer scope of the function.