In case someone uses Visual Studio Code with GDB and wants to achieve the same behavior, here is how I do it:
In launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "gdb",
...,
"autorun": [
"set substitute-path /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858 <your-home-dir>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust"
],
}
]
}
Notice that /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858 depends on the exact toolchain you're using. So updating your toolchain will probably require modifying this string. The way I easily find the hash is by running the following command in the project directory:
$ strings target/debug/<your-binary-name> | grep -o '^/rustc/[^/]\+/' | uniq
The idea is that Visual Studio Code will issue the GDB commands specified in the autorun array right after GDB is initialized, before actual debugging is started. The command set substitute-path of GDB is documented in Specifying Source Directories.