b223cf4f01d6746597e3f79ec9fc1096797c3a21
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / memattr.exp
1 # Copyright 2011-2021 Free Software Foundation, Inc.
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
20 standard_testfile .c
21
22 if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
23 return -1
24 }
25
26 runto_main
27
28 # Delete all target-supplied memory regions.
29 delete_memory_regions
30
31 set mem1start -1
32 set mem2start -1
33 set mem3start -1
34 set mem4start -1
35 set mem5start -1
36
37 set mem1end -1
38 set mem2end -1
39 set mem3end -1
40 set mem4end -1
41 set mem5end -1
42
43
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)
47 }
48 }
49
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)
53 }
54 }
55
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)
59 }
60 }
61
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)
65 }
66 }
67
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)
71 }
72 }
73
74 gdb_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
80 gdb_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
86 gdb_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
92 gdb_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
98 gdb_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
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"
109
110 set see1 0
111 set see2 0
112 set see3 0
113 set see4 0
114 set see5 0
115
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"
118
119 gdb_test_multiple "info mem" "info mem(1)" {
120 -re ${info_mem_header_pattern} {
121 # Discard the header.
122 exp_continue
123 }
124 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*\r\n" {
125 set see1 1
126 exp_continue
127 }
128 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*\r\n" {
129 set see2 1
130 exp_continue
131 }
132 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*\r\n" {
133 set see3 1
134 exp_continue
135 }
136 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*\r\n" {
137 set see4 1
138 exp_continue
139 }
140 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*\r\n" {
141 set see5 1
142 exp_continue
143 }
144 -re "$gdb_prompt $" {
145 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
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.
158 gdb_test "print mem1\[1\]" \
159 "Cannot access memory at address $hex" \
160 "mem1 cannot be read"
161
162 gdb_test "print mem1\[1\] = 9" \
163 "$decimal = 9" \
164 "mem1 can be written"
165
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"
170
171 gdb_test "print mem2\[1\]" \
172 "$decimal = 0" \
173 "mem2 can be read"
174
175 #
176 # Test disable and enable
177 #
178
179 gdb_test_no_output "disable mem 1" "disable mem 1"
180 gdb_test "info mem" "1 n .*" "mem 1 was disabled"
181
182 gdb_test_no_output "enable mem 1" "enable mem 1"
183 gdb_test "info mem" "1 y .*" "mem 1 was enabled"
184
185 gdb_test_no_output "disable mem 2 4"
186
187 set see1 0
188 set see2 0
189 set see3 0
190 set see4 0
191 set see5 0
192
193 gdb_test_multiple "info mem" "mem 2 and 4 were disabled" {
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\]*.." {
199 set see1 1
200 exp_continue
201 }
202 -re "^2 n \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
203 set see2 1
204 exp_continue
205 }
206 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
207 set see3 1
208 exp_continue
209 }
210 -re "^4 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
211 set see4 1
212 exp_continue
213 }
214 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
215 set see5 1
216 exp_continue
217 }
218 -re "$gdb_prompt $" {
219 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
220 pass "mem 2 and 4 were disabled"
221 } else {
222 fail "mem 2 and 4 were disabled"
223 }
224 }
225 }
226
227 gdb_test_no_output "enable mem 2-4" "enable mem 2-4"
228
229 set see1 0
230 set see2 0
231 set see3 0
232 set see4 0
233 set see5 0
234
235 gdb_test_multiple "info mem" "mem 2-4 were enabled" {
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\]*.." {
241 set see1 1
242 exp_continue
243 }
244 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
245 set see2 1
246 exp_continue
247 }
248 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
249 set see3 1
250 exp_continue
251 }
252 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
253 set see4 1
254 exp_continue
255 }
256 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
257 set see5 1
258 exp_continue
259 }
260 -re "$gdb_prompt $" {
261 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
262 pass "mem 2-4 were enabled"
263 } else {
264 fail "mem 2-4 were enabled"
265 }
266 }
267 }
268
269 gdb_test_no_output "disable mem" "disable mem"
270
271 set see1 0
272 set see2 0
273 set see3 0
274 set see4 0
275 set see5 0
276
277 gdb_test_multiple "info mem" "mem 1 to 5 were disabled" {
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\]*.." {
283 set see1 1
284 exp_continue
285 }
286 -re "^2 n \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
287 set see2 1
288 exp_continue
289 }
290 -re "^3 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
291 set see3 1
292 exp_continue
293 }
294 -re "^4 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
295 set see4 1
296 exp_continue
297 }
298 -re "^5 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
299 set see5 1
300 exp_continue
301 }
302 -re "$gdb_prompt $" {
303 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
304 pass "mem 1 to 5 were disabled"
305 } else {
306 fail "mem 1 to 5 were disabled"
307 }
308 }
309 }
310
311 gdb_test_no_output "enable mem" "enable mem"
312
313 set see1 0
314 set see2 0
315 set see3 0
316 set see4 0
317 set see5 0
318
319 gdb_test_multiple "info mem" "mem 1 to 5 were enabled" {
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\]*.." {
325 set see1 1
326 exp_continue
327 }
328 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
329 set see2 1
330 exp_continue
331 }
332 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
333 set see3 1
334 exp_continue
335 }
336 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
337 set see4 1
338 exp_continue
339 }
340 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
341 set see5 1
342 exp_continue
343 }
344 -re "$gdb_prompt $" {
345 if { $see1 && $see2 && $see3 && $see4 && $see5 } then {
346 pass "mem 1 to 5 were enabled"
347 } else {
348 fail "mem 1 to 5 were enabled"
349 }
350 }
351 }
352
353 gdb_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
361 set see1 0
362 set see2 0
363 set see3 0
364 set see4 0
365 set see5 0
366
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.
371 exp_continue
372 }
373 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
374 set see1 1
375 exp_continue
376 }
377 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
378 set see2 1
379 exp_continue
380 }
381 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
382 set see3 1
383 exp_continue
384 }
385 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
386 set see4 1
387 exp_continue
388 }
389 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
390 set see5 1
391 exp_continue
392 }
393 -re "$gdb_prompt $" {
394 if { !$see1 && $see2 && $see3 && $see4 && $see5 } then {
395 pass "mem 1 was deleted"
396 } else {
397 fail "mem 1 was deleted"
398 }
399 }
400 }
401
402 set see1 0
403 set see2 0
404 set see3 0
405 set see4 0
406 set see5 0
407
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.
412 exp_continue
413 }
414 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
415 set see1 1
416 exp_continue
417 }
418 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
419 set see2 1
420 exp_continue
421 }
422 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
423 set see3 1
424 exp_continue
425 }
426 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
427 set see4 1
428 exp_continue
429 }
430 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
431 set see5 1
432 exp_continue
433 }
434 -re "$gdb_prompt $" {
435 if { !$see1 && !$see2 && $see3 && !$see4 && $see5 } then {
436 pass "mem 2 and 4 were deleted"
437 } else {
438 fail "mem 2 and 4 were deleted"
439 }
440 }
441 }
442
443 set see1 0
444 set see2 0
445 set see3 0
446 set see4 0
447 set see5 0
448
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.
454 exp_continue
455 }
456 -re "^1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*.." {
457 set see1 1
458 exp_continue
459 }
460 -re "^2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*.." {
461 set see2 1
462 exp_continue
463 }
464 -re "^3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
465 set see3 1
466 exp_continue
467 }
468 -re "^4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
469 set see4 1
470 exp_continue
471 }
472 -re "^5 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*.." {
473 set see5 1
474 exp_continue
475 }
476 -re "$gdb_prompt $" {
477 if { !$see1 && !$see2 && !$see3 && !$see4 && $see5 } then {
478 pass "mem 2-4 were deleted"
479 } else {
480 fail "mem 2-4 were deleted"
481 }
482 }
483 }
484
485 gdb_test "delete mem 8" "No memory region number 8." \
486 "delete non-existant region"
487
488 #
489 # Test overlapping checking
490 #
491
492 # Create a region that doesn't overlap (a PASS in the table).
493
494 proc 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
500 proc 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
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"
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
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"
568 }
This page took 0.058292 seconds and 3 git commands to generate.