]>
Commit | Line | Data |
---|---|---|
85d721b8 PA |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | ||
213516ef | 3 | # Copyright 2010-2023 Free Software Foundation, Inc. |
85d721b8 PA |
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 | ||
85d721b8 PA |
18 | # This file is part of the gdb testsuite. |
19 | ||
20 | # | |
21 | # Tests involving read watchpoints, and other kinds of watchpoints | |
22 | # watching the same memory as read watchpoints. | |
23 | # | |
24 | ||
62cef515 | 25 | standard_testfile .c |
85d721b8 | 26 | |
b800ec70 UW |
27 | if {[skip_hw_watchpoint_access_tests]} { |
28 | return 0 | |
85d721b8 PA |
29 | } |
30 | ||
5b362f04 | 31 | if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { |
85d721b8 PA |
32 | return -1 |
33 | } | |
34 | ||
65a33d75 | 35 | if {![runto_main]} { |
85d721b8 PA |
36 | return |
37 | } | |
38 | ||
39 | set read_line [gdb_get_line_number "read line" $srcfile] | |
40 | ||
41 | # Test running to a read of `global', with a read watchpoint set | |
42 | # watching it. | |
43 | ||
44 | gdb_test "rwatch global" \ | |
45 | "Hardware read watchpoint .*: global" \ | |
46 | "set hardware read watchpoint on global variable" | |
47 | ||
48 | # The first read is on entry to the loop. | |
49 | ||
50 | gdb_test "continue" \ | |
51 | "read watchpoint .*: global.*.*Value = 0.*in main.*$srcfile:$read_line.*" \ | |
52 | "read watchpoint triggers on first read" | |
53 | ||
54 | # The second read happens on second loop iteration, after `global' | |
55 | # having been incremented. On architectures where gdb has to emulate | |
56 | # read watchpoints with access watchpoints, this tests the | |
57 | # only-report-if-value-changed logic. On targets that support real | |
58 | # read watchpoints, this tests that GDB ignores the watchpoint's old | |
59 | # value, knowing that some untrapped write could have changed it, and | |
60 | # so reports the read watchpoint unconditionally. | |
61 | ||
62 | gdb_test "continue" \ | |
63 | "read watchpoint .*: global.*.*Value = 1.*in main.*$srcfile:$read_line.*" \ | |
64 | "read watchpoint triggers on read after value changed" | |
65 | ||
66 | # The following tests check that when the user sets a write or access | |
67 | # watchpoint watching the same memory as a read watchpoint, GDB also | |
68 | # applies the only-report-if-value-changed logic even on targets that | |
69 | # support real read watchpoints. | |
70 | ||
71 | # The program should be stopped at the read line. Set a write | |
72 | # watchpoint (leaving the read watchpoint) and continue. Only the | |
73 | # write watchpoint should be reported as triggering. | |
74 | ||
75 | gdb_test "watch global" \ | |
76 | "atchpoint .*: global" \ | |
77 | "set write watchpoint on global variable" | |
78 | ||
79 | gdb_test "continue" \ | |
80 | "atchpoint .*: global.*Old value = 1.*New value = 2.*" \ | |
81 | "write watchpoint triggers" | |
82 | ||
83 | set exp "" | |
84 | set exp "${exp}2.*read watchpoint.*keep y.*global.*breakpoint already hit 2 times.*" | |
85 | set exp "${exp}3.*watchpoint.*keep y.*global.*breakpoint already hit 1 time.*" | |
86 | gdb_test "info watchpoints" \ | |
87 | "$exp" \ | |
88 | "only write watchpoint triggers when value changes" | |
89 | ||
90 | # The program is now stopped at the write line. Continuing should | |
91 | # stop at the read line, and only the read watchpoint should be | |
92 | # reported as triggering. | |
93 | ||
94 | gdb_test "continue" \ | |
95 | "read watchpoint .*: global.*Value = 2.*in main.*$srcfile:$read_line.*" \ | |
96 | "read watchpoint triggers when value doesn't change, trapping reads and writes" | |
97 | ||
98 | set exp "" | |
99 | set exp "${exp}2.*read watchpoint.*keep y.*global.*breakpoint already hit 3 times.*" | |
100 | set exp "${exp}3.*watchpoint.*keep y.*global.*breakpoint already hit 1 time.*" | |
101 | gdb_test "info watchpoints" \ | |
102 | "$exp" \ | |
103 | "only read watchpoint triggers when value doesn't change" |