Michael Woerister | 91a0e18 | 2014-12-03 22:48:18 | [diff] [blame] | 1 | #!/bin/sh |
Michael Woerister | 91a0e18 | 2014-12-03 22:48:18 | [diff] [blame] | 2 | # Exit if anything fails |
| 3 | set -e |
| 4 | |
Jeremy Fitzhardinge | 7a824c8 | 2020-04-02 18:49:33 | [diff] [blame] | 5 | # Prefer rustc in the same directory as this script |
| 6 | DIR="$(dirname "$0")" |
| 7 | if [ -x "$DIR/rustc" ]; then |
| 8 | RUSTC="$DIR/rustc" |
| 9 | else |
| 10 | RUSTC="rustc" |
| 11 | fi |
| 12 | |
Michael Woerister | 91a0e18 | 2014-12-03 22:48:18 | [diff] [blame] | 13 | # Find out where the pretty printer Python module is |
Jeremy Fitzhardinge | 7a824c8 | 2020-04-02 18:49:33 | [diff] [blame] | 14 | RUSTC_SYSROOT="$("$RUSTC" --print=sysroot)" |
Michael Woerister | 91a0e18 | 2014-12-03 22:48:18 | [diff] [blame] | 15 | GDB_PYTHON_MODULE_DIRECTORY="$RUSTC_SYSROOT/lib/rustlib/etc" |
Laurențiu Nicola | 8dd0ec6 | 2023-03-23 11:01:01 | [diff] [blame] | 16 | # Get the commit hash for path remapping |
Alan Somers | c6b1f31 | 2023-04-15 02:07:13 | [diff] [blame] | 17 | RUSTC_COMMIT_HASH="$("$RUSTC" -vV | sed -n 's/commit-hash: \([a-zA-Z0-9_]*\)/\1/p')" |
Michael Woerister | 91a0e18 | 2014-12-03 22:48:18 | [diff] [blame] | 18 | |
| 19 | # Run GDB with the additional arguments that load the pretty printers |
Nicolas Bigaouette | 61b7ebe | 2017-04-20 15:20:33 | [diff] [blame] | 20 | # Set the environment variable `RUST_GDB` to overwrite the call to a |
Nicolas Bigaouette | 82ed783 | 2017-04-18 18:00:08 | [diff] [blame] | 21 | # different/specific command (defaults to `gdb`). |
Nicolas Bigaouette | 61b7ebe | 2017-04-20 15:20:33 | [diff] [blame] | 22 | RUST_GDB="${RUST_GDB:-gdb}" |
ftilde | d6426e8a | 2018-08-18 21:48:26 | [diff] [blame] | 23 | PYTHONPATH="$PYTHONPATH:$GDB_PYTHON_MODULE_DIRECTORY" exec ${RUST_GDB} \ |
Benjamin Lamowski | f6df174 | 2018-05-22 00:58:19 | [diff] [blame] | 24 | --directory="$GDB_PYTHON_MODULE_DIRECTORY" \ |
Michael Woerister | 91a0e18 | 2014-12-03 22:48:18 | [diff] [blame] | 25 | -iex "add-auto-load-safe-path $GDB_PYTHON_MODULE_DIRECTORY" \ |
Laurențiu Nicola | 8dd0ec6 | 2023-03-23 11:01:01 | [diff] [blame] | 26 | -iex "set substitute-path /rustc/$RUSTC_COMMIT_HASH $RUSTC_SYSROOT/lib/rustlib/src/rust" \ |
Michael Woerister | 91a0e18 | 2014-12-03 22:48:18 | [diff] [blame] | 27 | "$@" |
Alan Somers | 2f45d19 | 2023-04-14 20:47:05 | [diff] [blame] | 28 | |