Thread overview
[Issue 17619] [REG2.072] Wrong debug line information with single line loops
Jul 07, 2017
Martin Krejcirik
Jul 08, 2017
Rainer Schuetze
Jul 08, 2017
Martin Krejcirik
Jul 22, 2017
Rainer Schuetze
Oct 03, 2017
Walter Bright
Oct 03, 2017
Walter Bright
Oct 07, 2017
Rainer Schuetze
July 07, 2017
https://issues.dlang.org/show_bug.cgi?id=17619

Martin Krejcirik <mk@krej.cz> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |symdeb

--
July 08, 2017
https://issues.dlang.org/show_bug.cgi?id=17619

Rainer Schuetze <r.sagitario@gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |r.sagitario@gmx.de

--- Comment #1 from Rainer Schuetze <r.sagitario@gmx.de> ---
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();

--
July 08, 2017
https://issues.dlang.org/show_bug.cgi?id=17619

--- Comment #2 from Martin Krejcirik <mk@krej.cz> ---
(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.

--
July 22, 2017
https://issues.dlang.org/show_bug.cgi?id=17619

--- Comment #3 from Rainer Schuetze <r.sagitario@gmx.de> ---
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).

--
October 03, 2017
https://issues.dlang.org/show_bug.cgi?id=17619

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com

--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> ---
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.

--
October 03, 2017
https://issues.dlang.org/show_bug.cgi?id=17619

--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> ---
> Introduced by https://github.com/dlang/dmd/pull/2867

Uh-oh! 574 lines and 21 files changed!

--
October 07, 2017
https://issues.dlang.org/show_bug.cgi?id=17619

Rainer Schuetze <r.sagitario@gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #6 from Rainer Schuetze <r.sagitario@gmx.de> ---
https://github.com/dlang/dmd/pull/7189

--
October 07, 2017
https://issues.dlang.org/show_bug.cgi?id=17619

--- Comment #7 from github-bugzilla@puremagic.com ---
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 <WalterBright@users.noreply.github.com>

--
October 07, 2017
https://issues.dlang.org/show_bug.cgi?id=17619

github-bugzilla@puremagic.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--
October 09, 2017
https://issues.dlang.org/show_bug.cgi?id=17619

--- Comment #8 from github-bugzilla@puremagic.com ---
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

--