about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-08-22 03:01:14 +0000
committerbors <bors@rust-lang.org>2018-08-22 03:01:14 +0000
commit786ccc336dc684cdb00402e84abe4a9bc53857cf (patch)
tree4132434226fb51ce9a13b30fbb48bf290974c9b4
parenta79cffb8b8330527d262bdde56387d45ac46dd44 (diff)
parentd6426e8a25baa3011b9db14aca660b39b9867578 (diff)
downloadrust-786ccc336dc684cdb00402e84abe4a9bc53857cf.tar.gz
rust-786ccc336dc684cdb00402e84abe4a9bc53857cf.zip
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).
-rwxr-xr-xsrc/etc/rust-gdb2
-rwxr-xr-xsrc/etc/rust-lldb21
2 files changed, 10 insertions, 13 deletions
diff --git a/src/etc/rust-gdb b/src/etc/rust-gdb
index 6835d6aa908..743952a5bef 100755
--- a/src/etc/rust-gdb
+++ b/src/etc/rust-gdb
@@ -20,7 +20,7 @@ GDB_PYTHON_MODULE_DIRECTORY="$RUSTC_SYSROOT/lib/rustlib/etc"
 # Set the environment variable `RUST_GDB` to overwrite the call to a
 # different/specific command (defaults to `gdb`).
 RUST_GDB="${RUST_GDB:-gdb}"
-PYTHONPATH="$PYTHONPATH:$GDB_PYTHON_MODULE_DIRECTORY" ${RUST_GDB} \
+PYTHONPATH="$PYTHONPATH:$GDB_PYTHON_MODULE_DIRECTORY" exec ${RUST_GDB} \
   --directory="$GDB_PYTHON_MODULE_DIRECTORY" \
   -iex "add-auto-load-safe-path $GDB_PYTHON_MODULE_DIRECTORY" \
   "$@"
diff --git a/src/etc/rust-lldb b/src/etc/rust-lldb
index f70ab65bce7..6a2849b5548 100755
--- a/src/etc/rust-lldb
+++ b/src/etc/rust-lldb
@@ -23,19 +23,16 @@ display the contents of local variables!"
     echo "***"
 fi
 
-# Create a tempfile containing the LLDB script we want to execute on startup
-TMPFILE=`mktemp /tmp/rust-lldb-commands.XXXXXX`
-
-# Make sure to delete the tempfile no matter what
-trap "rm -f $TMPFILE; exit" INT TERM EXIT
-
 # Find out where to look for the pretty printer Python module
 RUSTC_SYSROOT=`rustc --print sysroot`
 
-# Write the LLDB script to the tempfile
-echo "command script import \"$RUSTC_SYSROOT/lib/rustlib/etc/lldb_rust_formatters.py\"" >> $TMPFILE
-echo "type summary add --no-value --python-function lldb_rust_formatters.print_val -x \".*\" --category Rust" >> $TMPFILE
-echo "type category enable Rust" >> $TMPFILE
+# Prepare commands that will be loaded before any file on the command line has been loaded
+script_import="command script import \"$RUSTC_SYSROOT/lib/rustlib/etc/lldb_rust_formatters.py\""
+category_definition="type summary add --no-value --python-function lldb_rust_formatters.print_val -x \".*\" --category Rust"
+category_enable="type category enable Rust"
 
-# Call LLDB with the script added to the argument list
-lldb --source-before-file="$TMPFILE" "$@"
+# Call LLDB with the commands added to the argument list
+exec lldb --one-line-before-file="$script_import" \
+    --one-line-before-file="$category_definition" \
+    --one-line-before-file="$category_enable" \
+    "$@"