17441339506cb56fa7a5997df78ad23f79f1fbe2
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / dump.exp
1 # Copyright 2002, 2004, 2007, 2008, 2009, 2010, 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 was written by Michael Snyder (msnyder@redhat.com)
18 # This is a test for the gdb command "dump".
19
20 if $tracelevel then {
21 strace $tracelevel
22 }
23
24
25 set testfile "dump"
26
27 set srcfile ${testfile}.c
28 set binfile ${objdir}/${subdir}/${testfile}
29 set options {debug}
30
31 set is64bitonly "no"
32 set endian "auto"
33
34 if [istarget "alpha*-*-*"] then {
35 # SREC etc cannot handle 64-bit addresses. Force the test
36 # program into the low 31 bits of the address space.
37 lappend options "additional_flags=-Wl,-taso"
38 }
39
40 if {[istarget "ia64*-*-*"] || [istarget "hppa64-*-*"]} then {
41 set is64bitonly "yes"
42 }
43
44 if {[istarget "spu*-*-*"]} then {
45 # The internal address format used for the combined Cell/B.E.
46 # debugger requires 64-bit.
47 set is64bitonly "yes"
48 }
49
50 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable ${options}] != "" } {
51 untested dump.exp
52 return -1
53 }
54
55 # Start with a fresh gdb.
56
57 gdb_exit
58 gdb_start
59 gdb_reinitialize_dir $srcdir/$subdir
60
61 gdb_test "dump mem /dev/null 0x10 0x20" "Cannot access memory at address 0x10" \
62 "inaccessible memory is reported"
63
64 gdb_load ${binfile}
65
66 # Clean up any stale output files from previous test runs
67
68 remote_exec build "rm -f intarr1.bin intarr1b.bin intarr1.ihex intarr1.srec intarr1.tekhex intarr2.bin intarr2b.bin intarr2.ihex intarr2.srec intarr2.tekhex intstr1.bin intstr1b.bin intstr1.ihex intstr1.srec intstr1.tekhex intstr2.bin intstr2b.bin intstr2.ihex intstr2.srec intstr2.tekhex intarr3.srec"
69
70 # Test help (FIXME:)
71
72 # Run target program until data structs are initialized.
73
74 if { ! [ runto checkpoint1 ] } then {
75 untested dump.exp
76 return -1
77 }
78
79 # Get the endianness for the later use with endianless formats.
80
81 gdb_test_multiple "show endian" "show endian" {
82 -re ".* (big|little) endian.*$gdb_prompt $" {
83 set endian $expect_out(1,string)
84 pass "endianness: $endian"
85 }
86 }
87
88 # Now generate some dump files.
89
90 proc make_dump_file { command msg } {
91 global gdb_prompt
92
93 gdb_test_multiple "${command}" "$msg" {
94 -re ".*\[Ee\]rror.*$gdb_prompt $" { fail $msg }
95 -re ".*\[Ww\]arning.*$gdb_prompt $" { fail $msg }
96 -re ".*\[Uu\]ndefined .*$gdb_prompt $" { fail $msg }
97 -re ".*$gdb_prompt $" { pass $msg }
98 }
99 }
100
101 make_dump_file "dump val intarr1.bin intarray" \
102 "dump array as value, default"
103
104 make_dump_file "dump val intstr1.bin intstruct" \
105 "dump struct as value, default"
106
107 make_dump_file "dump bin val intarr1b.bin intarray" \
108 "dump array as value, binary"
109
110 make_dump_file "dump bin val intstr1b.bin intstruct" \
111 "dump struct as value, binary"
112
113 make_dump_file "dump srec val intarr1.srec intarray" \
114 "dump array as value, srec"
115
116 make_dump_file "dump srec val intstr1.srec intstruct" \
117 "dump struct as value, srec"
118
119 make_dump_file "dump ihex val intarr1.ihex intarray" \
120 "dump array as value, intel hex"
121
122 make_dump_file "dump ihex val intstr1.ihex intstruct" \
123 "dump struct as value, intel hex"
124
125 make_dump_file "dump tekhex val intarr1.tekhex intarray" \
126 "dump array as value, tekhex"
127
128 make_dump_file "dump tekhex val intstr1.tekhex intstruct" \
129 "dump struct as value, tekhex"
130
131 proc capture_value { expression args } {
132 global gdb_prompt
133 global expect_out
134
135 set output_string ""
136 if {[llength $args] > 0} {
137 # Convert $args into a simple string.
138 set test "[join $args]; capture $expression"
139 } {
140 set test "capture $expression"
141 }
142 gdb_test_multiple "print ${expression}" "$test" {
143 -re "\\$\[0-9\]+ = (\[^\r\n\]+).*$gdb_prompt $" {
144 set output_string "$expect_out(1,string)"
145 pass "$test"
146 }
147 -re "(Cannot access memory at address \[^\r\n\]+).*$gdb_prompt $" {
148 # Even a failed value is valid
149 set output_string "$expect_out(1,string)"
150 pass "$test"
151 }
152 }
153 return $output_string
154 }
155
156 # POINTER is a pointer and this proc captures the value of POINTER along
157 # with POINTER's type. For example, POINTER is "&intarray", this proc will
158 # call "p &intarray", capture "(int (*)[32]) 0x804a0e0", and return this
159 # string.
160
161 proc capture_pointer_with_type { pointer } {
162 global gdb_prompt
163 global expect_out
164
165 set test "capture type of pointer $pointer"
166 set output_string ""
167 gdb_test_multiple "p ${pointer}" $test {
168 -re "\\$\[0-9\]+ = .*$gdb_prompt $" {
169 # Expected output of "p ${pointer}" is like "$7 = (int (*)[32]) 0x804a0e0",
170 # and we want to extract "(int (*)[32]) 0x804a0e0" from it via
171 # following regexp.
172 if [regexp " \\(.*\\).* 0x\[0-9a-fA-F\]+" $expect_out(0,string) output_string] {
173 # OUTPUT_STRING is expected to be like "(int (*)[32]) 0x804a0e0".
174 pass "$test"
175 } else {
176 fail "$test"
177 }
178 }
179 }
180
181 return $output_string
182 }
183
184 set array_start [capture_value "/x &intarray\[0\]"]
185 set array_end [capture_value "/x &intarray\[32\]"]
186 set struct_start [capture_value "/x &intstruct"]
187 set struct_end [capture_value "/x &intstruct + 1"]
188
189 set array_val [capture_value "intarray"]
190 set struct_val [capture_value "intstruct"]
191
192 set array_ptr_type [capture_pointer_with_type "&intarray"]
193 set struct_ptr_type [capture_pointer_with_type "&intstruct"]
194
195 make_dump_file "dump mem intarr2.bin $array_start $array_end" \
196 "dump array as memory, default"
197
198 make_dump_file "dump mem intstr2.bin $struct_start $struct_end" \
199 "dump struct as memory, default"
200
201 make_dump_file "dump bin mem intarr2b.bin $array_start $array_end" \
202 "dump array as memory, binary"
203
204 make_dump_file "dump bin mem intstr2b.bin $struct_start $struct_end" \
205 "dump struct as memory, binary"
206
207 make_dump_file "dump srec mem intarr2.srec $array_start $array_end" \
208 "dump array as memory, srec"
209
210 make_dump_file "dump srec mem intstr2.srec $struct_start $struct_end" \
211 "dump struct as memory, srec"
212
213 make_dump_file "dump ihex mem intarr2.ihex $array_start $array_end" \
214 "dump array as memory, ihex"
215
216 make_dump_file "dump ihex mem intstr2.ihex $struct_start $struct_end" \
217 "dump struct as memory, ihex"
218
219 make_dump_file "dump tekhex mem intarr2.tekhex $array_start $array_end" \
220 "dump array as memory, tekhex"
221
222 make_dump_file "dump tekhex mem intstr2.tekhex $struct_start $struct_end" \
223 "dump struct as memory, tekhex"
224
225 # test complex expressions
226 make_dump_file \
227 "dump srec mem intarr3.srec &intarray \(char *\) &intarray + sizeof intarray" \
228 "dump array as mem, srec, expressions"
229
230 proc test_restore_saved_value { restore_args msg oldval newval } {
231 global gdb_prompt
232
233 gdb_test "restore $restore_args" \
234 "Restoring .*" \
235 "$msg; file restored ok"
236 if { ![string compare $oldval \
237 [capture_value $newval "$msg"]] } then {
238 pass "$msg; value restored ok"
239 } else {
240 fail "$msg; value restored ok"
241 }
242 }
243
244 if ![string compare $is64bitonly "no"] then {
245
246 gdb_test "print zero_all ()" ".*"
247
248 test_restore_saved_value "intarr1.srec" "array as value, srec" \
249 $array_val "intarray"
250
251 test_restore_saved_value "intstr1.srec" "struct as value, srec" \
252 $struct_val "intstruct"
253
254 gdb_test "print zero_all ()" "void" "zero all"
255
256 test_restore_saved_value "intarr2.srec" "array as memory, srec" \
257 $array_val "intarray"
258
259 test_restore_saved_value "intstr2.srec" "struct as memory, srec" \
260 $struct_val "intstruct"
261
262 gdb_test "print zero_all ()" ".*"
263
264 test_restore_saved_value "intarr1.ihex" "array as value, ihex" \
265 $array_val "intarray"
266
267 test_restore_saved_value "intstr1.ihex" "struct as value, ihex" \
268 $struct_val "intstruct"
269
270 gdb_test "print zero_all ()" ".*"
271
272 test_restore_saved_value "intarr2.ihex" "array as memory, ihex" \
273 $array_val "intarray"
274
275 test_restore_saved_value "intstr2.ihex" "struct as memory, ihex" \
276 $struct_val "intstruct"
277
278 gdb_test "print zero_all ()" ".*"
279
280 test_restore_saved_value "intarr1.tekhex" "array as value, tekhex" \
281 $array_val "intarray"
282
283 test_restore_saved_value "intstr1.tekhex" "struct as value, tekhex" \
284 $struct_val "intstruct"
285
286 gdb_test "print zero_all ()" ".*"
287
288 test_restore_saved_value "intarr2.tekhex" "array as memory, tekhex" \
289 $array_val "intarray"
290
291 test_restore_saved_value "intstr2.tekhex" "struct as memory, tekhex" \
292 $struct_val "intstruct"
293 }
294
295 gdb_test "print zero_all ()" ".*"
296
297 test_restore_saved_value "intarr1.bin binary $array_start" \
298 "array as value, binary" \
299 $array_val "intarray"
300
301 test_restore_saved_value "intstr1.bin binary $struct_start" \
302 "struct as value, binary" \
303 $struct_val "intstruct"
304
305 gdb_test "print zero_all ()" ".*"
306
307 test_restore_saved_value "intarr2.bin binary $array_start" \
308 "array as memory, binary" \
309 $array_val "intarray"
310
311 test_restore_saved_value "intstr2.bin binary $struct_start" \
312 "struct as memory, binary" \
313 $struct_val "intstruct"
314
315 # test restore with offset.
316
317 set array2_start [capture_value "/x &intarray2\[0\]"]
318 set struct2_start [capture_value "/x &intstruct2"]
319 set array2_offset \
320 [capture_value "(char *) &intarray2 - (char *) &intarray"]
321 set struct2_offset \
322 [capture_value "(char *) &intstruct2 - (char *) &intstruct"]
323
324 gdb_test "print zero_all ()" ".*"
325
326
327 if ![string compare $is64bitonly "no"] then {
328 test_restore_saved_value "intarr1.srec $array2_offset" \
329 "array copy, srec" \
330 $array_val "intarray2"
331
332 test_restore_saved_value "intstr1.srec $struct2_offset" \
333 "struct copy, srec" \
334 $struct_val "intstruct2"
335
336 gdb_test "print zero_all ()" ".*"
337
338 test_restore_saved_value "intarr1.ihex $array2_offset" \
339 "array copy, ihex" \
340 $array_val "intarray2"
341
342 test_restore_saved_value "intstr1.ihex $struct2_offset" \
343 "struct copy, ihex" \
344 $struct_val "intstruct2"
345
346 gdb_test "print zero_all ()" ".*"
347
348 test_restore_saved_value "intarr1.tekhex $array2_offset" \
349 "array copy, tekhex" \
350 $array_val "intarray2"
351
352 test_restore_saved_value "intstr1.tekhex $struct2_offset" \
353 "struct copy, tekhex" \
354 $struct_val "intstruct2"
355 }
356
357 gdb_test "print zero_all ()" ".*"
358
359 test_restore_saved_value "intarr1.bin binary $array2_start" \
360 "array copy, binary" \
361 $array_val "intarray2"
362
363 test_restore_saved_value "intstr1.bin binary $struct2_start" \
364 "struct copy, binary" \
365 $struct_val "intstruct2"
366
367 #
368 # test restore with start/stop addresses.
369 #
370 # For this purpose, we will restore just the third element of the array,
371 # and check to see that adjacent elements are not modified.
372 #
373 # We will need the address and offset of the third and fourth elements.
374 #
375
376 set element3_start [capture_value "/x &intarray\[3\]"]
377 set element4_start [capture_value "/x &intarray\[4\]"]
378 set element3_offset \
379 [capture_value "/x (char *) &intarray\[3\] - (char *) &intarray\[0\]"]
380 set element4_offset \
381 [capture_value "/x (char *) &intarray\[4\] - (char *) &intarray\[0\]"]
382
383 if ![string compare $is64bitonly "no"] then {
384 gdb_test "print zero_all ()" ".*"
385
386 test_restore_saved_value "intarr1.srec 0 $element3_start $element4_start" \
387 "array partial, srec" 4 "intarray\[3\]"
388
389 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 1"
390 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 1"
391
392 gdb_test "print zero_all ()" ".*"
393
394 test_restore_saved_value "intarr1.ihex 0 $element3_start $element4_start" \
395 "array partial, ihex" 4 "intarray\[3\]"
396
397 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 2"
398 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 2"
399
400 gdb_test "print zero_all ()" ".*"
401
402 test_restore_saved_value "intarr1.tekhex 0 $element3_start $element4_start" \
403 "array partial, tekhex" 4 "intarray\[3\]"
404
405 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 3"
406 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 3"
407 }
408
409 gdb_test "print zero_all ()" ".*"
410
411 test_restore_saved_value \
412 "intarr1.bin binary $array_start $element3_offset $element4_offset" \
413 "array partial, binary" 4 "intarray\[3\]"
414
415 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 4"
416 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 4"
417
418 if ![string compare $is64bitonly "no"] then {
419 gdb_test "print zero_all ()" ".*" ""
420
421 # restore with expressions
422 test_restore_saved_value \
423 "intarr3.srec (char*)${array2_start}-(char*)${array_start} &intarray\[3\] &intarray\[4\]" \
424 "array partial with expressions" 4 "intarray2\[3\]"
425
426 gdb_test "print intarray2\[2\] == 0" " = 1" "element 2 not changed, == 4"
427 gdb_test "print intarray2\[4\] == 0" " = 1" "element 4 not changed, == 4"
428 }
429
430
431 # Now start a fresh gdb session, and reload the saved value files.
432
433 gdb_exit
434 gdb_start
435 gdb_file_cmd ${binfile}
436
437 # Now fix the endianness at the correct state.
438
439 gdb_test_multiple "set endian $endian" "set endianness" {
440 -re ".* (big|little) endian.*$gdb_prompt $" {
441 pass "setting $endian endianness"
442 }
443 }
444
445 # Reload saved values one by one, and compare.
446
447 if { ![string compare $array_val \
448 [capture_value "intarray" "file binfile"]] } then {
449 fail "start with intarray un-initialized"
450 } else {
451 pass "start with intarray un-initialized"
452 }
453
454 if { ![string compare $struct_val \
455 [capture_value "intstruct" "file binfile"]] } then {
456 fail "start with intstruct un-initialized"
457 } else {
458 pass "start with intstruct un-initialized"
459 }
460
461 proc test_reload_saved_value { filename msg oldval newval } {
462 global gdb_prompt
463
464 gdb_file_cmd $filename
465 if { ![string compare $oldval \
466 [capture_value $newval "$msg"]] } then {
467 pass "$msg; value restored ok"
468 } else {
469 fail "$msg; value restored ok"
470 }
471 }
472
473 # srec format can not be loaded for 64-bit-only platforms
474 if ![string compare $is64bitonly "no"] then {
475 test_reload_saved_value "intarr1.srec" "reload array as value, srec" \
476 $array_val "\*$array_ptr_type"
477 test_reload_saved_value "intstr1.srec" "reload struct as value, srec" \
478 $struct_val "\*$struct_ptr_type"
479 test_reload_saved_value "intarr2.srec" "reload array as memory, srec" \
480 $array_val "\*$array_ptr_type"
481 test_reload_saved_value "intstr2.srec" "reload struct as memory, srec" \
482 $struct_val "\*$struct_ptr_type"
483 }
484
485 # ihex format can not be loaded for 64-bit-only platforms
486 if ![string compare $is64bitonly "no"] then {
487
488 test_reload_saved_value "intarr1.ihex" "reload array as value, intel hex" \
489 $array_val "\*$array_ptr_type"
490 test_reload_saved_value "intstr1.ihex" "reload struct as value, intel hex" \
491 $struct_val "\*$struct_ptr_type"
492 test_reload_saved_value "intarr2.ihex" "reload array as memory, intel hex" \
493 $array_val "\*$array_ptr_type"
494 test_reload_saved_value "intstr2.ihex" "reload struct as memory, intel hex" \
495 $struct_val "\*$struct_ptr_type"
496 }
497
498 # tekhex format can not be loaded for 64-bit-only platforms
499 if ![string compare $is64bitonly "no"] then {
500 test_reload_saved_value "intarr1.tekhex" "reload array as value, tekhex" \
501 $array_val "\*$array_ptr_type"
502 test_reload_saved_value "intstr1.tekhex" "reload struct as value, tekhex" \
503 $struct_val "\*$struct_ptr_type"
504 test_reload_saved_value "intarr2.tekhex" "reload array as memory, tekhex" \
505 $array_val "\*$array_ptr_type"
506 test_reload_saved_value "intstr2.tekhex" "reload struct as memory, tekhex" \
507 $struct_val "\*$struct_ptr_type"
508 }
509
510 # clean up files
511
512 remote_exec build "rm -f intarr1.bin intarr1b.bin intarr1.ihex intarr1.srec intarr1.tekhex intarr2.bin intarr2b.bin intarr2.ihex intarr2.srec intarr2.tekhex intstr1.bin intstr1b.bin intstr1.ihex intstr1.srec intstr1.tekhex intstr2.bin intstr2b.bin intstr2.ihex intstr2.srec intstr2.tekhex intarr3.srec"
This page took 0.040063 seconds and 4 git commands to generate.