Patchwork [4/6] testsuite: Don't use expect_background to reap gdbserver

login
register
mail settings
Submitter Yao Qi
Date April 13, 2015, 2:20 p.m.
Message ID <86zj6ct8hz.fsf@gmail.com>
Download mbox | patch
Permalink /patch/6183/
State New
Headers show

Comments

Yao Qi - April 13, 2015, 2:20 p.m.
Pedro Alves <palves@redhat.com> writes:

>> looks we can't prevent DejaGNU invoking send_user.
>
> I think we should just call raw "expect" instead then.

Using "expect" is OK to me, how about the patch below?
Pedro Alves - April 13, 2015, 2:22 p.m.
On 04/13/2015 03:20 PM, Yao Qi wrote:
> Pedro Alves <palves@redhat.com> writes:
> 
>>> looks we can't prevent DejaGNU invoking send_user.
>>
>> I think we should just call raw "expect" instead then.
> 
> Using "expect" is OK to me, how about the patch below?
> 

Looks good, thanks.
Yao Qi - April 13, 2015, 2:48 p.m.
On 13/04/15 15:22, Pedro Alves wrote:
> Looks good, thanks.

Thanks, patch is pushed in.

Patch

diff --git a/gdb/testsuite/lib/gdbserver-support.exp b/gdb/testsuite/lib/gdbserver-support.exp
index 53843b8..b3140c2 100644
--- a/gdb/testsuite/lib/gdbserver-support.exp
+++ b/gdb/testsuite/lib/gdbserver-support.exp
@@ -353,15 +353,23 @@  proc gdb_exit {} {
     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
-		unset inferior_spawn_id
+	# GDB may be terminated in an expected way or an unexpected way,
+	# but DejaGNU doesn't know that, so gdb_spawn_id isn't unset.
+	# Catch the exceptions.
+	catch {
+	    send_gdb "monitor exit\n";
+	    # We use expect rather than gdb_expect because
+	    # we want to suppress printing exception messages, otherwise,
+	    # remote_expect, invoked by gdb_expect, prints the exceptions.
+	    expect {
+		-i "$gdb_spawn_id" -re "$gdb_prompt $" {
+		    exp_continue
+		}
+		-i "$server_spawn_id" eof {
+		    wait -i $expect_out(spawn_id)
+		    unset server_spawn_id
+		    unset inferior_spawn_id
+		}
 	    }
 	}
     }