diff mbox

[06/14] gdb/testsuite: Fix gdb.mi exit function

Message ID 20200207150003.8383-7-shahab.vahedi@gmail.com
State New
Headers show

Commit Message

Shahab Vahedi Feb. 7, 2020, 2:59 p.m. UTC
From: Anton Kolesov <Anton.Kolesov@synopsys.com>

There was a bug in gdb.mi tests where GDB was trying to connect to same
GDBserver twice, because first instance wasn't properly killed after test is
finished. That was happening with tests that run MI in a separate tty. Spawn
id of this second UI was set as a default spawn_id of this application,
however function "exp_pid" couldn't return a valid process ID for that
spawn_id. As a result standard_close, invoked from gdb_exit failed to kill
GDB process by PID. This patch fixes this problem by making sure that
mi_gdb_exit will set current spawn_id to the ID of the main GDB tty, so that
exp_pid will work and GDB will be killed. This patch also adds explicit
invocation of mi_gdb_exit to the end of mi-break.exp tests, because those
tests use separate tty for MI, so should use mi_gdb_exit, but by default
runtest invokes gdb_exit when .exp file is finished, not the mi_gdb_exit.

gdb/testsuite/ChangeLog:
2016-07-14  Anton Kolesov <Anton.Kolesov@synopsys.com>

	* gdb.mi/mi-break.exp (test_break): Explicitly exit the MI gdb.
	* gdb.mi/mi-watch.exp (test_watchpoint_all): Likewise.
	* lib/mi-support.exp (mi_uncatched_gdb_exit): Switch back to
	"main spawn id" before "remote_close".

Signed-off-by: Anton Kolesov <Anton.Kolesov@synopsys.com>
---
 gdb/testsuite/gdb.mi/mi-break.exp | 5 +++++
 gdb/testsuite/gdb.mi/mi-watch.exp | 5 +++++
 gdb/testsuite/lib/mi-support.exp  | 7 +++++++
 3 files changed, 17 insertions(+)
diff mbox

Patch

diff --git a/gdb/testsuite/gdb.mi/mi-break.exp b/gdb/testsuite/gdb.mi/mi-break.exp
index acec246f52ee..925a08e7190a 100644
--- a/gdb/testsuite/gdb.mi/mi-break.exp
+++ b/gdb/testsuite/gdb.mi/mi-break.exp
@@ -432,6 +432,11 @@  proc test_break {mi_mode} {
     test_abreak_creation
 
     test_explicit_breakpoints
+
+    # If separate-mi-tty is used, GDB will not be properly closed by the
+    # default gdb_exit, which is called by default when .exp file is finished.
+    # Instead a mi_gdb_exit must be used.
+    mi_gdb_exit
 }
 
 if [gdb_debug_enabled] {
diff --git a/gdb/testsuite/gdb.mi/mi-watch.exp b/gdb/testsuite/gdb.mi/mi-watch.exp
index fe09f1dea404..1545f39bdc78 100644
--- a/gdb/testsuite/gdb.mi/mi-watch.exp
+++ b/gdb/testsuite/gdb.mi/mi-watch.exp
@@ -172,6 +172,11 @@  proc test_watchpoint_all {mi_mode type} {
     #test_rwatch_creation_and_listing
     #test_awatch_creation_and_listing
     test_watchpoint_triggering
+
+    # If separate-mi-tty is used, GDB will not be properly closed by the
+    # default gdb_exit, which is called by default when .exp file is finished.
+    # Instead a mi_gdb_exit must be used.
+    mi_gdb_exit
 }
 
 if [gdb_debug_enabled] {
diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp
index 2c67cc287dce..922b021099ac 100644
--- a/gdb/testsuite/lib/mi-support.exp
+++ b/gdb/testsuite/lib/mi-support.exp
@@ -91,6 +91,13 @@  proc mi_uncatched_gdb_exit {} {
     }
 
     if ![is_remote host] {
+	# DejaGNU's standard_close uses spawn_id to figure out PID through
+	# exp_pid and then kill process by ID. However, when MI runs on
+	# secondary UI exp_pid returns nothing for it's spawn_id, so we have to
+	# switch back to the main spawn_id for remote_close to succeed.
+	if { $gdb_main_spawn_id != $gdb_spawn_id } {
+	    switch_gdb_spawn_id $gdb_main_spawn_id
+	}
 	remote_close host
     }
     unset gdb_spawn_id