Skip to content

Commit 786ccc3

Browse files
committed
Auto merge of #53477 - ftilde:exec-rust-gdb-lldb, r=michaelwoerister
Exec gdb/lldb in rust-{gdb/lldb} wrapper scripts This way, the process we get by executing `rust-gdb` or `rust-lldb` (eventually) is an actual `gdb` or `lldb` process and behaves accordingly. Previously (and at least to me unexpectedly) it was just a script waiting for the debugger to exit. Sending a signal (e.g. SIGINT) to the spawned process did therefore not affect the debugger process (which was just a child of the wrapper script). In order to work around that we `exec` (according to [this](http://pubs.opengroup.org/onlinepubs/009695399/utilities/exec.html) part of the posix shell) and replace the script process with the debugger in the last line of the script. The lldb script had to be modified to not pass the configuration commands via a script file (which in my opinion is cleaner anyway).
2 parents a79cffb + d6426e8 commit 786ccc3

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

src/etc/rust-gdb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ GDB_PYTHON_MODULE_DIRECTORY="$RUSTC_SYSROOT/lib/rustlib/etc"
2020
# Set the environment variable `RUST_GDB` to overwrite the call to a
2121
# different/specific command (defaults to `gdb`).
2222
RUST_GDB="${RUST_GDB:-gdb}"
23-
PYTHONPATH="$PYTHONPATH:$GDB_PYTHON_MODULE_DIRECTORY" ${RUST_GDB} \
23+
PYTHONPATH="$PYTHONPATH:$GDB_PYTHON_MODULE_DIRECTORY" exec ${RUST_GDB} \
2424
--directory="$GDB_PYTHON_MODULE_DIRECTORY" \
2525
-iex "add-auto-load-safe-path $GDB_PYTHON_MODULE_DIRECTORY" \
2626
"$@"

src/etc/rust-lldb

+9-12
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,16 @@ display the contents of local variables!"
2323
echo "***"
2424
fi
2525

26-
# Create a tempfile containing the LLDB script we want to execute on startup
27-
TMPFILE=`mktemp /tmp/rust-lldb-commands.XXXXXX`
28-
29-
# Make sure to delete the tempfile no matter what
30-
trap "rm -f $TMPFILE; exit" INT TERM EXIT
31-
3226
# Find out where to look for the pretty printer Python module
3327
RUSTC_SYSROOT=`rustc --print sysroot`
3428

35-
# Write the LLDB script to the tempfile
36-
echo "command script import \"$RUSTC_SYSROOT/lib/rustlib/etc/lldb_rust_formatters.py\"" >> $TMPFILE
37-
echo "type summary add --no-value --python-function lldb_rust_formatters.print_val -x \".*\" --category Rust" >> $TMPFILE
38-
echo "type category enable Rust" >> $TMPFILE
29+
# Prepare commands that will be loaded before any file on the command line has been loaded
30+
script_import="command script import \"$RUSTC_SYSROOT/lib/rustlib/etc/lldb_rust_formatters.py\""
31+
category_definition="type summary add --no-value --python-function lldb_rust_formatters.print_val -x \".*\" --category Rust"
32+
category_enable="type category enable Rust"
3933

40-
# Call LLDB with the script added to the argument list
41-
lldb --source-before-file="$TMPFILE" "$@"
34+
# Call LLDB with the commands added to the argument list
35+
exec lldb --one-line-before-file="$script_import" \
36+
--one-line-before-file="$category_definition" \
37+
--one-line-before-file="$category_enable" \
38+
"$@"

0 commit comments

Comments
 (0)