xref: /aosp_15_r20/prebuilts/rust/linux-x86/1.80.1/bin/rust-gdb (revision b40554a23088fb75aa6945dfe8e65169c8484da3)
1#!/bin/sh
2# Exit if anything fails
3set -e
4
5# Prefer rustc in the same directory as this script
6DIR="$(dirname "$0")"
7if [ -x "$DIR/rustc" ]; then
8  RUSTC="$DIR/rustc"
9else
10  RUSTC="rustc"
11fi
12
13# Find out where the pretty printer Python module is
14RUSTC_SYSROOT="$("$RUSTC" --print=sysroot)"
15GDB_PYTHON_MODULE_DIRECTORY="$RUSTC_SYSROOT/lib/rustlib/etc"
16# Get the commit hash for path remapping
17RUSTC_COMMIT_HASH="$("$RUSTC" -vV | sed -n 's/commit-hash: \([a-zA-Z0-9_]*\)/\1/p')"
18
19# Run GDB with the additional arguments that load the pretty printers
20# Set the environment variable `RUST_GDB` to overwrite the call to a
21# different/specific command (defaults to `gdb`).
22RUST_GDB="${RUST_GDB:-gdb}"
23PYTHONPATH="$PYTHONPATH:$GDB_PYTHON_MODULE_DIRECTORY" exec ${RUST_GDB} \
24  --directory="$GDB_PYTHON_MODULE_DIRECTORY" \
25  -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" \
27  "$@"
28
29