public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: gdb-patches@sourceware.org
Subject: [PATCH 08/17] Make inferior/GDB share terminal in run+detach testcases
Date: Thu,  3 Jun 2021 20:02:34 +0100	[thread overview]
Message-ID: <20210603190243.2609886-9-pedro@palves.net> (raw)
In-Reply-To: <20210603190243.2609886-1-pedro@palves.net>

A following patch will make GDB put spawned inferiors in their own
terminal/session.  A consequence of that is that if you do "run", and
then "detach", GDB closes the terminal, and the inferior gets a
SIGHUP, after being detached, which likely means it'll die.  (The
referenced patch will make GDB detect the scenario and ask for
confirmation before detaching.)

To avoid that, testcases that explicitly want to do run/start + detach
need to tell GDB to not create a terminal for the inferior.  That's
what this patch does.

gdb/testsuite/ChangeLog:
yyyy-mm-dd  Pedro Alves  <pedro@palves.net>

	* gdb.base/attach-wait-input.exp: Issue "tty /dev/tty" before
	starting program.
	* gdb.base/auto-connect-native-target.exp: Likewise.
	* gdb/testsuite/gdb.base/detach.exp: Issue "tty /dev/tty" before
	starting program.  Use with_test_prefix.
	* gdb/testsuite/gdb.base/dprintf-detach.exp: Issue "tty /dev/tty"
	before starting program.
	* gdb/testsuite/gdb.base/jit-elf.exp: Likewise.
	* gdb/testsuite/gdb.base/multi-forks.exp: Likewise.
	* gdb/testsuite/gdb.base/watchpoint-hw-attach.exp: Likewise.
	* gdb/testsuite/gdb.mi/mi-detach.exp: Likewise.
	* gdb/testsuite/gdb.multi/watchpoint-multi-exit.exp: Likewise.
	* gdb.threads/process-dies-while-detaching.exp: Likewise.
	* gdb.threads/threadapply.exp: Likewise.

Change-Id: Ic62bca178295763fb9c47657ee459fe715f7865e
---
 gdb/testsuite/gdb.base/attach-wait-input.exp  |  4 ++++
 .../gdb.base/auto-connect-native-target.exp   |  3 +++
 gdb/testsuite/gdb.base/detach.exp             | 19 +++++++++++--------
 gdb/testsuite/gdb.base/dprintf-detach.exp     |  9 ++++++++-
 gdb/testsuite/gdb.base/jit-elf.exp            | 10 +++++++++-
 gdb/testsuite/gdb.base/multi-forks.exp        |  3 +++
 .../gdb.base/watchpoint-hw-attach.exp         |  3 +++
 gdb/testsuite/gdb.mi/mi-detach.exp            |  6 ++++++
 .../gdb.multi/watchpoint-multi-exit.exp       |  3 +++
 .../process-dies-while-detaching.exp          |  3 +++
 gdb/testsuite/gdb.threads/threadapply.exp     |  3 +++
 11 files changed, 56 insertions(+), 10 deletions(-)

diff --git a/gdb/testsuite/gdb.base/attach-wait-input.exp b/gdb/testsuite/gdb.base/attach-wait-input.exp
index f190af1811a..c16a1e87562 100644
--- a/gdb/testsuite/gdb.base/attach-wait-input.exp
+++ b/gdb/testsuite/gdb.base/attach-wait-input.exp
@@ -47,6 +47,10 @@ proc start_program {binfile} {
 
     clean_restart $binfile
 
+    # Let our spawned inferior run in GDB's terminal/session, so that
+    # we can detach from it.
+    gdb_test_no_output "tty /dev/tty"
+
     if ![runto setup_done] then {
 	fail "can't run to setup_done"
 	return 0
diff --git a/gdb/testsuite/gdb.base/auto-connect-native-target.exp b/gdb/testsuite/gdb.base/auto-connect-native-target.exp
index 10cddc042c5..5baabaab96f 100644
--- a/gdb/testsuite/gdb.base/auto-connect-native-target.exp
+++ b/gdb/testsuite/gdb.base/auto-connect-native-target.exp
@@ -147,6 +147,9 @@ with_test_prefix "kill" {
 }
 
 with_test_prefix "detach" {
+    # So we can safely detach after "start".
+    gdb_test_no_output "tty /dev/tty"
+
     gdb_test "start" "main.*"
 
     set test "detach"
diff --git a/gdb/testsuite/gdb.base/detach.exp b/gdb/testsuite/gdb.base/detach.exp
index e9b198705f5..06938be3be7 100644
--- a/gdb/testsuite/gdb.base/detach.exp
+++ b/gdb/testsuite/gdb.base/detach.exp
@@ -35,11 +35,13 @@ proc do_detach_tests {} {
   global binfile
   global escapedbinfile
   global subdir
-  global pass
+
+  # So we can safely detach after "run".
+  gdb_test_no_output "tty /dev/tty"
 
   runto_main
-  gdb_test_no_output "set should_exit = 1" "set should_exit, $pass"
-  gdb_test "detach" "Detaching from program: .*$escapedbinfile, .*" "detach, $pass"
+  gdb_test_no_output "set should_exit = 1" "set should_exit"
+  gdb_test "detach" "Detaching from program: .*$escapedbinfile, .*"
 }
 
 # Start with a fresh gdb
@@ -48,14 +50,15 @@ gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
 gdb_load ${binfile}
 
-global pass
-set pass "one"
-do_detach_tests
+with_test_prefix "one" {
+    do_detach_tests
+}
 
 # Wait a moment and do it again.
 exec sleep 1
 
-set pass "two"
-do_detach_tests
+with_test_prefix "two" {
+    do_detach_tests
+}
 
 return 0
diff --git a/gdb/testsuite/gdb.base/dprintf-detach.exp b/gdb/testsuite/gdb.base/dprintf-detach.exp
index 1a94d26f84c..261eeed05b6 100644
--- a/gdb/testsuite/gdb.base/dprintf-detach.exp
+++ b/gdb/testsuite/gdb.base/dprintf-detach.exp
@@ -39,7 +39,14 @@ proc dprintf_detach_test { breakpoint_always_inserted dprintf_style disconnected
 
     with_test_prefix "$test_prefix" {
 	# Start with a clean gdb
-	clean_restart ${binfile}
+
+	global GDBFLAGS
+	save_vars { GDBFLAGS } {
+	    # Make the inferior run in the same session as GDB, so
+	    # that we can detach from it.
+	    append GDBFLAGS " -ex \"tty /dev/tty\""
+	    clean_restart $binfile
+	}
 
 	gdb_test_no_output "set breakpoint always-inserted ${breakpoint_always_inserted}"
 	gdb_test_no_output "set dprintf-style ${dprintf_style}"
diff --git a/gdb/testsuite/gdb.base/jit-elf.exp b/gdb/testsuite/gdb.base/jit-elf.exp
index 2018814df7e..f4b4601d357 100644
--- a/gdb/testsuite/gdb.base/jit-elf.exp
+++ b/gdb/testsuite/gdb.base/jit-elf.exp
@@ -88,7 +88,15 @@ proc one_jit_test {jit_solibs_target match_str reattach} {
 	global test_verbose
 	global main_binfile main_srcfile
 
-	clean_restart ${main_binfile}
+	global GDBFLAGS
+	save_vars { GDBFLAGS } {
+	    if {$reattach} {
+		# Let our spawned inferior run in GDB's
+		# terminal/session, so that we can detach from it.
+		append GDBFLAGS { -ex "tty /dev/tty"}
+	    }
+	    clean_restart ${main_binfile}
+	}
 
 	# This is just to help debugging when things fail
 	if {$test_verbose > 0} {
diff --git a/gdb/testsuite/gdb.base/multi-forks.exp b/gdb/testsuite/gdb.base/multi-forks.exp
index 154b24c9c42..09fe48322e3 100644
--- a/gdb/testsuite/gdb.base/multi-forks.exp
+++ b/gdb/testsuite/gdb.base/multi-forks.exp
@@ -139,6 +139,9 @@ foreach mode { "child" "parent" } {
 
 clean_restart ${binfile}
 
+# So we can safely detach after "run".
+gdb_test_no_output "tty /dev/tty"
+
 runto_main
 gdb_breakpoint $exit_bp_loc
 
diff --git a/gdb/testsuite/gdb.base/watchpoint-hw-attach.exp b/gdb/testsuite/gdb.base/watchpoint-hw-attach.exp
index 270bc6c29af..ddbf1edbdc8 100644
--- a/gdb/testsuite/gdb.base/watchpoint-hw-attach.exp
+++ b/gdb/testsuite/gdb.base/watchpoint-hw-attach.exp
@@ -32,6 +32,9 @@ if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
 
 clean_restart $binfile
 
+# So we can safely detach after "run".
+gdb_test_no_output "tty /dev/tty"
+
 if ![runto_main] {
     untested "can't run to main"
     return -1
diff --git a/gdb/testsuite/gdb.mi/mi-detach.exp b/gdb/testsuite/gdb.mi/mi-detach.exp
index c25a63699cc..a23942f3d9b 100644
--- a/gdb/testsuite/gdb.mi/mi-detach.exp
+++ b/gdb/testsuite/gdb.mi/mi-detach.exp
@@ -26,6 +26,12 @@ if {[build_executable $testfile.exp $testfile $srcfile {debug}] == -1} {
 }
 
 mi_clean_restart $binfile
+
+# So we can safely detach after "-exec-run".
+mi_gdb_test "302-inferior-tty-set /dev/tty" \
+    "302\\\^done" \
+    "set tty to /dev/pts/1"
+
 mi_runto_main
 
 mi_gdb_test "-target-detach" "=thread-exited,id=\"1\".*=thread-group-exited,id=\"i1\".*" "detach"
diff --git a/gdb/testsuite/gdb.multi/watchpoint-multi-exit.exp b/gdb/testsuite/gdb.multi/watchpoint-multi-exit.exp
index 1dff0832255..6d7a55da4f2 100644
--- a/gdb/testsuite/gdb.multi/watchpoint-multi-exit.exp
+++ b/gdb/testsuite/gdb.multi/watchpoint-multi-exit.exp
@@ -31,6 +31,9 @@ proc do_test {dispose} {
 
     clean_restart $binfile
 
+    # So we can safely detach after "run".
+    gdb_test_no_output "tty /dev/tty"
+
     gdb_test_no_output "set follow-fork child"
     gdb_test_no_output "set detach-on-fork off"
 
diff --git a/gdb/testsuite/gdb.threads/process-dies-while-detaching.exp b/gdb/testsuite/gdb.threads/process-dies-while-detaching.exp
index ac1aad26ec5..f01d4cf0666 100644
--- a/gdb/testsuite/gdb.threads/process-dies-while-detaching.exp
+++ b/gdb/testsuite/gdb.threads/process-dies-while-detaching.exp
@@ -215,6 +215,7 @@ proc test_detach {multi_process cmd} {
 	global binfile
 
 	clean_restart ${binfile}
+	gdb_test_no_output "tty /dev/tty"
 
 	if ![runto_main] {
 	    fail "can't run to main"
@@ -240,6 +241,7 @@ proc test_detach_watch {multi_process cmd} {
 	global binfile decimal
 
 	clean_restart ${binfile}
+	gdb_test_no_output "tty /dev/tty"
 
 	if ![runto_main] {
 	    fail "can't run to main"
@@ -276,6 +278,7 @@ proc test_detach_killed_outside {multi_process cmd} {
 	global binfile
 
 	clean_restart ${binfile}
+	gdb_test_no_output "tty /dev/tty"
 
 	if ![runto_main] {
 	    fail "can't run to main"
diff --git a/gdb/testsuite/gdb.threads/threadapply.exp b/gdb/testsuite/gdb.threads/threadapply.exp
index ebc1cf15ad6..17a02084b09 100644
--- a/gdb/testsuite/gdb.threads/threadapply.exp
+++ b/gdb/testsuite/gdb.threads/threadapply.exp
@@ -76,6 +76,9 @@ proc thr_apply_detach {thread_set} {
 
 	clean_restart ${binfile}
 
+	# So we can safely detach after "run".
+	gdb_test_no_output "tty /dev/tty"
+
 	if ![runto_main] {
 	    fail "can't run to main"
 	    return -1
-- 
2.26.2


  parent reply	other threads:[~2021-06-03 19:03 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-03 19:02 [PATCH 00/17] Interrupting programs that block/ignore SIGINT Pedro Alves
2021-06-03 19:02 ` [PATCH 01/17] Test interrupting programs that block SIGINT [gdb/9425, gdb/14559] Pedro Alves
2021-06-03 19:02 ` [PATCH 02/17] prefork_hook: Remove 'args' parameter Pedro Alves
2021-06-03 19:02 ` [PATCH 03/17] Fix silent gdb.base/annota1.exp test coverage regression Pedro Alves
2021-06-03 19:28   ` Andrew Burgess
2021-06-14 20:30     ` Pedro Alves
2021-06-03 19:02 ` [PATCH 04/17] Make gdb.base/long-inferior-output.exp fail fast Pedro Alves
2021-06-03 19:02 ` [PATCH 05/17] Fix gdb.multi/multi-term-settings.exp race Pedro Alves
2021-06-03 19:02 ` [PATCH 06/17] Don't check parent pid in gdb.threads/{ia64-sigill, siginfo-threads, watchthreads-reorder}.c Pedro Alves
2021-06-03 19:02 ` [PATCH 07/17] Special-case "set inferior-tty /dev/tty" Pedro Alves
2021-06-03 19:02 ` Pedro Alves [this message]
2021-07-02 19:31   ` [PATCH 08/17] Make inferior/GDB share terminal in run+detach testcases Tom Tromey
2021-06-03 19:02 ` [PATCH 09/17] Make inferior/GDB share terminal in tests that exercise GDB/inferior reading same input Pedro Alves
2021-06-03 19:02 ` [PATCH 10/17] gdb.mi/mi-logging.exp, don't send input to GDB while the inferior is running Pedro Alves
2021-06-03 19:02 ` [PATCH 11/17] target_terminal::ours_for_output before printing signal received Pedro Alves
2021-06-03 19:02 ` [PATCH 12/17] Move scoped_ignore_sigttou to gdbsupport/ Pedro Alves
2021-06-03 19:02 ` [PATCH 13/17] Always put inferiors in their own terminal/session [gdb/9425, gdb/14559] Pedro Alves
2021-06-03 19:02 ` [PATCH 14/17] exists_non_stop_target: Avoid flushing frames Pedro Alves
2021-06-03 19:02 ` [PATCH 15/17] convert previous_inferior_ptid to strong reference to thread_info Pedro Alves
2021-06-03 19:02 ` [PATCH 16/17] GNU/Linux: Interrupt/Ctrl-C with SIGSTOP instead of SIGINT [PR gdb/9425, PR gdb/14559] Pedro Alves
2021-06-03 19:02 ` [PATCH 17/17] Document pseudo-terminal and interrupting changes Pedro Alves
2021-06-03 19:28   ` Eli Zaretskii
2021-06-03 19:51 ` [PATCH 00/17] Interrupting programs that block/ignore SIGINT Eli Zaretskii
2021-06-13 10:41   ` Eli Zaretskii
2021-06-14 16:29     ` Pedro Alves
2021-06-14 17:10       ` Eli Zaretskii
2021-06-14 17:55   ` Pedro Alves
2021-06-15 12:18     ` Eli Zaretskii
2021-06-15 15:50       ` John Baldwin
2021-06-15 16:18         ` Eli Zaretskii
2021-06-15 16:41           ` John Baldwin
2021-06-16 10:01             ` Pedro Alves
2021-06-16 12:10               ` Eli Zaretskii
2021-06-16 15:06               ` John Baldwin
2021-07-02 19:35 ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210603190243.2609886-9-pedro@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).