Commit | Line | Data |
---|---|---|
fbcb778d MS |
1 | # Copyright 2011 |
2 | # Free Software Foundation, Inc. | |
3 | ||
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. | |
8 | # | |
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. | |
13 | # | |
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/>. | |
16 | ||
17 | # This file is part of the gdb testsuite | |
18 | ||
19 | # Test the memory attribute commands. | |
20 | ||
21 | if $tracelevel then { | |
22 | strace $tracelevel | |
23 | } | |
24 | ||
25 | set testfile "memattr" | |
26 | set srcfile ${testfile}.c | |
27 | ||
28 | if { [prepare_for_testing $testfile.exp $testfile $srcfile] } { | |
29 | return -1 | |
30 | } | |
31 | ||
32 | runto main | |
33 | ||
34 | set mem1start -1 | |
35 | set mem2start -1 | |
36 | set mem3start -1 | |
37 | set mem4start -1 | |
38 | set mem5start -1 | |
39 | ||
40 | set mem1end -1 | |
41 | set mem2end -1 | |
42 | set mem3end -1 | |
43 | set mem4end -1 | |
44 | set mem5end -1 | |
45 | ||
46 | ||
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) | |
50 | } | |
51 | } | |
52 | ||
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) | |
56 | } | |
57 | } | |
58 | ||
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) | |
62 | } | |
63 | } | |
64 | ||
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) | |
68 | } | |
69 | } | |
70 | ||
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) | |
74 | } | |
75 | } | |
76 | ||
77 | gdb_test_multiple "print &mem1\[64\]" "get end of mem1" { | |
78 | -re "$decimal = .* ($hex).*$gdb_prompt $" { | |
79 | set mem1end $expect_out(1,string) | |
80 | } | |
81 | } | |
82 | ||
83 | gdb_test_multiple "print &mem2\[64\]" "get end of mem2" { | |
84 | -re "$decimal = .* ($hex).*$gdb_prompt $" { | |
85 | set mem2end $expect_out(1,string) | |
86 | } | |
87 | } | |
88 | ||
89 | gdb_test_multiple "print &mem3\[64\]" "get end of mem3" { | |
90 | -re "$decimal = .* ($hex).*$gdb_prompt $" { | |
91 | set mem3end $expect_out(1,string) | |
92 | } | |
93 | } | |
94 | ||
95 | gdb_test_multiple "print &mem4\[64\]" "get end of mem4" { | |
96 | -re "$decimal = .* ($hex).*$gdb_prompt $" { | |
97 | set mem4end $expect_out(1,string) | |
98 | } | |
99 | } | |
100 | ||
101 | gdb_test_multiple "print &mem5\[64\]" "get end of mem5" { | |
102 | -re "$decimal = .* ($hex).*$gdb_prompt $" { | |
103 | set mem5end $expect_out(1,string) | |
104 | } | |
105 | } | |
106 | ||
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" | |
112 | ||
113 | set see1 0 | |
114 | set see2 0 | |
115 | set see3 0 | |
116 | set see4 0 | |
117 | set see5 0 | |
118 | ||
119 | gdb_test_multiple "info mem" "info mem(1)" { | |
b66e66ee | 120 | -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" { |
fbcb778d MS |
121 | set see1 1 |
122 | exp_continue | |
123 | } | |
b66e66ee | 124 | -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" { |
fbcb778d MS |
125 | set see2 1 |
126 | exp_continue | |
127 | } | |
b66e66ee | 128 | -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" { |
fbcb778d MS |
129 | set see3 1 |
130 | exp_continue | |
131 | } | |
b66e66ee | 132 | -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" { |
fbcb778d MS |
133 | set see4 1 |
134 | exp_continue | |
135 | } | |
b66e66ee | 136 | -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" { |
fbcb778d MS |
137 | set see5 1 |
138 | exp_continue | |
139 | } | |
140 | -re "$gdb_prompt $" { | |
141 | if { $see1 && $see2 && $see3 && $see4 && $see5 } then { | |
142 | pass "info mem (1)" | |
143 | } else { | |
144 | fail "info mem (1)" | |
145 | } | |
146 | } | |
147 | } | |
148 | ||
149 | # | |
150 | # Test read-only, write-only | |
151 | # | |
152 | ||
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" | |
157 | ||
158 | gdb_test "print mem1\[1\] = 9" \ | |
159 | "$decimal = 9" \ | |
160 | "mem1 can be written" | |
161 | ||
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" | |
166 | ||
167 | gdb_test "print mem2\[1\]" \ | |
168 | "$decimal = 0" \ | |
169 | "mem2 can be read" | |
170 | ||
171 | # | |
172 | # Test disable and enable | |
173 | # | |
174 | ||
175 | gdb_test_no_output "disable mem 1" "disable mem 1" | |
176 | gdb_test "info mem" "1 n .*" "mem 1 was disabled" | |
177 | ||
178 | gdb_test_no_output "enable mem 1" "enable mem 1" | |
179 | gdb_test "info mem" "1 y .*" "mem 1 was enabled" | |
180 | ||
181 | gdb_test_no_output "disable mem 2 4" | |
182 | ||
183 | set see1 0 | |
184 | set see2 0 | |
185 | set see3 0 | |
186 | set see4 0 | |
187 | set see5 0 | |
188 | ||
189 | gdb_test_multiple "info mem" "mem 2 and 4 were disabled" { | |
b66e66ee | 190 | -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" { |
fbcb778d MS |
191 | set see1 1 |
192 | exp_continue | |
193 | } | |
b66e66ee | 194 | -re "2 n \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" { |
fbcb778d MS |
195 | set see2 1 |
196 | exp_continue | |
197 | } | |
b66e66ee | 198 | -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" { |
fbcb778d MS |
199 | set see3 1 |
200 | exp_continue | |
201 | } | |
b66e66ee | 202 | -re "4 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" { |
fbcb778d MS |
203 | set see4 1 |
204 | exp_continue | |
205 | } | |
b66e66ee | 206 | -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" { |
fbcb778d MS |
207 | set see5 1 |
208 | exp_continue | |
209 | } | |
210 | -re "$gdb_prompt $" { | |
211 | if { $see1 && $see2 && $see3 && $see4 && $see5 } then { | |
212 | pass "mem 2 and 4 were disabled" | |
213 | } else { | |
214 | fail "mem 2 and 4 were disabled" | |
215 | } | |
216 | } | |
217 | } | |
218 | ||
219 | gdb_test_no_output "enable mem 2-4" "enable mem 2-4" | |
220 | ||
221 | set see1 0 | |
222 | set see2 0 | |
223 | set see3 0 | |
224 | set see4 0 | |
225 | set see5 0 | |
226 | ||
227 | gdb_test_multiple "info mem" "mem 2-4 were enabled" { | |
b66e66ee | 228 | -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" { |
fbcb778d MS |
229 | set see1 1 |
230 | exp_continue | |
231 | } | |
b66e66ee | 232 | -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" { |
fbcb778d MS |
233 | set see2 1 |
234 | exp_continue | |
235 | } | |
b66e66ee | 236 | -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" { |
fbcb778d MS |
237 | set see3 1 |
238 | exp_continue | |
239 | } | |
b66e66ee | 240 | -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" { |
fbcb778d MS |
241 | set see4 1 |
242 | exp_continue | |
243 | } | |
b66e66ee | 244 | -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" { |
fbcb778d MS |
245 | set see5 1 |
246 | exp_continue | |
247 | } | |
248 | -re "$gdb_prompt $" { | |
249 | if { $see1 && $see2 && $see3 && $see4 && $see5 } then { | |
250 | pass "mem 2-4 were enabled" | |
251 | } else { | |
252 | fail "mem 2-4 were enabled" | |
253 | } | |
254 | } | |
255 | } | |
256 | ||
257 | gdb_test_no_output "disable mem" "disable mem" | |
258 | ||
259 | set see1 0 | |
260 | set see2 0 | |
261 | set see3 0 | |
262 | set see4 0 | |
263 | set see5 0 | |
264 | ||
265 | gdb_test_multiple "info mem" "mem 1 to 5 were disabled" { | |
b66e66ee | 266 | -re "1 n \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" { |
fbcb778d MS |
267 | set see1 1 |
268 | exp_continue | |
269 | } | |
b66e66ee | 270 | -re "2 n \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" { |
fbcb778d MS |
271 | set see2 1 |
272 | exp_continue | |
273 | } | |
b66e66ee | 274 | -re "3 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" { |
fbcb778d MS |
275 | set see3 1 |
276 | exp_continue | |
277 | } | |
b66e66ee | 278 | -re "4 n \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" { |
fbcb778d MS |
279 | set see4 1 |
280 | exp_continue | |
281 | } | |
b66e66ee | 282 | -re "5 n \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" { |
fbcb778d MS |
283 | set see5 1 |
284 | exp_continue | |
285 | } | |
286 | -re "$gdb_prompt $" { | |
287 | if { $see1 && $see2 && $see3 && $see4 && $see5 } then { | |
288 | pass "mem 1 to 5 were disabled" | |
289 | } else { | |
290 | fail "mem 1 to 5 were disabled" | |
291 | } | |
292 | } | |
293 | } | |
294 | ||
295 | gdb_test_no_output "enable mem" "enable mem" | |
296 | ||
297 | set see1 0 | |
298 | set see2 0 | |
299 | set see3 0 | |
300 | set see4 0 | |
301 | set see5 0 | |
302 | ||
303 | gdb_test_multiple "info mem" "mem 1 to 5 were enabled" { | |
b66e66ee | 304 | -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" { |
fbcb778d MS |
305 | set see1 1 |
306 | exp_continue | |
307 | } | |
b66e66ee | 308 | -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" { |
fbcb778d MS |
309 | set see2 1 |
310 | exp_continue | |
311 | } | |
b66e66ee | 312 | -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" { |
fbcb778d MS |
313 | set see3 1 |
314 | exp_continue | |
315 | } | |
b66e66ee | 316 | -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" { |
fbcb778d MS |
317 | set see4 1 |
318 | exp_continue | |
319 | } | |
b66e66ee | 320 | -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" { |
fbcb778d MS |
321 | set see5 1 |
322 | exp_continue | |
323 | } | |
324 | -re "$gdb_prompt $" { | |
325 | if { $see1 && $see2 && $see3 && $see4 && $see5 } then { | |
326 | pass "mem 1 to 5 were enabled" | |
327 | } else { | |
328 | fail "mem 1 to 5 were enabled" | |
329 | } | |
330 | } | |
331 | } | |
332 | ||
333 | gdb_test "disable mem 7 8" \ | |
334 | "No memory region number 7.*No memory region number 8." \ | |
335 | "disable non-existant regions" | |
336 | ||
337 | # | |
338 | # Test delete | |
339 | # | |
340 | ||
341 | set see1 0 | |
342 | set see2 0 | |
343 | set see3 0 | |
344 | set see4 0 | |
345 | set see5 0 | |
346 | ||
347 | gdb_test_no_output "delete mem 1" "delete mem 1" | |
348 | gdb_test_multiple "info mem" "mem 1 was deleted" { | |
b66e66ee | 349 | -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" { |
fbcb778d MS |
350 | set see1 1 |
351 | exp_continue | |
352 | } | |
b66e66ee | 353 | -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" { |
fbcb778d MS |
354 | set see2 1 |
355 | exp_continue | |
356 | } | |
b66e66ee | 357 | -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" { |
fbcb778d MS |
358 | set see3 1 |
359 | exp_continue | |
360 | } | |
b66e66ee | 361 | -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" { |
fbcb778d MS |
362 | set see4 1 |
363 | exp_continue | |
364 | } | |
b66e66ee | 365 | -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" { |
fbcb778d MS |
366 | set see5 1 |
367 | exp_continue | |
368 | } | |
369 | -re "$gdb_prompt $" { | |
370 | if { !$see1 && $see2 && $see3 && $see4 && $see5 } then { | |
371 | pass "mem 1 was deleted" | |
372 | } else { | |
373 | fail "mem 1 was deleted" | |
374 | } | |
375 | } | |
376 | } | |
377 | ||
378 | set see1 0 | |
379 | set see2 0 | |
380 | set see3 0 | |
381 | set see4 0 | |
382 | set see5 0 | |
383 | ||
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" { | |
b66e66ee | 386 | -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" { |
fbcb778d MS |
387 | set see1 1 |
388 | exp_continue | |
389 | } | |
b66e66ee | 390 | -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" { |
fbcb778d MS |
391 | set see2 1 |
392 | exp_continue | |
393 | } | |
b66e66ee | 394 | -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" { |
fbcb778d MS |
395 | set see3 1 |
396 | exp_continue | |
397 | } | |
b66e66ee | 398 | -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" { |
fbcb778d MS |
399 | set see4 1 |
400 | exp_continue | |
401 | } | |
b66e66ee | 402 | -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" { |
fbcb778d MS |
403 | set see5 1 |
404 | exp_continue | |
405 | } | |
406 | -re "$gdb_prompt $" { | |
407 | if { !$see1 && !$see2 && $see3 && !$see4 && $see5 } then { | |
408 | pass "mem 2 and 4 were deleted" | |
409 | } else { | |
410 | fail "mem 2 and 4 were deleted" | |
411 | } | |
412 | } | |
413 | } | |
414 | ||
415 | set see1 0 | |
416 | set see2 0 | |
417 | set see3 0 | |
418 | set see4 0 | |
419 | set see5 0 | |
420 | ||
421 | gdb_test "delete mem 2-4" \ | |
422 | "No memory region number 2.*No memory region number 4." \ | |
423 | "delete mem 2-4" | |
424 | gdb_test_multiple "info mem" "mem 2-4 were deleted" { | |
b66e66ee | 425 | -re "1 y \[ \t\]+$hex $hex wo nocache \[^\r\n\]*" { |
fbcb778d MS |
426 | set see1 1 |
427 | exp_continue | |
428 | } | |
b66e66ee | 429 | -re "2 y \[ \t\]+$hex $hex ro nocache \[^\r\n\]*" { |
fbcb778d MS |
430 | set see2 1 |
431 | exp_continue | |
432 | } | |
b66e66ee | 433 | -re "3 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" { |
fbcb778d MS |
434 | set see3 1 |
435 | exp_continue | |
436 | } | |
b66e66ee | 437 | -re "4 y \[ \t\]+$hex $hex rw nocache \[^\r\n\]*" { |
fbcb778d MS |
438 | set see4 1 |
439 | exp_continue | |
440 | } | |
b66e66ee | 441 | -re "5 y \[ \t\]+$hex $hex rw nocache .\[^\r\n\]*" { |
fbcb778d MS |
442 | set see5 1 |
443 | exp_continue | |
444 | } | |
445 | -re "$gdb_prompt $" { | |
446 | if { !$see1 && !$see2 && !$see3 && !$see4 && $see5 } then { | |
447 | pass "mem 2-4 were deleted" | |
448 | } else { | |
449 | fail "mem 2-4 were deleted" | |
450 | } | |
451 | } | |
452 | } | |
453 | ||
454 | gdb_test "delete mem 8" "No memory region number 8." \ | |
455 | "delete non-existant region" |