]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.mi/mi-watch.exp
gdb/testsuite introduce foreach_mi_ui_mode helper proc
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-watch.exp
CommitLineData
213516ef 1# Copyright 1999-2023 Free Software Foundation, Inc.
fb40c209
AC
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
fb40c209 6# (at your option) any later version.
e22f8b7c 7#
fb40c209
AC
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.
e22f8b7c 12#
fb40c209 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
fb40c209 15
17282693 16# Test Machine interface (MI) operations
fb40c209 17#
17282693 18# Test MI watchpoint commands.
fb40c209 19#
17282693
PA
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.
fb40c209 22
e379cbb1 23# The allow_hw_watchpoint_tests checks if watchpoints are supported by the
f760c4f2
CL
24# processor. On PowerPC, the check runs a small test program under gdb
25# to determine if the Power processor supports HW watchpoints. The check
26# must be done before starting the test so as to not disrupt the execution
27# of the actual test.
28
e379cbb1 29set allow_hw_watchpoint_tests_p [allow_hw_watchpoint_tests]
f760c4f2 30
fb40c209 31load_lib mi-support.exp
b30bf9ee 32set MIFLAGS "-i=mi"
fb40c209 33
298a9cf0
TT
34standard_testfile basics.c
35
9357e021 36if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
5b362f04 37 untested "failed to compile"
b60f0898 38 return -1
fb40c209
AC
39}
40
468afe6c 41proc test_watchpoint_creation_and_listing {} {
fb40c209
AC
42 global mi_gdb_prompt
43 global srcfile
44 global hex
45
45f07fef
MC
46 set line_callee4_head [gdb_get_line_number "callee4 ("]
47 set line_callee4_body [expr $line_callee4_head + 2]
48
fb40c209
AC
49 # Insert a watchpoint and list
50 # Tests:
51 # -break-watch C
52 # -break-list
53
54 mi_gdb_test "111-break-watch C" \
55 "111\\^done,wpt=\{number=\"2\",exp=\"C\"\}" \
56 "break-watch operation"
57
58 mi_gdb_test "222-break-list" \
998580f1 59 "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\"\}\\\]\}" \
fb40c209
AC
60 "list of watchpoints"
61
62}
63
64# UNUSED at the time
468afe6c 65proc test_awatch_creation_and_listing {} {
fb40c209
AC
66 global mi_gdb_prompt
67 global srcfile
68 global hex
69
45f07fef
MC
70 set line_main_head [gdb_get_line_number "main ("]
71 set line_main_body [expr $line_main_head + 2]
72
fb40c209
AC
73 # Insert an access watchpoint and list it
74 # Tests:
75 # -break-watch -a A
76 # -break-list
77
78 mi_gdb_test "333-break-watch -a A" \
45f07fef 79 "333\\^done,bkpt=\{number=\"1\",addr=\"$hex\",file=\".*basics.c\",line=\"$line_main_body\"\}" \
fb40c209
AC
80 "break-watch -a operation"
81
82 mi_gdb_test "444-break-list" \
998580f1 83 "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\"\},.*\}\\\]\}" \
fb40c209
AC
84 "list of watchpoints awatch"
85
86 mi_gdb_test "777-break-delete 3" \
87 "777\\^done" \
88 "delete access watchpoint"
89}
90
91# UNUSED at the time
468afe6c 92proc test_rwatch_creation_and_listing {} {
fb40c209
AC
93 global mi_gdb_prompt
94 global srcfile
95 global hex
96
45f07fef
MC
97 set line_main_head [gdb_get_line_number "main ("]
98 set line_main_body [expr $line_main_head + 2]
99
fb40c209
AC
100 # Insert a read watchpoint and list it.
101 # Tests:
e714f336 102 # -break-watch -r B
fb40c209
AC
103 # -break-list
104
105 mi_gdb_test "200-break-watch -r C" \
45f07fef 106 "200\\^done,bkpt=\{number=\"5\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"callee4\",file=\".*basics.c\",line=\"$line_main_body\",times=\"0\"\}" \
e714f336 107 "break-watch -r operation"
fb40c209
AC
108
109 mi_gdb_test "300-break-list" \
998580f1 110 "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\"\},.*\}\\\}\}" \
fb40c209
AC
111 "list of breakpoints"
112
113 mi_gdb_test "177-break-delete 4" \
114 "177\\^done" \
115 "delete read watchpoint"
116}
117
468afe6c 118proc test_watchpoint_triggering {} {
fb40c209 119 global mi_gdb_prompt
76ff342d 120 global hex fullname_syntax srcfile
fb40c209 121
45f07fef
MC
122 set line_callee4_return_0 [gdb_get_line_number "return 0;"]
123 set line_callee3_head [gdb_get_line_number "callee3 ("]
124 set line_callee3_close_brace [expr $line_callee3_head + 3]
125
fb40c209
AC
126 # Continue execution until the watchpoint is reached, continue again,
127 # to see the watchpoint go out of scope.
128 # Does:
129 # -exec-continue (Here wp triggers)
130 # -exec-continue (Here wp goes out of scope)
131
bb378428
VP
132 mi_execute_to "exec-continue" "watchpoint-trigger" "callee4" "" \
133 ".*basics.c" $line_callee4_return_0 \
134 {"" "wpt=\{number=\"2\",exp=\"C\"\},value=\{old=\".*\",new=\"3\"\}"} \
135 "watchpoint trigger"
fb40c209 136
bb378428
VP
137 mi_execute_to "exec-continue" "watchpoint-scope" "callee3" ".*" \
138 ".*basics.c" $line_callee3_close_brace \
139 {"" "wpnum=\"2\""} \
b6846ba5 140 "watchpoint scope"
fb40c209
AC
141}
142
468afe6c
PA
143proc test_watchpoint_all {mi_mode type} {
144 upvar srcdir srcdir
145 upvar subdir subdir
146 upvar binfile binfile
e379cbb1 147 global allow_hw_watchpoint_tests_p
468afe6c 148
e379cbb1 149 if {$type == "hw" && !$allow_hw_watchpoint_tests_p } {
468afe6c 150 return
0a251e08 151 }
5509918f 152
468afe6c
PA
153 if {$mi_mode == "separate"} {
154 set start_ops "separate-mi-tty"
155 } else {
156 set start_ops ""
157 }
1ccc4abb 158 if [mi_clean_restart ${binfile} $start_ops] {
468afe6c
PA
159 return
160 }
5509918f 161
468afe6c
PA
162 if {$type == "sw"} {
163 set option 0
164 } else {
165 set option 1
166 }
167 mi_gdb_test "567-gdb-set can-use-hw-watchpoints $option" \
168 "567\\^done" \
169 "hw watchpoints toggle"
3e347599 170
468afe6c
PA
171 mi_runto callee4
172 test_watchpoint_creation_and_listing
173 #test_rwatch_creation_and_listing
174 #test_awatch_creation_and_listing
175 test_watchpoint_triggering
176}
fb40c209 177
468afe6c
PA
178# Run the tests twice, once using software watchpoints, and another
179# with hardware watchpoints.
292deeba 180foreach_mi_ui_mode mi-mode {
468afe6c
PA
181 foreach_with_prefix wp-type {"sw" "hw"} {
182 test_watchpoint_all ${mi-mode} ${wp-type}
183 }
184}