Commit | Line | Data |
---|---|---|
61baf725 | 1 | # Copyright 2015-2017 Free Software Foundation, Inc. |
bb556f1f TK |
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 | # This testsuite is to test examining memory backward by specifying a negative | |
17 | # number in the 'x' command. | |
18 | ||
19 | standard_testfile | |
20 | if { [prepare_for_testing "failed to prepare for examine-backward" \ | |
21 | ${testfile} ${srcfile}] } { | |
22 | return -1 | |
23 | } | |
24 | ||
25 | if ![runto_main] { | |
26 | untested "could not run to main" | |
27 | return -1 | |
28 | } | |
29 | ||
30 | proc get_first_mapped_address {} { | |
31 | global gdb_prompt | |
32 | ||
33 | set addr "0" | |
34 | gdb_test_multiple "info proc mappings" "info proc mappings" { | |
35 | -re "objfile\[\r\n\t \]+(0x\[0-9a-fA-F\]+).*\[\r\n\]*$gdb_prompt $" { | |
36 | set addr $expect_out(1,string) | |
37 | } | |
38 | -re "$gdb_prompt $" { | |
bc6c7af4 | 39 | unsupported "current target does not support 'info proc mappings'" |
bb556f1f TK |
40 | } |
41 | } | |
42 | return ${addr} | |
43 | } | |
44 | ||
45 | with_test_prefix "invalid format" { | |
46 | gdb_test "x/- 10xb main" "Invalid number \"10xb\"\." \ | |
47 | "a whitespace after a leading hyphen" | |
48 | gdb_test "x/--10xb main" "Invalid number \"10xb\"\." \ | |
49 | "double hyphen" | |
50 | gdb_test "x/-a10xb main" "Invalid number \"10xb\"\." \ | |
51 | "an alphabet after a leading hyphen" | |
52 | gdb_test_no_output "x/-0i main" "zero with backward disassemble" | |
53 | gdb_test_no_output "x/-0sh main" "zero with backward examine string" | |
54 | } | |
55 | ||
56 | with_test_prefix "memory page boundary" { | |
57 | set boundary [get_first_mapped_address] | |
58 | if {![is_address_zero_readable] && $boundary != 0} { | |
59 | gdb_test_no_output "set print elements 0" | |
60 | gdb_test_sequence "x/3s ${boundary}" "take 3 strings forward" { | |
61 | "0x" | |
62 | "0x" | |
63 | "0x" | |
64 | } | |
65 | gdb_test_sequence "x/-4s" "take 4 strings backward" { | |
66 | "Cannot access memory at address 0x" | |
67 | "0x" | |
68 | "0x" | |
69 | "0x" | |
70 | } | |
71 | gdb_test_sequence "x/3s ${boundary}" "take 3 strings forward again" { | |
72 | "0x" | |
73 | "0x" | |
74 | "0x" | |
75 | } | |
76 | gdb_test_sequence "x/-3s" "take 3 strings backward" { | |
77 | "Cannot access memory at address 0x" | |
78 | "0x" | |
79 | "0x" | |
80 | "0x" | |
81 | } | |
82 | } | |
83 | } | |
84 | ||
85 | with_test_prefix "address zero boundary" { | |
86 | if {[is_address_zero_readable]} { | |
87 | set address_zero "0x0" | |
88 | set byte "\t0x\[0-9a-f\]+" | |
89 | gdb_test "x/3xb ${address_zero}" \ | |
90 | "0x\[0-9a-f\]+00.*:${byte}${byte}${byte}" \ | |
91 | "examine 3 bytes forward from ${address_zero}" | |
92 | gdb_test "x/-6x" \ | |
93 | "0x\[0-9a-f\]+fd.*:${byte}${byte}${byte}${byte}${byte}${byte}" \ | |
94 | "examine 6 bytes backward" | |
95 | gdb_test "x/-3x ${address_zero}" \ | |
96 | "0x\[0-9a-f\]+fd.*:${byte}${byte}${byte}" \ | |
97 | "examine 3 bytes backward from ${address_zero}" | |
98 | } | |
99 | } | |
100 | ||
101 | gdb_test_no_output "set charset ASCII" | |
102 | ||
103 | with_test_prefix "char-width=1, print-max=20" { | |
104 | gdb_test_no_output "set print elements 20" | |
105 | gdb_test_sequence "x/6s &TestStrings" "take 6 strings forward" { | |
106 | "\"ABCDEFGHIJKLMNOPQRST\"\.\.\." | |
107 | "\"UVWXYZ\"" | |
108 | "\"\"" | |
109 | "\"\"" | |
110 | "\"[^\"]+\"" | |
111 | "\"01234567890123456789\"\.\.\." | |
112 | } | |
113 | gdb_test "x/-1xb" "0x39" "take 1 char backward" | |
114 | gdb_test_sequence "x/-6s" "take 6 strings backward" { | |
115 | "\"ABCDEFGHIJKLMNOPQRST\"\.\.\." | |
116 | "\"UVWXYZ\"" | |
117 | "\"\"" | |
118 | "\"\"" | |
119 | "\"[^\"]+\"" | |
120 | "\"01234567890123456789\"\.\.\." | |
121 | } | |
122 | gdb_test_sequence "x/6s &TestStrings" "take 6 strings forward again" { | |
123 | "\"ABCDEFGHIJKLMNOPQRST\"\.\.\." | |
124 | "\"UVWXYZ\"" | |
125 | "\"\"" | |
126 | "\"\"" | |
127 | "\"[^\"]+\"" | |
128 | "\"01234567890123456789\"\.\.\." | |
129 | } | |
130 | gdb_test "x/-xb" "0x39" "take 1 char backward again" | |
131 | gdb_test "x/-s" "\"01234567890123456789\"\.\.\." \ | |
132 | "take 1 string backward (1/6)" | |
133 | gdb_test "x/-s" "\".+\"" \ | |
134 | "take 1 string backward (2/6)" | |
135 | gdb_test "x/-s" "\"\"" \ | |
136 | "take 1 string backward (3/6)" | |
137 | gdb_test "x/-s" "\"\"" \ | |
138 | "take 1 string backward (4/6)" | |
139 | gdb_test "x/-s" "\"GHIJKLMNOPQRSTUVWXYZ\"" \ | |
140 | "take 1 string backward (5/6)" | |
141 | gdb_test "x/-s" "\"ABCDEFGHIJKLMNOPQRST\"\.\.\." \ | |
142 | "take 1 string backward (6/6)" | |
143 | } | |
144 | ||
145 | with_test_prefix "char-width=2, print-max=20" { | |
146 | gdb_test_no_output "set print elements 20" | |
147 | gdb_test_sequence "x/6sh &TestStringsH" "take 6 strings forward" { | |
148 | "u\"ABCDEFGHIJKLMNOPQRST\"\.\.\." | |
149 | "u\"UVWXYZ\"" | |
150 | "u\"\"" | |
151 | "u\"\"" | |
152 | "u\"[^\"]+\"" | |
153 | "u\"01234567890123456789\"\.\.\." | |
154 | } | |
155 | gdb_test "x/-1xh" "0x0039" "take 1 char backward" | |
156 | gdb_test_sequence "x/-6sh" "take 6 strings backward" { | |
157 | "u\"ABCDEFGHIJKLMNOPQRST\"\.\.\." | |
158 | "u\"UVWXYZ\"" | |
159 | "u\"\"" | |
160 | "u\"\"" | |
161 | "u\"[^\"]+\"" | |
162 | "u\"01234567890123456789\"\.\.\." | |
163 | } | |
164 | gdb_test_sequence "x/6sh &TestStringsH" "take 6 strings forward again" { | |
165 | "u\"ABCDEFGHIJKLMNOPQRST\"\.\.\." | |
166 | "u\"UVWXYZ\"" | |
167 | "u\"\"" | |
168 | "u\"\"" | |
169 | "u\"[^\"]+\"" | |
170 | "u\"01234567890123456789\"\.\.\." | |
171 | } | |
172 | gdb_test "x/-xh" "0x0039" "take 1 char backward again" | |
173 | gdb_test "x/-sh" "u\"01234567890123456789\"\.\.\." \ | |
174 | "take 1 string backward (1/6)" | |
175 | gdb_test "x/-sh" "u\".+\"" \ | |
176 | "take 1 string backward (2/6)" | |
177 | gdb_test "x/-sh" "u\"\"" \ | |
178 | "take 1 string backward (3/6)" | |
179 | gdb_test "x/-sh" "u\"\"" \ | |
180 | "take 1 string backward (4/6)" | |
181 | gdb_test "x/-sh" "u\"GHIJKLMNOPQRSTUVWXYZ\"" \ | |
182 | "take 1 string backward (5/6)" | |
183 | gdb_test "x/-sh" "u\"ABCDEFGHIJKLMNOPQRST\"\.\.\." \ | |
184 | "take 1 string backward (6/6)" | |
185 | } | |
186 | ||
187 | with_test_prefix "char-width=4, print-max=20" { | |
188 | gdb_test_no_output "set print elements 20" | |
189 | gdb_test_sequence "x/6sw &TestStringsW" "take 6 strings forward" { | |
190 | "U\"ABCDEFGHIJKLMNOPQRST\"\.\.\." | |
191 | "U\"UVWXYZ\"" | |
192 | "U\"\"" | |
193 | "U\"\"" | |
194 | "U\"[^\"]+\"" | |
195 | "U\"01234567890123456789\"\.\.\." | |
196 | } | |
197 | gdb_test "x/-1xw" "0x00000039" "take 1 char backward" | |
198 | gdb_test_sequence "x/-6sw" "take 6 strings backward" { | |
199 | "U\"ABCDEFGHIJKLMNOPQRST\"\.\.\." | |
200 | "U\"UVWXYZ\"" | |
201 | "U\"\"" | |
202 | "U\"\"" | |
203 | "U\"[^\"]+\"" | |
204 | "U\"01234567890123456789\"\.\.\." | |
205 | } | |
206 | gdb_test_sequence "x/6sw &TestStringsW" "take 6 strings forward again" { | |
207 | "U\"ABCDEFGHIJKLMNOPQRST\"\.\.\." | |
208 | "U\"UVWXYZ\"" | |
209 | "U\"\"" | |
210 | "U\"\"" | |
211 | "U\"[^\"]+\"" | |
212 | "U\"01234567890123456789\"\.\.\." | |
213 | } | |
214 | gdb_test "x/-xw" "0x00000039" "take 1 char backward again" | |
215 | gdb_test "x/-sw" "U\"01234567890123456789\"\.\.\." \ | |
216 | "take 1 string backward (1/6)" | |
217 | gdb_test "x/-sw" "U\".+\"" \ | |
218 | "take 1 string backward (2/6)" | |
219 | gdb_test "x/-sw" "U\"\"" \ | |
220 | "take 1 string backward (3/6)" | |
221 | gdb_test "x/-sw" "U\"\"" \ | |
222 | "take 1 string backward (4/6)" | |
223 | gdb_test "x/-sw" "U\"GHIJKLMNOPQRSTUVWXYZ\"" \ | |
224 | "take 1 string backward (5/6)" | |
225 | gdb_test "x/-sw" "U\"ABCDEFGHIJKLMNOPQRST\"\.\.\." \ | |
226 | "take 1 string backward (6/6)" | |
227 | } | |
228 | ||
229 | with_test_prefix "char-width=2, print-max=0" { | |
230 | gdb_test_no_output "set print elements 0" | |
231 | gdb_test_sequence "x/6sh &TestStringsH" "take 6 strings forward" { | |
232 | "u\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"" | |
233 | "u\"\"" | |
234 | "u\"\"" | |
235 | "u\"\\\\x307b\\\\x3052\\\\x307b\\\\x3052\"" | |
236 | "u\"012345678901234567890123456789\"" | |
237 | "u\"!!!!!!\"" | |
238 | } | |
239 | gdb_test "x/-4xh" "0x0021\[\t \]+0x0021\[\t \]+0x0021\[\t \]+0x0000" \ | |
240 | "take 4 characters backward" | |
241 | gdb_test_sequence "x/-6sh" "take 6 strings backward" { | |
242 | "u\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"" | |
243 | "u\"\"" | |
244 | "u\"\"" | |
245 | "u\"[^\"]+\"" | |
246 | "u\"012345678901234567890123456789\"" | |
247 | "u\"!!!!!!\"" | |
248 | } | |
249 | gdb_test_sequence "x/6sh &TestStringsH" "take 6 strings forward again" { | |
250 | "u\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"" | |
251 | "u\"\"" | |
252 | "u\"\"" | |
253 | "u\"\\\\x307b\\\\x3052\\\\x307b\\\\x3052\"" | |
254 | "u\"012345678901234567890123456789\"" | |
255 | "u\"!!!!!!\"" | |
256 | } | |
257 | gdb_test "x/-xh" "0x0000" "take 1 char backward" | |
258 | gdb_test "x/-sh" "u\"!!!!!!\"" \ | |
259 | "take 1 string backward (1/6)" | |
260 | gdb_test "x/-sh" "u\"012345678901234567890123456789\"" \ | |
261 | "take 1 string backward (2/6)" | |
262 | gdb_test "x/-sh" "u\".+\"" \ | |
263 | "take 1 string backward (3/6)" | |
264 | gdb_test "x/-sh" "u\"\"" \ | |
265 | "take 1 string backward (4/6)" | |
266 | gdb_test "x/-sh" "u\"\"" \ | |
267 | "take 1 string backward (5/6)" | |
268 | gdb_test "x/-sh" "u\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"" \ | |
269 | "take 1 string backward (6/6)" | |
270 | } | |
271 | ||
272 | with_test_prefix "char-width=1, print-max=4" { | |
273 | gdb_test_no_output "set print elements 4" | |
274 | gdb_test_sequence "x/9s &TestStrings" "take 9 strings forward" { | |
275 | "\"ABCD\"\.\.\." | |
276 | "\"EFGH\"\.\.\." | |
277 | "\"IJKL\"\.\.\." | |
278 | "\"MNOP\"\.\.\." | |
279 | "\"QRST\"\.\.\." | |
280 | "\"UVWX\"\.\.\." | |
281 | "\"YZ\"" | |
282 | "\"\"" | |
283 | "\"\"" | |
284 | } | |
285 | gdb_test "x/-xb" "0x00" "take 1 byte backward" | |
286 | gdb_test_sequence "x/-4s" "take 4 strings backward (1/2)" { | |
287 | "\"TUVW\"\.\.\." | |
288 | "\"XYZ\"" | |
289 | "\"\"" | |
290 | "\"\"" | |
291 | } | |
292 | gdb_test_sequence "x/-4s" "take 4 strings backward (2/2)" { | |
293 | "\"CDEF\"\.\.\." | |
294 | "\"GHIJ\"\.\.\." | |
295 | "\"KLMN\"\.\.\." | |
296 | "\"OPQR\"\.\.\." | |
297 | } | |
298 | } | |
299 | ||
300 | with_test_prefix "backward disassemble general" { | |
301 | set length_to_examine {1 2 3 4 10} | |
302 | set disassmbly {} | |
303 | ||
304 | gdb_test "x/i main" "0x\[0-9a-fA-F\]+ <main>:\t.*" \ | |
305 | "move the current position to main (x/i)" | |
306 | gdb_test "x/-i" "0x\[0-9a-fA-F\]+ <main>:\t.*" \ | |
307 | "move the current position to main (x/-i)" | |
308 | for {set i 0} {$i < [llength $length_to_examine]} {incr i} { | |
309 | set len [lindex $length_to_examine $i] | |
310 | set instructions [capture_command_output "x/${len}i" ""] | |
311 | lappend disassmbly $instructions | |
312 | } | |
313 | for {set i 0} {$i < [llength $length_to_examine]} {incr i} { | |
314 | set idx [expr [llength $length_to_examine] - $i - 1] | |
315 | set len [lindex $length_to_examine $idx] | |
316 | set actual [capture_command_output "x/-${len}i" ""] | |
317 | set expected [lindex $disassmbly $idx] | |
318 | if {$actual == $expected} { | |
319 | pass "inst:$idx" | |
320 | } else { | |
321 | fail "inst:$idx" | |
322 | } | |
323 | } | |
324 | } |