|
| 1 | +#!/bin/sh |
| 2 | +# Copyright 2014 The Rust Project Developers. See the COPYRIGHT |
| 3 | +# file at the top-level directory of this distribution and at |
| 4 | +# http://rust-lang.org/COPYRIGHT. |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 8 | +# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 9 | +# option. This file may not be copied, modified, or distributed |
| 10 | +# except according to those terms. |
| 11 | + |
| 12 | +# Exit if anything fails |
| 13 | +set -e |
| 14 | + |
| 15 | +if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ] || [ "$1" = "--help" ]; then |
| 16 | + echo " |
| 17 | +rust-gdbgui |
| 18 | +=========== |
| 19 | +gdbgui - https://gdbgui.com - is a graphical front-end to GDB |
| 20 | +that runs in a browser. This script invokes gdbgui with the Rust |
| 21 | +pretty printers loaded. |
| 22 | +
|
| 23 | +Simple usage : rust-gdbgui target/debug/myprog |
| 24 | +With arguments: rust-gdbgui 'target/debug/myprog arg1 arg2...' |
| 25 | + (note the quotes) |
| 26 | +
|
| 27 | +
|
| 28 | +Hints |
| 29 | +===== |
| 30 | +gdbgui won't be able to find the rust 'main' method automatically, so |
| 31 | +in its options make sure to disable the 'Add breakpoint to main after |
| 32 | +loading executable' setting to avoid a 'File not found: main' warning |
| 33 | +on startup. |
| 34 | +
|
| 35 | +Instead, type 'main' into gdbgui's file browser and you should get |
| 36 | +auto-completion on the filename. Just pick 'main.rs', add a breakpoint |
| 37 | +by clicking in the line number gutter, and type 'r' or hit the Restart |
| 38 | +icon to start your program running. |
| 39 | +" |
| 40 | + exit 0 |
| 41 | +fi |
| 42 | + |
| 43 | +# Find out where the pretty printer Python module is |
| 44 | +RUSTC_SYSROOT=`rustc --print=sysroot` |
| 45 | +GDB_PYTHON_MODULE_DIRECTORY="$RUSTC_SYSROOT/lib/rustlib/etc" |
| 46 | + |
| 47 | +# Set the environment variable `RUST_GDB` to overwrite the call to a |
| 48 | +# different/specific command (defaults to `gdb`). |
| 49 | +RUST_GDB="${RUST_GDB:-gdb}" |
| 50 | + |
| 51 | +# Set the environment variable `RUST_GDBGUI` to overwrite the call to a |
| 52 | +# different/specific command (defaults to `gdbgui`). |
| 53 | +RUST_GDBGUI="${RUST_GDBGUI:-gdbgui}" |
| 54 | + |
| 55 | +# These arguments get passed through to GDB and make it load the |
| 56 | +# Rust pretty printers. |
| 57 | +GDB_ARGS="--directory=\"$GDB_PYTHON_MODULE_DIRECTORY\" -iex \"add-auto-load-safe-path $GDB_PYTHON_MODULE_DIRECTORY\"" |
| 58 | + |
| 59 | +# Finally we execute gdbgui. |
| 60 | +PYTHONPATH="$PYTHONPATH:$GDB_PYTHON_MODULE_DIRECTORY" \ |
| 61 | + exec ${RUST_GDBGUI} \ |
| 62 | + --gdb ${RUST_GDB} \ |
| 63 | + --gdb-args "${GDB_ARGS}" \ |
| 64 | + "${@}" |
| 65 | + |
0 commit comments