1 # Copyright 2011-2024 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 "failed to prepare" $testfile $srcfile] } {
28 # Delete all target-supplied memory regions.
44 gdb_test_multiple "info address mem1" "get address of mem1" {
45 -re "Symbol \"mem1\" is static storage at address ($hex).*$gdb_prompt $" {
46 set mem1start $expect_out(1,string)
50 gdb_test_multiple "info address mem2" "get address of mem2" {
51 -re "Symbol \"mem2\" is static storage at address ($hex).*$gdb_prompt $" {
52 set mem2start $expect_out(1,string)
56 gdb_test_multiple "info address mem3" "get address of mem3" {
57 -re "Symbol \"mem3\" is static storage at address ($hex).*$gdb_prompt $" {
58 set mem3start $expect_out(1,string)
62 gdb_test_multiple "info address mem4" "get address of mem4" {
63 -re "Symbol \"mem4\" is static storage at address ($hex).*$gdb_prompt $" {
64 set mem4start $expect_out(1,string)
68 gdb_test_multiple "info address mem5" "get address of mem5" {
69 -re "Symbol \"mem5\" is static storage at address ($hex).*$gdb_prompt $" {
70 set mem5start $expect_out(1,string)
74 gdb_test_multiple "print &mem1\[64\]" "get end of mem1" {
75 -re "$decimal = .* ($hex).*$gdb_prompt $" {
76 set mem1end $expect_out(1,string)
80 gdb_test_multiple "print &mem2\[64\]" "get end of mem2" {
81 -re "$decimal = .* ($hex).*$gdb_prompt $" {
82 set mem2end $expect_out(1,string)
86 gdb_test_multiple "print &mem3\[64\]" "get end of mem3" {
87 -re "$decimal = .* ($hex).*$gdb_prompt $" {
88 set mem3end $expect_out(1,string)
92 gdb_test_multiple "print &mem4\[64\]" "get end of mem4" {
93 -re "$decimal = .* ($hex).*$gdb_prompt $" {
94 set mem4end $expect_out(1,string)
98 gdb_test_multiple "print &mem5\[64\]" "get end of mem5" {
99 -re "$decimal = .* ($hex).*$gdb_prompt $" {
100 set mem5end $expect_out(1,string)
104 gdb_test_no_output "mem $mem1start $mem1end wo" "create mem region 1"
105 gdb_test_no_output "mem $mem2start $mem2end ro" "create mem region 2"
106 gdb_test_no_output "mem $mem3start $mem3end rw" "create mem region 3"
107 gdb_test_no_output "mem $mem4start $mem4end rw" "create mem region 4"
108 gdb_test_no_output "mem $mem5start $mem5end rw" "create mem region 5"
116 set info_mem_header_pattern \
117 "info mem.*Num\[ \t\]+Enb\[ \t\]+Low\[ \t\]+Addr\[ \t\]+High\[ \t\]+Addr\[ \t\]+Attrs\[^\r\n\]*\r\n"
119 gdb_test_multiple "info mem" "info mem(1)" {
120 -re ${info_mem_header_pattern} {
121 # Discard the header.
124 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*\r\n" {
128 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*\r\n" {
132 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*\r\n" {
136 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*\r\n" {
140 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*\r\n" {
144 -re "$gdb_prompt $" {
145 if {$see1 && $see2 && $see3 && $see4 && $see5} {
154 # Test read-only, write-only
157 # mem1 is write only: read should fail.
158 gdb_test "print mem1\[1\]" \
159 "Cannot access memory at address $hex" \
160 "mem1 cannot be read"
162 gdb_test "print mem1\[1\] = 9" \
164 "mem1 can be written"
166 # mem2 is read only: write should fail.
167 gdb_test "print mem2\[1\] = 9" \
168 "Cannot access memory at address $hex" \
169 "mem2 cannot be written"
171 gdb_test "print mem2\[1\]" \
176 # Test disable and enable
179 gdb_test_no_output "disable mem 1" "disable mem 1"
180 gdb_test "info mem" "1 n .*" "mem 1 was disabled"
182 gdb_test_no_output "enable mem 1" "enable mem 1"
183 gdb_test "info mem" "1 y .*" "mem 1 was enabled"
185 gdb_test_no_output "disable mem 2 4"
193 gdb_test_multiple "info mem" "mem 2 and 4 were disabled" {
194 -re ${info_mem_header_pattern} {
195 # Discard the header.
198 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
202 -re "^2 n \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
206 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
210 -re "^4 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
214 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
218 -re "$gdb_prompt $" {
219 if {$see1 && $see2 && $see3 && $see4 && $see5} {
220 pass "mem 2 and 4 were disabled"
222 fail "mem 2 and 4 were disabled"
227 gdb_test_no_output "enable mem 2-4" "enable mem 2-4"
235 gdb_test_multiple "info mem" "mem 2-4 were enabled" {
236 -re ${info_mem_header_pattern} {
237 # Discard the header.
240 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
244 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
248 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
252 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
256 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
260 -re "$gdb_prompt $" {
261 if {$see1 && $see2 && $see3 && $see4 && $see5} {
262 pass "mem 2-4 were enabled"
264 fail "mem 2-4 were enabled"
269 gdb_test_no_output "disable mem" "disable mem"
277 gdb_test_multiple "info mem" "mem 1 to 5 were disabled" {
278 -re ${info_mem_header_pattern} {
279 # Discard the header.
282 -re "^1 n \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
286 -re "^2 n \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
290 -re "^3 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
294 -re "^4 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
298 -re "^5 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
302 -re "$gdb_prompt $" {
303 if {$see1 && $see2 && $see3 && $see4 && $see5} {
304 pass "mem 1 to 5 were disabled"
306 fail "mem 1 to 5 were disabled"
311 gdb_test_no_output "enable mem" "enable mem"
319 gdb_test_multiple "info mem" "mem 1 to 5 were enabled" {
320 -re ${info_mem_header_pattern} {
321 # Discard the header.
324 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
328 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
332 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
336 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
340 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
344 -re "$gdb_prompt $" {
345 if {$see1 && $see2 && $see3 && $see4 && $see5} {
346 pass "mem 1 to 5 were enabled"
348 fail "mem 1 to 5 were enabled"
353 gdb_test "disable mem 7 8" \
354 "No memory region number 7.*No memory region number 8." \
355 "disable non-existant regions"
367 gdb_test_no_output "delete mem 1" "delete mem 1"
368 gdb_test_multiple "info mem" "mem 1 was deleted" {
369 -re ${info_mem_header_pattern} {
370 # Discard the header.
373 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
377 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
381 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
385 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
389 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
393 -re "$gdb_prompt $" {
394 if {!$see1 && $see2 && $see3 && $see4 && $see5} {
395 pass "mem 1 was deleted"
397 fail "mem 1 was deleted"
408 gdb_test_no_output "delete mem 2 4" "delete mem 2 4"
409 gdb_test_multiple "info mem" "mem 2 and 4 were deleted" {
410 -re ${info_mem_header_pattern} {
411 # Discard the header.
414 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
418 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
422 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
426 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
430 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
434 -re "$gdb_prompt $" {
435 if {!$see1 && !$see2 && $see3 && !$see4 && $see5} {
436 pass "mem 2 and 4 were deleted"
438 fail "mem 2 and 4 were deleted"
449 gdb_test "delete mem 2-4" \
450 "No memory region number 2.*No memory region number 4."
451 gdb_test_multiple "info mem" "mem 2-4 were deleted" {
452 -re ${info_mem_header_pattern} {
453 # Discard the header.
456 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
460 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
464 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
468 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
472 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
476 -re "$gdb_prompt $" {
477 if {!$see1 && !$see2 && !$see3 && !$see4 && $see5} {
478 pass "mem 2-4 were deleted"
480 fail "mem 2-4 were deleted"
485 gdb_test "delete mem 8" "No memory region number 8." \
486 "delete non-existant region"
489 # Test overlapping checking
492 # Create a region that doesn't overlap (a PASS in the table).
494 proc region_pass { region } {
495 gdb_test_no_output "mem $region ro" "$region: no-overlap"
498 # Try to create a region that overlaps (a FAIL in the table).
500 proc region_fail { region } {
501 gdb_test "mem $region ro" "overlapping memory region" "$region: overlap"
504 # Test normal case (upper != 0)
508 # 10 20 30 40 50 60 70 80 90
515 # |--------------| FAIL
516 # |--------------------- FAIL
517 # |------------------ FAIL
518 # |--------------- FAIL
523 # Clear the memory regions list.
524 delete_memory_regions
525 gdb_test_no_output "mem 0x30 0x60 ro"
526 with_test_prefix "0x30 0x60" {
527 region_fail "0x20 0x40"
528 region_fail "0x30 0x40"
529 region_fail "0x40 0x50"
530 region_fail "0x50 0x60"
531 region_fail "0x50 0x70"
532 region_fail "0x30 0x60"
533 region_fail "0x20 0x70"
534 region_fail "0x20 0x0"
535 region_fail "0x30 0x0"
536 region_fail "0x40 0x0"
537 region_pass "0x20 0x30"
538 region_pass "0x60 0x70"
539 region_pass "0x80 0x0"
542 # Test special case (upper == 0)
546 # 00 10 20 30 40 50 60 70 80
550 # |------------------ FAIL
551 # |--------------- FAIL
556 # Clear the memory regions list.
557 delete_memory_regions
558 gdb_test_no_output "mem 0x30 0x0 ro"
559 with_test_prefix "0x30 0x0" {
560 region_fail "0x20 0x50"
561 region_fail "0x30 0x50"
562 region_fail "0x40 0x50"
563 region_fail "0x20 0x0"
564 region_fail "0x30 0x0"
565 region_fail "0x40 0x0"
566 region_pass "0x20 0x30"
567 region_pass "0x00 0x10"