如何在将 debuginfo 添加到可执行文件时使 cargo 输入正确的 stdlib 源文件路径
How to make cargo enter the correct path to source files of stdlib while adding debuginfo to exectuable
我正在调试一个 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.
如果您在 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
我正在调试一个 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.
如果您在 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