[1/3] Adjust gdb.threads/schedlock.exp for Cygwin

Message ID 20260505124210.1450101-2-pedro@palves.net
State New
Headers
Series Adjust a few gdb.threads/ testcases for Cygwin |

Commit Message

Pedro Alves May 5, 2026, 12:42 p.m. UTC
  This commit adjusts gdb.threads/schedlock.exp to work on Cygwin too.
The main difference to other systems is that on Windows, a Ctrl-C in
the terminal results in Windows injecting a new thread in the inferior
to report a EXCEPTION_DEBUG_EVENT/DBG_CONTROL_C event.  That means
that even with schedlock on, Ctrl-C always switches focus to a
different thread.

With this, gdb.threads/schedlock.exp passes cleanly on Cygwin.

Change-Id: I574c702d370da6eaf92e82ce81efe1a44660b24f
commit-id: f96fcdea
---
 gdb/testsuite/gdb.threads/schedlock.exp | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
  

Patch

diff --git a/gdb/testsuite/gdb.threads/schedlock.exp b/gdb/testsuite/gdb.threads/schedlock.exp
index eeca3f8fd0f..169f6876b62 100644
--- a/gdb/testsuite/gdb.threads/schedlock.exp
+++ b/gdb/testsuite/gdb.threads/schedlock.exp
@@ -105,6 +105,17 @@  proc goto_loop { msg } {
 }
 
 proc my_continue { msg } {
+
+    # On Cygwin, a Ctrl-C in the terminal results in Windows injecting
+    # a new thread in the inferior to report a
+    # EXCEPTION_DEBUG_EVENT/DBG_CONTROL_C event.  That means that even
+    # with schedlock on, Ctrl-C always switches focus to a different
+    # thread.  Hide that fact here by saving/restoring the current
+    # thread.
+    if {[istarget *-*-cygwin*]} {
+	set gdb_thr [get_valueof "" "\$_thread" 0 "save current gdb thread"]
+    }
+
     set test "continue ($msg)"
     gdb_test_multiple "continue" $test {
 	-re "Continuing" {
@@ -114,6 +125,13 @@  proc my_continue { msg } {
 
     stop_process "stop all threads ($msg)"
 
+    # See above.  This must be done before goto_loop, otherwise with
+    # schedlock on, we'd be resuming the injected Ctrl-C thread.
+    if {[istarget *-*-cygwin*]} {
+	gdb_test "thread $gdb_thr" "Switching to thread .*" \
+	    "restore current gdb thread"
+    }
+
     goto_loop $msg
 }
 
@@ -201,6 +219,9 @@  if { $bad == 0 } {
 # before the command was run.  BEFORE_ARGS is the value of the
 # thread's args before the command was run.  LOCKED indicates whether
 # we expect threads other than the selected thread remained locked.
+#
+# Note, on Cygwin, the "we didn't switch threads" test is pointless,
+# see my_continue.
 
 proc check_result { cmd before_thread before_args locked } {
     global NUM