1 # Copyright 2011-2013 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.
20 set testfile "memattr"
21 set srcfile ${testfile}.c
23 if { [prepare_for_testing $testfile.exp $testfile $srcfile] } {
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)
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)
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)
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)
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)
72 gdb_test_multiple "print &mem1\[64\]" "get end of mem1" {
73 -re "$decimal = .* ($hex).*$gdb_prompt $" {
74 set mem1end $expect_out(1,string)
78 gdb_test_multiple "print &mem2\[64\]" "get end of mem2" {
79 -re "$decimal = .* ($hex).*$gdb_prompt $" {
80 set mem2end $expect_out(1,string)
84 gdb_test_multiple "print &mem3\[64\]" "get end of mem3" {
85 -re "$decimal = .* ($hex).*$gdb_prompt $" {
86 set mem3end $expect_out(1,string)
90 gdb_test_multiple "print &mem4\[64\]" "get end of mem4" {
91 -re "$decimal = .* ($hex).*$gdb_prompt $" {
92 set mem4end $expect_out(1,string)
96 gdb_test_multiple "print &mem5\[64\]" "get end of mem5" {
97 -re "$decimal = .* ($hex).*$gdb_prompt $" {
98 set mem5end $expect_out(1,string)
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"
114 gdb_test_multiple "info mem" "info mem(1)" {
115 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
119 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
123 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
127 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
131 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
135 -re "$gdb_prompt $" {
136 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
145 # Test read-only, write-only
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"
153 gdb_test "print mem1\[1\] = 9" \
155 "mem1 can be written"
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"
162 gdb_test "print mem2\[1\]" \
167 # Test disable and enable
170 gdb_test_no_output "disable mem 1" "disable mem 1"
171 gdb_test "info mem" "1 n .*" "mem 1 was disabled"
173 gdb_test_no_output "enable mem 1" "enable mem 1"
174 gdb_test "info mem" "1 y .*" "mem 1 was enabled"
176 gdb_test_no_output "disable mem 2 4"
184 gdb_test_multiple "info mem" "mem 2 and 4 were disabled" {
185 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
189 -re "2 n \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
193 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
197 -re "4 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
201 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
205 -re "$gdb_prompt $" {
206 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
207 pass "mem 2 and 4 were disabled"
209 fail "mem 2 and 4 were disabled"
214 gdb_test_no_output "enable mem 2-4" "enable mem 2-4"
222 gdb_test_multiple "info mem" "mem 2-4 were enabled" {
223 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
227 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
231 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
235 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
239 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
243 -re "$gdb_prompt $" {
244 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
245 pass "mem 2-4 were enabled"
247 fail "mem 2-4 were enabled"
252 gdb_test_no_output "disable mem" "disable mem"
260 gdb_test_multiple "info mem" "mem 1 to 5 were disabled" {
261 -re "1 n \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
265 -re "2 n \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
269 -re "3 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
273 -re "4 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
277 -re "5 n \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
281 -re "$gdb_prompt $" {
282 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
283 pass "mem 1 to 5 were disabled"
285 fail "mem 1 to 5 were disabled"
290 gdb_test_no_output "enable mem" "enable mem"
298 gdb_test_multiple "info mem" "mem 1 to 5 were enabled" {
299 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
303 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
307 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
311 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
315 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
319 -re "$gdb_prompt $" {
320 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
321 pass "mem 1 to 5 were enabled"
323 fail "mem 1 to 5 were enabled"
328 gdb_test "disable mem 7 8" \
329 "No memory region number 7.*No memory region number 8." \
330 "disable non-existant regions"
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\]*" {
348 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
352 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
356 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
360 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
364 -re "$gdb_prompt $" {
365 if { !$see1 && $see2 && $see3 && $see4 && $see5 } then {
366 pass "mem 1 was deleted"
368 fail "mem 1 was deleted"
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\]*" {
385 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
389 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
393 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
397 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
401 -re "$gdb_prompt $" {
402 if { !$see1 && !$see2 && $see3 && !$see4 && $see5 } then {
403 pass "mem 2 and 4 were deleted"
405 fail "mem 2 and 4 were deleted"
416 gdb_test "delete mem 2-4" \
417 "No memory region number 2.*No memory region number 4." \
419 gdb_test_multiple "info mem" "mem 2-4 were deleted" {
420 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
424 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
428 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
432 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
436 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
440 -re "$gdb_prompt $" {
441 if { !$see1 && !$see2 && !$see3 && !$see4 && $see5 } then {
442 pass "mem 2-4 were deleted"
444 fail "mem 2-4 were deleted"
449 gdb_test "delete mem 8" "No memory region number 8." \
450 "delete non-existant region"
453 # Test overlapping checking
456 proc delete_memory {} {
459 gdb_test_multiple "delete mem" "delete mem" {
460 -re "Delete all memory regions.*y or n.*$" {
464 -re "$gdb_prompt $" { }
468 # Create a region that doesn't overlap (a PASS in the table).
470 proc region_pass { region } {
471 gdb_test_no_output "mem $region ro" "$region: no-overlap"
474 # Try to create a region that overlaps (a FAIL in the table).
476 proc region_fail { region } {
477 gdb_test "mem $region ro" "overlapping memory region" "$region: overlap"
480 # Test normal case (upper != 0)
484 # 10 20 30 40 50 60 70 80 90
491 # |--------------| FAIL
492 # |--------------------- FAIL
493 # |------------------ FAIL
494 # |--------------- FAIL
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"
517 # Test special case (upper == 0)
521 # 00 10 20 30 40 50 60 70 80
525 # |------------------ FAIL
526 # |--------------- FAIL
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"