]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Convert gdb.base/watchpoint-hw-attach.exp to spawn_wait_for_attach
authorPedro Alves <pedro@palves.net>
Wed, 3 Apr 2024 21:34:47 +0000 (22:34 +0100)
committerPedro Alves <pedro@palves.net>
Wed, 11 Jun 2025 13:54:21 +0000 (14:54 +0100)
On Cygwin, starting an inferior under GDB, and detaching it, quitting
GDB, and then closing the shell, like so:

  (gdb) start
  (gdb) detach
  (gdb) quit
  # close shell

... hangs the parent shell of GDB (not GDB!) until the inferior
process that was detached (as it is still using the same terminal GDB
was using) exits too.

This leads to odd failures in gdb.base/watchpoint-hw-attach.exp like
so:

 detach
 Detaching from program: .../outputs/gdb.base/watchpoint-hw-attach/watchpoint-hw-attach, process 16580
 [Inferior 1 (process 16580) detached]
 (gdb) FAIL: gdb.base/watchpoint-hw-attach.exp: detach

Fix this by converting the testcase to spawn the inferior outside GDB,
with spawn_wait_for_attach.

With this patch, the testcase passes cleanly on Cygwin, for me.

Approved-By: Tom Tromey <tom@tromey.com>
Change-Id: I8e3884073a510d6fd2fff611e1d26fc808adc4fa

gdb/testsuite/gdb.base/watchpoint-hw-attach.exp

index b3892f3989b79d08734d784f779f8ad9e15da24d..fa63edb935d82095deb8deb28d5725d47a59b6a6 100644 (file)
@@ -26,29 +26,18 @@ if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
     return -1
 }
 
-if ![runto_main] {
-    return -1
-}
+set test_spawn_id [spawn_wait_for_attach $binfile]
+set testpid [spawn_id_get_pid $test_spawn_id]
 
-# Run to the point where mypid in the test program has been
-# populated.
-gdb_breakpoint [gdb_get_line_number "pidacquired"]
-gdb_continue_to_breakpoint "pidacquired"
-
-# Get the PID of the test process.
-set testpid [get_integer_valueof "mypid" 0]
+gdb_test "attach $testpid" "Attaching to program: .*, process $testpid.*" "attach once"
 
 gdb_test "detach" "Detaching from program: .*, process $testpid\r\n\\\[Inferior $decimal \\(process $testpid\\) detached\\\]"
 
-if {$testpid == ""} {
-    return -1
-}
-
 # A clean restart is needed to force the hardware watchpoint setup
 # logic to run post attach rather than post inferior launch.
 clean_restart $binfile
 
-gdb_test "attach $testpid" "Attaching to program: .*, process $testpid.*" "attach"
+gdb_test "attach $testpid" "Attaching to program: .*, process $testpid.*" "attach twice"
 
 # Ensure the test program is in the top frame so the required
 # variables are in scope.
@@ -62,3 +51,5 @@ gdb_test "watch watched_variable" \
 
 gdb_test "continue" \
         "continue.*Continuing.*\.Hardware watchpoint $decimal: watched_variable.*Old value = 0.*New value = 4.*watched_variable\\);"
+
+kill_wait_spawned_process $test_spawn_id