Thread overview
[Issue 15432] Win64: bad code offset in debug line number info
Dec 12, 2015
Rainer Schuetze
Jul 03, 2017
Vladimir Panteleev
Jul 03, 2017
Rainer Schuetze
Jul 09, 2017
Rainer Schuetze
December 11, 2015
https://issues.dlang.org/show_bug.cgi?id=15432

yazan.dabain@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yazan.dabain@gmail.com

--- Comment #1 from yazan.dabain@gmail.com ---
I understand that you are talking about the debug symbols, right? If so, the following is not the cause of this bug.

This bug reminded me of a change I made in the stack trace addresses generation (https://github.com/D-Programming-Language/druntime/commit/8822115bc8d52fa61c15cef38fe77349f18747b9) that I did not test the effect of on Windows.

I made this change so that the addresses coming from the stack trace point before the return address (i.e. to point at the call instruction even though it most probably won't point at the start of it). I don't know if the address to line handler on Windows produces correct mappings for such addresses.

--
December 12, 2015
https://issues.dlang.org/show_bug.cgi?id=15432

--- Comment #2 from Rainer Schuetze <r.sagitario@gmx.de> ---
Yes, I'm referring to the debug information generated by dmd, so libraries cannot cause this.

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

Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |symdeb
                 CC|                            |dlang-bugzilla@thecybershad
                   |                            |ow.net

--- Comment #3 from Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> ---
I reproduced this with 2.074.1.

Detailed steps to reproduce (without assuming prior knowledge):

1. You need:
  - dumpbin.exe (Visual Studio or Windows SDK)
  - dumplines.exe (build from source from https://github.com/rainers/cv2pdb,
install Visual D from https://github.com/dlang/visuald/releases, or download
stand-alone binary I compiled from
https://dump.thecybershadow.net/3d28f947dd7aeeb30325935bc2463d5d/dumplines.exe)

2. Save code to test.d
3. Run: dmd -g -m64 -c test.d
4. Run: dumpbin.exe /DISASM test.obj > test.asm
5. Run: dumplines.exe test.obj > test-lines.txt
6. In test-lines.txt, note the offsets (Off 0x### numbers) for the _Dmain
function (should be the first in the file)
7. In test.asm, note the offsets (first column of hex numbers) for the
instructions for the _Dmain function (should be the first in the file)

If there are any offsets in test-lines.txt's _Dmain which do not appear in test.asm's _Dmain, then it is an instance of this bug.

A self-contained example would be nice. Would it be possible to reproduce this issue e.g. by throwing an exception and looking at the stack trace for an address not mapped to a line number OSLT?

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

--- Comment #4 from Rainer Schuetze <r.sagitario@gmx.de> ---
Here's a further reduction:

///////////////////
void call15432(string col) {}

int test15432() // line 8
{
    call15432(null);
    return 0;
}
///////////////////

dumpbin:
_D7testpdb9test15432FZi:
  0000000000000000: 55                 push        rbp
  0000000000000001: 48 8B EC           mov         rbp,rsp
  0000000000000004: 48 83 EC 10        sub         rsp,10h
  0000000000000008: 48 C7 45 F0 00 00  mov         qword ptr [rbp-10h],0
                    00 00
  0000000000000010: 48 C7 45 F8 00 00  mov         qword ptr [rbp-8],0
                    00 00
  0000000000000018: 48 8D 4D F0        lea         rcx,[rbp-10h]
  000000000000001C: 48 83 EC 20        sub         rsp,20h
  0000000000000020: E8 00 00 00 00     call        _D7testpdb9call15432FAyaZv
  0000000000000025: 48 83 C4 20        add         rsp,20h
  0000000000000029: 31 C0              xor         eax,eax
  000000000000002B: 48 8B E5           mov         rsp,rbp
  000000000000002E: 5D                 pop         rbp
  000000000000002F: C3                 ret

cvdump
(https://github.com/Microsoft/microsoft-pdb/blob/master/cvdump/cvdump.exe):
*** LINES
      8 00000000     10 00000008     11 00000029     12 0000002A

You could get the offset to the line number before a stack address, but the return adress is still in the preceding line because there is some cleanup code after the call. In this code, the bad adress is even after the line with "return".

Enumerating the line number info is possible in test/runnable/testpdb.d, but a test will have to check specific code to be generated. At least, I don't have an idea what to test for instead.

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

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

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

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

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

--- Comment #6 from github-bugzilla@puremagic.com ---
Commits pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/399b12d8d6feaf43ced88c2559404f29ab70c496 fix issue 15432: Win64: bad code offset in debug line number info

pinhole optimization should not yield different results if run twice

https://github.com/dlang/dmd/commit/a7867ca72bf51a6db9e3ed44428e142a21d3de75 Merge pull request #6979 from rainers/issue15432

fix issue 15432: Win64: bad code offset in debug line number info merged-on-behalf-of: Rainer Schuetze <rainers@users.noreply.github.com>

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

github-bugzilla@puremagic.com changed:

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

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

--- Comment #7 from github-bugzilla@puremagic.com ---
Commits pushed to newCTFE at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/399b12d8d6feaf43ced88c2559404f29ab70c496 fix issue 15432: Win64: bad code offset in debug line number info

https://github.com/dlang/dmd/commit/a7867ca72bf51a6db9e3ed44428e142a21d3de75 Merge pull request #6979 from rainers/issue15432

--
August 16, 2017
https://issues.dlang.org/show_bug.cgi?id=15432

--- Comment #8 from github-bugzilla@puremagic.com ---
Commits pushed to stable at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/399b12d8d6feaf43ced88c2559404f29ab70c496 fix issue 15432: Win64: bad code offset in debug line number info

https://github.com/dlang/dmd/commit/a7867ca72bf51a6db9e3ed44428e142a21d3de75 Merge pull request #6979 from rainers/issue15432

--