Skip to content

Commit 8dd0ec6

Browse files
committedMar 23, 2023
Set up standard library path substitution in rust-gdb and gdbgui
1 parent 356c651 commit 8dd0ec6

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed
 

‎src/etc/rust-gdb

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ fi
1313
# Find out where the pretty printer Python module is
1414
RUSTC_SYSROOT="$("$RUSTC" --print=sysroot)"
1515
GDB_PYTHON_MODULE_DIRECTORY="$RUSTC_SYSROOT/lib/rustlib/etc"
16+
# Get the commit hash for path remapping
17+
RUSTC_COMMIT_HASH="$("$RUSTC" -vV | sed -n 's/commit-hash: \(\w*\)/\1/p')"
1618

1719
# Run GDB with the additional arguments that load the pretty printers
1820
# Set the environment variable `RUST_GDB` to overwrite the call to a
@@ -21,4 +23,6 @@ RUST_GDB="${RUST_GDB:-gdb}"
2123
PYTHONPATH="$PYTHONPATH:$GDB_PYTHON_MODULE_DIRECTORY" exec ${RUST_GDB} \
2224
--directory="$GDB_PYTHON_MODULE_DIRECTORY" \
2325
-iex "add-auto-load-safe-path $GDB_PYTHON_MODULE_DIRECTORY" \
26+
-iex "set substitute-path /rustc/$RUSTC_COMMIT_HASH $RUSTC_SYSROOT/lib/rustlib/src/rust" \
2427
"$@"
28+

‎src/etc/rust-gdbgui

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ fi
4242
# Find out where the pretty printer Python module is
4343
RUSTC_SYSROOT="$("$RUSTC" --print=sysroot)"
4444
GDB_PYTHON_MODULE_DIRECTORY="$RUSTC_SYSROOT/lib/rustlib/etc"
45+
# Get the commit hash for path remapping
46+
RUSTC_COMMIT_HASH="$("$RUSTC" -vV | sed -n 's/commit-hash: \(\w*\)/\1/p')"
4547

4648
# Set the environment variable `RUST_GDB` to overwrite the call to a
4749
# different/specific command (defaults to `gdb`).
@@ -53,7 +55,9 @@ RUST_GDBGUI="${RUST_GDBGUI:-gdbgui}"
5355

5456
# These arguments get passed through to GDB and make it load the
5557
# Rust pretty printers.
56-
GDB_ARGS="--directory=\"$GDB_PYTHON_MODULE_DIRECTORY\" -iex \"add-auto-load-safe-path $GDB_PYTHON_MODULE_DIRECTORY\""
58+
GDB_ARGS="--directory=\"$GDB_PYTHON_MODULE_DIRECTORY\"" \
59+
"-iex \"add-auto-load-safe-path $GDB_PYTHON_MODULE_DIRECTORY\"" \
60+
"-iex \"set substitute-path /rustc/$RUSTC_COMMIT_HASH $RUSTC_SYSROOT/lib/rustlib/src/rust\""
5761

5862
# Finally we execute gdbgui.
5963
PYTHONPATH="$PYTHONPATH:$GDB_PYTHON_MODULE_DIRECTORY" \

0 commit comments

Comments
 (0)
Please sign in to comment.