1 # Copyright 2011-2012 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.
24 set testfile "memattr"
25 set srcfile ${testfile}.c
27 if { [prepare_for_testing $testfile.exp $testfile $srcfile] } {
46 gdb_test_multiple "info address mem1" "get address of mem1" {
47 -re "Symbol \"mem1\" is static storage at address ($hex).*$gdb_prompt $" {
48 set mem1start $expect_out(1,string)
52 gdb_test_multiple "info address mem2" "get address of mem2" {
53 -re "Symbol \"mem2\" is static storage at address ($hex).*$gdb_prompt $" {
54 set mem2start $expect_out(1,string)
58 gdb_test_multiple "info address mem3" "get address of mem3" {
59 -re "Symbol \"mem3\" is static storage at address ($hex).*$gdb_prompt $" {
60 set mem3start $expect_out(1,string)
64 gdb_test_multiple "info address mem4" "get address of mem4" {
65 -re "Symbol \"mem4\" is static storage at address ($hex).*$gdb_prompt $" {
66 set mem4start $expect_out(1,string)
70 gdb_test_multiple "info address mem5" "get address of mem5" {
71 -re "Symbol \"mem5\" is static storage at address ($hex).*$gdb_prompt $" {
72 set mem5start $expect_out(1,string)
76 gdb_test_multiple "print &mem1\[64\]" "get end of mem1" {
77 -re "$decimal = .* ($hex).*$gdb_prompt $" {
78 set mem1end $expect_out(1,string)
82 gdb_test_multiple "print &mem2\[64\]" "get end of mem2" {
83 -re "$decimal = .* ($hex).*$gdb_prompt $" {
84 set mem2end $expect_out(1,string)
88 gdb_test_multiple "print &mem3\[64\]" "get end of mem3" {
89 -re "$decimal = .* ($hex).*$gdb_prompt $" {
90 set mem3end $expect_out(1,string)
94 gdb_test_multiple "print &mem4\[64\]" "get end of mem4" {
95 -re "$decimal = .* ($hex).*$gdb_prompt $" {
96 set mem4end $expect_out(1,string)
100 gdb_test_multiple "print &mem5\[64\]" "get end of mem5" {
101 -re "$decimal = .* ($hex).*$gdb_prompt $" {
102 set mem5end $expect_out(1,string)
106 gdb_test_no_output "mem $mem1start $mem1end wo" "create mem region 1"
107 gdb_test_no_output "mem $mem2start $mem2end ro" "create mem region 2"
108 gdb_test_no_output "mem $mem3start $mem3end rw" "create mem region 3"
109 gdb_test_no_output "mem $mem4start $mem4end rw" "create mem region 4"
110 gdb_test_no_output "mem $mem5start $mem5end rw" "create mem region 5"
118 gdb_test_multiple "info mem" "info mem(1)" {
119 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
123 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
127 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
131 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
135 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
139 -re "$gdb_prompt $" {
140 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
149 # Test read-only, write-only
152 # mem1 is write only: read should fail.
153 gdb_test "print mem1\[1\]" \
154 "Cannot access memory at address $hex" \
155 "mem1 cannot be read"
157 gdb_test "print mem1\[1\] = 9" \
159 "mem1 can be written"
161 # mem2 is read only: write should fail.
162 gdb_test "print mem2\[1\] = 9" \
163 "Cannot access memory at address $hex" \
164 "mem2 cannot be written"
166 gdb_test "print mem2\[1\]" \
171 # Test disable and enable
174 gdb_test_no_output "disable mem 1" "disable mem 1"
175 gdb_test "info mem" "1 n .*" "mem 1 was disabled"
177 gdb_test_no_output "enable mem 1" "enable mem 1"
178 gdb_test "info mem" "1 y .*" "mem 1 was enabled"
180 gdb_test_no_output "disable mem 2 4"
188 gdb_test_multiple "info mem" "mem 2 and 4 were disabled" {
189 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
193 -re "2 n \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
197 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
201 -re "4 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
205 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
209 -re "$gdb_prompt $" {
210 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
211 pass "mem 2 and 4 were disabled"
213 fail "mem 2 and 4 were disabled"
218 gdb_test_no_output "enable mem 2-4" "enable mem 2-4"
226 gdb_test_multiple "info mem" "mem 2-4 were enabled" {
227 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
231 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
235 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
239 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
243 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
247 -re "$gdb_prompt $" {
248 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
249 pass "mem 2-4 were enabled"
251 fail "mem 2-4 were enabled"
256 gdb_test_no_output "disable mem" "disable mem"
264 gdb_test_multiple "info mem" "mem 1 to 5 were disabled" {
265 -re "1 n \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
269 -re "2 n \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
273 -re "3 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
277 -re "4 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
281 -re "5 n \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
285 -re "$gdb_prompt $" {
286 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
287 pass "mem 1 to 5 were disabled"
289 fail "mem 1 to 5 were disabled"
294 gdb_test_no_output "enable mem" "enable mem"
302 gdb_test_multiple "info mem" "mem 1 to 5 were enabled" {
303 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
307 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
311 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
315 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
319 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
323 -re "$gdb_prompt $" {
324 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
325 pass "mem 1 to 5 were enabled"
327 fail "mem 1 to 5 were enabled"
332 gdb_test "disable mem 7 8" \
333 "No memory region number 7.*No memory region number 8." \
334 "disable non-existant regions"
346 gdb_test_no_output "delete mem 1" "delete mem 1"
347 gdb_test_multiple "info mem" "mem 1 was deleted" {
348 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
352 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
356 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
360 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
364 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
368 -re "$gdb_prompt $" {
369 if { !$see1 && $see2 && $see3 && $see4 && $see5 } then {
370 pass "mem 1 was deleted"
372 fail "mem 1 was deleted"
383 gdb_test_no_output "delete mem 2 4" "delete mem 2 4"
384 gdb_test_multiple "info mem" "mem 2 and 4 were deleted" {
385 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
389 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
393 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
397 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
401 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
405 -re "$gdb_prompt $" {
406 if { !$see1 && !$see2 && $see3 && !$see4 && $see5 } then {
407 pass "mem 2 and 4 were deleted"
409 fail "mem 2 and 4 were deleted"
420 gdb_test "delete mem 2-4" \
421 "No memory region number 2.*No memory region number 4." \
423 gdb_test_multiple "info mem" "mem 2-4 were deleted" {
424 -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" {
428 -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" {
432 -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
436 -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" {
440 -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" {
444 -re "$gdb_prompt $" {
445 if { !$see1 && !$see2 && !$see3 && !$see4 && $see5 } then {
446 pass "mem 2-4 were deleted"
448 fail "mem 2-4 were deleted"
453 gdb_test "delete mem 8" "No memory region number 8." \
454 "delete non-existant region"