]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.mi/mi-watch.exp
update copyright year range in GDB files
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-watch.exp
1 # Copyright 1999-2017 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
16 # Test Machine interface (MI) operations
17 #
18 # Test MI watchpoint commands.
19 #
20 # The goal is not to test gdb functionality, which is done by other
21 # tests, but to verify the correct output response to MI operations.
22
23 load_lib mi-support.exp
24 set MIFLAGS "-i=mi"
25
26 gdb_exit
27
28 standard_testfile basics.c
29
30 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
31 untested "failed to compile"
32 return -1
33 }
34
35 proc test_watchpoint_creation_and_listing {} {
36 global mi_gdb_prompt
37 global srcfile
38 global hex
39
40 set line_callee4_head [gdb_get_line_number "callee4 ("]
41 set line_callee4_body [expr $line_callee4_head + 2]
42
43 # Insert a watchpoint and list
44 # Tests:
45 # -break-watch C
46 # -break-list
47
48 mi_gdb_test "111-break-watch C" \
49 "111\\^done,wpt=\{number=\"2\",exp=\"C\"\}" \
50 "break-watch operation"
51
52 mi_gdb_test "222-break-list" \
53 "222\\\^done,BreakpointTable=\{nr_rows=\".\",nr_cols=\".\",hdr=\\\[\{width=\".*\",alignment=\".*\",col_name=\"number\",colhdr=\"Num\"\}.*colhdr=\"Type\".*colhdr=\"Disp\".*colhdr=\"Enb\".*colhdr=\"Address\".*colhdr=\"What\".*\\\],body=\\\[bkpt=\{number=\"2\",type=\".*watchpoint\",disp=\"keep\",enabled=\"y\",what=\"C\",thread-groups=\\\[\"i1\"\\\],times=\"0\",original-location=\"C\"\}\\\]\}" \
54 "list of watchpoints"
55
56 }
57
58 # UNUSED at the time
59 proc test_awatch_creation_and_listing {} {
60 global mi_gdb_prompt
61 global srcfile
62 global hex
63
64 set line_main_head [gdb_get_line_number "main ("]
65 set line_main_body [expr $line_main_head + 2]
66
67 # Insert an access watchpoint and list it
68 # Tests:
69 # -break-watch -a A
70 # -break-list
71
72 mi_gdb_test "333-break-watch -a A" \
73 "333\\^done,bkpt=\{number=\"1\",addr=\"$hex\",file=\".*basics.c\",line=\"$line_main_body\"\}" \
74 "break-watch -a operation"
75
76 mi_gdb_test "444-break-list" \
77 "444\\^done,BreakpointTable=\{.*,hdr=\\\[.*\\\],body=\\\[bkpt=\{number=\"3\",type=\"watchpoint\",disp=\"del\",enabled=\"y\",addr=\"$hex\",func=\"main\",file=\".*basics.c\",line=\"$line_main_body\",thread-groups=\\\[\"i1\"\\\],times=\"0\"\},.*\}\\\]\}" \
78 "list of watchpoints awatch"
79
80 mi_gdb_test "777-break-delete 3" \
81 "777\\^done" \
82 "delete access watchpoint"
83 }
84
85 # UNUSED at the time
86 proc test_rwatch_creation_and_listing {} {
87 global mi_gdb_prompt
88 global srcfile
89 global hex
90
91 set line_main_head [gdb_get_line_number "main ("]
92 set line_main_body [expr $line_main_head + 2]
93
94 # Insert a read watchpoint and list it.
95 # Tests:
96 # -break-watch -r B
97 # -break-list
98
99 mi_gdb_test "200-break-watch -r C" \
100 "200\\^done,bkpt=\{number=\"5\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"callee4\",file=\".*basics.c\",line=\"$line_main_body\",times=\"0\"\}" \
101 "break-watch -r operation"
102
103 mi_gdb_test "300-break-list" \
104 "300\\^done,BreakpointTable=\{.*,hdr=\\\[.*\\\],body=\\\[bkpt=\{number=\"5\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"main\",file=\".*basics.c\",line=\"$line_main_body\",thread-groups=\\\[\"i1\"\\\],times=\"0\"\},.*\}\\\}\}" \
105 "list of breakpoints"
106
107 mi_gdb_test "177-break-delete 4" \
108 "177\\^done" \
109 "delete read watchpoint"
110 }
111
112 proc test_watchpoint_triggering {} {
113 global mi_gdb_prompt
114 global hex fullname_syntax srcfile
115
116 set line_callee4_return_0 [gdb_get_line_number "return 0;"]
117 set line_callee3_head [gdb_get_line_number "callee3 ("]
118 set line_callee3_close_brace [expr $line_callee3_head + 3]
119
120 # Continue execution until the watchpoint is reached, continue again,
121 # to see the watchpoint go out of scope.
122 # Does:
123 # -exec-continue (Here wp triggers)
124 # -exec-continue (Here wp goes out of scope)
125
126 mi_execute_to "exec-continue" "watchpoint-trigger" "callee4" "" \
127 ".*basics.c" $line_callee4_return_0 \
128 {"" "wpt=\{number=\"2\",exp=\"C\"\},value=\{old=\".*\",new=\"3\"\}"} \
129 "watchpoint trigger"
130
131 mi_execute_to "exec-continue" "watchpoint-scope" "callee3" ".*" \
132 ".*basics.c" $line_callee3_close_brace \
133 {"" "wpnum=\"2\""} \
134 "watchpoint trigger"
135 }
136
137 proc test_watchpoint_all {mi_mode type} {
138 upvar srcdir srcdir
139 upvar subdir subdir
140 upvar binfile binfile
141
142 if {$type == "hw" && [target_info exists gdb,no_hardware_watchpoints] } {
143 return
144 }
145
146 mi_gdb_exit
147
148 if {$mi_mode == "separate"} {
149 set start_ops "separate-mi-tty"
150 } else {
151 set start_ops ""
152 }
153 if [mi_gdb_start $start_ops] {
154 return
155 }
156
157 if {$type == "sw"} {
158 set option 0
159 } else {
160 set option 1
161 }
162 mi_gdb_test "567-gdb-set can-use-hw-watchpoints $option" \
163 "567\\^done" \
164 "hw watchpoints toggle"
165
166 mi_delete_breakpoints
167 mi_gdb_reinitialize_dir $srcdir/$subdir
168 mi_gdb_load ${binfile}
169
170 mi_runto callee4
171 test_watchpoint_creation_and_listing
172 #test_rwatch_creation_and_listing
173 #test_awatch_creation_and_listing
174 test_watchpoint_triggering
175 }
176
177 # Run the tests twice, once using software watchpoints, and another
178 # with hardware watchpoints.
179 foreach_with_prefix mi-mode {"main" "separate"} {
180 foreach_with_prefix wp-type {"sw" "hw"} {
181 test_watchpoint_all ${mi-mode} ${wp-type}
182 }
183 }