]>
Commit | Line | Data |
---|---|---|
37e4754d LM |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | ||
1d506c26 | 3 | # Copyright 2007-2024 Free Software Foundation, Inc. |
37e4754d LM |
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 | # watch-thread_num.exp Test thread <thread_num> parameter for | |
19 | # watch commands. | |
20 | # | |
21 | ||
8e6a5956 UW |
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. | |
63fc80ce AA |
24 | # More specifically, the implementation of this test uses access |
25 | # watchpoints, so skip it when those are not available. | |
435d5837 | 26 | require allow_hw_watchpoint_access_tests |
8e6a5956 | 27 | |
62cef515 | 28 | standard_testfile .c |
37e4754d | 29 | |
62172bb9 UW |
30 | if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { |
31 | return -1 | |
37e4754d LM |
32 | } |
33 | ||
62cef515 | 34 | clean_restart ${binfile} |
37e4754d | 35 | |
65a33d75 | 36 | if {![runto_main]} { |
37e4754d LM |
37 | return |
38 | } | |
39 | ||
cdc7edd7 LM |
40 | gdb_test "watch shared_var thread 0" "Invalid thread ID: 0" "watchpoint on invalid thread" |
41 | gdb_test "watch shared_var thread" "A syntax error in expression, near `thread'\." "invalid watch syntax" | |
37e4754d | 42 | |
a7b796db PA |
43 | set bpexitline [gdb_get_line_number "all threads started"] |
44 | gdb_breakpoint "$bpexitline" | |
45 | gdb_continue_to_breakpoint "all threads started" | |
37e4754d | 46 | |
a7b796db PA |
47 | gdb_test "break loop" "Breakpoint \[0-9\].*" \ |
48 | "Set breakpoint at loop" | |
37e4754d | 49 | |
cdc7edd7 | 50 | gdb_test "continue" ".*Breakpoint .*loop.*" "stopped in loop" |
abc8a88d | 51 | |
de97fdd4 | 52 | gdb_test_multiple "thread" "thread command" { |
02746bbc | 53 | -re ".*Current thread is (\[0-9\]*).*$gdb_prompt $" { |
bc6c7af4 | 54 | pass "thread command" |
02746bbc | 55 | } |
abc8a88d PM |
56 | } |
57 | ||
58 | set thread_num "$expect_out(1,string)" | |
59 | ||
a7b796db | 60 | delete_breakpoints |
abc8a88d | 61 | |
a7b796db PA |
62 | # We use an access watchpoint rather than a write watchpoint, because |
63 | # GDB can drop the latter when multiple threads trigger events | |
64 | # simultaneously, on targets with continuable watchpoints, such as | |
65 | # x86. See PR breakpoints/10116. | |
66 | ||
67 | gdb_test "awatch shared_var thread $thread_num" \ | |
68 | "Hardware access \\(read/write\\) watchpoint .*: shared_var.*" \ | |
bb95117e | 69 | "watchpoint on shared variable" |
a7b796db PA |
70 | |
71 | gdb_test "info breakpoint \$bpnum" \ | |
72 | "stop only in thread $thread_num" \ | |
73 | "info breakpoint shows watchpoint is thread-specific" | |
74 | ||
5048549a TV |
75 | # Uncomment to see additional information. |
76 | #gdb_test "set debug infrun 1" | |
77 | ||
a7b796db | 78 | for {set i 1} {$i <= 5} {incr i} { |
ac0bb574 NF |
79 | set watchpoint "Watchpoint triggered iteration $i" |
80 | set check "Check thread that triggered iteration $i" | |
81 | ||
a7b796db | 82 | set test $watchpoint |
5048549a | 83 | set seen_watchpoint 0 |
a7b796db | 84 | gdb_test_multiple "continue" $test { |
5048549a TV |
85 | -re "Hardware access \\(read/write\\) watchpoint .*: shared_var" { |
86 | set seen_watchpoint 1 | |
a7b796db PA |
87 | exp_continue |
88 | } | |
5048549a TV |
89 | -re "$gdb_prompt " { |
90 | if { $seen_watchpoint } { | |
91 | pass $test | |
92 | } else { | |
93 | fail $test | |
94 | } | |
95 | } | |
96 | -re "\\\[infrun\\\] " { | |
97 | # Avoid timeouts when debugging GDB. | |
98 | exp_continue | |
a7b796db PA |
99 | } |
100 | } | |
2992cbe0 | 101 | gdb_test "thread" ".*Current thread is $thread_num .*" $check |
37e4754d LM |
102 | } |
103 |