Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 3/3] [gdb/testsuite] Exit left-over gdb in gdb.mi/mi-break.exp
Date: Mon, 17 Feb 2025 17:36:19 +0100	[thread overview]
Message-ID: <20250217163619.8662-4-tdevries@suse.de> (raw)
In-Reply-To: <20250217163619.8662-1-tdevries@suse.de>

After test-case gdb.mi/mi-break.exp, a gdb instance is left running.

The test-case starts two instances using mi_clean_restart, one using
separate-mi-tty.

For each instance, gdb_exit is called once, from two different locations:
- mi_clean_restart, and
- gdb_finish.

But this doesn't seem to be effective for the separate-mi-tty case.

Fix this by calling gdb_mi_exit at the end of proc test_break.

Likewise in a few more more test-case.

Tested on x86_64-linux.

PR testsuite/32709
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32709
---
 gdb/testsuite/gdb.mi/mi-break.exp             |  4 ++
 gdb/testsuite/gdb.mi/mi-multi-commands.exp    |  4 ++
 gdb/testsuite/gdb.mi/mi-thread-bp-deleted.exp |  6 ++-
 .../gdb.mi/mi-thread-specific-bp.exp          | 41 +++++++++++++------
 gdb/testsuite/gdb.mi/mi-watch.exp             |  4 ++
 gdb/testsuite/gdb.mi/new-ui-bp-deleted.exp    |  6 ++-
 gdb/testsuite/gdb.mi/new-ui-mi-sync.exp       | 26 ++++++++----
 gdb/testsuite/gdb.mi/run-with-two-mi-uis.exp  |  4 ++
 .../gdb.mi/user-selected-context-sync.exp     | 35 ++++++++++------
 9 files changed, 92 insertions(+), 38 deletions(-)

diff --git a/gdb/testsuite/gdb.mi/mi-break.exp b/gdb/testsuite/gdb.mi/mi-break.exp
index 86e7b57260a..aa8603f4ef0 100644
--- a/gdb/testsuite/gdb.mi/mi-break.exp
+++ b/gdb/testsuite/gdb.mi/mi-break.exp
@@ -417,6 +417,10 @@ proc test_break {mi_mode} {
     test_explicit_breakpoints
 
     test_forced_conditions
+
+    # mi_clean_restart and gdb_finish call gdb_exit, which doesn't work for
+    # separate-mi-tty.  Use mi_gdb_exit instead.
+    mi_gdb_exit
 }
 
 foreach_mi_ui_mode mi-mode {
diff --git a/gdb/testsuite/gdb.mi/mi-multi-commands.exp b/gdb/testsuite/gdb.mi/mi-multi-commands.exp
index 028e187366a..ce4379c8636 100644
--- a/gdb/testsuite/gdb.mi/mi-multi-commands.exp
+++ b/gdb/testsuite/gdb.mi/mi-multi-commands.exp
@@ -123,6 +123,10 @@ proc run_test { args } {
 	    break
 	}
     }
+
+    # mi_clean_restart and gdb_finish call gdb_exit, which doesn't work for
+    # separate-mi-tty.  Use mi_gdb_exit instead.
+    mi_gdb_exit
 }
 
 foreach_with_prefix args { "" "separate-mi-tty" } {
diff --git a/gdb/testsuite/gdb.mi/mi-thread-bp-deleted.exp b/gdb/testsuite/gdb.mi/mi-thread-bp-deleted.exp
index 08c72182217..261ab7d0369 100644
--- a/gdb/testsuite/gdb.mi/mi-thread-bp-deleted.exp
+++ b/gdb/testsuite/gdb.mi/mi-thread-bp-deleted.exp
@@ -36,8 +36,6 @@ if { [build_executable "failed to prepare" $testfile $srcfile \
 }
 
 foreach_mi_ui_mode mode {
-    mi_gdb_exit
-
     if {$mode eq "separate"} {
 	set start_ops "separate-mi-tty"
     } else {
@@ -279,4 +277,8 @@ foreach_mi_ui_mode mode {
 	"set do_spin variable in inferior, inferior should now finish"
     mi_expect_stop "breakpoint-hit" "breakpt" ".*" ".*" "$::decimal" \
 	{"" "disp=\"keep\""} "stop in breakpt at the end of the test"
+
+    # mi_clean_restart and gdb_finish call gdb_exit, which doesn't work for
+    # separate-mi-tty.  Use mi_gdb_exit instead.
+    mi_gdb_exit
 }
diff --git a/gdb/testsuite/gdb.mi/mi-thread-specific-bp.exp b/gdb/testsuite/gdb.mi/mi-thread-specific-bp.exp
index 715e0f7e804..6026e7b4727 100644
--- a/gdb/testsuite/gdb.mi/mi-thread-specific-bp.exp
+++ b/gdb/testsuite/gdb.mi/mi-thread-specific-bp.exp
@@ -33,17 +33,7 @@ proc make_loc {num} {
     return [mi_make_breakpoint_loc -thread "1" -number "$::decimal\\.$num"]
 }
 
-foreach_mi_ui_mode mode {
-
-    if {$mode == "separate"} {
-	set start_ops "separate-mi-tty"
-    } else {
-	set start_ops ""
-    }
-
-    if {[mi_clean_restart $binfile $start_ops]} {
-	return -1
-    }
+proc do_test { mode } {
 
     # Ensure we get an error when placing a b/p for thread 1 at a point
     # where thread 1 doesn't exist.
@@ -55,7 +45,7 @@ foreach_mi_ui_mode mode {
     # would succeed, and then 'info breakpoint' on the CLI would
     # trigger an assertion.
     if {$mode eq "separate"} {
-	with_spawn_id $gdb_main_spawn_id {
+	with_spawn_id $::gdb_main_spawn_id {
 	    gdb_test "info breakpoints" "No breakpoints, watchpoints, tracepoints, or catchpoints\\." \
 		"check CLI 'info breakpoints' when there are no breakpoints"
 	}
@@ -83,9 +73,34 @@ foreach_mi_ui_mode mode {
 
     # Check that 'info breakpoints' on the CLI succeeds.
     if {$mode eq "separate"} {
-	with_spawn_id $gdb_main_spawn_id {
+	with_spawn_id $::gdb_main_spawn_id {
 	    gdb_test "info breakpoints" ".*" \
 		"check CLI 'info breakpoints' when there are some breakpoints"
 	}
     }
+
+    return 1
+}
+
+foreach_mi_ui_mode mode {
+
+    if {$mode == "separate"} {
+	set start_ops "separate-mi-tty"
+    } else {
+	set start_ops ""
+    }
+
+    if {[mi_clean_restart $binfile $start_ops]} {
+	break
+    }
+
+    set res [do_test $mode]
+
+    # mi_clean_restart and gdb_finish call gdb_exit, which doesn't work for
+    # separate-mi-tty.  Use mi_gdb_exit instead.
+    mi_gdb_exit
+
+    if { $res == -1 } {
+	break
+    }
 }
diff --git a/gdb/testsuite/gdb.mi/mi-watch.exp b/gdb/testsuite/gdb.mi/mi-watch.exp
index a5a442eb13e..cf97d416535 100644
--- a/gdb/testsuite/gdb.mi/mi-watch.exp
+++ b/gdb/testsuite/gdb.mi/mi-watch.exp
@@ -173,6 +173,10 @@ proc test_watchpoint_all {mi_mode type} {
     #test_rwatch_creation_and_listing
     #test_awatch_creation_and_listing
     test_watchpoint_triggering
+
+    # mi_clean_restart and gdb_finish call gdb_exit, which doesn't work for
+    # separate-mi-tty.  Use mi_gdb_exit instead.
+    mi_gdb_exit
 }
 
 # Run the tests twice, once using software watchpoints, and another
diff --git a/gdb/testsuite/gdb.mi/new-ui-bp-deleted.exp b/gdb/testsuite/gdb.mi/new-ui-bp-deleted.exp
index 938e6deec05..9e529880814 100644
--- a/gdb/testsuite/gdb.mi/new-ui-bp-deleted.exp
+++ b/gdb/testsuite/gdb.mi/new-ui-bp-deleted.exp
@@ -45,8 +45,6 @@ proc make_bp_loc { num } {
 }
 
 foreach_mi_ui_mode mode {
-    mi_gdb_exit
-
     if {$mode eq "separate"} {
 	set start_ops "separate-mi-tty"
     } else {
@@ -109,4 +107,8 @@ foreach_mi_ui_mode mode {
 		 "=breakpoint-deleted,id=\"$bpnum\"" \
 		 "\\^done"]
     }
+
+    # mi_clean_restart and gdb_finish call gdb_exit, which doesn't work for
+    # separate-mi-tty.  Use mi_gdb_exit instead.
+    mi_gdb_exit
 }
diff --git a/gdb/testsuite/gdb.mi/new-ui-mi-sync.exp b/gdb/testsuite/gdb.mi/new-ui-mi-sync.exp
index 28a42dcb665..bf1365e18ad 100644
--- a/gdb/testsuite/gdb.mi/new-ui-mi-sync.exp
+++ b/gdb/testsuite/gdb.mi/new-ui-mi-sync.exp
@@ -40,27 +40,22 @@ proc do_test {sync_command} {
     global gdb_spawn_id gdb_main_spawn_id mi_spawn_id inferior_spawn_id
     global gdb_prompt mi_gdb_prompt
 
-    if {[mi_clean_restart $binfile "separate-mi-tty"] != 0} {
-	fail "could not start gdb"
-	return
-    }
-
     # Start a synchronous run/continue on the MI UI.
     set test "send synchronous execution command"
     if {$sync_command == "run"} {
 	if {[mi_run_cmd] >= 0} {
 	    pass $test
 	} else {
-	    return
+	    return -1
 	}
     } else {
 	if {[mi_runto_main] < 0} {
-	    return
+	    return -1
 	}
 	if {[mi_send_resuming_command_raw "123-exec-continue" $test] >= 0} {
 	    pass $test
 	} else {
-	    return
+	    return -1
 	}
     }
 
@@ -107,5 +102,18 @@ proc do_test {sync_command} {
 }
 
 foreach_with_prefix sync-command {"run" "continue"} {
-    do_test ${sync-command}
+    if {[mi_clean_restart $binfile "separate-mi-tty"] != 0} {
+	fail "could not start gdb"
+	break
+    }
+
+    set res [do_test ${sync-command}]
+
+    # mi_clean_restart and gdb_finish call gdb_exit, which doesn't work for
+    # separate-mi-tty.  Use mi_gdb_exit instead.
+    mi_gdb_exit
+
+    if { $res == -1 } {
+	break
+    }
 }
diff --git a/gdb/testsuite/gdb.mi/run-with-two-mi-uis.exp b/gdb/testsuite/gdb.mi/run-with-two-mi-uis.exp
index 5981bc1ad24..effc760d6a7 100644
--- a/gdb/testsuite/gdb.mi/run-with-two-mi-uis.exp
+++ b/gdb/testsuite/gdb.mi/run-with-two-mi-uis.exp
@@ -59,6 +59,10 @@ proc do_test { ui_to_run } {
 	# the expected ^running record.
 	mi_runto_main
     }
+
+    # mi_clean_restart and gdb_finish call gdb_exit, which doesn't work for
+    # separate-mi-tty.  Use mi_gdb_exit instead.
+    mi_gdb_exit
 }
 
 foreach_with_prefix ui_to_run {first second} {
diff --git a/gdb/testsuite/gdb.mi/user-selected-context-sync.exp b/gdb/testsuite/gdb.mi/user-selected-context-sync.exp
index e168a5eee45..675965fec60 100644
--- a/gdb/testsuite/gdb.mi/user-selected-context-sync.exp
+++ b/gdb/testsuite/gdb.mi/user-selected-context-sync.exp
@@ -385,21 +385,10 @@ proc_with_prefix test_setup { mode } {
     global mi_spawn_id
     global decimal
     global binfile
-    global GDBFLAGS
     global async
 
     set any "\[^\r\n\]*"
 
-    save_vars { GDBFLAGS } {
-	if { $mode == "non-stop" } {
-	    set GDBFLAGS [concat $GDBFLAGS " -ex \"set non-stop 1\""]
-	}
-
-	if { [mi_clean_restart $binfile "separate-mi-tty"] != 0 } {
-	    return -1
-	}
-    }
-
     if { [mi_runto_main] < 0 } {
 	return -1
     }
@@ -1300,7 +1289,7 @@ proc_with_prefix test_cli_in_mi_frame { mode cli_in_mi_mode } {
     }
 }
 
-foreach_with_prefix mode { "all-stop" "non-stop" } {
+proc do_test { mode } {
     set test "setup done"
     if { [test_setup $mode] == -1 } {
 	fail $test
@@ -1331,3 +1320,25 @@ foreach_with_prefix mode { "all-stop" "non-stop" } {
 	test_cli_in_mi_frame $mode $exec_mode
     }
 }
+
+foreach_with_prefix mode { "all-stop" "non-stop" } {
+    save_vars { GDBFLAGS } {
+	if { $mode == "non-stop" } {
+	    set GDBFLAGS [concat $GDBFLAGS " -ex \"set non-stop 1\""]
+	}
+
+	if { [mi_clean_restart $binfile "separate-mi-tty"] != 0 } {
+	    break
+	}
+    }
+
+    set res [do_test $mode]
+
+    # mi_clean_restart and gdb_finish call gdb_exit, which doesn't work for
+    # separate-mi-tty.  Use mi_gdb_exit instead.
+    mi_gdb_exit
+
+    if { $res == -1 } {
+	break
+    }
+}
-- 
2.43.0


  parent reply	other threads:[~2025-02-17 16:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-17 16:36 [PATCH 0/3] [gdb/testsuite] Clean up left-over processes Tom de Vries
2025-02-17 16:36 ` [PATCH 1/3] [gdb/testsuite] Don't start gdb in gdb.base/gstack.exp Tom de Vries
2025-02-17 17:20   ` Keith Seitz
2025-02-18  7:59     ` Tom de Vries
2025-02-17 16:36 ` [PATCH 2/3] [gdb/testsuite] Kill left-over process in gdb.base/add-symbol-file-attach.exp Tom de Vries
2025-02-24 17:26   ` Tom Tromey
2025-02-24 17:57     ` Tom de Vries
2025-02-24 18:05       ` Tom Tromey
2025-02-24 18:43         ` Tom de Vries
2025-02-17 16:36 ` Tom de Vries [this message]
2025-02-24 17:28   ` [PATCH 3/3] [gdb/testsuite] Exit left-over gdb in gdb.mi/mi-break.exp 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=20250217163619.8662-4-tdevries@suse.de \
    --to=tdevries@suse.de \
    --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