Skip to content

Instantly share code, notes, and snippets.

@MabezDev
Last active October 28, 2019 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MabezDev/24f55fdd089570d66a8ce940aa980e0d to your computer and use it in GitHub Desktop.
Save MabezDev/24f55fdd089570d66a8ce940aa980e0d to your computer and use it in GitHub Desktop.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment