Files
binutils-gdb/gdb/testsuite/gdb.base/watchpoint-hw-attach.exp
Pedro Alves bcacc8e58c 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 <tom@tromey.com>
Change-Id: I8e3884073a510d6fd2fff611e1d26fc808adc4fa
2025-06-11 14:54:21 +01:00

56 lines
2.0 KiB
Plaintext

# Copyright 2018-2025 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# watchpoint-hw-attach.exp -- Test if hardware watchpoints are used
# when attaching to a target.
require allow_hw_watchpoint_tests
require can_spawn_for_attach
standard_testfile
if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
return -1
}
set test_spawn_id [spawn_wait_for_attach $binfile]
set testpid [spawn_id_get_pid $test_spawn_id]
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\\\]"
# 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 twice"
# Ensure the test program is in the top frame so the required
# variables are in scope.
gdb_breakpoint $srcfile:[gdb_get_line_number "pidacquired"]
gdb_continue_to_breakpoint "$srcfile:pidacquired"
gdb_test_no_output "set should_continue = 1"
gdb_test "watch watched_variable" \
"Hardware watchpoint $decimal: 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