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