I have the following sample code in D:
import std.stdio;
int g(int i) {
auto l = [1, 2, 3, 4];
return l[i];
}
void f(int i) {
writeln(g(i));
}
void main(string[] args) {
f(1);
f(10);
f(2);
}
I compiled this code with DMD (using v2.056 on OS X). When I run it, it obviously crashes:
core.exception.RangeError@test(5): Range violation
----------------
5 test 0x000b823a _d_array_bounds + 30
6 test 0x000aa44b D4test7__arrayZ + 27
7 test 0x000aa4ae int test.g(int) + 94
8 test 0x000aa4c7 void test.f(int) + 11
9 test 0x000aa422 _Dmain + 26
10 test 0x000b87b3 extern (C) int rt.dmain2.main(int, char**).void runMain() + 23
11 test 0x000b835d extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void delegate()) + 29
12 test 0x000b8800 extern (C) int rt.dmain2.main(int, char**).void runAll() + 64
13 test 0x000b835d extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void delegate()) + 29
14 test 0x000b82f7 main + 179
15 test 0x000aa3fd start + 53
16 ??? 0x00000001 0x0 + 1
----------------
Is there a way to get line numbers in the backtrace instead of locations? I can see the line number of the crash (the 5
in core.exception.RangeError@test(5)
), but it is only the top of the backtrace. Can I get the line numbers inside f()
and main()
?