1 # Copyright 2011-2014 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file is part of the gdb testsuite
18 # Test the memory attribute commands.
22 if { [prepare_for_testing $testfile.exp $testfile $srcfile] } {
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)
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)
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)
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)
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)
71 gdb_test_multiple "print &mem1\[64\]" "get end of mem1" {
72 -re "$decimal = .* ($hex).*$gdb_prompt $" {
73 set mem1end $expect_out(1,string)
77 gdb_test_multiple "print &mem2\[64\]" "get end of mem2" {
78 -re "$decimal = .* ($hex).*$gdb_prompt $" {
79 set mem2end $expect_out(1,string)
83 gdb_test_multiple "print &mem3\[64\]" "get end of mem3" {
84 -re "$decimal = .* ($hex).*$gdb_prompt $" {
85 set mem3end $expect_out(1,string)
89 gdb_test_multiple "print &mem4\[64\]" "get end of mem4" {
90 -re "$decimal = .* ($hex).*$gdb_prompt $" {
91 set mem4end $expect_out(1,string)
95 gdb_test_multiple "print &mem5\[64\]" "get end of mem5" {
96 -re "$decimal = .* ($hex).*$gdb_prompt $" {
97 set mem5end $expect_out(1,string)
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"
113 gdb_test_multiple "info mem" "info mem(1)" {
114 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
118 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
122 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
126 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
130 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
134 -re "$gdb_prompt $" {
135 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
144 # Test read-only, write-only
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"
152 gdb_test "print mem1\[1\] = 9" \
154 "mem1 can be written"
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"
161 gdb_test "print mem2\[1\]" \
166 # Test disable and enable
169 gdb_test_no_output "disable mem 1" "disable mem 1"
170 gdb_test "info mem" "1 n .*" "mem 1 was disabled"
172 gdb_test_no_output "enable mem 1" "enable mem 1"
173 gdb_test "info mem" "1 y .*" "mem 1 was enabled"
175 gdb_test_no_output "disable mem 2 4"
183 gdb_test_multiple "info mem" "mem 2 and 4 were disabled" {
184 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
188 -re "2 n \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
192 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
196 -re "4 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
200 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
204 -re "$gdb_prompt $" {
205 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
206 pass "mem 2 and 4 were disabled"
208 fail "mem 2 and 4 were disabled"
213 gdb_test_no_output "enable mem 2-4" "enable mem 2-4"
221 gdb_test_multiple "info mem" "mem 2-4 were enabled" {
222 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
226 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
230 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
234 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
238 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
242 -re "$gdb_prompt $" {
243 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
244 pass "mem 2-4 were enabled"
246 fail "mem 2-4 were enabled"
251 gdb_test_no_output "disable mem" "disable mem"
259 gdb_test_multiple "info mem" "mem 1 to 5 were disabled" {
260 -re "1 n \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
264 -re "2 n \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
268 -re "3 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
272 -re "4 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
276 -re "5 n \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
280 -re "$gdb_prompt $" {
281 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
282 pass "mem 1 to 5 were disabled"
284 fail "mem 1 to 5 were disabled"
289 gdb_test_no_output "enable mem" "enable mem"
297 gdb_test_multiple "info mem" "mem 1 to 5 were enabled" {
298 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
302 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
306 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
310 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
314 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
318 -re "$gdb_prompt $" {
319 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
320 pass "mem 1 to 5 were enabled"
322 fail "mem 1 to 5 were enabled"
327 gdb_test "disable mem 7 8" \
328 "No memory region number 7.*No memory region number 8." \
329 "disable non-existant regions"
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\]*" {
347 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
351 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
355 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
359 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
363 -re "$gdb_prompt $" {
364 if { !$see1 && $see2 && $see3 && $see4 && $see5 } then {
365 pass "mem 1 was deleted"
367 fail "mem 1 was deleted"
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\]*" {
384 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
388 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
392 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
396 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
400 -re "$gdb_prompt $" {
401 if { !$see1 && !$see2 && $see3 && !$see4 && $see5 } then {
402 pass "mem 2 and 4 were deleted"
404 fail "mem 2 and 4 were deleted"
415 gdb_test "delete mem 2-4" \
416 "No memory region number 2.*No memory region number 4." \
418 gdb_test_multiple "info mem" "mem 2-4 were deleted" {
419 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
423 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
427 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
431 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
435 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
439 -re "$gdb_prompt $" {
440 if { !$see1 && !$see2 && !$see3 && !$see4 && $see5 } then {
441 pass "mem 2-4 were deleted"
443 fail "mem 2-4 were deleted"
448 gdb_test "delete mem 8" "No memory region number 8." \
449 "delete non-existant region"
452 # Test overlapping checking
455 proc delete_memory {} {
458 gdb_test_multiple "delete mem" "delete mem" {
459 -re "Delete all memory regions.*y or n.*$" {
463 -re "$gdb_prompt $" { }
467 # Create a region that doesn't overlap (a PASS in the table).
469 proc region_pass { region } {
470 gdb_test_no_output "mem $region ro" "$region: no-overlap"
473 # Try to create a region that overlaps (a FAIL in the table).
475 proc region_fail { region } {
476 gdb_test "mem $region ro" "overlapping memory region" "$region: overlap"
479 # Test normal case (upper != 0)
483 # 10 20 30 40 50 60 70 80 90
490 # |--------------| FAIL
491 # |--------------------- FAIL
492 # |------------------ FAIL
493 # |--------------- FAIL
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"
516 # Test special case (upper == 0)
520 # 00 10 20 30 40 50 60 70 80
524 # |------------------ FAIL
525 # |--------------- FAIL
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"