Bug 16977 – bad debug info for function default arguments

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
Windows
Creation time
2016-12-17T10:40:00Z
Last change time
2017-01-16T23:25:45Z
Keywords
pull, symdeb
Assigned to
nobody
Creator
r.sagitario

Comments

Comment #0 by r.sagitario — 2016-12-17T10:40:06Z
When compiling this code with debug information for OMF: void main() { foo(1, 2); } size_t foo(int x, int y, int z = 3) { return x; } it results in line number info displayed by the debugger like this: 1: 2: void main() 00402010 55 push ebp 00402011 8B EC mov ebp,esp 3: { 4: foo(1, 2); 00402013 6A 01 push 1 3: { 4: foo(1, 2); 00402015 6A 02 push 2 6: 7: size_t foo(int x, int y, int z = 3) 00402017 B8 03 00 00 00 mov eax,3 0040201C E8 07 00 00 00 call cvdefarg@foo (0402028h) 00402021 31 C0 xor eax,eax 5: } 00402023 5D pop ebp 00402024 C3 ret This has issues: - loading the default argument inherits the location of the function declaration, so the debugger is prematurely redirected to the source line of the function before actually calling it. The user thinks the function is already called, but using "step until return" will stop after returning from the calling function instead. - the return address on the stack is considered at line 7, i.e. at the function declaration. This makes the call stack pretty unusable. Compiling for COFF is even worse because there is a (gratuitious?) limitation on increasing line numbers.
Comment #1 by r.sagitario — 2016-12-17T11:12:03Z
Comment #2 by github-bugzilla — 2016-12-19T17:40:01Z
Commit pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/d2b804b4fbff6187d31a5c854b096d21ab09edc9 Merge pull request #6327 from rainers/noloc_defaultarg Fix issue 16977 - bad debug info for function default arguments
Comment #3 by github-bugzilla — 2016-12-27T14:41:37Z
Commit pushed to scope at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/d2b804b4fbff6187d31a5c854b096d21ab09edc9 Merge pull request #6327 from rainers/noloc_defaultarg
Comment #4 by github-bugzilla — 2017-01-16T23:25:45Z
Commit pushed to newCTFE at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/d2b804b4fbff6187d31a5c854b096d21ab09edc9 Merge pull request #6327 from rainers/noloc_defaultarg