1 # Copyright 2011-2016 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 set info_mem_header_pattern \
114 "info mem.*Num\[ \t\]+Enb\[ \t\]+Low\[ \t\]+Addr\[ \t\]+High\[ \t\]+Addr\[ \t\]+Attrs\[^\n\r]*.."
116 gdb_test_multiple "info mem" "info mem(1)" {
117 -re ${info_mem_header_pattern} {
118 # Discard the header.
121 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
125 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
129 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
133 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
137 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
141 -re "$gdb_prompt $" {
142 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
151 # Test read-only, write-only
154 # mem1 is write only: read should fail.
155 gdb_test "print mem1\[1\]" \
156 "Cannot access memory at address $hex" \
157 "mem1 cannot be read"
159 gdb_test "print mem1\[1\] = 9" \
161 "mem1 can be written"
163 # mem2 is read only: write should fail.
164 gdb_test "print mem2\[1\] = 9" \
165 "Cannot access memory at address $hex" \
166 "mem2 cannot be written"
168 gdb_test "print mem2\[1\]" \
173 # Test disable and enable
176 gdb_test_no_output "disable mem 1" "disable mem 1"
177 gdb_test "info mem" "1 n .*" "mem 1 was disabled"
179 gdb_test_no_output "enable mem 1" "enable mem 1"
180 gdb_test "info mem" "1 y .*" "mem 1 was enabled"
182 gdb_test_no_output "disable mem 2 4"
190 gdb_test_multiple "info mem" "mem 2 and 4 were disabled" {
191 -re ${info_mem_header_pattern} {
192 # Discard the header.
195 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
199 -re "^2 n \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
203 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
207 -re "^4 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
211 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
215 -re "$gdb_prompt $" {
216 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
217 pass "mem 2 and 4 were disabled"
219 fail "mem 2 and 4 were disabled"
224 gdb_test_no_output "enable mem 2-4" "enable mem 2-4"
232 gdb_test_multiple "info mem" "mem 2-4 were enabled" {
233 -re ${info_mem_header_pattern} {
234 # Discard the header.
237 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
241 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
245 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
249 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
253 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
257 -re "$gdb_prompt $" {
258 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
259 pass "mem 2-4 were enabled"
261 fail "mem 2-4 were enabled"
266 gdb_test_no_output "disable mem" "disable mem"
274 gdb_test_multiple "info mem" "mem 1 to 5 were disabled" {
275 -re ${info_mem_header_pattern} {
276 # Discard the header.
279 -re "^1 n \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
283 -re "^2 n \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
287 -re "^3 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
291 -re "^4 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
295 -re "^5 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
299 -re "$gdb_prompt $" {
300 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
301 pass "mem 1 to 5 were disabled"
303 fail "mem 1 to 5 were disabled"
308 gdb_test_no_output "enable mem" "enable mem"
316 gdb_test_multiple "info mem" "mem 1 to 5 were enabled" {
317 -re ${info_mem_header_pattern} {
318 # Discard the header.
321 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
325 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
329 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
333 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
337 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
341 -re "$gdb_prompt $" {
342 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
343 pass "mem 1 to 5 were enabled"
345 fail "mem 1 to 5 were enabled"
350 gdb_test "disable mem 7 8" \
351 "No memory region number 7.*No memory region number 8." \
352 "disable non-existant regions"
364 gdb_test_no_output "delete mem 1" "delete mem 1"
365 gdb_test_multiple "info mem" "mem 1 was deleted" {
366 -re ${info_mem_header_pattern} {
367 # Discard the header.
370 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
374 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
378 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
382 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
386 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
390 -re "$gdb_prompt $" {
391 if { !$see1 && $see2 && $see3 && $see4 && $see5 } then {
392 pass "mem 1 was deleted"
394 fail "mem 1 was deleted"
405 gdb_test_no_output "delete mem 2 4" "delete mem 2 4"
406 gdb_test_multiple "info mem" "mem 2 and 4 were deleted" {
407 -re ${info_mem_header_pattern} {
408 # Discard the header.
411 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
415 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
419 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
423 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
427 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
431 -re "$gdb_prompt $" {
432 if { !$see1 && !$see2 && $see3 && !$see4 && $see5 } then {
433 pass "mem 2 and 4 were deleted"
435 fail "mem 2 and 4 were deleted"
446 gdb_test "delete mem 2-4" \
447 "No memory region number 2.*No memory region number 4." \
449 gdb_test_multiple "info mem" "mem 2-4 were deleted" {
450 -re ${info_mem_header_pattern} {
451 # Discard the header.
454 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
458 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
462 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
466 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
470 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
474 -re "$gdb_prompt $" {
475 if { !$see1 && !$see2 && !$see3 && !$see4 && $see5 } then {
476 pass "mem 2-4 were deleted"
478 fail "mem 2-4 were deleted"
483 gdb_test "delete mem 8" "No memory region number 8." \
484 "delete non-existant region"
487 # Test overlapping checking
490 proc delete_memory {} {
493 gdb_test_multiple "delete mem" "delete mem" {
494 -re "Delete all memory regions.*y or n.*$" {
498 -re "$gdb_prompt $" { }
502 # Create a region that doesn't overlap (a PASS in the table).
504 proc region_pass { region } {
505 gdb_test_no_output "mem $region ro" "$region: no-overlap"
508 # Try to create a region that overlaps (a FAIL in the table).
510 proc region_fail { region } {
511 gdb_test "mem $region ro" "overlapping memory region" "$region: overlap"
514 # Test normal case (upper != 0)
518 # 10 20 30 40 50 60 70 80 90
525 # |--------------| FAIL
526 # |--------------------- FAIL
527 # |------------------ FAIL
528 # |--------------- FAIL
534 gdb_test_no_output "mem 0x30 0x60 ro"
535 with_test_prefix "0x30 0x60" {
536 region_fail "0x20 0x40"
537 region_fail "0x30 0x40"
538 region_fail "0x40 0x50"
539 region_fail "0x50 0x60"
540 region_fail "0x50 0x70"
541 region_fail "0x30 0x60"
542 region_fail "0x20 0x70"
543 region_fail "0x20 0x0"
544 region_fail "0x30 0x0"
545 region_fail "0x40 0x0"
546 region_pass "0x20 0x30"
547 region_pass "0x60 0x70"
548 region_pass "0x80 0x0"
551 # Test special case (upper == 0)
555 # 00 10 20 30 40 50 60 70 80
559 # |------------------ FAIL
560 # |--------------- FAIL
566 gdb_test_no_output "mem 0x30 0x0 ro"
567 with_test_prefix "0x30 0x0" {
568 region_fail "0x20 0x50"
569 region_fail "0x30 0x50"
570 region_fail "0x40 0x50"
571 region_fail "0x20 0x0"
572 region_fail "0x30 0x0"
573 region_fail "0x40 0x0"
574 region_pass "0x20 0x30"
575 region_pass "0x00 0x10"