Issue 19747 - No debug line info for code in scope(exit)
Summary: No debug line info for code in scope(exit)
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Windows
: P1 major
Assignee: No Owner
URL:
Keywords: DebugInfo, pull
Depends on:
Blocks:
 
Reported: 2019-03-17 14:37 UTC by Rainer Schuetze
Modified: 2019-03-18 02:45 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Rainer Schuetze 2019-03-17 14:37:13 UTC
Compiling this code for COFF with "dmd -m64 -g":

module dbgi;

__gshared int recurse;

int foo(int n)
{
	recurse++;
	scope(exit)
	{
		recurse--;
		if (recurse < 0)
			assert(false);
	}
	int r = n + n;
	int s = r + 2;
	return r;
}

void main()
{
	int x = foo(7);
}

yields missing debug line information for the code in scope(exit), e.g. disassembly in VS looks like this:

     5: int foo(int n)
00007FF797F0BF80  push        rbp  
00007FF797F0BF81  mov         rbp,rsp  
00007FF797F0BF84  sub         rsp,18h  
00007FF797F0BF88  push        rbx  
00007FF797F0BF89  mov         dword ptr [n],ecx  
     6: {
     7: 	recurse++;
00007FF797F0BF8C  inc         dword ptr [dbgi.recurse (07FF79800A4A0h)]  
     8: 	scope(exit)
     9: 	{
    10: 		recurse--;
    11: 		if (recurse < 0)
    12: 			assert(false);
    13: 	}
    14: 	int r = n + n;
00007FF797F0BF92  mov         eax,dword ptr [n]  
     8: 	scope(exit)
     9: 	{
    10: 		recurse--;
    11: 		if (recurse < 0)
    12: 			assert(false);
    13: 	}
    14: 	int r = n + n;
00007FF797F0BF95  mov         ecx,eax  
00007FF797F0BF97  lea         edx,[rax+rcx]  
00007FF797F0BF9A  mov         dword ptr [r],edx  
    15: 	int s = r + 2;
00007FF797F0BF9D  lea         ebx,[rdx+2]  
00007FF797F0BFA0  mov         dword ptr [s],ebx  
00007FF797F0BFA3  mov         eax,edx  
00007FF797F0BFA5  mov         qword ptr [rbp-10h],rax  
00007FF797F0BFA9  sub         rsp,8  
00007FF797F0BFAD  call        dbgi.foo+4Fh (07FF797F0BFCFh)  
00007FF797F0BFB2  add         rsp,8  
00007FF797F0BFB6  mov         rax,qword ptr [rbp-10h]  
00007FF797F0BFBA  pop         rbx  
00007FF797F0BFBB  mov         rsp,rbp  
00007FF797F0BFBE  pop         rbp  
00007FF797F0BFBF  ret  
00007FF797F0BFC0  sub         rsp,8  
00007FF797F0BFC4  call        dbgi.foo+4Fh (07FF797F0BFCFh)  
00007FF797F0BFC9  add         rsp,8  
00007FF797F0BFCD  jmp         dbgi.foo+76h (07FF797F0BFF6h)  
00007FF797F0BFCF  dec         dword ptr [dbgi.recurse (07FF79800A4A0h)]  
00007FF797F0BFD5  cmp         dword ptr [dbgi.recurse (07FF79800A4A0h)],0  
00007FF797F0BFDC  jns         dbgi.foo+75h (07FF797F0BFF5h)  
00007FF797F0BFDE  mov         edx,0Ch  
00007FF797F0BFE3  lea         rcx,[__a6_646267692e64 (07FF797FF7E20h)]  
00007FF797F0BFEA  sub         rsp,20h  
00007FF797F0BFEE  call        _d_assertp (07FF797F0643Dh)  
00007FF797F0BFF3  ud2  
00007FF797F0BFF5  ret  
    16: 	return r;
    17: }
00007FF797F0BFF6  pop         rbx  
    16: 	return r;
    17: }
00007FF797F0BFF7  mov         rsp,rbp  
00007FF797F0BFFA  pop         rbp  
00007FF797F0BFFB  ret  

This prevents setting breakpoints in the scope(exit)-code or stepping through the code.
Comment 1 Dlang Bot 2019-03-17 18:14:38 UTC
@rainers created dlang/dmd pull request #9459 "fix Issue 19747 - No debug line info for code in scope(exit)" fixing this issue:

- fix Issue 19747 - No debug line info for code in scope(exit)
  
  remove gratuitous requirement of ascending source
  
  testpdb.d now also supports registration free use of COM interfac to msdia140.dll as used by VS2017 and VS2019

https://github.com/dlang/dmd/pull/9459
Comment 2 Dlang Bot 2019-03-18 02:45:46 UTC
dlang/dmd pull request #9459 "fix Issue 19747 - No debug line info for code in scope(exit)" was merged into master:

- 494913ded60ba275b8caae09a3a09ad478f750eb by Rainer Schuetze:
  fix Issue 19747 - No debug line info for code in scope(exit)
  
  remove gratuitous requirement of ascending source
  
  testpdb.d now also supports registration free use of COM interfac to msdia140.dll as used by VS2017 and VS2019

https://github.com/dlang/dmd/pull/9459