2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # This file is part of the gdb testsuite
19 # Test the memory attribute commands.
25 set testfile "memattr"
26 set srcfile ${testfile}.c
28 if { [prepare_for_testing $testfile.exp $testfile $srcfile] } {
47 gdb_test_multiple "info address mem1" "get address of mem1" {
48 -re "Symbol \"mem1\" is static storage at address ($hex).*$gdb_prompt $" {
49 set mem1start $expect_out(1,string)
53 gdb_test_multiple "info address mem2" "get address of mem2" {
54 -re "Symbol \"mem2\" is static storage at address ($hex).*$gdb_prompt $" {
55 set mem2start $expect_out(1,string)
59 gdb_test_multiple "info address mem3" "get address of mem3" {
60 -re "Symbol \"mem3\" is static storage at address ($hex).*$gdb_prompt $" {
61 set mem3start $expect_out(1,string)
65 gdb_test_multiple "info address mem4" "get address of mem4" {
66 -re "Symbol \"mem4\" is static storage at address ($hex).*$gdb_prompt $" {
67 set mem4start $expect_out(1,string)
71 gdb_test_multiple "info address mem5" "get address of mem5" {
72 -re "Symbol \"mem5\" is static storage at address ($hex).*$gdb_prompt $" {
73 set mem5start $expect_out(1,string)
77 gdb_test_multiple "print &mem1\[64\]" "get end of mem1" {
78 -re "$decimal = .* ($hex).*$gdb_prompt $" {
79 set mem1end $expect_out(1,string)
83 gdb_test_multiple "print &mem2\[64\]" "get end of mem2" {
84 -re "$decimal = .* ($hex).*$gdb_prompt $" {
85 set mem2end $expect_out(1,string)
89 gdb_test_multiple "print &mem3\[64\]" "get end of mem3" {
90 -re "$decimal = .* ($hex).*$gdb_prompt $" {
91 set mem3end $expect_out(1,string)
95 gdb_test_multiple "print &mem4\[64\]" "get end of mem4" {
96 -re "$decimal = .* ($hex).*$gdb_prompt $" {
97 set mem4end $expect_out(1,string)
101 gdb_test_multiple "print &mem5\[64\]" "get end of mem5" {
102 -re "$decimal = .* ($hex).*$gdb_prompt $" {
103 set mem5end $expect_out(1,string)
107 gdb_test_no_output "mem $mem1start $mem1end wo" "create mem region 1"
108 gdb_test_no_output "mem $mem2start $mem2end ro" "create mem region 2"
109 gdb_test_no_output "mem $mem3start $mem3end rw" "create mem region 3"
110 gdb_test_no_output "mem $mem4start $mem4end rw" "create mem region 4"
111 gdb_test_no_output "mem $mem5start $mem5end rw" "create mem region 5"
119 gdb_test_multiple "info mem" "info mem(1)" {
120 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
124 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
128 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
132 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
136 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
140 -re "$gdb_prompt $" {
141 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
150 # Test read-only, write-only
153 # mem1 is write only: read should fail.
154 gdb_test "print mem1\[1\]" \
155 "Cannot access memory at address $hex" \
156 "mem1 cannot be read"
158 gdb_test "print mem1\[1\] = 9" \
160 "mem1 can be written"
162 # mem2 is read only: write should fail.
163 gdb_test "print mem2\[1\] = 9" \
164 "Cannot access memory at address $hex" \
165 "mem2 cannot be written"
167 gdb_test "print mem2\[1\]" \
172 # Test disable and enable
175 gdb_test_no_output "disable mem 1" "disable mem 1"
176 gdb_test "info mem" "1 n .*" "mem 1 was disabled"
178 gdb_test_no_output "enable mem 1" "enable mem 1"
179 gdb_test "info mem" "1 y .*" "mem 1 was enabled"
181 gdb_test_no_output "disable mem 2 4"
189 gdb_test_multiple "info mem" "mem 2 and 4 were disabled" {
190 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
194 -re "2 n \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
198 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
202 -re "4 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
206 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
210 -re "$gdb_prompt $" {
211 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
212 pass "mem 2 and 4 were disabled"
214 fail "mem 2 and 4 were disabled"
219 gdb_test_no_output "enable mem 2-4" "enable mem 2-4"
227 gdb_test_multiple "info mem" "mem 2-4 were enabled" {
228 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
232 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
236 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
240 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
244 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
248 -re "$gdb_prompt $" {
249 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
250 pass "mem 2-4 were enabled"
252 fail "mem 2-4 were enabled"
257 gdb_test_no_output "disable mem" "disable mem"
265 gdb_test_multiple "info mem" "mem 1 to 5 were disabled" {
266 -re "1 n \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
270 -re "2 n \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
274 -re "3 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
278 -re "4 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
282 -re "5 n \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
286 -re "$gdb_prompt $" {
287 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
288 pass "mem 1 to 5 were disabled"
290 fail "mem 1 to 5 were disabled"
295 gdb_test_no_output "enable mem" "enable mem"
303 gdb_test_multiple "info mem" "mem 1 to 5 were enabled" {
304 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
308 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
312 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
316 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
320 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
324 -re "$gdb_prompt $" {
325 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
326 pass "mem 1 to 5 were enabled"
328 fail "mem 1 to 5 were enabled"
333 gdb_test "disable mem 7 8" \
334 "No memory region number 7.*No memory region number 8." \
335 "disable non-existant regions"
347 gdb_test_no_output "delete mem 1" "delete mem 1"
348 gdb_test_multiple "info mem" "mem 1 was deleted" {
349 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
353 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
357 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
361 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
365 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
369 -re "$gdb_prompt $" {
370 if { !$see1 && $see2 && $see3 && $see4 && $see5 } then {
371 pass "mem 1 was deleted"
373 fail "mem 1 was deleted"
384 gdb_test_no_output "delete mem 2 4" "delete mem 2 4"
385 gdb_test_multiple "info mem" "mem 2 and 4 were deleted" {
386 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
390 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
394 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
398 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
402 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
406 -re "$gdb_prompt $" {
407 if { !$see1 && !$see2 && $see3 && !$see4 && $see5 } then {
408 pass "mem 2 and 4 were deleted"
410 fail "mem 2 and 4 were deleted"
421 gdb_test "delete mem 2-4" \
422 "No memory region number 2.*No memory region number 4." \
424 gdb_test_multiple "info mem" "mem 2-4 were deleted" {
425 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
429 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
433 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
437 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
441 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
445 -re "$gdb_prompt $" {
446 if { !$see1 && !$see2 && !$see3 && !$see4 && $see5 } then {
447 pass "mem 2-4 were deleted"
449 fail "mem 2-4 were deleted"
454 gdb_test "delete mem 8" "No memory region number 8." \
455 "delete non-existant region"