Fix build failure in inf-ptrace.c.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / watchthreads2.exp
CommitLineData
dc621c35
DE
1# This testcase is part of GDB, the GNU debugger.
2
3# Copyright 2009 Free Software Foundation, Inc.
4
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.
9#
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.
14#
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/>.
17
18# Check that watchpoints get propagated to all existing threads when the
19# watchpoint is created.
20
21set NR_THREADS 4
22set X_INCR_COUNT 10
23
24if $tracelevel {
25 strace $tracelevel
26}
27
28set prms_id 0
29set bug_id 0
30
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.
33if [target_info exists gdb,no_hardware_watchpoints] {
34 return 0;
35}
36
37set testfile "watchthreads2"
38set srcfile ${testfile}.c
39set binfile ${objdir}/${subdir}/${testfile}
40if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}" "additional_flags=-DNR_THREADS=$NR_THREADS -DX_INCR_COUNT=$X_INCR_COUNT"]] != "" } {
41 return -1
42}
43
44gdb_exit
45gdb_start
46gdb_reinitialize_dir $srcdir/$subdir
47gdb_load ${binfile}
48
49gdb_test "set can-use-hw-watchpoints 1" "" ""
50
51#
52# Run to `main' where we begin our tests.
53#
54
55if ![runto_main] then {
56 gdb_suppress_tests
57}
58
59gdb_test "break thread_started" \
60 "Breakpoint 2 at .*: file .*${srcfile}, line .*" \
61 "breakpoint on thread_started"
62
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).
66
67set nr_started 0
68set message "run to thread_started"
69for { set i 0 } { $i < $NR_THREADS } { incr i } {
70 gdb_test_multiple "continue" $message {
71 -re ".*Breakpoint 2, thread_started ().*$gdb_prompt $" {
72 incr nr_started
73 }
74 timeout {
75 set i $NR_THREADS
76 }
77 }
78}
79if { $nr_started == $NR_THREADS } {
80 pass "all threads started"
81} else {
82 fail "all threads started"
83 # No point in continuing.
84 return -1
85}
86
87# Watch X, it will be modified by all threads.
88# We want this watchpoint to be set *after* all threads are running.
89gdb_test "watch x" "Hardware watchpoint 3: x"
90
91# Now that the watchpoint is set, we can let the threads increment X.
92gdb_test "set var test_ready = 1" ""
93
94# While debugging.
95#gdb_test "set debug infrun 1" ""
96
97set x_inc_line [gdb_get_line_number "X increment"]
98set x_thread_loc "thread_function \\\(arg=.*\\\) at .*watchthreads.c:$x_inc_line"
99
100# X is incremented under a mutex, so we should get NR_THREADS * X_INCR_COUNT
101# hits.
102set limit [expr $NR_THREADS*$X_INCR_COUNT]
103set x_count 0
104set done 0
105
106set message "x watch loop"
107
108for {set i 0} {!$done && $i < $limit} {incr i} {
109 set test_flag 0
110
111 gdb_test_multiple "continue" $message {
112 -re "(.*Hardware watchpoint.*)$gdb_prompt $" {
113 set string $expect_out(1,string)
114
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] {
116 incr x_count
117 set test_flag 1
118 } else {
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.
122 }
123 }
124 -re "The program is not being run.*$gdb_prompt $" {
125 fail "$message (program terminated)"
126 }
127 }
128
129 # If we fail above, don't bother continuing loop.
130 if { $test_flag == 0 } {
131 set done 1
132 }
133}
134
135if { $i == $limit } {
136 pass "all threads incremented x"
137} else {
138 kfail "gdb/10116" "gdb can drop watchpoints in multithreaded app"
139}
This page took 0.098032 seconds and 4 git commands to generate.