1# Copyright 2009-2013 Free Software Foundation, Inc.
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16if {[skip_hw_watchpoint_tests]} {
17    return 0
18}
19
20load_lib mi-support.exp
21set MIFLAGS "-i=mi"
22
23standard_testfile .c
24
25if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
26     untested pr11022.exp
27     return
28}
29
30proc test_memory_changed_observer { mi_command } { with_test_prefix "${mi_command}" {
31    global srcfile
32
33    if [mi_gdb_start] {
34	return
35    }
36    mi_run_to_main
37
38    set line_number [gdb_get_line_number "break here"]
39    mi_gdb_test "-break-insert ${srcfile}:${line_number}" \
40	{\^done,bkpt=.number="2",type="breakpoint".*\}} \
41	"set breakpoint"
42
43    mi_gdb_test "watch x" ".*" "set watchpoint"
44
45    mi_execute_to "exec-continue" "breakpoint-hit" "main" "" ".*" ".*" \
46	{ "" "disp=\"keep\"" } "breakpoint hit"
47
48    mi_execute_to "exec-continue" "watchpoint-trigger" "main" "" ".*" ".*" \
49	{ "" "wpt=\{number=\"3\",exp=\"x\"\},value=\{old=\"0\",new=\"42\"\}" } \
50	"watchpoint hit"
51
52    mi_execute_to "exec-continue" "breakpoint-hit" "main" "" ".*" ".*" \
53	{ "" "disp=\"keep\"" } "breakpoint hit 2"
54
55    mi_gdb_test "-${mi_command}" {\^done} "set x"
56
57    mi_execute_to "exec-continue" "watchpoint-trigger" "main" "" ".*" ".*" \
58	{ "" "wpt=\{number=\"3\",exp=\"x\"\},value=\{old=\"1\",new=\"42\"\}" } \
59	"watchpoint hit 2"
60
61    mi_gdb_exit
62}}
63
64test_memory_changed_observer "data-write-memory-bytes &x \"01\""
65# We want to trigger a target memory write here, so the word size (4 or 8)
66# is not that important.
67test_memory_changed_observer "data-write-memory &x x 4 \"01\""
68