Remove superfluous semicolons from testsuite throughout.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / memattr.exp
1 # Copyright 2011-2013 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 # This file is part of the gdb testsuite
17
18 # Test the memory attribute commands.
19
20 set testfile "memattr"
21 set srcfile ${testfile}.c
22
23 if { [prepare_for_testing $testfile.exp $testfile $srcfile] } {
24 return -1
25 }
26
27 runto main
28
29 set mem1start -1
30 set mem2start -1
31 set mem3start -1
32 set mem4start -1
33 set mem5start -1
34
35 set mem1end -1
36 set mem2end -1
37 set mem3end -1
38 set mem4end -1
39 set mem5end -1
40
41
42 gdb_test_multiple "info address mem1" "get address of mem1" {
43 -re "Symbol \"mem1\" is static storage at address ($hex).*$gdb_prompt $" {
44 set mem1start $expect_out(1,string)
45 }
46 }
47
48 gdb_test_multiple "info address mem2" "get address of mem2" {
49 -re "Symbol \"mem2\" is static storage at address ($hex).*$gdb_prompt $" {
50 set mem2start $expect_out(1,string)
51 }
52 }
53
54 gdb_test_multiple "info address mem3" "get address of mem3" {
55 -re "Symbol \"mem3\" is static storage at address ($hex).*$gdb_prompt $" {
56 set mem3start $expect_out(1,string)
57 }
58 }
59
60 gdb_test_multiple "info address mem4" "get address of mem4" {
61 -re "Symbol \"mem4\" is static storage at address ($hex).*$gdb_prompt $" {
62 set mem4start $expect_out(1,string)
63 }
64 }
65
66 gdb_test_multiple "info address mem5" "get address of mem5" {
67 -re "Symbol \"mem5\" is static storage at address ($hex).*$gdb_prompt $" {
68 set mem5start $expect_out(1,string)
69 }
70 }
71
72 gdb_test_multiple "print &mem1\[64\]" "get end of mem1" {
73 -re "$decimal = .* ($hex).*$gdb_prompt $" {
74 set mem1end $expect_out(1,string)
75 }
76 }
77
78 gdb_test_multiple "print &mem2\[64\]" "get end of mem2" {
79 -re "$decimal = .* ($hex).*$gdb_prompt $" {
80 set mem2end $expect_out(1,string)
81 }
82 }
83
84 gdb_test_multiple "print &mem3\[64\]" "get end of mem3" {
85 -re "$decimal = .* ($hex).*$gdb_prompt $" {
86 set mem3end $expect_out(1,string)
87 }
88 }
89
90 gdb_test_multiple "print &mem4\[64\]" "get end of mem4" {
91 -re "$decimal = .* ($hex).*$gdb_prompt $" {
92 set mem4end $expect_out(1,string)
93 }
94 }
95
96 gdb_test_multiple "print &mem5\[64\]" "get end of mem5" {
97 -re "$decimal = .* ($hex).*$gdb_prompt $" {
98 set mem5end $expect_out(1,string)
99 }
100 }
101
102 gdb_test_no_output "mem $mem1start $mem1end wo" "create mem region 1"
103 gdb_test_no_output "mem $mem2start $mem2end ro" "create mem region 2"
104 gdb_test_no_output "mem $mem3start $mem3end rw" "create mem region 3"
105 gdb_test_no_output "mem $mem4start $mem4end rw" "create mem region 4"
106 gdb_test_no_output "mem $mem5start $mem5end rw" "create mem region 5"
107
108 set see1 0
109 set see2 0
110 set see3 0
111 set see4 0
112 set see5 0
113
114 gdb_test_multiple "info mem" "info mem(1)" {
115 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
116 set see1 1
117 exp_continue
118 }
119 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
120 set see2 1
121 exp_continue
122 }
123 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
124 set see3 1
125 exp_continue
126 }
127 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
128 set see4 1
129 exp_continue
130 }
131 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
132 set see5 1
133 exp_continue
134 }
135 -re "$gdb_prompt $" {
136 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
137 pass "info mem (1)"
138 } else {
139 fail "info mem (1)"
140 }
141 }
142 }
143
144 #
145 # Test read-only, write-only
146 #
147
148 # mem1 is write only: read should fail.
149 gdb_test "print mem1\[1\]" \
150 "Cannot access memory at address $hex" \
151 "mem1 cannot be read"
152
153 gdb_test "print mem1\[1\] = 9" \
154 "$decimal = 9" \
155 "mem1 can be written"
156
157 # mem2 is read only: write should fail.
158 gdb_test "print mem2\[1\] = 9" \
159 "Cannot access memory at address $hex" \
160 "mem2 cannot be written"
161
162 gdb_test "print mem2\[1\]" \
163 "$decimal = 0" \
164 "mem2 can be read"
165
166 #
167 # Test disable and enable
168 #
169
170 gdb_test_no_output "disable mem 1" "disable mem 1"
171 gdb_test "info mem" "1 n .*" "mem 1 was disabled"
172
173 gdb_test_no_output "enable mem 1" "enable mem 1"
174 gdb_test "info mem" "1 y .*" "mem 1 was enabled"
175
176 gdb_test_no_output "disable mem 2 4"
177
178 set see1 0
179 set see2 0
180 set see3 0
181 set see4 0
182 set see5 0
183
184 gdb_test_multiple "info mem" "mem 2 and 4 were disabled" {
185 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
186 set see1 1
187 exp_continue
188 }
189 -re "2 n \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
190 set see2 1
191 exp_continue
192 }
193 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
194 set see3 1
195 exp_continue
196 }
197 -re "4 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
198 set see4 1
199 exp_continue
200 }
201 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
202 set see5 1
203 exp_continue
204 }
205 -re "$gdb_prompt $" {
206 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
207 pass "mem 2 and 4 were disabled"
208 } else {
209 fail "mem 2 and 4 were disabled"
210 }
211 }
212 }
213
214 gdb_test_no_output "enable mem 2-4" "enable mem 2-4"
215
216 set see1 0
217 set see2 0
218 set see3 0
219 set see4 0
220 set see5 0
221
222 gdb_test_multiple "info mem" "mem 2-4 were enabled" {
223 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
224 set see1 1
225 exp_continue
226 }
227 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
228 set see2 1
229 exp_continue
230 }
231 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
232 set see3 1
233 exp_continue
234 }
235 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
236 set see4 1
237 exp_continue
238 }
239 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
240 set see5 1
241 exp_continue
242 }
243 -re "$gdb_prompt $" {
244 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
245 pass "mem 2-4 were enabled"
246 } else {
247 fail "mem 2-4 were enabled"
248 }
249 }
250 }
251
252 gdb_test_no_output "disable mem" "disable mem"
253
254 set see1 0
255 set see2 0
256 set see3 0
257 set see4 0
258 set see5 0
259
260 gdb_test_multiple "info mem" "mem 1 to 5 were disabled" {
261 -re "1 n \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
262 set see1 1
263 exp_continue
264 }
265 -re "2 n \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
266 set see2 1
267 exp_continue
268 }
269 -re "3 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
270 set see3 1
271 exp_continue
272 }
273 -re "4 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
274 set see4 1
275 exp_continue
276 }
277 -re "5 n \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
278 set see5 1
279 exp_continue
280 }
281 -re "$gdb_prompt $" {
282 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
283 pass "mem 1 to 5 were disabled"
284 } else {
285 fail "mem 1 to 5 were disabled"
286 }
287 }
288 }
289
290 gdb_test_no_output "enable mem" "enable mem"
291
292 set see1 0
293 set see2 0
294 set see3 0
295 set see4 0
296 set see5 0
297
298 gdb_test_multiple "info mem" "mem 1 to 5 were enabled" {
299 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
300 set see1 1
301 exp_continue
302 }
303 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
304 set see2 1
305 exp_continue
306 }
307 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
308 set see3 1
309 exp_continue
310 }
311 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
312 set see4 1
313 exp_continue
314 }
315 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
316 set see5 1
317 exp_continue
318 }
319 -re "$gdb_prompt $" {
320 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
321 pass "mem 1 to 5 were enabled"
322 } else {
323 fail "mem 1 to 5 were enabled"
324 }
325 }
326 }
327
328 gdb_test "disable mem 7 8" \
329 "No memory region number 7.*No memory region number 8." \
330 "disable non-existant regions"
331
332 #
333 # Test delete
334 #
335
336 set see1 0
337 set see2 0
338 set see3 0
339 set see4 0
340 set see5 0
341
342 gdb_test_no_output "delete mem 1" "delete mem 1"
343 gdb_test_multiple "info mem" "mem 1 was deleted" {
344 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
345 set see1 1
346 exp_continue
347 }
348 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
349 set see2 1
350 exp_continue
351 }
352 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
353 set see3 1
354 exp_continue
355 }
356 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
357 set see4 1
358 exp_continue
359 }
360 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
361 set see5 1
362 exp_continue
363 }
364 -re "$gdb_prompt $" {
365 if { !$see1 && $see2 && $see3 && $see4 && $see5 } then {
366 pass "mem 1 was deleted"
367 } else {
368 fail "mem 1 was deleted"
369 }
370 }
371 }
372
373 set see1 0
374 set see2 0
375 set see3 0
376 set see4 0
377 set see5 0
378
379 gdb_test_no_output "delete mem 2 4" "delete mem 2 4"
380 gdb_test_multiple "info mem" "mem 2 and 4 were deleted" {
381 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
382 set see1 1
383 exp_continue
384 }
385 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
386 set see2 1
387 exp_continue
388 }
389 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
390 set see3 1
391 exp_continue
392 }
393 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
394 set see4 1
395 exp_continue
396 }
397 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
398 set see5 1
399 exp_continue
400 }
401 -re "$gdb_prompt $" {
402 if { !$see1 && !$see2 && $see3 && !$see4 && $see5 } then {
403 pass "mem 2 and 4 were deleted"
404 } else {
405 fail "mem 2 and 4 were deleted"
406 }
407 }
408 }
409
410 set see1 0
411 set see2 0
412 set see3 0
413 set see4 0
414 set see5 0
415
416 gdb_test "delete mem 2-4" \
417 "No memory region number 2.*No memory region number 4." \
418 "delete mem 2-4"
419 gdb_test_multiple "info mem" "mem 2-4 were deleted" {
420 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
421 set see1 1
422 exp_continue
423 }
424 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
425 set see2 1
426 exp_continue
427 }
428 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
429 set see3 1
430 exp_continue
431 }
432 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
433 set see4 1
434 exp_continue
435 }
436 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
437 set see5 1
438 exp_continue
439 }
440 -re "$gdb_prompt $" {
441 if { !$see1 && !$see2 && !$see3 && !$see4 && $see5 } then {
442 pass "mem 2-4 were deleted"
443 } else {
444 fail "mem 2-4 were deleted"
445 }
446 }
447 }
448
449 gdb_test "delete mem 8" "No memory region number 8." \
450 "delete non-existant region"
451
452 #
453 # Test overlapping checking
454 #
455
456 proc delete_memory {} {
457 global gdb_prompt
458
459 gdb_test_multiple "delete mem" "delete mem" {
460 -re "Delete all memory regions.*y or n.*$" {
461 send_gdb "y\n"
462 exp_continue
463 }
464 -re "$gdb_prompt $" { }
465 }
466 }
467
468 # Create a region that doesn't overlap (a PASS in the table).
469
470 proc region_pass { region } {
471 gdb_test_no_output "mem $region ro" "$region: no-overlap"
472 }
473
474 # Try to create a region that overlaps (a FAIL in the table).
475
476 proc region_fail { region } {
477 gdb_test "mem $region ro" "overlapping memory region" "$region: overlap"
478 }
479
480 # Test normal case (upper != 0)
481 #
482 # lo' hi'
483 # |--------|
484 # 10 20 30 40 50 60 70 80 90
485 # |-----| FAIL
486 # |--| FAIL
487 # |--| FAIL
488 # |--| FAIL
489 # |-----| FAIL
490 # |--------| FAIL
491 # |--------------| FAIL
492 # |--------------------- FAIL
493 # |------------------ FAIL
494 # |--------------- FAIL
495 # |--| PASS
496 # |--| PASS
497 # |--- PASS
498
499 delete_memory
500 gdb_test_no_output "mem 0x30 0x60 ro"
501 with_test_prefix "0x30 0x60" {
502 region_fail "0x20 0x40"
503 region_fail "0x30 0x40"
504 region_fail "0x40 0x50"
505 region_fail "0x50 0x60"
506 region_fail "0x50 0x70"
507 region_fail "0x30 0x60"
508 region_fail "0x20 0x70"
509 region_fail "0x20 0x0"
510 region_fail "0x30 0x0"
511 region_fail "0x40 0x0"
512 region_pass "0x20 0x30"
513 region_pass "0x60 0x70"
514 region_pass "0x80 0x0"
515 }
516
517 # Test special case (upper == 0)
518 #
519 # lo' hi'
520 # |---------------
521 # 00 10 20 30 40 50 60 70 80
522 # |--------| FAIL
523 # |-----| FAIL
524 # |--| FAIL
525 # |------------------ FAIL
526 # |--------------- FAIL
527 # |------------ FAIL
528 # |--| PASS
529 # |--| PASS
530
531 delete_memory
532 gdb_test_no_output "mem 0x30 0x0 ro"
533 with_test_prefix "0x30 0x0" {
534 region_fail "0x20 0x50"
535 region_fail "0x30 0x50"
536 region_fail "0x40 0x50"
537 region_fail "0x20 0x0"
538 region_fail "0x30 0x0"
539 region_fail "0x40 0x0"
540 region_pass "0x20 0x30"
541 region_pass "0x00 0x10"
542 }
This page took 0.0465140000000001 seconds and 5 git commands to generate.