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