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