1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2007-2015 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 # watch-thread_num.exp Test thread <thread_num> parameter for
22 # This test verifies that a watchpoint is detected in the proper thread
23 # so the test is only meaningful on a system with hardware watchpoints.
24 if {[skip_hw_watchpoint_tests]} {
30 # What compiler are we using?
32 if [get_compiler_info] {
36 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
40 clean_restart ${binfile}
42 if { ![runto main] } then {
47 gdb_test "watch shared_var thread 0" "Unknown thread 0\." "Watchpoint on invalid thread"
48 gdb_test "watch shared_var thread" "A syntax error in expression, near `thread'\." "Invalid watch syntax"
50 set bpexitline [gdb_get_line_number "all threads started"]
51 gdb_breakpoint "$bpexitline"
52 gdb_continue_to_breakpoint "all threads started"
54 gdb_test "break loop" "Breakpoint \[0-9\].*" \
55 "Set breakpoint at loop"
57 gdb_test "continue" ".*Breakpoint .*loop.*" "Stopped in loop"
59 gdb_test_multiple "thread" "Thread command" {
60 -re ".*Current thread is (\[0-9\]*).*$gdb_prompt $" {
65 set thread_num "$expect_out(1,string)"
69 # We use an access watchpoint rather than a write watchpoint, because
70 # GDB can drop the latter when multiple threads trigger events
71 # simultaneously, on targets with continuable watchpoints, such as
72 # x86. See PR breakpoints/10116.
74 gdb_test "awatch shared_var thread $thread_num" \
75 "Hardware access \\(read/write\\) watchpoint .*: shared_var.*" \
76 "Watchpoint on shared variable"
78 gdb_test "info breakpoint \$bpnum" \
79 "stop only in thread $thread_num" \
80 "info breakpoint shows watchpoint is thread-specific"
82 for {set i 1} {$i <= 5} {incr i} {
83 set watchpoint "Watchpoint triggered iteration $i"
84 set check "Check thread that triggered iteration $i"
87 gdb_test_multiple "continue" $test {
89 # Avoid timeouts when debugging GDB.
92 -re "Hardware access \\(read/write\\) watchpoint .*: shared_var.*$gdb_prompt $" {
96 gdb_test "thread" ".*Current thread is $thread_num .*" $check