1 # Copyright 2002, 2004 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Michael Snyder (msnyder@redhat.com)
21 # This is a test for the gdb command "dump".
32 set srcfile ${testfile}.c
33 set binfile ${objdir}/${subdir}/${testfile}
38 if [istarget "alpha*-*-*"] then {
39 # SREC etc cannot handle 64-bit addresses. Force the test
40 # program into the low 31 bits of the address space.
41 lappend options "additional_flags=-Wl,-taso"
44 if {[istarget "ia64*-*-*"] || [istarget "hppa64-*-*"]} then {
48 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable ${options}] != "" } {
49 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
52 # Start with a fresh gdb.
56 gdb_reinitialize_dir $srcdir/$subdir
59 # Clean up any stale output files from previous test runs
61 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"
65 # Run target program until data structs are initialized.
67 if { ! [ runto checkpoint1 ] } then {
68 gdb_suppress_entire_file "Program failed to run, so all tests in this file will automatically fail."
71 # Now generate some dump files.
73 proc make_dump_file { command msg } {
76 send_gdb "${command}\n"
78 -re ".*\[Ee\]rror.*$gdb_prompt $" { fail $msg }
79 -re ".*\[Ww\]arning.*$gdb_prompt $" { fail $msg }
80 -re ".*\[Uu\]ndefined .*$gdb_prompt $" { fail $msg }
81 -re ".*$gdb_prompt $" { pass $msg }
82 timeout { fail "$msg (timeout)" }
86 make_dump_file "dump val intarr1.bin intarray" \
87 "dump array as value, default"
89 make_dump_file "dump val intstr1.bin intstruct" \
90 "dump struct as value, default"
92 make_dump_file "dump bin val intarr1b.bin intarray" \
93 "dump array as value, binary"
95 make_dump_file "dump bin val intstr1b.bin intstruct" \
96 "dump struct as value, binary"
98 make_dump_file "dump srec val intarr1.srec intarray" \
99 "dump array as value, srec"
101 make_dump_file "dump srec val intstr1.srec intstruct" \
102 "dump struct as value, srec"
104 make_dump_file "dump ihex val intarr1.ihex intarray" \
105 "dump array as value, intel hex"
107 make_dump_file "dump ihex val intstr1.ihex intstruct" \
108 "dump struct as value, intel hex"
110 make_dump_file "dump tekhex val intarr1.tekhex intarray" \
111 "dump array as value, tekhex"
113 make_dump_file "dump tekhex val intstr1.tekhex intstruct" \
114 "dump struct as value, tekhex"
116 proc capture_value { expression args } {
121 if {[llength $args] > 0} {
122 # Convert $args into a simple string.
123 set test "[join $args]; capture $expression"
125 set test "capture $expression"
127 gdb_test_multiple "print ${expression}" "$test" {
128 -re "\\$\[0-9\]+ = (\[^\r\n\]+).*$gdb_prompt $" {
129 set output_string "$expect_out(1,string)"
132 -re "(Cannot access memory at address \[^\r\n\]+).*$gdb_prompt $" {
133 # Even a failed value is valid
134 set output_string "$expect_out(1,string)"
138 return $output_string
141 set array_start [capture_value "/x &intarray\[0\]"]
142 set array_end [capture_value "/x &intarray\[32\]"]
143 set struct_start [capture_value "/x &intstruct"]
144 set struct_end [capture_value "/x &intstruct + 1"]
146 set array_val [capture_value "intarray"]
147 set struct_val [capture_value "intstruct"]
149 make_dump_file "dump mem intarr2.bin $array_start $array_end" \
150 "dump array as memory, default"
152 make_dump_file "dump mem intstr2.bin $struct_start $struct_end" \
153 "dump struct as memory, default"
155 make_dump_file "dump bin mem intarr2b.bin $array_start $array_end" \
156 "dump array as memory, binary"
158 make_dump_file "dump bin mem intstr2b.bin $struct_start $struct_end" \
159 "dump struct as memory, binary"
161 make_dump_file "dump srec mem intarr2.srec $array_start $array_end" \
162 "dump array as memory, srec"
164 make_dump_file "dump srec mem intstr2.srec $struct_start $struct_end" \
165 "dump struct as memory, srec"
167 make_dump_file "dump ihex mem intarr2.ihex $array_start $array_end" \
168 "dump array as memory, ihex"
170 make_dump_file "dump ihex mem intstr2.ihex $struct_start $struct_end" \
171 "dump struct as memory, ihex"
173 make_dump_file "dump tekhex mem intarr2.tekhex $array_start $array_end" \
174 "dump array as memory, tekhex"
176 make_dump_file "dump tekhex mem intstr2.tekhex $struct_start $struct_end" \
177 "dump struct as memory, tekhex"
179 # test complex expressions
181 "dump srec mem intarr3.srec &intarray \(char *\) &intarray + sizeof intarray" \
182 "dump array as mem, srec, expressions"
185 # Now start a fresh gdb session, and reload the saved value files.
189 gdb_file_cmd ${binfile}
191 # Reload saved values one by one, and compare.
193 if { ![string compare $array_val \
194 [capture_value "intarray" "file binfile"]] } then {
195 fail "start with intarray un-initialized"
197 pass "start with intarray un-initialized"
200 if { ![string compare $struct_val \
201 [capture_value "intstruct" "file binfile"]] } then {
202 fail "start with intstruct un-initialized"
204 pass "start with intstruct un-initialized"
207 proc test_reload_saved_value { filename msg oldval newval } {
210 gdb_file_cmd $filename
211 if { ![string compare $oldval \
212 [capture_value $newval "$msg"]] } then {
213 pass "$msg; value restored ok"
215 fail "$msg; value restored ok"
219 proc test_restore_saved_value { restore_args msg oldval newval } {
222 gdb_test "restore $restore_args" \
224 "$msg; file restored ok"
225 if { ![string compare $oldval \
226 [capture_value $newval "$msg"]] } then {
227 pass "$msg; value restored ok"
229 fail "$msg; value restored ok"
233 # srec format can not be loaded for 64-bit-only platforms
234 if ![string compare $is64bitonly "no"] then {
235 test_reload_saved_value "intarr1.srec" "reload array as value, srec" \
236 $array_val "intarray"
237 test_reload_saved_value "intstr1.srec" "reload struct as value, srec" \
238 $struct_val "intstruct"
239 test_reload_saved_value "intarr2.srec" "reload array as memory, srec" \
240 $array_val "intarray"
241 test_reload_saved_value "intstr2.srec" "reload struct as memory, srec" \
242 $struct_val "intstruct"
245 # ihex format can not be loaded for 64-bit-only platforms
246 if ![string compare $is64bitonly "no"] then {
248 test_reload_saved_value "intarr1.ihex" "reload array as value, intel hex" \
249 $array_val "intarray"
250 test_reload_saved_value "intstr1.ihex" "reload struct as value, intel hex" \
251 $struct_val "intstruct"
252 test_reload_saved_value "intarr2.ihex" "reload array as memory, intel hex" \
253 $array_val "intarray"
254 test_reload_saved_value "intstr2.ihex" "reload struct as memory, intel hex" \
255 $struct_val "intstruct"
258 # tekhex format can not be loaded for 64-bit-only platforms
259 if ![string compare $is64bitonly "no"] then {
260 test_reload_saved_value "intarr1.tekhex" "reload array as value, tekhex" \
261 $array_val "intarray"
262 test_reload_saved_value "intstr1.tekhex" "reload struct as value, tekhex" \
263 $struct_val "intstruct"
264 test_reload_saved_value "intarr2.tekhex" "reload array as memory, tekhex" \
265 $array_val "intarray"
266 test_reload_saved_value "intstr2.tekhex" "reload struct as memory, tekhex" \
267 $struct_val "intstruct"
270 # Start a fresh gdb session
274 gdb_reinitialize_dir $srcdir/$subdir
278 if { ! [ runto_main ] } then {
279 gdb_suppress_entire_file "Program failed to run, so remaining tests in this file will automatically fail."
282 if { ![string compare $array_val \
283 [capture_value "intarray" "load binfile"]] } then {
284 fail "start with intarray un-initialized, runto main"
286 pass "start with intarray un-initialized, runto main"
289 if { ![string compare $struct_val \
290 [capture_value "intstruct" "load binfile"]] } then {
291 fail "start with intstruct un-initialized, runto main"
293 pass "start with intstruct un-initialized, runto main"
296 if ![string compare $is64bitonly "no"] then {
297 test_restore_saved_value "intarr1.srec" "array as value, srec" \
298 $array_val "intarray"
300 test_restore_saved_value "intstr1.srec" "struct as value, srec" \
301 $struct_val "intstruct"
303 gdb_test "print zero_all ()" "void" "zero all"
305 test_restore_saved_value "intarr2.srec" "array as memory, srec" \
306 $array_val "intarray"
308 test_restore_saved_value "intstr2.srec" "struct as memory, srec" \
309 $struct_val "intstruct"
311 gdb_test "print zero_all ()" ""
313 test_restore_saved_value "intarr1.ihex" "array as value, ihex" \
314 $array_val "intarray"
316 test_restore_saved_value "intstr1.ihex" "struct as value, ihex" \
317 $struct_val "intstruct"
319 gdb_test "print zero_all ()" ""
321 test_restore_saved_value "intarr2.ihex" "array as memory, ihex" \
322 $array_val "intarray"
324 test_restore_saved_value "intstr2.ihex" "struct as memory, ihex" \
325 $struct_val "intstruct"
327 gdb_test "print zero_all ()" ""
329 test_restore_saved_value "intarr1.tekhex" "array as value, tekhex" \
330 $array_val "intarray"
332 test_restore_saved_value "intstr1.tekhex" "struct as value, tekhex" \
333 $struct_val "intstruct"
335 gdb_test "print zero_all ()" ""
337 test_restore_saved_value "intarr2.tekhex" "array as memory, tekhex" \
338 $array_val "intarray"
340 test_restore_saved_value "intstr2.tekhex" "struct as memory, tekhex" \
341 $struct_val "intstruct"
344 gdb_test "print zero_all ()" ""
346 test_restore_saved_value "intarr1.bin binary $array_start" \
347 "array as value, binary" \
348 $array_val "intarray"
350 test_restore_saved_value "intstr1.bin binary $struct_start" \
351 "struct as value, binary" \
352 $struct_val "intstruct"
354 gdb_test "print zero_all ()" ""
356 test_restore_saved_value "intarr2.bin binary $array_start" \
357 "array as memory, binary" \
358 $array_val "intarray"
360 test_restore_saved_value "intstr2.bin binary $struct_start" \
361 "struct as memory, binary" \
362 $struct_val "intstruct"
364 # test restore with offset.
366 set array2_start [capture_value "/x &intarray2\[0\]"]
367 set struct2_start [capture_value "/x &intstruct2"]
369 [capture_value "(char *) &intarray2 - (char *) &intarray"]
371 [capture_value "(char *) &intstruct2 - (char *) &intstruct"]
373 gdb_test "print zero_all ()" ""
376 if ![string compare $is64bitonly "no"] then {
377 test_restore_saved_value "intarr1.srec $array2_offset" \
379 $array_val "intarray2"
381 test_restore_saved_value "intstr1.srec $struct2_offset" \
382 "struct copy, srec" \
383 $struct_val "intstruct2"
385 gdb_test "print zero_all ()" ""
387 test_restore_saved_value "intarr1.ihex $array2_offset" \
389 $array_val "intarray2"
391 test_restore_saved_value "intstr1.ihex $struct2_offset" \
392 "struct copy, ihex" \
393 $struct_val "intstruct2"
395 gdb_test "print zero_all ()" ""
397 test_restore_saved_value "intarr1.tekhex $array2_offset" \
398 "array copy, tekhex" \
399 $array_val "intarray2"
401 test_restore_saved_value "intstr1.tekhex $struct2_offset" \
402 "struct copy, tekhex" \
403 $struct_val "intstruct2"
406 gdb_test "print zero_all ()" ""
408 test_restore_saved_value "intarr1.bin binary $array2_start" \
409 "array copy, binary" \
410 $array_val "intarray2"
412 test_restore_saved_value "intstr1.bin binary $struct2_start" \
413 "struct copy, binary" \
414 $struct_val "intstruct2"
417 # test restore with start/stop addresses.
419 # For this purpose, we will restore just the third element of the array,
420 # and check to see that adjacent elements are not modified.
422 # We will need the address and offset of the third and fourth elements.
425 set element3_start [capture_value "/x &intarray\[3\]"]
426 set element4_start [capture_value "/x &intarray\[4\]"]
427 set element3_offset \
428 [capture_value "/x (char *) &intarray\[3\] - (char *) &intarray\[0\]"]
429 set element4_offset \
430 [capture_value "/x (char *) &intarray\[4\] - (char *) &intarray\[0\]"]
432 if ![string compare $is64bitonly "no"] then {
433 gdb_test "print zero_all ()" ""
435 test_restore_saved_value "intarr1.srec 0 $element3_start $element4_start" \
436 "array partial, srec" 4 "intarray\[3\]"
438 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 1"
439 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 1"
441 gdb_test "print zero_all ()" ""
443 test_restore_saved_value "intarr1.ihex 0 $element3_start $element4_start" \
444 "array partial, ihex" 4 "intarray\[3\]"
446 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 2"
447 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 2"
449 gdb_test "print zero_all ()" ""
451 test_restore_saved_value "intarr1.tekhex 0 $element3_start $element4_start" \
452 "array partial, tekhex" 4 "intarray\[3\]"
454 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 3"
455 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 3"
458 gdb_test "print zero_all ()" ""
460 test_restore_saved_value \
461 "intarr1.bin binary $array_start $element3_offset $element4_offset" \
462 "array partial, binary" 4 "intarray\[3\]"
464 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 4"
465 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 4"
467 if ![string compare $is64bitonly "no"] then {
468 gdb_test "print zero_all ()" "" ""
470 # restore with expressions
471 test_restore_saved_value \
472 "intarr3.srec ${array2_start}-${array_start} &intarray\[3\] &intarray\[4\]" \
473 "array partial with expressions" 4 "intarray2\[3\]"
475 gdb_test "print intarray2\[2\] == 0" " = 1" "element 2 not changed, == 4"
476 gdb_test "print intarray2\[4\] == 0" " = 1" "element 4 not changed, == 4"
481 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"