1 # Copyright 2002, 2004, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file was written by Michael Snyder (msnyder@redhat.com)
17 # This is a test for the gdb command "dump".
26 set srcfile ${testfile}.c
27 set binfile ${objdir}/${subdir}/${testfile}
33 if [istarget "alpha*-*-*"] then {
34 # SREC etc cannot handle 64-bit addresses. Force the test
35 # program into the low 31 bits of the address space.
36 lappend options "additional_flags=-Wl,-taso"
39 if {[istarget "ia64*-*-*"] || [istarget "hppa64-*-*"]} then {
43 if {[istarget "spu*-*-*"]} then {
44 # The internal address format used for the combined Cell/B.E.
45 # debugger requires 64-bit.
49 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable ${options}] != "" } {
54 # Start with a fresh gdb.
58 gdb_reinitialize_dir $srcdir/$subdir
60 gdb_test "dump mem /dev/null 0x10 0x20" "Cannot access memory at address 0x10" \
61 "inaccessible memory is reported"
65 # Clean up any stale output files from previous test runs
67 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"
71 # Run target program until data structs are initialized.
73 if { ! [ runto checkpoint1 ] } then {
78 # Get the endianness for the later use with endianless formats.
80 gdb_test_multiple "show endian" "show endian" {
81 -re ".* (big|little) endian.*$gdb_prompt $" {
82 set endian $expect_out(1,string)
83 pass "endianness: $endian"
87 # Now generate some dump files.
89 proc make_dump_file { command msg } {
92 gdb_test_multiple "${command}" "$msg" {
93 -re ".*\[Ee\]rror.*$gdb_prompt $" { fail $msg }
94 -re ".*\[Ww\]arning.*$gdb_prompt $" { fail $msg }
95 -re ".*\[Uu\]ndefined .*$gdb_prompt $" { fail $msg }
96 -re ".*$gdb_prompt $" { pass $msg }
100 make_dump_file "dump val intarr1.bin intarray" \
101 "dump array as value, default"
103 make_dump_file "dump val intstr1.bin intstruct" \
104 "dump struct as value, default"
106 make_dump_file "dump bin val intarr1b.bin intarray" \
107 "dump array as value, binary"
109 make_dump_file "dump bin val intstr1b.bin intstruct" \
110 "dump struct as value, binary"
112 make_dump_file "dump srec val intarr1.srec intarray" \
113 "dump array as value, srec"
115 make_dump_file "dump srec val intstr1.srec intstruct" \
116 "dump struct as value, srec"
118 make_dump_file "dump ihex val intarr1.ihex intarray" \
119 "dump array as value, intel hex"
121 make_dump_file "dump ihex val intstr1.ihex intstruct" \
122 "dump struct as value, intel hex"
124 make_dump_file "dump tekhex val intarr1.tekhex intarray" \
125 "dump array as value, tekhex"
127 make_dump_file "dump tekhex val intstr1.tekhex intstruct" \
128 "dump struct as value, tekhex"
130 proc capture_value { expression args } {
135 if {[llength $args] > 0} {
136 # Convert $args into a simple string.
137 set test "[join $args]; capture $expression"
139 set test "capture $expression"
141 gdb_test_multiple "print ${expression}" "$test" {
142 -re "\\$\[0-9\]+ = (\[^\r\n\]+).*$gdb_prompt $" {
143 set output_string "$expect_out(1,string)"
146 -re "(Cannot access memory at address \[^\r\n\]+).*$gdb_prompt $" {
147 # Even a failed value is valid
148 set output_string "$expect_out(1,string)"
152 return $output_string
155 set array_start [capture_value "/x &intarray\[0\]"]
156 set array_end [capture_value "/x &intarray\[32\]"]
157 set struct_start [capture_value "/x &intstruct"]
158 set struct_end [capture_value "/x &intstruct + 1"]
160 set array_val [capture_value "intarray"]
161 set struct_val [capture_value "intstruct"]
163 make_dump_file "dump mem intarr2.bin $array_start $array_end" \
164 "dump array as memory, default"
166 make_dump_file "dump mem intstr2.bin $struct_start $struct_end" \
167 "dump struct as memory, default"
169 make_dump_file "dump bin mem intarr2b.bin $array_start $array_end" \
170 "dump array as memory, binary"
172 make_dump_file "dump bin mem intstr2b.bin $struct_start $struct_end" \
173 "dump struct as memory, binary"
175 make_dump_file "dump srec mem intarr2.srec $array_start $array_end" \
176 "dump array as memory, srec"
178 make_dump_file "dump srec mem intstr2.srec $struct_start $struct_end" \
179 "dump struct as memory, srec"
181 make_dump_file "dump ihex mem intarr2.ihex $array_start $array_end" \
182 "dump array as memory, ihex"
184 make_dump_file "dump ihex mem intstr2.ihex $struct_start $struct_end" \
185 "dump struct as memory, ihex"
187 make_dump_file "dump tekhex mem intarr2.tekhex $array_start $array_end" \
188 "dump array as memory, tekhex"
190 make_dump_file "dump tekhex mem intstr2.tekhex $struct_start $struct_end" \
191 "dump struct as memory, tekhex"
193 # test complex expressions
195 "dump srec mem intarr3.srec &intarray \(char *\) &intarray + sizeof intarray" \
196 "dump array as mem, srec, expressions"
199 # Now start a fresh gdb session, and reload the saved value files.
203 gdb_file_cmd ${binfile}
205 # Now fix the endianness at the correct state.
207 gdb_test_multiple "set endian $endian" "set endianness" {
208 -re ".* (big|little) endian.*$gdb_prompt $" {
209 pass "setting $endian endianness"
213 # Reload saved values one by one, and compare.
215 if { ![string compare $array_val \
216 [capture_value "intarray" "file binfile"]] } then {
217 fail "start with intarray un-initialized"
219 pass "start with intarray un-initialized"
222 if { ![string compare $struct_val \
223 [capture_value "intstruct" "file binfile"]] } then {
224 fail "start with intstruct un-initialized"
226 pass "start with intstruct un-initialized"
229 proc test_reload_saved_value { filename msg oldval newval } {
232 gdb_file_cmd $filename
233 if { ![string compare $oldval \
234 [capture_value $newval "$msg"]] } then {
235 pass "$msg; value restored ok"
237 fail "$msg; value restored ok"
241 proc test_restore_saved_value { restore_args msg oldval newval } {
244 gdb_test "restore $restore_args" \
246 "$msg; file restored ok"
247 if { ![string compare $oldval \
248 [capture_value $newval "$msg"]] } then {
249 pass "$msg; value restored ok"
251 fail "$msg; value restored ok"
255 # srec format can not be loaded for 64-bit-only platforms
256 if ![string compare $is64bitonly "no"] then {
257 test_reload_saved_value "intarr1.srec" "reload array as value, srec" \
258 $array_val "intarray"
259 test_reload_saved_value "intstr1.srec" "reload struct as value, srec" \
260 $struct_val "intstruct"
261 test_reload_saved_value "intarr2.srec" "reload array as memory, srec" \
262 $array_val "intarray"
263 test_reload_saved_value "intstr2.srec" "reload struct as memory, srec" \
264 $struct_val "intstruct"
267 # ihex format can not be loaded for 64-bit-only platforms
268 if ![string compare $is64bitonly "no"] then {
270 test_reload_saved_value "intarr1.ihex" "reload array as value, intel hex" \
271 $array_val "intarray"
272 test_reload_saved_value "intstr1.ihex" "reload struct as value, intel hex" \
273 $struct_val "intstruct"
274 test_reload_saved_value "intarr2.ihex" "reload array as memory, intel hex" \
275 $array_val "intarray"
276 test_reload_saved_value "intstr2.ihex" "reload struct as memory, intel hex" \
277 $struct_val "intstruct"
280 # tekhex format can not be loaded for 64-bit-only platforms
281 if ![string compare $is64bitonly "no"] then {
282 test_reload_saved_value "intarr1.tekhex" "reload array as value, tekhex" \
283 $array_val "intarray"
284 test_reload_saved_value "intstr1.tekhex" "reload struct as value, tekhex" \
285 $struct_val "intstruct"
286 test_reload_saved_value "intarr2.tekhex" "reload array as memory, tekhex" \
287 $array_val "intarray"
288 test_reload_saved_value "intstr2.tekhex" "reload struct as memory, tekhex" \
289 $struct_val "intstruct"
292 # Start a fresh gdb session
296 gdb_reinitialize_dir $srcdir/$subdir
300 if { ! [ runto_main ] } then {
305 if { ![string compare $array_val \
306 [capture_value "intarray" "load binfile"]] } then {
307 fail "start with intarray un-initialized, runto main"
309 pass "start with intarray un-initialized, runto main"
312 if { ![string compare $struct_val \
313 [capture_value "intstruct" "load binfile"]] } then {
314 fail "start with intstruct un-initialized, runto main"
316 pass "start with intstruct un-initialized, runto main"
319 if ![string compare $is64bitonly "no"] then {
320 test_restore_saved_value "intarr1.srec" "array as value, srec" \
321 $array_val "intarray"
323 test_restore_saved_value "intstr1.srec" "struct as value, srec" \
324 $struct_val "intstruct"
326 gdb_test "print zero_all ()" "void" "zero all"
328 test_restore_saved_value "intarr2.srec" "array as memory, srec" \
329 $array_val "intarray"
331 test_restore_saved_value "intstr2.srec" "struct as memory, srec" \
332 $struct_val "intstruct"
334 gdb_test "print zero_all ()" ""
336 test_restore_saved_value "intarr1.ihex" "array as value, ihex" \
337 $array_val "intarray"
339 test_restore_saved_value "intstr1.ihex" "struct as value, ihex" \
340 $struct_val "intstruct"
342 gdb_test "print zero_all ()" ""
344 test_restore_saved_value "intarr2.ihex" "array as memory, ihex" \
345 $array_val "intarray"
347 test_restore_saved_value "intstr2.ihex" "struct as memory, ihex" \
348 $struct_val "intstruct"
350 gdb_test "print zero_all ()" ""
352 test_restore_saved_value "intarr1.tekhex" "array as value, tekhex" \
353 $array_val "intarray"
355 test_restore_saved_value "intstr1.tekhex" "struct as value, tekhex" \
356 $struct_val "intstruct"
358 gdb_test "print zero_all ()" ""
360 test_restore_saved_value "intarr2.tekhex" "array as memory, tekhex" \
361 $array_val "intarray"
363 test_restore_saved_value "intstr2.tekhex" "struct as memory, tekhex" \
364 $struct_val "intstruct"
367 gdb_test "print zero_all ()" ""
369 test_restore_saved_value "intarr1.bin binary $array_start" \
370 "array as value, binary" \
371 $array_val "intarray"
373 test_restore_saved_value "intstr1.bin binary $struct_start" \
374 "struct as value, binary" \
375 $struct_val "intstruct"
377 gdb_test "print zero_all ()" ""
379 test_restore_saved_value "intarr2.bin binary $array_start" \
380 "array as memory, binary" \
381 $array_val "intarray"
383 test_restore_saved_value "intstr2.bin binary $struct_start" \
384 "struct as memory, binary" \
385 $struct_val "intstruct"
387 # test restore with offset.
389 set array2_start [capture_value "/x &intarray2\[0\]"]
390 set struct2_start [capture_value "/x &intstruct2"]
392 [capture_value "(char *) &intarray2 - (char *) &intarray"]
394 [capture_value "(char *) &intstruct2 - (char *) &intstruct"]
396 gdb_test "print zero_all ()" ""
399 if ![string compare $is64bitonly "no"] then {
400 test_restore_saved_value "intarr1.srec $array2_offset" \
402 $array_val "intarray2"
404 test_restore_saved_value "intstr1.srec $struct2_offset" \
405 "struct copy, srec" \
406 $struct_val "intstruct2"
408 gdb_test "print zero_all ()" ""
410 test_restore_saved_value "intarr1.ihex $array2_offset" \
412 $array_val "intarray2"
414 test_restore_saved_value "intstr1.ihex $struct2_offset" \
415 "struct copy, ihex" \
416 $struct_val "intstruct2"
418 gdb_test "print zero_all ()" ""
420 test_restore_saved_value "intarr1.tekhex $array2_offset" \
421 "array copy, tekhex" \
422 $array_val "intarray2"
424 test_restore_saved_value "intstr1.tekhex $struct2_offset" \
425 "struct copy, tekhex" \
426 $struct_val "intstruct2"
429 gdb_test "print zero_all ()" ""
431 test_restore_saved_value "intarr1.bin binary $array2_start" \
432 "array copy, binary" \
433 $array_val "intarray2"
435 test_restore_saved_value "intstr1.bin binary $struct2_start" \
436 "struct copy, binary" \
437 $struct_val "intstruct2"
440 # test restore with start/stop addresses.
442 # For this purpose, we will restore just the third element of the array,
443 # and check to see that adjacent elements are not modified.
445 # We will need the address and offset of the third and fourth elements.
448 set element3_start [capture_value "/x &intarray\[3\]"]
449 set element4_start [capture_value "/x &intarray\[4\]"]
450 set element3_offset \
451 [capture_value "/x (char *) &intarray\[3\] - (char *) &intarray\[0\]"]
452 set element4_offset \
453 [capture_value "/x (char *) &intarray\[4\] - (char *) &intarray\[0\]"]
455 if ![string compare $is64bitonly "no"] then {
456 gdb_test "print zero_all ()" ""
458 test_restore_saved_value "intarr1.srec 0 $element3_start $element4_start" \
459 "array partial, srec" 4 "intarray\[3\]"
461 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 1"
462 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 1"
464 gdb_test "print zero_all ()" ""
466 test_restore_saved_value "intarr1.ihex 0 $element3_start $element4_start" \
467 "array partial, ihex" 4 "intarray\[3\]"
469 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 2"
470 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 2"
472 gdb_test "print zero_all ()" ""
474 test_restore_saved_value "intarr1.tekhex 0 $element3_start $element4_start" \
475 "array partial, tekhex" 4 "intarray\[3\]"
477 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 3"
478 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 3"
481 gdb_test "print zero_all ()" ""
483 test_restore_saved_value \
484 "intarr1.bin binary $array_start $element3_offset $element4_offset" \
485 "array partial, binary" 4 "intarray\[3\]"
487 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 4"
488 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 4"
490 if ![string compare $is64bitonly "no"] then {
491 gdb_test "print zero_all ()" "" ""
493 # restore with expressions
494 test_restore_saved_value \
495 "intarr3.srec (char*)${array2_start}-(char*)${array_start} &intarray\[3\] &intarray\[4\]" \
496 "array partial with expressions" 4 "intarray2\[3\]"
498 gdb_test "print intarray2\[2\] == 0" " = 1" "element 2 not changed, == 4"
499 gdb_test "print intarray2\[4\] == 0" " = 1" "element 4 not changed, == 4"
504 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"