Skip to content

Commit 2e543e9

Browse files
authored
Rollup merge of rust-lang#53774 - PhilipDaniels:master, r=tromey
Add rust-gdbgui script. This script invokes the [gdbgui](https://gdbgui.com/) graphical GDB front-end with the Rust pretty printers loaded. The script does not install gdbgui, that must be done manually. As an escapee from Visual Studio it is nice to have a point-and-click debugger. This script invokes `gdbgui` similarly to the way that `rust-gdb` invokes `gdb` - I copied that script as a starting point. Because it is a wrapper around a wrapper you don't have as much flexibility in passing arguments to GDB and I could not find a way to eliminate the single quotes you have to use when you want to pass arguments to your program (`gdbgui` supposedly supports an `--args` option which I think should allow this, but I couldn't get it to work, my shell-fu is weak). Still, I find this very usable for debugging programs, and it is a lot more approachable than gdb in the terminal.
2 parents 7cf6ea5 + 47aa475 commit 2e543e9

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

src/etc/rust-gdbgui

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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

Comments
 (0)