Bug 17619 – [REG2.072] Wrong debug line information with single line loops

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
Linux
Creation time
2017-07-07T18:10:40Z
Last change time
2017-10-09T23:45:44Z
Keywords
pull, symdeb
Assigned to
No Owner
Creator
Martin Krejcirik

Comments

Comment #0 by mk — 2017-07-07T18:10:40Z
void main() { foreach (i; 0 .. 3) i++; int bad; // shown during loop } Breakpoint 1, D main () at loop3.d:3 3 foreach (i; 0 .. 3) (gdb) n 4 i++; (gdb) 6 int bad; // shown during loop (gdb) 4 i++; (gdb) 6 int bad; // shown during loop (gdb) 4 i++; (gdb) 6 int bad; // shown during loop (gdb) 6 int bad; // shown during loop (gdb) 7 } When compiled with older DMD: Breakpoint 1, D main () at loop3.d:3 3 foreach (i; 0 .. 3) (gdb) n 4 i++; (gdb) 3 foreach (i; 0 .. 3) (gdb) 4 i++; (gdb) 3 foreach (i; 0 .. 3) (gdb) 4 i++; (gdb) 3 foreach (i; 0 .. 3) (gdb) 6 int bad; // shown during loop (gdb) 7 } Introduced by https://github.com/dlang/dmd/pull/2867
Comment #1 by r.sagitario — 2017-07-08T08:26:58Z
I think there are (at least) two issues here: 1. the line number attached to the end of the for statement is the line of the token following the loop, while it should be the line after the last token of the statement. That would not really help if the declaration of "bad" would not be separated by an empty line, though. 2. there is no perfect fit for the line number attached to the loop iteration and jump back to the start: - if it is after the loop, it looks as if the loop has already terminated (as reported here). This also happens sometimes for C++ code with VC (not sure about gcc). - if it is on the loop statement the call stack of a function call inside the loop can get confusing, e.g. void main() { test1(); foreach (i; 0 .. 3) test2(); } When breaking inside test2, the call stack will look like it is being called by test1();
Comment #2 by mk — 2017-07-08T10:30:32Z
(In reply to Rainer Schuetze from comment #1) > 1. the line number attached to the end of the for statement is the line of > the token following the loop, while it should be the line after the last > token of the statement. That would not really help if the declaration of > "bad" would not be separated by an empty line, though. I wonder if it could just stay in the loop body if there is no closing curly bracket. However, if I add curly brackets to the single body line, it shows foreach line on every iteration, so for consistency, it should be the same without curlys; > When breaking inside test2, the call stack will look like it is being > called by test1(); I don't observe such behaviour with an older dmd.
Comment #3 by r.sagitario — 2017-07-22T10:10:47Z
I recently analyzed this a bit: dmd now attaches both lines 3 and 6 to the DWARF info for the loop increment, and gdb selects 6 now. dmd also elides some unconditional jumps, even in debug builds. I suspect avoiding this can help. >> When breaking inside test2, the call stack will look like it is being >> called by test1(); > I don't observe such behaviour with an older dmd. gdb seems to be a bit better in this regard than the VS debugger: even if the return address after the call instruction is annotated with a different line, it still displays the line of the call itself. VS shows the line after the call (if there are no call cleanup instructions).
Comment #4 by bugzilla — 2017-10-03T09:16:39Z
Looking at the x86 output: 0000: enter 010h,0 0004: mov dword ptr -010h[EBP],0 3 000b: mov dword ptr -0Ch[EBP],3 0012: mov EAX,-010h[EBP] 0015: cmp EAX,-0Ch[EBP] 0018: jge $+Fh 001a: mov ECX,-010h[EBP] 001d: mov -8[EBP],ECX 0020: inc dword ptr -8[EBP] 4 0023: inc dword ptr -010h[EBP] 6 0026: jmp short $+FFFFFFEBh 0028: xor EDX,EDX 002a: mov -4[EBP],EDX 002d: mov EAX,EDX 002f: leave 7 0030: ret Line 6 is the `int bad;` line. This happens also if the foreach is rewritten as a for loop.
Comment #5 by bugzilla — 2017-10-03T09:20:39Z
> Introduced by https://github.com/dlang/dmd/pull/2867 Uh-oh! 574 lines and 21 files changed!
Comment #6 by r.sagitario — 2017-10-07T11:52:47Z
Comment #7 by github-bugzilla — 2017-10-07T20:05:08Z
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/056160d108df108d99783b77ea5b9e0b04a9d592 fix issue 17619: for statements without curly braces, default endloc to location of last token, not next token https://github.com/dlang/dmd/commit/64fda491f77ca98a1814dd20e7be917c1c767369 Merge pull request #7189 from rainers/fix_17619 fix issue 17619: [REG2.072] Wrong debug line information with single line loops merged-on-behalf-of: Walter Bright <[email protected]>
Comment #8 by github-bugzilla — 2017-10-09T23:45:44Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/056160d108df108d99783b77ea5b9e0b04a9d592 fix issue 17619: for statements without curly braces, default endloc to location of last token, not next token https://github.com/dlang/dmd/commit/64fda491f77ca98a1814dd20e7be917c1c767369 Merge pull request #7189 from rainers/fix_17619