From: Pedro Alves Date: Wed, 3 Apr 2024 21:34:47 +0000 (+0100) Subject: Convert gdb.base/watchpoint-hw-attach.exp to spawn_wait_for_attach X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bcacc8e58cd86bf9cbbeb75c5103aed5e6f84cb4;p=thirdparty%2Fbinutils-gdb.git Convert gdb.base/watchpoint-hw-attach.exp to spawn_wait_for_attach 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 Change-Id: I8e3884073a510d6fd2fff611e1d26fc808adc4fa --- diff --git a/gdb/testsuite/gdb.base/watchpoint-hw-attach.exp b/gdb/testsuite/gdb.base/watchpoint-hw-attach.exp index b3892f3989b..fa63edb935d 100644 --- a/gdb/testsuite/gdb.base/watchpoint-hw-attach.exp +++ b/gdb/testsuite/gdb.base/watchpoint-hw-attach.exp @@ -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