将debuginfo添加到exectuable时如何使货物输入到stdlib源文件的正确路径

时间:2019-06-17 09:35:57

标签: rust rust-cargo

我正在调试rust程序,但是每当我尝试使用任何标准库功能时,gdb(或lldb)都找不到stdlib源文件,出现如下错误:

/rustc/3c235d5600393dfe6c36eeed34042efad8d4f26e/src/libcore/slice/mod.rs: No such file or directory.

复制步骤:

cargo new test

test / src / main.rs:

fn main() {
    let a:Vec<char> = Vec::new();
}
$ cd test
$ cargo build
$ rust-gdb target/debug/test

...

(gdb) b main.rs:1
Breakpoint 1 at 0x4a04: file src/main.rs, line 2.

(gdb) r
Starting program: /home/xyz/code/rust/test/target/debug/test 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, test::main () at src/main.rs:2
2           let a: Vec<i32> = Vec::new();

(gdb) s
alloc::vec::Vec<T>::new ()
    at /rustc/3c235d5600393dfe6c36eeed34042efad8d4f26e/src/liballoc/vec.rs:318
318     /rustc/3c235d5600393dfe6c36eeed34042efad8d4f26e/src/liballoc/vec.rs: No such file or directory.

1 个答案:

答案 0 :(得分:0)

如果您在Windows的vscode中运行,则可以将以下内容添加到launch.json中:

        "sourceFileMap": {
            "/rustc/3c235d5600393dfe6c36eeed34042efad8d4f26e": "${env:USERPROFILE}\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\src\\rust"
        }

有关更多参考,请参见:https://users.rust-lang.org/t/solved-how-to-step-into-std-source-code-when-debugging-in-vs-code/25319/6