1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2009, 2010 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Check that watchpoints get propagated to all existing threads when the
19 # watchpoint is created.
31 # This test verifies that a watchpoint is detected in the proper thread
32 # so the test is only meaningful on a system with hardware watchpoints.
33 if [target_info exists gdb,no_hardware_watchpoints] {
37 set testfile "watchthreads2"
38 set srcfile ${testfile}.c
39 set binfile ${objdir}/${subdir}/${testfile}
40 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}" "additional_flags=-DNR_THREADS=$NR_THREADS -DX_INCR_COUNT=$X_INCR_COUNT"]] != "" } {
46 gdb_reinitialize_dir $srcdir/$subdir
49 gdb_test "set can-use-hw-watchpoints 1" "" ""
52 # Run to `main' where we begin our tests.
55 if ![runto_main] then {
59 gdb_test "break thread_started" \
60 "Breakpoint 2 at .*: file .*${srcfile}, line .*" \
61 "breakpoint on thread_started"
63 # Run the program until all threads have hit thread_started.
64 # We use this as the vehicle to determine when gdb is aware
65 # of all threads (i.e. "info threads" would show all threads).
68 set message "run to thread_started"
69 for { set i 0 } { $i < $NR_THREADS } { incr i } {
70 gdb_test_multiple "continue" $message {
71 -re ".*Breakpoint 2, thread_started ().*$gdb_prompt $" {
79 if { $nr_started == $NR_THREADS } {
80 pass "all threads started"
82 fail "all threads started"
83 # No point in continuing.
87 # Watch X, it will be modified by all threads.
88 # We want this watchpoint to be set *after* all threads are running.
89 gdb_test "watch x" "Hardware watchpoint 3: x"
91 # Now that the watchpoint is set, we can let the threads increment X.
92 gdb_test "set var test_ready = 1" ""
95 #gdb_test "set debug infrun 1" ""
97 set x_inc_line [gdb_get_line_number "X increment"]
98 set x_thread_loc "thread_function \\\(arg=.*\\\) at .*watchthreads.c:$x_inc_line"
100 # X is incremented under a mutex, so we should get NR_THREADS * X_INCR_COUNT
102 set limit [expr $NR_THREADS*$X_INCR_COUNT]
106 set message "x watch loop"
108 for {set i 0} {!$done && $i < $limit} {incr i} {
111 gdb_test_multiple "continue" $message {
112 -re "(.*Hardware watchpoint.*)$gdb_prompt $" {
113 set string $expect_out(1,string)
115 if [regexp "Hardware watchpoint 3: x\[^\r\]*\r\[^\r\]*\r\[^\r\]*Old value = $x_count\[^\r\]*\r\[^\r\]*New value = [expr $x_count+1]\r" $string] {
119 # We test for new value = old value + 1 each iteration.
120 # This can fail due to gdb/10116.
121 # This is caught after the loop exits.
124 -re "The program is not being run.*$gdb_prompt $" {
125 fail "$message (program terminated)"
129 # If we fail above, don't bother continuing loop.
130 if { $test_flag == 0 } {
135 if { $i == $limit } {
136 pass "all threads incremented x"
138 kfail "gdb/10116" "gdb can drop watchpoints in multithreaded app"