1 # Copyright 2002, 2004, 2007, 2008, 2009 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".
28 set srcfile ${testfile}.c
29 set binfile ${objdir}/${subdir}/${testfile}
35 if [istarget "alpha*-*-*"] then {
36 # SREC etc cannot handle 64-bit addresses. Force the test
37 # program into the low 31 bits of the address space.
38 lappend options "additional_flags=-Wl,-taso"
41 if {[istarget "ia64*-*-*"] || [istarget "hppa64-*-*"]} then {
45 if {[istarget "spu*-*-*"]} then {
46 # The internal address format used for the combined Cell/B.E.
47 # debugger requires 64-bit.
51 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable ${options}] != "" } {
56 # Start with a fresh gdb.
60 gdb_reinitialize_dir $srcdir/$subdir
63 # Clean up any stale output files from previous test runs
65 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 # Run target program until data structs are initialized.
71 if { ! [ runto checkpoint1 ] } then {
76 # Get the endianness for the later use with endianless formats.
78 send_gdb "show endian\n"
80 -re ".* (big|little) endian.*$gdb_prompt $" {
81 set endian $expect_out(1,string)
82 pass "endianness: $endian"
85 fail "(timeout) getting target endianness"
89 # Now generate some dump files.
91 proc make_dump_file { command msg } {
94 send_gdb "${command}\n"
96 -re ".*\[Ee\]rror.*$gdb_prompt $" { fail $msg }
97 -re ".*\[Ww\]arning.*$gdb_prompt $" { fail $msg }
98 -re ".*\[Uu\]ndefined .*$gdb_prompt $" { fail $msg }
99 -re ".*$gdb_prompt $" { pass $msg }
100 timeout { fail "$msg (timeout)" }
104 make_dump_file "dump val intarr1.bin intarray" \
105 "dump array as value, default"
107 make_dump_file "dump val intstr1.bin intstruct" \
108 "dump struct as value, default"
110 make_dump_file "dump bin val intarr1b.bin intarray" \
111 "dump array as value, binary"
113 make_dump_file "dump bin val intstr1b.bin intstruct" \
114 "dump struct as value, binary"
116 make_dump_file "dump srec val intarr1.srec intarray" \
117 "dump array as value, srec"
119 make_dump_file "dump srec val intstr1.srec intstruct" \
120 "dump struct as value, srec"
122 make_dump_file "dump ihex val intarr1.ihex intarray" \
123 "dump array as value, intel hex"
125 make_dump_file "dump ihex val intstr1.ihex intstruct" \
126 "dump struct as value, intel hex"
128 make_dump_file "dump tekhex val intarr1.tekhex intarray" \
129 "dump array as value, tekhex"
131 make_dump_file "dump tekhex val intstr1.tekhex intstruct" \
132 "dump struct as value, tekhex"
134 proc capture_value { expression args } {
139 if {[llength $args] > 0} {
140 # Convert $args into a simple string.
141 set test "[join $args]; capture $expression"
143 set test "capture $expression"
145 gdb_test_multiple "print ${expression}" "$test" {
146 -re "\\$\[0-9\]+ = (\[^\r\n\]+).*$gdb_prompt $" {
147 set output_string "$expect_out(1,string)"
150 -re "(Cannot access memory at address \[^\r\n\]+).*$gdb_prompt $" {
151 # Even a failed value is valid
152 set output_string "$expect_out(1,string)"
156 return $output_string
159 set array_start [capture_value "/x &intarray\[0\]"]
160 set array_end [capture_value "/x &intarray\[32\]"]
161 set struct_start [capture_value "/x &intstruct"]
162 set struct_end [capture_value "/x &intstruct + 1"]
164 set array_val [capture_value "intarray"]
165 set struct_val [capture_value "intstruct"]
167 make_dump_file "dump mem intarr2.bin $array_start $array_end" \
168 "dump array as memory, default"
170 make_dump_file "dump mem intstr2.bin $struct_start $struct_end" \
171 "dump struct as memory, default"
173 make_dump_file "dump bin mem intarr2b.bin $array_start $array_end" \
174 "dump array as memory, binary"
176 make_dump_file "dump bin mem intstr2b.bin $struct_start $struct_end" \
177 "dump struct as memory, binary"
179 make_dump_file "dump srec mem intarr2.srec $array_start $array_end" \
180 "dump array as memory, srec"
182 make_dump_file "dump srec mem intstr2.srec $struct_start $struct_end" \
183 "dump struct as memory, srec"
185 make_dump_file "dump ihex mem intarr2.ihex $array_start $array_end" \
186 "dump array as memory, ihex"
188 make_dump_file "dump ihex mem intstr2.ihex $struct_start $struct_end" \
189 "dump struct as memory, ihex"
191 make_dump_file "dump tekhex mem intarr2.tekhex $array_start $array_end" \
192 "dump array as memory, tekhex"
194 make_dump_file "dump tekhex mem intstr2.tekhex $struct_start $struct_end" \
195 "dump struct as memory, tekhex"
197 # test complex expressions
199 "dump srec mem intarr3.srec &intarray \(char *\) &intarray + sizeof intarray" \
200 "dump array as mem, srec, expressions"
203 # Now start a fresh gdb session, and reload the saved value files.
207 gdb_file_cmd ${binfile}
209 # Now fix the endianness at the correct state.
211 send_gdb "set endian $endian\n"
213 -re ".* (big|little) endian.*$gdb_prompt $" {
214 pass "setting $endian endianness"
217 fail "(timeout) setting $endian endianness"
221 # Reload saved values one by one, and compare.
223 if { ![string compare $array_val \
224 [capture_value "intarray" "file binfile"]] } then {
225 fail "start with intarray un-initialized"
227 pass "start with intarray un-initialized"
230 if { ![string compare $struct_val \
231 [capture_value "intstruct" "file binfile"]] } then {
232 fail "start with intstruct un-initialized"
234 pass "start with intstruct un-initialized"
237 proc test_reload_saved_value { filename msg oldval newval } {
240 gdb_file_cmd $filename
241 if { ![string compare $oldval \
242 [capture_value $newval "$msg"]] } then {
243 pass "$msg; value restored ok"
245 fail "$msg; value restored ok"
249 proc test_restore_saved_value { restore_args msg oldval newval } {
252 gdb_test "restore $restore_args" \
254 "$msg; file restored ok"
255 if { ![string compare $oldval \
256 [capture_value $newval "$msg"]] } then {
257 pass "$msg; value restored ok"
259 fail "$msg; value restored ok"
263 # srec format can not be loaded for 64-bit-only platforms
264 if ![string compare $is64bitonly "no"] then {
265 test_reload_saved_value "intarr1.srec" "reload array as value, srec" \
266 $array_val "intarray"
267 test_reload_saved_value "intstr1.srec" "reload struct as value, srec" \
268 $struct_val "intstruct"
269 test_reload_saved_value "intarr2.srec" "reload array as memory, srec" \
270 $array_val "intarray"
271 test_reload_saved_value "intstr2.srec" "reload struct as memory, srec" \
272 $struct_val "intstruct"
275 # ihex format can not be loaded for 64-bit-only platforms
276 if ![string compare $is64bitonly "no"] then {
278 test_reload_saved_value "intarr1.ihex" "reload array as value, intel hex" \
279 $array_val "intarray"
280 test_reload_saved_value "intstr1.ihex" "reload struct as value, intel hex" \
281 $struct_val "intstruct"
282 test_reload_saved_value "intarr2.ihex" "reload array as memory, intel hex" \
283 $array_val "intarray"
284 test_reload_saved_value "intstr2.ihex" "reload struct as memory, intel hex" \
285 $struct_val "intstruct"
288 # tekhex format can not be loaded for 64-bit-only platforms
289 if ![string compare $is64bitonly "no"] then {
290 test_reload_saved_value "intarr1.tekhex" "reload array as value, tekhex" \
291 $array_val "intarray"
292 test_reload_saved_value "intstr1.tekhex" "reload struct as value, tekhex" \
293 $struct_val "intstruct"
294 test_reload_saved_value "intarr2.tekhex" "reload array as memory, tekhex" \
295 $array_val "intarray"
296 test_reload_saved_value "intstr2.tekhex" "reload struct as memory, tekhex" \
297 $struct_val "intstruct"
300 # Start a fresh gdb session
304 gdb_reinitialize_dir $srcdir/$subdir
308 if { ! [ runto_main ] } then {
313 if { ![string compare $array_val \
314 [capture_value "intarray" "load binfile"]] } then {
315 fail "start with intarray un-initialized, runto main"
317 pass "start with intarray un-initialized, runto main"
320 if { ![string compare $struct_val \
321 [capture_value "intstruct" "load binfile"]] } then {
322 fail "start with intstruct un-initialized, runto main"
324 pass "start with intstruct un-initialized, runto main"
327 if ![string compare $is64bitonly "no"] then {
328 test_restore_saved_value "intarr1.srec" "array as value, srec" \
329 $array_val "intarray"
331 test_restore_saved_value "intstr1.srec" "struct as value, srec" \
332 $struct_val "intstruct"
334 gdb_test "print zero_all ()" "void" "zero all"
336 test_restore_saved_value "intarr2.srec" "array as memory, srec" \
337 $array_val "intarray"
339 test_restore_saved_value "intstr2.srec" "struct as memory, srec" \
340 $struct_val "intstruct"
342 gdb_test "print zero_all ()" ""
344 test_restore_saved_value "intarr1.ihex" "array as value, ihex" \
345 $array_val "intarray"
347 test_restore_saved_value "intstr1.ihex" "struct as value, ihex" \
348 $struct_val "intstruct"
350 gdb_test "print zero_all ()" ""
352 test_restore_saved_value "intarr2.ihex" "array as memory, ihex" \
353 $array_val "intarray"
355 test_restore_saved_value "intstr2.ihex" "struct as memory, ihex" \
356 $struct_val "intstruct"
358 gdb_test "print zero_all ()" ""
360 test_restore_saved_value "intarr1.tekhex" "array as value, tekhex" \
361 $array_val "intarray"
363 test_restore_saved_value "intstr1.tekhex" "struct as value, tekhex" \
364 $struct_val "intstruct"
366 gdb_test "print zero_all ()" ""
368 test_restore_saved_value "intarr2.tekhex" "array as memory, tekhex" \
369 $array_val "intarray"
371 test_restore_saved_value "intstr2.tekhex" "struct as memory, tekhex" \
372 $struct_val "intstruct"
375 gdb_test "print zero_all ()" ""
377 test_restore_saved_value "intarr1.bin binary $array_start" \
378 "array as value, binary" \
379 $array_val "intarray"
381 test_restore_saved_value "intstr1.bin binary $struct_start" \
382 "struct as value, binary" \
383 $struct_val "intstruct"
385 gdb_test "print zero_all ()" ""
387 test_restore_saved_value "intarr2.bin binary $array_start" \
388 "array as memory, binary" \
389 $array_val "intarray"
391 test_restore_saved_value "intstr2.bin binary $struct_start" \
392 "struct as memory, binary" \
393 $struct_val "intstruct"
395 # test restore with offset.
397 set array2_start [capture_value "/x &intarray2\[0\]"]
398 set struct2_start [capture_value "/x &intstruct2"]
400 [capture_value "(char *) &intarray2 - (char *) &intarray"]
402 [capture_value "(char *) &intstruct2 - (char *) &intstruct"]
404 gdb_test "print zero_all ()" ""
407 if ![string compare $is64bitonly "no"] then {
408 test_restore_saved_value "intarr1.srec $array2_offset" \
410 $array_val "intarray2"
412 test_restore_saved_value "intstr1.srec $struct2_offset" \
413 "struct copy, srec" \
414 $struct_val "intstruct2"
416 gdb_test "print zero_all ()" ""
418 test_restore_saved_value "intarr1.ihex $array2_offset" \
420 $array_val "intarray2"
422 test_restore_saved_value "intstr1.ihex $struct2_offset" \
423 "struct copy, ihex" \
424 $struct_val "intstruct2"
426 gdb_test "print zero_all ()" ""
428 test_restore_saved_value "intarr1.tekhex $array2_offset" \
429 "array copy, tekhex" \
430 $array_val "intarray2"
432 test_restore_saved_value "intstr1.tekhex $struct2_offset" \
433 "struct copy, tekhex" \
434 $struct_val "intstruct2"
437 gdb_test "print zero_all ()" ""
439 test_restore_saved_value "intarr1.bin binary $array2_start" \
440 "array copy, binary" \
441 $array_val "intarray2"
443 test_restore_saved_value "intstr1.bin binary $struct2_start" \
444 "struct copy, binary" \
445 $struct_val "intstruct2"
448 # test restore with start/stop addresses.
450 # For this purpose, we will restore just the third element of the array,
451 # and check to see that adjacent elements are not modified.
453 # We will need the address and offset of the third and fourth elements.
456 set element3_start [capture_value "/x &intarray\[3\]"]
457 set element4_start [capture_value "/x &intarray\[4\]"]
458 set element3_offset \
459 [capture_value "/x (char *) &intarray\[3\] - (char *) &intarray\[0\]"]
460 set element4_offset \
461 [capture_value "/x (char *) &intarray\[4\] - (char *) &intarray\[0\]"]
463 if ![string compare $is64bitonly "no"] then {
464 gdb_test "print zero_all ()" ""
466 test_restore_saved_value "intarr1.srec 0 $element3_start $element4_start" \
467 "array partial, srec" 4 "intarray\[3\]"
469 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 1"
470 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 1"
472 gdb_test "print zero_all ()" ""
474 test_restore_saved_value "intarr1.ihex 0 $element3_start $element4_start" \
475 "array partial, ihex" 4 "intarray\[3\]"
477 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 2"
478 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 2"
480 gdb_test "print zero_all ()" ""
482 test_restore_saved_value "intarr1.tekhex 0 $element3_start $element4_start" \
483 "array partial, tekhex" 4 "intarray\[3\]"
485 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 3"
486 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 3"
489 gdb_test "print zero_all ()" ""
491 test_restore_saved_value \
492 "intarr1.bin binary $array_start $element3_offset $element4_offset" \
493 "array partial, binary" 4 "intarray\[3\]"
495 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 4"
496 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 4"
498 if ![string compare $is64bitonly "no"] then {
499 gdb_test "print zero_all ()" "" ""
501 # restore with expressions
502 test_restore_saved_value \
503 "intarr3.srec ${array2_start}-${array_start} &intarray\[3\] &intarray\[4\]" \
504 "array partial with expressions" 4 "intarray2\[3\]"
506 gdb_test "print intarray2\[2\] == 0" " = 1" "element 2 not changed, == 4"
507 gdb_test "print intarray2\[4\] == 0" " = 1" "element 4 not changed, == 4"
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"