]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/memattr.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / memattr.exp
CommitLineData
1d506c26 1# Copyright 2011-2024 Free Software Foundation, Inc.
fbcb778d
MS
2
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.
7#
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.
12#
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/>.
15
16# This file is part of the gdb testsuite
17
18# Test the memory attribute commands.
19
f8b41b00 20standard_testfile .c
fbcb778d 21
5b362f04 22if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
fbcb778d
MS
23 return -1
24}
25
50441f0f 26runto_main
fbcb778d 27
e309aa65
LM
28# Delete all target-supplied memory regions.
29delete_memory_regions
30
fbcb778d
MS
31set mem1start -1
32set mem2start -1
33set mem3start -1
34set mem4start -1
35set mem5start -1
36
37set mem1end -1
38set mem2end -1
39set mem3end -1
40set mem4end -1
41set mem5end -1
42
43
44gdb_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)
47 }
48}
49
50gdb_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)
53 }
54}
55
56gdb_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)
59 }
60}
61
62gdb_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)
65 }
66}
67
68gdb_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)
71 }
72}
73
74gdb_test_multiple "print &mem1\[64\]" "get end of mem1" {
75 -re "$decimal = .* ($hex).*$gdb_prompt $" {
76 set mem1end $expect_out(1,string)
77 }
78}
79
80gdb_test_multiple "print &mem2\[64\]" "get end of mem2" {
81 -re "$decimal = .* ($hex).*$gdb_prompt $" {
82 set mem2end $expect_out(1,string)
83 }
84}
85
86gdb_test_multiple "print &mem3\[64\]" "get end of mem3" {
87 -re "$decimal = .* ($hex).*$gdb_prompt $" {
88 set mem3end $expect_out(1,string)
89 }
90}
91
92gdb_test_multiple "print &mem4\[64\]" "get end of mem4" {
93 -re "$decimal = .* ($hex).*$gdb_prompt $" {
94 set mem4end $expect_out(1,string)
95 }
96}
97
98gdb_test_multiple "print &mem5\[64\]" "get end of mem5" {
99 -re "$decimal = .* ($hex).*$gdb_prompt $" {
100 set mem5end $expect_out(1,string)
101 }
102}
103
104gdb_test_no_output "mem $mem1start $mem1end wo" "create mem region 1"
105gdb_test_no_output "mem $mem2start $mem2end ro" "create mem region 2"
106gdb_test_no_output "mem $mem3start $mem3end rw" "create mem region 3"
107gdb_test_no_output "mem $mem4start $mem4end rw" "create mem region 4"
108gdb_test_no_output "mem $mem5start $mem5end rw" "create mem region 5"
109
110set see1 0
111set see2 0
112set see3 0
113set see4 0
114set see5 0
115
fc98a809 116set info_mem_header_pattern \
2c88253f 117 "info mem.*Num\[ \t\]+Enb\[ \t\]+Low\[ \t\]+Addr\[ \t\]+High\[ \t\]+Addr\[ \t\]+Attrs\[^\r\n\]*\r\n"
fc98a809 118
fbcb778d 119gdb_test_multiple "info mem" "info mem(1)" {
fc98a809
AB
120 -re ${info_mem_header_pattern} {
121 # Discard the header.
122 exp_continue
123 }
2c88253f 124 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*\r\n" {
fbcb778d
MS
125 set see1 1
126 exp_continue
127 }
2c88253f 128 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*\r\n" {
fbcb778d
MS
129 set see2 1
130 exp_continue
131 }
2c88253f 132 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*\r\n" {
fbcb778d
MS
133 set see3 1
134 exp_continue
135 }
2c88253f 136 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*\r\n" {
fbcb778d
MS
137 set see4 1
138 exp_continue
139 }
2c88253f 140 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*\r\n" {
fbcb778d
MS
141 set see5 1
142 exp_continue
143 }
144 -re "$gdb_prompt $" {
65a33d75 145 if {$see1 && $see2 && $see3 && $see4 && $see5} {
fbcb778d
MS
146 pass "info mem (1)"
147 } else {
148 fail "info mem (1)"
149 }
150 }
151}
152
153#
154# Test read-only, write-only
155#
156
157# mem1 is write only: read should fail.
158gdb_test "print mem1\[1\]" \
159 "Cannot access memory at address $hex" \
160 "mem1 cannot be read"
161
162gdb_test "print mem1\[1\] = 9" \
163 "$decimal = 9" \
164 "mem1 can be written"
165
166# mem2 is read only: write should fail.
167gdb_test "print mem2\[1\] = 9" \
168 "Cannot access memory at address $hex" \
169 "mem2 cannot be written"
170
171gdb_test "print mem2\[1\]" \
172 "$decimal = 0" \
173 "mem2 can be read"
174
175#
176# Test disable and enable
177#
178
179gdb_test_no_output "disable mem 1" "disable mem 1"
180gdb_test "info mem" "1 n .*" "mem 1 was disabled"
181
182gdb_test_no_output "enable mem 1" "enable mem 1"
183gdb_test "info mem" "1 y .*" "mem 1 was enabled"
184
185gdb_test_no_output "disable mem 2 4"
186
187set see1 0
188set see2 0
189set see3 0
190set see4 0
191set see5 0
192
193gdb_test_multiple "info mem" "mem 2 and 4 were disabled" {
fc98a809
AB
194 -re ${info_mem_header_pattern} {
195 # Discard the header.
196 exp_continue
197 }
198 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
fbcb778d
MS
199 set see1 1
200 exp_continue
201 }
fc98a809 202 -re "^2 n \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
fbcb778d
MS
203 set see2 1
204 exp_continue
205 }
fc98a809 206 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
fbcb778d
MS
207 set see3 1
208 exp_continue
209 }
fc98a809 210 -re "^4 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
fbcb778d
MS
211 set see4 1
212 exp_continue
213 }
fc98a809 214 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
fbcb778d
MS
215 set see5 1
216 exp_continue
217 }
218 -re "$gdb_prompt $" {
65a33d75 219 if {$see1 && $see2 && $see3 && $see4 && $see5} {
fbcb778d
MS
220 pass "mem 2 and 4 were disabled"
221 } else {
222 fail "mem 2 and 4 were disabled"
223 }
224 }
225}
226
227gdb_test_no_output "enable mem 2-4" "enable mem 2-4"
228
229set see1 0
230set see2 0
231set see3 0
232set see4 0
233set see5 0
234
235gdb_test_multiple "info mem" "mem 2-4 were enabled" {
fc98a809
AB
236 -re ${info_mem_header_pattern} {
237 # Discard the header.
238 exp_continue
239 }
240 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
fbcb778d
MS
241 set see1 1
242 exp_continue
243 }
fc98a809 244 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
fbcb778d
MS
245 set see2 1
246 exp_continue
247 }
fc98a809 248 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
fbcb778d
MS
249 set see3 1
250 exp_continue
251 }
fc98a809 252 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
fbcb778d
MS
253 set see4 1
254 exp_continue
255 }
fc98a809 256 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
fbcb778d
MS
257 set see5 1
258 exp_continue
259 }
260 -re "$gdb_prompt $" {
65a33d75 261 if {$see1 && $see2 && $see3 && $see4 && $see5} {
fbcb778d
MS
262 pass "mem 2-4 were enabled"
263 } else {
264 fail "mem 2-4 were enabled"
265 }
266 }
267}
268
269gdb_test_no_output "disable mem" "disable mem"
270
271set see1 0
272set see2 0
273set see3 0
274set see4 0
275set see5 0
276
277gdb_test_multiple "info mem" "mem 1 to 5 were disabled" {
fc98a809
AB
278 -re ${info_mem_header_pattern} {
279 # Discard the header.
280 exp_continue
281 }
282 -re "^1 n \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
fbcb778d
MS
283 set see1 1
284 exp_continue
285 }
fc98a809 286 -re "^2 n \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
fbcb778d
MS
287 set see2 1
288 exp_continue
289 }
fc98a809 290 -re "^3 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
fbcb778d
MS
291 set see3 1
292 exp_continue
293 }
fc98a809 294 -re "^4 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
fbcb778d
MS
295 set see4 1
296 exp_continue
297 }
fc98a809 298 -re "^5 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
fbcb778d
MS
299 set see5 1
300 exp_continue
301 }
302 -re "$gdb_prompt $" {
65a33d75 303 if {$see1 && $see2 && $see3 && $see4 && $see5} {
fbcb778d
MS
304 pass "mem 1 to 5 were disabled"
305 } else {
306 fail "mem 1 to 5 were disabled"
307 }
308 }
309}
310
311gdb_test_no_output "enable mem" "enable mem"
312
313set see1 0
314set see2 0
315set see3 0
316set see4 0
317set see5 0
318
319gdb_test_multiple "info mem" "mem 1 to 5 were enabled" {
fc98a809
AB
320 -re ${info_mem_header_pattern} {
321 # Discard the header.
322 exp_continue
323 }
324 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
fbcb778d
MS
325 set see1 1
326 exp_continue
327 }
fc98a809 328 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
fbcb778d
MS
329 set see2 1
330 exp_continue
331 }
fc98a809 332 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
fbcb778d
MS
333 set see3 1
334 exp_continue
335 }
fc98a809 336 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
fbcb778d
MS
337 set see4 1
338 exp_continue
339 }
fc98a809 340 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
fbcb778d
MS
341 set see5 1
342 exp_continue
343 }
344 -re "$gdb_prompt $" {
65a33d75 345 if {$see1 && $see2 && $see3 && $see4 && $see5} {
fbcb778d
MS
346 pass "mem 1 to 5 were enabled"
347 } else {
348 fail "mem 1 to 5 were enabled"
349 }
350 }
351}
352
353gdb_test "disable mem 7 8" \
354 "No memory region number 7.*No memory region number 8." \
355 "disable non-existant regions"
356
357#
358# Test delete
359#
360
361set see1 0
362set see2 0
363set see3 0
364set see4 0
365set see5 0
366
367gdb_test_no_output "delete mem 1" "delete mem 1"
368gdb_test_multiple "info mem" "mem 1 was deleted" {
fc98a809
AB
369 -re ${info_mem_header_pattern} {
370 # Discard the header.
371 exp_continue
372 }
373 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
fbcb778d
MS
374 set see1 1
375 exp_continue
376 }
fc98a809 377 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
fbcb778d
MS
378 set see2 1
379 exp_continue
380 }
fc98a809 381 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
fbcb778d
MS
382 set see3 1
383 exp_continue
384 }
fc98a809 385 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
fbcb778d
MS
386 set see4 1
387 exp_continue
388 }
fc98a809 389 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
fbcb778d
MS
390 set see5 1
391 exp_continue
392 }
393 -re "$gdb_prompt $" {
65a33d75 394 if {!$see1 && $see2 && $see3 && $see4 && $see5} {
fbcb778d
MS
395 pass "mem 1 was deleted"
396 } else {
397 fail "mem 1 was deleted"
398 }
399 }
400}
401
402set see1 0
403set see2 0
404set see3 0
405set see4 0
406set see5 0
407
408gdb_test_no_output "delete mem 2 4" "delete mem 2 4"
409gdb_test_multiple "info mem" "mem 2 and 4 were deleted" {
fc98a809
AB
410 -re ${info_mem_header_pattern} {
411 # Discard the header.
412 exp_continue
413 }
414 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
fbcb778d
MS
415 set see1 1
416 exp_continue
417 }
fc98a809 418 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
fbcb778d
MS
419 set see2 1
420 exp_continue
421 }
fc98a809 422 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
fbcb778d
MS
423 set see3 1
424 exp_continue
425 }
fc98a809 426 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
fbcb778d
MS
427 set see4 1
428 exp_continue
429 }
fc98a809 430 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
fbcb778d
MS
431 set see5 1
432 exp_continue
433 }
434 -re "$gdb_prompt $" {
65a33d75 435 if {!$see1 && !$see2 && $see3 && !$see4 && $see5} {
fbcb778d
MS
436 pass "mem 2 and 4 were deleted"
437 } else {
438 fail "mem 2 and 4 were deleted"
439 }
440 }
441}
442
443set see1 0
444set see2 0
445set see3 0
446set see4 0
447set see5 0
448
449gdb_test "delete mem 2-4" \
11af934b 450 "No memory region number 2.*No memory region number 4."
fbcb778d 451gdb_test_multiple "info mem" "mem 2-4 were deleted" {
fc98a809
AB
452 -re ${info_mem_header_pattern} {
453 # Discard the header.
454 exp_continue
455 }
456 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
fbcb778d
MS
457 set see1 1
458 exp_continue
459 }
fc98a809 460 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
fbcb778d
MS
461 set see2 1
462 exp_continue
463 }
fc98a809 464 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
fbcb778d
MS
465 set see3 1
466 exp_continue
467 }
fc98a809 468 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
fbcb778d
MS
469 set see4 1
470 exp_continue
471 }
fc98a809 472 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
fbcb778d
MS
473 set see5 1
474 exp_continue
475 }
476 -re "$gdb_prompt $" {
65a33d75 477 if {!$see1 && !$see2 && !$see3 && !$see4 && $see5} {
fbcb778d
MS
478 pass "mem 2-4 were deleted"
479 } else {
480 fail "mem 2-4 were deleted"
481 }
482 }
483}
484
485gdb_test "delete mem 8" "No memory region number 8." \
486 "delete non-existant region"
1591a1e8
PA
487
488#
489# Test overlapping checking
490#
491
1591a1e8
PA
492# Create a region that doesn't overlap (a PASS in the table).
493
494proc region_pass { region } {
495 gdb_test_no_output "mem $region ro" "$region: no-overlap"
496}
497
498# Try to create a region that overlaps (a FAIL in the table).
499
500proc region_fail { region } {
501 gdb_test "mem $region ro" "overlapping memory region" "$region: overlap"
502}
503
504# Test normal case (upper != 0)
505#
506# lo' hi'
507# |--------|
508# 10 20 30 40 50 60 70 80 90
509# |-----| FAIL
510# |--| FAIL
511# |--| FAIL
512# |--| FAIL
513# |-----| FAIL
514# |--------| FAIL
515# |--------------| FAIL
516# |--------------------- FAIL
517# |------------------ FAIL
518# |--------------- FAIL
519# |--| PASS
520# |--| PASS
521# |--- PASS
522
e309aa65
LM
523# Clear the memory regions list.
524delete_memory_regions
1591a1e8
PA
525gdb_test_no_output "mem 0x30 0x60 ro"
526with_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"
540}
541
542# Test special case (upper == 0)
543#
544# lo' hi'
545# |---------------
546# 00 10 20 30 40 50 60 70 80
547# |--------| FAIL
548# |-----| FAIL
549# |--| FAIL
550# |------------------ FAIL
551# |--------------- FAIL
552# |------------ FAIL
553# |--| PASS
554# |--| PASS
555
e309aa65
LM
556# Clear the memory regions list.
557delete_memory_regions
1591a1e8
PA
558gdb_test_no_output "mem 0x30 0x0 ro"
559with_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"
568}