【问题标题】:Cannot get current line of `main` in a Rust program in GDB [duplicate]无法在 GDB 的 Rust 程序中获取“main”的当前行 [重复]
【发布时间】:2020-09-15 19:28:19
【问题描述】:

即使在启用调试信息的情况下进行编译,例如使用 dev 配置文件的常规 cargo build,似乎无法查找当前执行在哪个源代码行中。

为了重现,生成一个新的项目与货物;示例项目就足够了。

$ cargo new helloworld-rs
$ cd helloworld-rs
$ cargo build
$ rust-gdb target/debug/helloworld-rs
(gdb) b main
Breakpoint 1 at 0x5430
(gdb) run
Starting program: /tmp/helloworld-rs/target/debug/helloworld-rs
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".

Breakpoint 1, 0x0000555555559430 in main ()
(gdb) info line
No line number information available.

与 C 相比,C 没有任何问题:

$ cat > hw.c <<EOF
#include <stdio.h>

int main() {
    printf("Hello, world!");
}
EOF
$ clang -g -o hw hw.c
$ gdb hw
(gdb) b main
Breakpoint 1 at 0x1148: file hw.c, line 4.
(gdb) run
Starting program: /tmp/helloworld-c/hw 

Breakpoint 1, main () at hw.c:4
4      printf("Hello, world!");
(gdb) info line
Line 4 of "hw.c" starts at address 0x555555555148 <main+8> and ends at 0x55555555515b <main+27>.

我做错了什么,是我的系统出了问题(在撰写本文时是最新的 Arch),还是 Rust 本身的问题?

【问题讨论】:

标签: debugging rust gdb debug-information


【解决方案1】:
(gdb) b main

这将在 main 函数处设置断点 -- 但在 Rust 中,此函数由系统提供,并安排调用您程序的真实 main

相反,您通常想要做的是:

(gdb) start

这会在您提供的 main 上设置一个临时断点,然后是 run

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-17
    • 2023-03-10
    • 2016-03-28
    • 1970-01-01
    相关资源
    最近更新 更多