[gdb/testsuite] Factor out lib/valgrind.exp
[external/binutils.git] / gdb / testsuite / gdb.base / remote.exp
1 # Copyright 1999-2018 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 only on boards that actually use the remote protocol.
17 if {[target_info gdb_protocol] != "remote"
18     && [target_info gdb_protocol] != "extended-remote"} {
19     return
20 }
21
22 standard_testfile .c
23
24 set result [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}]
25 if {$result != "" } then {
26     untested "failed to compile"
27     return -1
28 }
29
30 gdb_start
31
32 # Make sure we're disconnected, in case we're testing with an
33 # extended-remote board, therefore already connected.
34 gdb_test "disconnect" ".*"
35
36 #
37 # Part ONE: Check the down load commands
38 #
39
40 gdb_test "show remote memory-write-packet-size" \
41         "The memory-write-packet-size is 0 \\(default\\). The actual limit will be further reduced dependent on the target\." \
42         "write-packet default"
43
44 gdb_test "set remote memory-write-packet-size" \
45         "Argument required .integer, `fixed' or `limited'.\." \
46         "set write-packet - NULL"
47
48 gdb_test_no_output "set remote memory-write-packet-size 20"
49 gdb_test "show remote memory-write-packet-size" \
50         "The memory-write-packet-size is 20. The actual limit will be further reduced dependent on the target\." \
51         "set write-packet - small"
52
53 gdb_test_no_output "set remote memory-write-packet-size 1"
54 gdb_test "show remote memory-write-packet-size" \
55         "The memory-write-packet-size is 1. The actual limit will be further reduced dependent on the target\." \
56         "set write-packet - very-small"
57
58 gdb_test_no_output "set remote memory-write-packet-size 0"
59 gdb_test "show remote memory-write-packet-size" \
60         "The memory-write-packet-size is 0 \\(default\\). The actual limit will be further reduced dependent on the target\." \
61         "write-packet default again"
62
63 set test "set remote memory-write-packet-size fixed"
64 gdb_test_multiple $test $test {
65     -re "Change the packet size. .y or n. " {
66         gdb_test_multiple "y" $test {
67             -re "$gdb_prompt $" {
68                 pass $test
69             }
70         }
71     }
72 }
73 gdb_test "show remote memory-write-packet-size" \
74         "The memory-write-packet-size is 0 \\(default\\). Packets are fixed at 16384 bytes\." \
75         "write-packet default fixed"
76
77 gdb_test_no_output "set remote memory-write-packet-size limit"
78 gdb_test "show remote memory-write-packet-size" \
79         "The memory-write-packet-size is 0 \\(default\\). The actual limit will be further reduced dependent on the target\." \
80         "write-packet default limit again"
81
82 #
83 # Part TWO: Check the download behavior.
84 #
85
86 proc gdb_load_timed {executable class writesize} {
87     global test gdb_prompt
88     set test "timed download `[file tail $executable]' - $class, $writesize"
89
90     if {$writesize != ""} then {
91         gdb_test_no_output "set remote memory-write-packet-size $writesize" \
92             "$test - set packet size"
93
94         send_gdb "set remote memory-write-packet-size $class\n"
95         gdb_expect 5 {
96             -re ".*Change the packet size.*$" {
97                 send_gdb "y\n"
98                 gdb_expect 5 {
99                     -re ".*$gdb_prompt $" {
100                         pass "$test - set write size class"
101                     }
102                     timeout {
103                         fail "$test - set write size class"
104                         return
105                     }
106                 }
107             }
108             -re ".*$gdb_prompt $" { }
109             timeout {
110                 fail "$test - set write size class"
111                 return
112             }
113         }
114     }
115
116     # Do not try to load using fixed sizes; we may overflow the remote target.
117     if { $class == "fixed" } {
118         return
119     }
120
121     set load_begin_time [clock clicks]
122     set result [gdb_load $executable]
123     set load_end_time [clock clicks]
124     if { $result != 0 } then {
125         fail "$test - loading executable"
126         return
127     }
128     verbose "$test - time [expr ($load_end_time - $load_begin_time) / 1000] ms"
129     pass $test
130 }
131
132 clean_restart $binfile
133
134 # These download tests won't actually download anything on !is_remote
135 # target boards, but we run them anyway because it's simpler, and
136 # harmless.
137
138 # Typically about 400-1 bytes can be downloaded
139 gdb_load_timed $binfile "limit" 398
140 gdb_load_timed $binfile "limit" 400
141
142 # Absolute max is 16384
143 gdb_load_timed $binfile "fixed" 0
144 gdb_load_timed $binfile "fixed" 16385
145
146 # fall back to the default
147 gdb_load_timed $binfile "limit" 0
148
149 # Get size of data uploaded
150
151 #
152 # Query GDB for the size of various types
153 #
154
155 # Get the size of random_data table (defaults to 48K).
156 set sizeof_random_data [get_sizeof "random_data" 48*1024]
157
158 #
159 # Part THREE: Check the upload behavour
160 #
161 if ![runto_main] then {
162     fail "cannot run to main"
163     return
164 }
165
166 # Carefully check memory around each of the most common packet edge
167 # conditions
168
169 gdb_test "x/8ub random_data" \
170         "<random_data>:\[ \t\]+60\[ \t\]+74\[ \t\]+216\[ \t\]+38\[ \t\]+149\[ \t\]+49\[ \t\]+207\[ \t\]+44"
171
172 gdb_test "x/8ub random_data + 400 - 4" \
173         "<random_data\\+396>:\[ \t\]+185\[ \t\]+255\[ \t\]+50\[ \t\]+140\[ \t\]+237\[ \t\]+172\[ \t\]+143\[ \t\]+93"
174
175 if {$sizeof_random_data > 16380 } then {
176     gdb_test "x/8ub random_data + 16384 - 4" \
177         "<random_data\\+16380>:\[ \t\]+178\[ \t\]+180\[ \t\]+135\[ \t\]+93\[ \t\]+70\[ \t\]+62\[ \t\]+205\[ \t\]+76"
178 }
179
180 # Read a chunk just larger than the packet size (reduce the packet
181 # size to make life easier)
182 gdb_test_no_output "set remote memory-read-packet-size 16"
183
184 gdb_test "show remote memory-read-packet-size" \
185         "The memory-read-packet-size is 16. Packets are limited to 20 bytes."
186 gdb_test "x/17ub random_data" \
187         "<random_data>:\[ \t\]+60\[ \t\]+74\[ \t\]+216\[ \t\]+38\[ \t\]+149\[ \t\]+49\[ \t\]+207\[ \t\]+44.*<random_data\\+8>:\[ \t\]+124\[ \t\]+38\[ \t\]+93\[ \t\]+125\[ \t\]+232\[ \t\]+67\[ \t\]+228\[ \t\]+56.*<random_data\\+16>:\[ \t\]+161"
188
189 # Regression test for gdb/15289.  Make sure -1 is accepted and handled
190 # as "unlimited".
191 gdb_test_no_output "set remote hardware-watchpoint-limit -1"
192 gdb_test_no_output "set remote hardware-breakpoint-limit -1"
193
194 # This is just being thorough.  Assume (at least) a 32-bit host int,
195 # and make sure 32-bit INT_MAX is accepted by a zinteger command.
196 gdb_test_no_output "set remote hardware-watchpoint-limit 2147483647"
197 gdb_test_no_output "set remote hardware-breakpoint-limit 2147483647"
198
199 gdb_exit