-
-
Notifications
You must be signed in to change notification settings - Fork 609
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix issue 17559 - [REG2.073.0] Wrong line number in stack trace
only emit line number info for the first emission of common sub expressions
- Loading branch information
Showing
2 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| // REQUIRED_ARGS: -g -L-export-dynamic | ||
| // PERMUTE_ARGS: | ||
|
|
||
| import core.stdc.stdio; | ||
|
|
||
| void main() | ||
| { | ||
| fun(1); | ||
| fun(2); | ||
| fun(3); | ||
| #line 30 | ||
| fun(4); | ||
|
|
||
| foo(1, 10); | ||
| foo(2, 10); | ||
| foo(3, 10); | ||
| #line 40 | ||
| foo(4, 10); | ||
| } | ||
|
|
||
| void fun(int n, int defParam = 10) | ||
| { | ||
| try | ||
| { | ||
| if (n == 4) | ||
| throw new Exception("fun"); | ||
| } | ||
| catch(Exception e) | ||
| { | ||
| string s = e.toString(); | ||
| printf("%.*s\n", cast(int)s.length, s.ptr); | ||
| int line = lineInMain(e.toString()); | ||
| assert(line >= 30 && line <= 32); // return address might be next statement | ||
| } | ||
| } | ||
|
|
||
| void foo(int n, int m) | ||
| { | ||
| try | ||
| { | ||
| if (n == 4) | ||
| throw new Exception("foo"); | ||
| } | ||
| catch(Exception e) | ||
| { | ||
| string s = e.toString(); | ||
| printf("%.*s\n", cast(int)s.length, s.ptr); | ||
| int line = lineInMain(e.toString()); | ||
| assert(line >= 40 && line <= 41); // return address might be next statement | ||
| } | ||
| } | ||
|
|
||
| int lineInMain(string msg) | ||
| { | ||
| // find line number of _Dmain in stack trace | ||
| // on linux: file.d:line _Dmain [addr] | ||
| // on windows: addr in _Dmain at file.d(line) | ||
| int line = 0; | ||
| bool mainFound = false; | ||
| for (size_t pos = 0; pos + 6 < msg.length; pos++) | ||
| { | ||
| if (msg[pos] == '\n') | ||
| { | ||
| line = 0; | ||
| mainFound = false; | ||
| } | ||
| else if ((msg[pos] == ':' || msg[pos] == '(') && line == 0) | ||
| { | ||
| for (pos++; pos < msg.length && msg[pos] >= '0' && msg[pos] <= '9'; pos++) | ||
| line = line * 10 + msg[pos] - '0'; | ||
| if (line > 0 && mainFound) | ||
| return line; | ||
| } | ||
| else if (msg[pos .. pos + 6] == "_Dmain" || msg[pos .. pos + 6] == "D main") | ||
| { | ||
| mainFound = true; | ||
| if (line > 0 && mainFound) | ||
| return line; | ||
| } | ||
| } | ||
| return 0; | ||
| } |