On 07/16/2018 03:50 PM, Richard Biener wrote: > On Mon, 16 Jul 2018, Tom de Vries wrote: > >> Hi, >> >> this is an idea that I'm currently playing around with: adding nops in >> an optimized application with debug info can improve the debug info. >> >> >> Consider f.i. this gdb session in foo of pr54200-2.c (using -Os): >> ... >> (gdb) n >> 26 return a; /* { dg-final { gdb-test . "(int)a" "6" } } */ >> (gdb) p a >> 'a' has unknown type; cast it to its declared type >> (gdb) n >> main () at pr54200-2.c:34 >> 34 return 0; >> ... >> >> The problem is that the scope in which a is declared ends at .LBE7, and the >> statement .loc for line 26 ends up attached to the ret insn: >> ... >> .loc 1 24 11 >> addl %edx, %eax >> .LVL1: >> # DEBUG a => ax >> .loc 1 26 7 is_stmt 1 >> .LBE7: >> .loc 1 28 1 is_stmt 0 >> ret >> .cfi_endproc >> ... >> >> This patch fixes the problem (for Og and Os, the 'DEBUG a => ax' is missing >> for O1 and higher) by adding a nop before the ret insn: >> ... >> .loc 1 24 11 >> addl %edx, %eax >> .LVL1: >> # DEBUG a => ax >> .loc 1 26 7 is_stmt 1 >> + nop >> .LBE7: >> .loc 1 28 1 is_stmt 0 >> ret >> .cfi_endproc >> ... >> >> and instead we have: >> ... >> (gdb) n >> 26 return a; /* { dg-final { gdb-test . "(int)a" "6" } } */ >> (gdb) p a >> $1 = 6 >> (gdb) n >> main () at pr54200-2.c:34 >> 34 return 0; >> ... >> >> Any comments? > > Interesting idea. I wonder if that should be generalized > to other places
I kept the option name general, to allow for that. And indeed, this is a point-fix patch. I've been playing around with a more generic patch that adds nops such that each is_stmt .loc is associated with a unique insn, but that was embedded in an fkeep-vars-live branch, so this patch is minimally addressing the first problem I managed to reproduce on trunk. > and how we can avoid compare-debug failures > (var-tracking usually doesn't change code-generation). > I could remove the cfun->debug_nonbind_markers test and move the nop-insertion to a separate pass or some such. Thanks, - Tom