1 # Copyright 2002 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}
36 if [istarget "alpha*-*-*"] then {
37 # SREC etc cannot handle 64-bit addresses. Force the test
38 # program into the low 31 bits of the address space.
39 lappend options "additional_flags=-Wl,-taso"
42 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable ${options}] != "" } {
43 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
46 # Start with a fresh gdb.
50 gdb_reinitialize_dir $srcdir/$subdir
53 # Clean up any stale output files from previous test runs
55 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"
59 # Run target program until data structs are initialized.
61 if { ! [ runto checkpoint1 ] } then {
62 gdb_suppress_entire_file "Program failed to run, so all tests in this file will automatically fail."
65 # Now generate some dump files.
67 proc make_dump_file { command msg } {
70 send_gdb "${command}\n"
72 -re ".*\[Ee\]rror.*$gdb_prompt $" { fail $msg }
73 -re ".*\[Ww\]arning.*$gdb_prompt $" { fail $msg }
74 -re ".*\[Uu\]ndefined .*$gdb_prompt $" { fail $msg }
75 -re ".*$gdb_prompt $" { pass $msg }
76 timeout { fail "$msg (timeout)" }
80 make_dump_file "dump val intarr1.bin intarray" \
81 "dump array as value, default"
83 make_dump_file "dump val intstr1.bin intstruct" \
84 "dump struct as value, default"
86 make_dump_file "dump bin val intarr1b.bin intarray" \
87 "dump array as value, binary"
89 make_dump_file "dump bin val intstr1b.bin intstruct" \
90 "dump struct as value, binary"
92 make_dump_file "dump srec val intarr1.srec intarray" \
93 "dump array as value, srec"
95 make_dump_file "dump srec val intstr1.srec intstruct" \
96 "dump struct as value, srec"
98 make_dump_file "dump ihex val intarr1.ihex intarray" \
99 "dump array as value, intel hex"
101 make_dump_file "dump ihex val intstr1.ihex intstruct" \
102 "dump struct as value, intel hex"
104 make_dump_file "dump tekhex val intarr1.tekhex intarray" \
105 "dump array as value, tekhex"
107 make_dump_file "dump tekhex val intstr1.tekhex intstruct" \
108 "dump struct as value, tekhex"
110 proc capture_value { expression } {
115 send_gdb "print ${expression}\n"
117 -re ".*\[\r\n\]+.\[0123456789\]+ = (\[^\r\n\]+).*$gdb_prompt $" {
118 set output_string $expect_out(1,string)
121 fail "capture_value failed on $expression."
124 return $output_string
127 set array_start [capture_value "/x &intarray\[0\]"]
128 set array_end [capture_value "/x &intarray\[32\]"]
129 set struct_start [capture_value "/x &intstruct"]
130 set struct_end [capture_value "/x &intstruct + 1"]
132 set array_val [capture_value "intarray"]
133 set struct_val [capture_value "intstruct"]
135 make_dump_file "dump mem intarr2.bin $array_start $array_end" \
136 "dump array as memory, default"
138 make_dump_file "dump mem intstr2.bin $struct_start $struct_end" \
139 "dump struct as memory, default"
141 make_dump_file "dump bin mem intarr2b.bin $array_start $array_end" \
142 "dump array as memory, binary"
144 make_dump_file "dump bin mem intstr2b.bin $struct_start $struct_end" \
145 "dump struct as memory, binary"
147 make_dump_file "dump srec mem intarr2.srec $array_start $array_end" \
148 "dump array as memory, srec"
150 make_dump_file "dump srec mem intstr2.srec $struct_start $struct_end" \
151 "dump struct as memory, srec"
153 make_dump_file "dump ihex mem intarr2.ihex $array_start $array_end" \
154 "dump array as memory, ihex"
156 make_dump_file "dump ihex mem intstr2.ihex $struct_start $struct_end" \
157 "dump struct as memory, ihex"
159 make_dump_file "dump tekhex mem intarr2.tekhex $array_start $array_end" \
160 "dump array as memory, tekhex"
162 make_dump_file "dump tekhex mem intstr2.tekhex $struct_start $struct_end" \
163 "dump struct as memory, tekhex"
165 # test complex expressions
167 "dump srec mem intarr3.srec &intarray \(char *\) &intarray + sizeof intarray" \
168 "dump array as mem, srec, expressions"
171 # Now start a fresh gdb session, and reload the saved value files.
175 gdb_file_cmd ${binfile}
177 # Reload saved values one by one, and compare.
179 if { ![string compare $array_val [capture_value "intarray"]] } then {
180 fail "start with intarray un-initialized"
182 pass "start with intarray un-initialized"
185 if { ![string compare $struct_val [capture_value "intstruct"]] } then {
186 fail "start with intstruct un-initialized"
188 pass "start with intstruct un-initialized"
191 proc test_reload_saved_value { filename msg oldval newval } {
194 gdb_file_cmd $filename
195 if { ![string compare $oldval [capture_value $newval]] } then {
202 proc test_restore_saved_value { restore_args msg oldval newval } {
205 gdb_test "restore $restore_args" \
207 "Restore command, $msg"
209 if { ![string compare $oldval [capture_value $newval]] } then {
210 pass "Restored value, $msg"
212 fail "Restored value, $msg"
216 test_reload_saved_value "intarr1.srec" "reload array as value, srec" \
217 $array_val "intarray"
218 test_reload_saved_value "intstr1.srec" "reload struct as value, srec" \
219 $struct_val "intstruct"
220 test_reload_saved_value "intarr2.srec" "reload array as memory, srec" \
221 $array_val "intarray"
222 test_reload_saved_value "intstr2.srec" "reload struct as memory, srec" \
223 $struct_val "intstruct"
225 test_reload_saved_value "intarr1.ihex" "reload array as value, intel hex" \
226 $array_val "intarray"
227 test_reload_saved_value "intstr1.ihex" "reload struct as value, intel hex" \
228 $struct_val "intstruct"
229 test_reload_saved_value "intarr2.ihex" "reload array as memory, intel hex" \
230 $array_val "intarray"
231 test_reload_saved_value "intstr2.ihex" "reload struct as memory, intel hex" \
232 $struct_val "intstruct"
234 test_reload_saved_value "intarr1.tekhex" "reload array as value, tekhex" \
235 $array_val "intarray"
236 test_reload_saved_value "intstr1.tekhex" "reload struct as value, tekhex" \
237 $struct_val "intstruct"
238 test_reload_saved_value "intarr2.tekhex" "reload array as memory, tekhex" \
239 $array_val "intarray"
240 test_reload_saved_value "intstr2.tekhex" "reload struct as memory, tekhex" \
241 $struct_val "intstruct"
243 # Start a fresh gdb session
247 gdb_reinitialize_dir $srcdir/$subdir
251 if { ! [ runto main ] } then {
252 gdb_suppress_entire_file "Program failed to run, so remaining tests in this file will automatically fail."
255 if { ![string compare $array_val [capture_value "intarray"]] } then {
256 fail "start with intarray un-initialized, runto main"
258 pass "start with intarray un-initialized, runto main"
261 if { ![string compare $struct_val [capture_value "intstruct"]] } then {
262 fail "start with intstruct un-initialized, runto main"
264 pass "start with intstruct un-initialized, runto main"
267 test_restore_saved_value "intarr1.srec" "array as value, srec" \
268 $array_val "intarray"
270 test_restore_saved_value "intstr1.srec" "struct as value, srec" \
271 $struct_val "intstruct"
273 gdb_test "print zero_all ()" "void" "zero all"
275 test_restore_saved_value "intarr2.srec" "array as memory, srec" \
276 $array_val "intarray"
278 test_restore_saved_value "intstr2.srec" "struct as memory, srec" \
279 $struct_val "intstruct"
281 gdb_test "print zero_all ()" ""
283 test_restore_saved_value "intarr1.ihex" "array as value, ihex" \
284 $array_val "intarray"
286 test_restore_saved_value "intstr1.ihex" "struct as value, ihex" \
287 $struct_val "intstruct"
289 gdb_test "print zero_all ()" ""
291 test_restore_saved_value "intarr2.ihex" "array as memory, ihex" \
292 $array_val "intarray"
294 test_restore_saved_value "intstr2.ihex" "struct as memory, ihex" \
295 $struct_val "intstruct"
297 gdb_test "print zero_all ()" ""
299 test_restore_saved_value "intarr1.tekhex" "array as value, tekhex" \
300 $array_val "intarray"
302 test_restore_saved_value "intstr1.tekhex" "struct as value, tekhex" \
303 $struct_val "intstruct"
305 gdb_test "print zero_all ()" ""
307 test_restore_saved_value "intarr2.tekhex" "array as memory, tekhex" \
308 $array_val "intarray"
310 test_restore_saved_value "intstr2.tekhex" "struct as memory, tekhex" \
311 $struct_val "intstruct"
313 gdb_test "print zero_all ()" ""
315 test_restore_saved_value "intarr1.bin binary $array_start" \
316 "array as value, binary" \
317 $array_val "intarray"
319 test_restore_saved_value "intstr1.bin binary $struct_start" \
320 "struct as value, binary" \
321 $struct_val "intstruct"
323 gdb_test "print zero_all ()" ""
325 test_restore_saved_value "intarr2.bin binary $array_start" \
326 "array as memory, binary" \
327 $array_val "intarray"
329 test_restore_saved_value "intstr2.bin binary $struct_start" \
330 "struct as memory, binary" \
331 $struct_val "intstruct"
333 # test restore with offset.
335 set array2_start [capture_value "/x &intarray2\[0\]"]
336 set struct2_start [capture_value "/x &intstruct2"]
338 [capture_value "/x (char *) &intarray2 - (char *) &intarray"]
340 [capture_value "/x (char *) &intstruct2 - (char *) &intstruct"]
342 gdb_test "print zero_all ()" ""
344 test_restore_saved_value "intarr1.srec $array2_offset" \
346 $array_val "intarray2"
348 test_restore_saved_value "intstr1.srec $struct2_offset" \
349 "struct copy, srec" \
350 $struct_val "intstruct2"
352 gdb_test "print zero_all ()" ""
354 test_restore_saved_value "intarr1.ihex $array2_offset" \
356 $array_val "intarray2"
358 test_restore_saved_value "intstr1.ihex $struct2_offset" \
359 "struct copy, ihex" \
360 $struct_val "intstruct2"
362 gdb_test "print zero_all ()" ""
364 test_restore_saved_value "intarr1.tekhex $array2_offset" \
365 "array copy, tekhex" \
366 $array_val "intarray2"
368 test_restore_saved_value "intstr1.tekhex $struct2_offset" \
369 "struct copy, tekhex" \
370 $struct_val "intstruct2"
372 gdb_test "print zero_all ()" ""
374 test_restore_saved_value "intarr1.bin binary $array2_start" \
375 "array copy, binary" \
376 $array_val "intarray2"
378 test_restore_saved_value "intstr1.bin binary $struct2_start" \
379 "struct copy, binary" \
380 $struct_val "intstruct2"
383 # test restore with start/stop addresses.
385 # For this purpose, we will restore just the third element of the array,
386 # and check to see that adjacent elements are not modified.
388 # We will need the address and offset of the third and fourth elements.
391 set element3_start [capture_value "/x &intarray\[3\]"]
392 set element4_start [capture_value "/x &intarray\[4\]"]
393 set element3_offset \
394 [capture_value "/x (char *) &intarray\[3\] - (char *) &intarray\[0\]"]
395 set element4_offset \
396 [capture_value "/x (char *) &intarray\[4\] - (char *) &intarray\[0\]"]
398 gdb_test "print zero_all ()" ""
400 test_restore_saved_value "intarr1.srec 0 $element3_start $element4_start" \
401 "array partial, srec" \
402 [capture_value "4"] "intarray\[3\]"
404 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 1"
405 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 1"
407 gdb_test "print zero_all ()" ""
409 test_restore_saved_value "intarr1.ihex 0 $element3_start $element4_start" \
410 "array partial, ihex" \
411 [capture_value "4"] "intarray\[3\]"
413 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 2"
414 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 2"
416 gdb_test "print zero_all ()" ""
418 test_restore_saved_value "intarr1.tekhex 0 $element3_start $element4_start" \
419 "array partial, tekhex" \
420 [capture_value "4"] "intarray\[3\]"
422 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 3"
423 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 3"
425 gdb_test "print zero_all ()" ""
427 test_restore_saved_value \
428 "intarr1.bin binary $array_start $element3_offset $element4_offset" \
429 "array partial, binary" \
430 [capture_value "4"] "intarray\[3\]"
432 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 4"
433 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 4"
435 gdb_test "print zero_all ()" "" ""
437 # restore with expressions
438 test_restore_saved_value \
439 "intarr3.srec ${array2_start}-${array_start} &intarray\[3\] &intarray\[4\]" \
440 "array partial with expressions" \
441 [capture_value "4"] "intarray2\[3\]"
443 gdb_test "print intarray2\[2\] == 0" " = 1" "element 2 not changed, == 4"
444 gdb_test "print intarray2\[4\] == 0" " = 1" "element 4 not changed, == 4"
449 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"