Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 4/6] testsuite: Don't use expect_background to reap gdbserver
Date: Mon, 23 Feb 2015 13:54:00 -0000	[thread overview]
Message-ID: <1424699660-11727-5-git-send-email-palves@redhat.com> (raw)
In-Reply-To: <1424699660-11727-1-git-send-email-palves@redhat.com>

I adjusted a test to do 'expect -i $server_spawn_id -re ...', and saw
really strange behavior.  Whether that expect would work, depended on
whether GDB would also send output and the same expect matched it too
(on $gdb_spawn_id).  I was perplexed until I noticed that
gdbserver_spawn spawns gdbserver and then uses expect_background to
reap gdbserver.  That expect_background conflicts/races with any
"expect -i $server_spawn_id" done anywhere else in parallel...

In order to make it possible for tests to read inferior I/O out of
$server_spawn_id, we to get rid of that expect_background.  This patch
makes us instead reap gdbserver's spawn id when GDB exits.  If GDB is
still around, this gives a chance for gdbserver to exit cleanly.  The
current code in gdb_finish uses "kill", but that doesn't work with
extended-remote (gdbserver doesn't exit).  We now use "monitor exit"
instead which works in both remote and extended-remote modes.

gdb/testsuite/ChangeLog:
2015-02-23  Pedro Alves  <palves@redhat.com>

	* lib/gdb.exp (gdb_finish): Delete persistent gdbserver handling.
	* lib/gdbserver-support.exp (gdbserver_start): Make
	$server_spawn_id global.
	(gdbserver_start): Don't wait for gdbserver's spawn id with
	expect_background.
	(close_gdbserver): New procedure.
	(gdb_exit): Rename the default version and reimplement.
---
 gdb/testsuite/lib/gdb.exp               | 14 --------
 gdb/testsuite/lib/gdbserver-support.exp | 61 ++++++++++++++++++++++++++-------
 2 files changed, 48 insertions(+), 27 deletions(-)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 8e12ea4..3e8e574 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3986,20 +3986,6 @@ proc gdb_finish { } {
     global gdb_prompt
     global cleanfiles
 
-    # Give persistent gdbserver a chance to terminate before GDB is killed.
-    if {[info exists gdbserver_reconnect_p] && $gdbserver_reconnect_p
-	&& [info exists gdb_spawn_id]} {
-	send_gdb "kill\n";
-	gdb_expect 10 {
-	    -re "y or n" {
-		send_gdb "y\n";
-		exp_continue;
-	    }
-	    -re "$gdb_prompt $" {
-	    }
-	}
-    }
-
     # Exit first, so that the files are no longer in use.
     gdb_exit
 
diff --git a/gdb/testsuite/lib/gdbserver-support.exp b/gdb/testsuite/lib/gdbserver-support.exp
index 4a59154..f19b796 100644
--- a/gdb/testsuite/lib/gdbserver-support.exp
+++ b/gdb/testsuite/lib/gdbserver-support.exp
@@ -270,6 +270,7 @@ proc gdbserver_start { options arguments } {
 	    append gdbserver_command " $arguments"
 	}
 
+	global server_spawn_id
 	set server_spawn_id [remote_spawn target $gdbserver_command]
 
 	# Wait for the server to open its TCP socket, so that GDB can connect.
@@ -294,19 +295,6 @@ proc gdbserver_start { options arguments } {
 	break
     }
 
-    # We can't just call close, because if gdbserver is local then that means
-    # that it will get a SIGHUP.  Doing it this way could also allow us to
-    # get at the inferior's input or output if necessary, and means that we
-    # don't need to redirect output.
-    expect_background {
-	-i $server_spawn_id
-	full_buffer { }
-	eof {
-	    # The spawn ID is already closed now (but not yet waited for).
-	    wait -i $expect_out(spawn_id)
-	}
-    }
-
     return [list $protocol [$get_remote_address $debughost $portnum]]
 }
 
@@ -328,6 +316,53 @@ proc gdbserver_spawn { child_args } {
     return [gdbserver_start "" $arguments]
 }
 
+# Close the GDBserver connection.
+
+proc close_gdbserver {} {
+    global server_spawn_id
+
+    # We can't just call close, because if gdbserver is local then that means
+    # that it will get a SIGHUP.  Doing it this way could also allow us to
+    # get at the inferior's input or output if necessary, and means that we
+    # don't need to redirect output.
+
+    if {![info exists server_spawn_id]} {
+	return
+    }
+
+    verbose "Quitting GDBserver"
+
+    catch "close -i $server_spawn_id"
+    catch "wait -i $server_spawn_id"
+    unset server_spawn_id
+}
+
+# Hook into GDB exit, and close GDBserver.
+
+if { [info procs gdbserver_gdb_exit] == "" } {
+    rename gdb_exit gdbserver_orig_gdb_exit
+}
+proc gdb_exit {} {
+    global gdb_spawn_id server_spawn_id
+    global gdb_prompt
+
+    if {[info exists gdb_spawn_id] && [info exists server_spawn_id]} {
+	send_gdb "monitor exit\n";
+	gdb_expect {
+	    -re "$gdb_prompt $" {
+		exp_continue
+	    }
+	    -i "$server_spawn_id" eof {
+		wait -i $expect_out(spawn_id)
+		unset server_spawn_id
+	    }
+	}
+    }
+    close_gdbserver
+
+    gdbserver_orig_gdb_exit
+}
+
 # Start a gdbserver process running HOST_EXEC and pass CHILD_ARGS
 # to it.  Return 0 on success, or non-zero on failure: 2 if gdbserver
 # failed to start or 1 if we couldn't connect to it.
-- 
1.9.3


  parent reply	other threads:[~2015-02-23 13:54 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-23 13:54 [PATCH 0/6] Introduce $inferior_spawn_id, make interrupt.exp work with GDBserver Pedro Alves
2015-02-23 13:54 ` [PATCH 3/6] gdb_test_multiple: Fix user code argument processing Pedro Alves
2015-02-23 13:54 ` Pedro Alves [this message]
2015-04-13 11:42   ` [PATCH 4/6] testsuite: Don't use expect_background to reap gdbserver Yao Qi
2015-04-13 12:09     ` Pedro Alves
2015-04-13 13:25       ` Yao Qi
2015-04-13 13:52         ` Pedro Alves
2015-04-13 14:20           ` Yao Qi
2015-04-13 14:22             ` Pedro Alves
2015-04-13 14:48               ` Yao Qi
2015-02-23 13:54 ` [PATCH 1/6] gdb.base/interrupt.exp: Fix race Pedro Alves
2015-02-23 13:54 ` [PATCH 6/6] gdb.base/interrupt.exp: Use send_inferior/$inferior_spawn_id Pedro Alves
2015-02-23 13:54 ` [PATCH 2/6] gdb.base/interrupt.exp: Use gdb_test_multiple instead of gdb_expect Pedro Alves
2015-02-23 14:28 ` [PATCH 5/6] testsuite: Introduce $inferior_spawn_id Pedro Alves
2015-02-24 16:31   ` Yao Qi
2015-02-27 10:42     ` Pedro Alves
2015-02-27 10:59       ` Pedro Alves
2015-02-27 11:01         ` Pedro Alves
2015-02-27 12:12         ` Yao Qi
2015-02-27 13:59           ` [pushed] Add "../lib/unbuffer_output.c" and use it in gdb.base/interrupt.c (Re: [PATCH 5/6] testsuite: Introduce $inferior_spawn_id) Pedro Alves
2015-02-27 14:13             ` Yao Qi
2015-02-27 14:42             ` Eli Zaretskii
2015-02-27 14:47               ` Pedro Alves
2015-02-27 12:08       ` [PATCH 5/6] testsuite: Introduce $inferior_spawn_id Yao Qi
2015-02-27 12:30         ` Pedro Alves
2015-04-16 16:55           ` Antoine Tremblay
2015-04-16 17:14             ` Pedro Alves
2015-04-21 18:25               ` Pedro Alves
2015-04-21 18:32                 ` Antoine Tremblay
2015-04-07 17:31 ` [PATCH 0/6] Introduce $inferior_spawn_id, make interrupt.exp work with GDBserver Pedro Alves

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=1424699660-11727-5-git-send-email-palves@redhat.com \
    --to=palves@redhat.com \
    --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