d - 如何在 D 回溯中显示行号?

标签 d backtrace

我在 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 中的 core.exception.RangeError@test(5) ),但它只是回溯的顶部。我可以在 f() 中获取行号吗?和 main() ?

最佳答案

因为 D 运行时没有实现足够的调试信息解析来获取行号,所以您将需要使用调试器。可以预期,您想要的将在某个时候实现。

现在,用 -gc 编译你的程序编译器标志,然后通过 gdb 运行程序.

关于d - 如何在 D 回溯中显示行号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8209494/

相关文章:

winapi - 如何将资源添加到我的 D 可执行文件中?如何嵌入 list ?

d - D 程序中的语法与 R 中的 set.seed (1234)"相同

shell - GDB:backtrace命令的格式:在另一个shell/ssh中运行时将帧行分为几行

Prolog 剪切行为对我来说没有意义

xcode-select 错误格式错误的开发者路径

d - 如何检测函数是否用@property注释

c - ARM 平台上没有来自 SIGABRT 信号的回溯?

debugging - 无法从 gdb backtrace 获取任何信息

assembly - 汇编中的堆栈/基指针

c - 为什么 C 比 Go 或 D 更快地构建小程序?