我在 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);
}
我用 DMD 编译了这段代码(在 OS X 上使用 v2.056)。当我运行它时,它显然崩溃了:
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
----------------
有没有办法在回溯中获取行号而不是位置?我可以看到崩溃的行号(5
in core.exception.RangeError@test(5)
),但它只是回溯的顶部。我可以得到里面的行号f()
吗main()
?