summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/watchpoints.exp
blob: 3ed69ccaa2f7ede7f352533393e490e6be84762d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Copyright 2009-2017 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# This file was written by Pierre Muller. (muller@ics.u-strasbg.fr)


standard_testfile

set wp_set 1

if [get_compiler_info] {
    return -1
}

if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
    return -1
}

with_test_prefix "before inferior start" {
    # Ensure that if we turn off hardware watchpoints and set a watch point
    # before starting the inferior the watchpoint created will not be a
    # hardware watchpoint.
    gdb_test_no_output "set can-use-hw-watchpoints 0" ""
    gdb_test "watch ival1" "Watchpoint \[0-9\]+: ival1" \
        "create watchpoint"

    # The next tests are written to match the current state of gdb: access
    # and read watchpoints require hardware watchpoint support, with this
    # turned off these can't be created.
    gdb_test "awatch ival1" \
        "Can't set read/access watchpoint when hardware watchpoints are disabled." \
        "create access watchpoint"
    gdb_test "rwatch ival1" \
        "Can't set read/access watchpoint when hardware watchpoints are disabled." \
        "create read watchpoint"
}

    # This will turn hardware watchpoints back on and delete the watchpoint
    # we just created.
    clean_restart ${binfile}

    # Disable hardware watchpoints if necessary.
    if [target_info exists gdb,no_hardware_watchpoints] {
        gdb_test_no_output "set can-use-hw-watchpoints 0" ""
    }

    runto_main
    gdb_test "watch ival1" ".*" ""
    gdb_test "watch ival3" ".*" ""

    set prev_timeout $timeout
    set timeout 600

    gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival1.*Old value = -1.*New value = 0.*ival1 = count; ival2 = count;.*" "watchpoint hit, first time"

    gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count; ival4 = count;.*" "watchpoint hit, first time"

    # Check that the ival3 hit count is reported correctly
    gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 1 time.*" "watchpoint hit count is 1"

    # Continue until the next change for ival1, from 0 to 1.
    gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival1.*Old value = 0.*New value = 1.*ival1 = count; ival2 = count;.*" "watchpoint ival1 hit, second time"

    # Check that the hit count for ival1 is reported correctly
    gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival1\r\n\[ \t]+breakpoint already hit 2 times.*" "watchpoint ival1 hit count is 2"

    # Continue until the next change for ival3, from 0 to 1.
    gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 0.*New value = 1.*ival3 = count; ival4 = count;.*" "watchpoint hit, second time"

    # Check that the hit count is reported correctly
    gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 2 times.*" "watchpoint hit count is 2"

    # Continue until the next change, from 1 to 2.
    gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival1.*Old value = 1.*New value = 2.*ival1 = count; ival2 = count;.*" "watchpoint ival1 hit, third time"

    # Check that the hit count is reported correctly
    gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival1\r\n\[ \t]+breakpoint already hit 3 times.*" "watchpoint ival1 hit count is 3"
    # Disable ival1 watchpoint
    gdb_test_no_output "disable 2" ""
 
    # Continue until the next change, from 1 to 2.
    gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 1.*New value = 2.*ival3 = count; ival4 = count;.*" "watchpoint hit, third time"

    # Check that the hit count is reported correctly
    gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 3 times.*" "watchpoint hit count is 3"
    
    # Continue until the next change, from 2 to 3.
    gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 2.*New value = 3.*ival3 = count; ival4 = count;.*" "watchpoint hit, fourth time"

    # Check that the hit count is reported correctly
    gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 4 times.*" "watchpoint hit count is 4"

    # Continue until the next change, from 3 to 4.
    # Note that this one is outside the loop.

    gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 3.*New value = 4.*ival3 = count; ival4 = count;.*" "watchpoint hit, fifth time"

    # Check that the hit count is reported correctly
    gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 5 times.*" "watchpoint hit count is 5"

set timeout $prev_timeout