xref: /aosp_15_r20/prebuilts/rust/linux-x86/1.80.1/bin/rust-gdbgui (revision b40554a23088fb75aa6945dfe8e65169c8484da3)
1#!/bin/sh
2
3# Exit if anything fails
4set -e
5
6if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ] || [ "$1" = "--help" ]; then
7    echo "
8rust-gdbgui
9===========
10gdbgui - https://gdbgui.com - is a graphical front-end to GDB
11that runs in a browser. This script invokes gdbgui with the Rust
12pretty printers loaded.
13
14Simple usage  : rust-gdbgui target/debug/myprog
15With arguments: rust-gdbgui 'target/debug/myprog arg1 arg2...'
16  (note the quotes)
17
18
19Hints
20=====
21gdbgui won't be able to find the rust 'main' method automatically, so
22in its options make sure to disable the 'Add breakpoint to main after
23loading executable' setting to avoid a 'File not found: main' warning
24on startup.
25
26Instead, type 'main' into gdbgui's file browser and you should get
27auto-completion on the filename. Just pick 'main.rs', add a breakpoint
28by clicking in the line number gutter, and type 'r' or hit the Restart
29icon to start your program running.
30"
31    exit 0
32fi
33
34# Prefer rustc in the same directory as this script
35DIR="$(dirname "$0")"
36if [ -x "$DIR/rustc" ]; then
37  RUSTC="$DIR/rustc"
38else
39  RUSTC="rustc"
40fi
41
42# Find out where the pretty printer Python module is
43RUSTC_SYSROOT="$("$RUSTC" --print=sysroot)"
44GDB_PYTHON_MODULE_DIRECTORY="$RUSTC_SYSROOT/lib/rustlib/etc"
45# Get the commit hash for path remapping
46RUSTC_COMMIT_HASH="$("$RUSTC" -vV | sed -n 's/commit-hash: \([a-zA-Z0-9_]*\)/\1/p')"
47
48# Set the environment variable `RUST_GDB` to overwrite the call to a
49# different/specific command (defaults to `gdb`).
50RUST_GDB="${RUST_GDB:-gdb}"
51
52# Set the environment variable `RUST_GDBGUI` to overwrite the call to a
53# different/specific command (defaults to `gdbgui`).
54RUST_GDBGUI="${RUST_GDBGUI:-gdbgui}"
55
56# These arguments get passed through to GDB and make it load the
57# Rust pretty printers.
58GDB_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\""
61
62# Finally we execute gdbgui.
63PYTHONPATH="$PYTHONPATH:$GDB_PYTHON_MODULE_DIRECTORY" \
64  exec ${RUST_GDBGUI} \
65  --gdb-cmd "${RUST_GDB} ${GDB_ARGS}" \
66  "${@}"
67
68