To find the substitute path for the from section:
find $(rustc --print sysroot) -maxdepth 2 -mindepth 2 -type f -name "libstd-*" -exec strings {} \; | grep -o '^/rustc/[^/]\+/' | uniq
which produces something like /rustc/9a90d03ad171856dc016c2dcc19292ec49a8a26f/
Next install rust-src
component if you haven't already.
Then combine the output of rustc --print sysroot
with /lib/rustlib/src/rust
to find your downloaded sources.
Putting the two together as a GDB command:
set substitute-path /rustc/9a90d03ad171856dc016c2dcc19292ec49a8a26f/ ~/.rustup/toolchains/nightly-2019-06-30-x86_64-unknown-linux-gnu/lib/rustlib/src/rust
As both sections can be generated from CLI commands, it is possible to automate this, here is an example .gdbinit
that uses python.
python
import subprocess
from_cmd = "find $(rustc --print sysroot) -maxdepth 2 -mindepth 2 -type f -name \"libstd-*\" -exec strings {} \; | grep -o '^/rustc/[^/]\+/' | uniq"
to_cmd = "rustc --print sysroot"
from_path = subprocess.check_output(from_cmd,shell=True).decode().rstrip()
to_path = subprocess.check_output(to_cmd,shell=True).decode().rstrip() + '/lib/rustlib/src/rust'
final = 'set substitute-path ' + from_path + ' ' + to_path;
print(final)
gdb.execute(final)
end