Debian Codegraph @

gcc/testsuite/gdc.test/runnable/test19086.d

raw
1 // REQUIRED_ARGS: -g
2 // REQUIRED_ARGS(linux freebsd openbsd dragonflybsd): -L-export-dynamic
3 // PERMUTE_ARGS:
4 // DISABLED: osx
5
6 void run19086()
7 {
8 long x = 1;
9 int y = 0;
10 #line 20
11 throw newException();
12 }
13
14 // moved here to keep run19086 short
15 Exception newException() { return new Exception("hi"); }
16
17 void test19086()
18 {
19 try
20 {
21 run19086();
22 }
23 catch(Exception e)
24 {
25 int line = findLineStackTrace(e.toString(), "run19086");
26 assert(line >= 20 && line <= 21);
27 }
28 }
29
30 int findLineStackTrace(string msg, string func)
31 {
32 // find line number of _Dmain in stack trace
33 // on linux: file.d:line _Dmain [addr]
34 // on windows: addr in _Dmain at file.d(line)
35 int line = 0;
36 bool found = false;
37 for (size_t pos = 0; pos + func.length < msg.length; pos++)
38 {
39 if (msg[pos] == '\n')
40 {
41 line = 0;
42 found = false;
43 }
44 else if ((msg[pos] == ':' || msg[pos] == '(') && line == 0)
45 {
46 for (pos++; pos < msg.length && msg[pos] >= '0' && msg[pos] <= '9'; pos++)
47 line = line * 10 + msg[pos] - '0';
48 if (line > 0 && found)
49 return line;
50 }
51 else if (msg[pos .. pos + func.length] == func)
52 {
53 found = true;
54 if (line > 0 && found)
55 return line;
56 }
57 }
58 return 0;
59 }
60
61 void main()
62 {
63 test19086();
64 }