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