如何在 D 回溯中显示行号?
我在 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
----------------
有没有办法在回溯中获取行号而不是位置?我可以看到崩溃的行号(core.exception.RangeError@test(5)
中的 5
),但它只是回溯的顶部。我可以获取 f()
和 main()
中的行号吗?
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()
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 D 运行时没有实现足够的调试信息解析来获取行号,因此您将需要使用调试器。可以预期,您想要的将会在某个时候实现。
现在,使用
-gc
编译器标志编译您的程序,然后通过gdb
运行该程序。Because the D run-time doesn't implement enough debug information parsing to obtaining line numbers, you will need to use a debugger. It can be expected that what you want will be implemented at some point.
For now, compile your program with the
-gc
compiler flag, then run the program viagdb
.