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