Last active
May 3, 2022 21:37
-
-
Save daniellivingston/9c93e0697bf159e429df589344ce7ed8 to your computer and use it in GitHub Desktop.
Rust `std` source mappings in VSCode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# ============================================================================== # | |
# MIT License # | |
# ------------------------------------------------------------------------------ # | |
# Displays the CodeLLDB standard library mapping for debugging Rust binaries. # | |
# Generates a JSON string used in VSCode debug task list. # | |
# Requires the `jq` utility to be installed. # | |
# ============================================================================== # | |
# OUTPUT: # | |
# "lldb.launch.sourceMap": { | |
# "/rustc/<hash>/": "/home/<username>/<rust-toolchain>/lib/rustlib/src/rust/src", | |
# } | |
# ============================================================================== # | |
cargo_bin="$(cargo metadata --no-deps --format-version 1 | jq -r -c '.target_directory')" | |
crates="$(cargo metadata --no-deps --format-version 1 | jq -r -c '.packages[].targets[] | if .kind[0] == "bin" then .name else empty end')" | |
function srcmap_to() { realpath "$(rustc --print sysroot)/lib/rustlib/src/rust/src"; } | |
function srcmap_from() { strings target/debug/$1 | grep -o '^/rustc/[^/]\+/' | uniq; } | |
echo "\"lldb.launch.sourceMap\": {" | |
for target in `echo $crates`; do | |
target_path="$(realpath $cargo_bin/debug/$target)" | |
if [ -f "${target_path}" ]; then | |
echo " \"$(srcmap_from $target)\": \"$(srcmap_to)\"," | |
fi | |
done | |
echo "}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment