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}
35 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
36 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
39 # Start with a fresh gdb.
43 gdb_reinitialize_dir $srcdir/$subdir
46 # Clean up any stale output files from previous test runs
48 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"
52 # Run target program until data structs are initialized.
54 if { ! [ runto checkpoint1 ] } then {
55 gdb_suppress_entire_file "Program failed to run, so all tests in this file will automatically fail."
58 # Now generate some dump files.
60 proc make_dump_file { command msg } {
63 send_gdb "${command}\n"
65 -re ".*\[Ee\]rror.*$gdb_prompt $" { fail $msg }
66 -re ".*\[Ww\]arning.*$gdb_prompt $" { fail $msg }
67 -re ".*\[Uu\]ndefined .*$gdb_prompt $" { fail $msg }
68 -re ".*$gdb_prompt $" { pass $msg }
69 timeout { fail "$msg (timeout)" }
73 make_dump_file "dump val intarr1.bin intarray" \
74 "dump array as value, default"
76 make_dump_file "dump val intstr1.bin intstruct" \
77 "dump struct as value, default"
79 make_dump_file "dump bin val intarr1b.bin intarray" \
80 "dump array as value, binary"
82 make_dump_file "dump bin val intstr1b.bin intstruct" \
83 "dump struct as value, binary"
85 make_dump_file "dump srec val intarr1.srec intarray" \
86 "dump array as value, srec"
88 make_dump_file "dump srec val intstr1.srec intstruct" \
89 "dump struct as value, srec"
91 make_dump_file "dump ihex val intarr1.ihex intarray" \
92 "dump array as value, intel hex"
94 make_dump_file "dump ihex val intstr1.ihex intstruct" \
95 "dump struct as value, intel hex"
97 make_dump_file "dump tekhex val intarr1.tekhex intarray" \
98 "dump array as value, tekhex"
100 make_dump_file "dump tekhex val intstr1.tekhex intstruct" \
101 "dump struct as value, tekhex"
103 proc capture_value { expression } {
108 send_gdb "print ${expression}\n"
110 -re ".*\[\r\n\]+.\[0123456789\]+ = (\[^\r\n\]+).*$gdb_prompt $" {
111 set output_string $expect_out(1,string)
114 fail "capture_value failed on $expression."
117 return $output_string
120 set array_start [capture_value "/x &intarray\[0\]"]
121 set array_end [capture_value "/x &intarray\[32\]"]
122 set struct_start [capture_value "/x &intstruct"]
123 set struct_end [capture_value "/x &intstruct + 1"]
125 set array_val [capture_value "intarray"]
126 set struct_val [capture_value "intstruct"]
128 make_dump_file "dump mem intarr2.bin $array_start $array_end" \
129 "dump array as memory, default"
131 make_dump_file "dump mem intstr2.bin $struct_start $struct_end" \
132 "dump struct as memory, default"
134 make_dump_file "dump bin mem intarr2b.bin $array_start $array_end" \
135 "dump array as memory, binary"
137 make_dump_file "dump bin mem intstr2b.bin $struct_start $struct_end" \
138 "dump struct as memory, binary"
140 make_dump_file "dump srec mem intarr2.srec $array_start $array_end" \
141 "dump array as memory, srec"
143 make_dump_file "dump srec mem intstr2.srec $struct_start $struct_end" \
144 "dump struct as memory, srec"
146 make_dump_file "dump ihex mem intarr2.ihex $array_start $array_end" \
147 "dump array as memory, ihex"
149 make_dump_file "dump ihex mem intstr2.ihex $struct_start $struct_end" \
150 "dump struct as memory, ihex"
152 make_dump_file "dump tekhex mem intarr2.tekhex $array_start $array_end" \
153 "dump array as memory, tekhex"
155 make_dump_file "dump tekhex mem intstr2.tekhex $struct_start $struct_end" \
156 "dump struct as memory, tekhex"
158 # test complex expressions
160 "dump srec mem intarr3.srec &intarray \(char *\) &intarray + sizeof intarray" \
161 "dump array as mem, srec, expressions"
164 # Now start a fresh gdb session, and reload the saved value files.
168 gdb_file_cmd ${binfile}
170 # Reload saved values one by one, and compare.
172 if { ![string compare $array_val [capture_value "intarray"]] } then {
173 fail "start with intarray un-initialized"
175 pass "start with intarray un-initialized"
178 if { ![string compare $struct_val [capture_value "intstruct"]] } then {
179 fail "start with intstruct un-initialized"
181 pass "start with intstruct un-initialized"
184 proc test_reload_saved_value { filename msg oldval newval } {
187 gdb_file_cmd $filename
188 if { ![string compare $oldval [capture_value $newval]] } then {
195 proc test_restore_saved_value { restore_args msg oldval newval } {
198 gdb_test "restore $restore_args" \
200 "Restore command, $msg"
202 if { ![string compare $oldval [capture_value $newval]] } then {
203 pass "Restored value, $msg"
205 fail "Restored value, $msg"
209 test_reload_saved_value "intarr1.srec" "reload array as value, srec" \
210 $array_val "intarray"
211 test_reload_saved_value "intstr1.srec" "reload struct as value, srec" \
212 $struct_val "intstruct"
213 test_reload_saved_value "intarr2.srec" "reload array as memory, srec" \
214 $array_val "intarray"
215 test_reload_saved_value "intstr2.srec" "reload struct as memory, srec" \
216 $struct_val "intstruct"
218 test_reload_saved_value "intarr1.ihex" "reload array as value, intel hex" \
219 $array_val "intarray"
220 test_reload_saved_value "intstr1.ihex" "reload struct as value, intel hex" \
221 $struct_val "intstruct"
222 test_reload_saved_value "intarr2.ihex" "reload array as memory, intel hex" \
223 $array_val "intarray"
224 test_reload_saved_value "intstr2.ihex" "reload struct as memory, intel hex" \
225 $struct_val "intstruct"
227 test_reload_saved_value "intarr1.tekhex" "reload array as value, tekhex" \
228 $array_val "intarray"
229 test_reload_saved_value "intstr1.tekhex" "reload struct as value, tekhex" \
230 $struct_val "intstruct"
231 test_reload_saved_value "intarr2.tekhex" "reload array as memory, tekhex" \
232 $array_val "intarray"
233 test_reload_saved_value "intstr2.tekhex" "reload struct as memory, tekhex" \
234 $struct_val "intstruct"
236 # Start a fresh gdb session
240 gdb_reinitialize_dir $srcdir/$subdir
244 if { ! [ runto main ] } then {
245 gdb_suppress_entire_file "Program failed to run, so remaining tests in this file will automatically fail."
248 if { ![string compare $array_val [capture_value "intarray"]] } then {
249 fail "start with intarray un-initialized, runto main"
251 pass "start with intarray un-initialized, runto main"
254 if { ![string compare $struct_val [capture_value "intstruct"]] } then {
255 fail "start with intstruct un-initialized, runto main"
257 pass "start with intstruct un-initialized, runto main"
260 test_restore_saved_value "intarr1.srec" "array as value, srec" \
261 $array_val "intarray"
263 test_restore_saved_value "intstr1.srec" "struct as value, srec" \
264 $struct_val "intstruct"
266 gdb_test "print zero_all ()" "void" "zero all"
268 test_restore_saved_value "intarr2.srec" "array as memory, srec" \
269 $array_val "intarray"
271 test_restore_saved_value "intstr2.srec" "struct as memory, srec" \
272 $struct_val "intstruct"
274 gdb_test "print zero_all ()" ""
276 test_restore_saved_value "intarr1.ihex" "array as value, ihex" \
277 $array_val "intarray"
279 test_restore_saved_value "intstr1.ihex" "struct as value, ihex" \
280 $struct_val "intstruct"
282 gdb_test "print zero_all ()" ""
284 test_restore_saved_value "intarr2.ihex" "array as memory, ihex" \
285 $array_val "intarray"
287 test_restore_saved_value "intstr2.ihex" "struct as memory, ihex" \
288 $struct_val "intstruct"
290 gdb_test "print zero_all ()" ""
292 test_restore_saved_value "intarr1.tekhex" "array as value, tekhex" \
293 $array_val "intarray"
295 test_restore_saved_value "intstr1.tekhex" "struct as value, tekhex" \
296 $struct_val "intstruct"
298 gdb_test "print zero_all ()" ""
300 test_restore_saved_value "intarr2.tekhex" "array as memory, tekhex" \
301 $array_val "intarray"
303 test_restore_saved_value "intstr2.tekhex" "struct as memory, tekhex" \
304 $struct_val "intstruct"
306 gdb_test "print zero_all ()" ""
308 test_restore_saved_value "intarr1.bin binary $array_start" \
309 "array as value, binary" \
310 $array_val "intarray"
312 test_restore_saved_value "intstr1.bin binary $struct_start" \
313 "struct as value, binary" \
314 $struct_val "intstruct"
316 gdb_test "print zero_all ()" ""
318 test_restore_saved_value "intarr2.bin binary $array_start" \
319 "array as memory, binary" \
320 $array_val "intarray"
322 test_restore_saved_value "intstr2.bin binary $struct_start" \
323 "struct as memory, binary" \
324 $struct_val "intstruct"
326 # test restore with offset.
328 set array2_start [capture_value "/x &intarray2\[0\]"]
329 set struct2_start [capture_value "/x &intstruct2"]
331 [capture_value "/x (char *) &intarray2 - (char *) &intarray"]
333 [capture_value "/x (char *) &intstruct2 - (char *) &intstruct"]
335 gdb_test "print zero_all ()" ""
337 test_restore_saved_value "intarr1.srec $array2_offset" \
339 $array_val "intarray2"
341 test_restore_saved_value "intstr1.srec $struct2_offset" \
342 "struct copy, srec" \
343 $struct_val "intstruct2"
345 gdb_test "print zero_all ()" ""
347 test_restore_saved_value "intarr1.ihex $array2_offset" \
349 $array_val "intarray2"
351 test_restore_saved_value "intstr1.ihex $struct2_offset" \
352 "struct copy, ihex" \
353 $struct_val "intstruct2"
355 gdb_test "print zero_all ()" ""
357 test_restore_saved_value "intarr1.tekhex $array2_offset" \
358 "array copy, tekhex" \
359 $array_val "intarray2"
361 test_restore_saved_value "intstr1.tekhex $struct2_offset" \
362 "struct copy, tekhex" \
363 $struct_val "intstruct2"
365 gdb_test "print zero_all ()" ""
367 test_restore_saved_value "intarr1.bin binary $array2_start" \
368 "array copy, binary" \
369 $array_val "intarray2"
371 test_restore_saved_value "intstr1.bin binary $struct2_start" \
372 "struct copy, binary" \
373 $struct_val "intstruct2"
376 # test restore with start/stop addresses.
378 # For this purpose, we will restore just the third element of the array,
379 # and check to see that adjacent elements are not modified.
381 # We will need the address and offset of the third and fourth elements.
384 set element3_start [capture_value "/x &intarray\[3\]"]
385 set element4_start [capture_value "/x &intarray\[4\]"]
386 set element3_offset \
387 [capture_value "/x (char *) &intarray\[3\] - (char *) &intarray\[0\]"]
388 set element4_offset \
389 [capture_value "/x (char *) &intarray\[4\] - (char *) &intarray\[0\]"]
391 gdb_test "print zero_all ()" ""
393 test_restore_saved_value "intarr1.srec 0 $element3_start $element4_start" \
394 "array partial, srec" \
395 [capture_value "4"] "intarray\[3\]"
397 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 1"
398 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 1"
400 gdb_test "print zero_all ()" ""
402 test_restore_saved_value "intarr1.ihex 0 $element3_start $element4_start" \
403 "array partial, ihex" \
404 [capture_value "4"] "intarray\[3\]"
406 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 2"
407 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 2"
409 gdb_test "print zero_all ()" ""
411 test_restore_saved_value "intarr1.tekhex 0 $element3_start $element4_start" \
412 "array partial, tekhex" \
413 [capture_value "4"] "intarray\[3\]"
415 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 3"
416 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 3"
418 gdb_test "print zero_all ()" ""
420 test_restore_saved_value \
421 "intarr1.bin binary $array_start $element3_offset $element4_offset" \
422 "array partial, binary" \
423 [capture_value "4"] "intarray\[3\]"
425 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 4"
426 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 4"
428 gdb_test "print zero_all ()" "" ""
430 # restore with expressions
431 test_restore_saved_value \
432 "intarr3.srec ${array2_start}-${array_start} &intarray\[3\] &intarray\[4\]" \
433 "array partial with expressions" \
434 [capture_value "4"] "intarray2\[3\]"
436 gdb_test "print intarray2\[2\] == 0" " = 1" "element 2 not changed, == 4"
437 gdb_test "print intarray2\[4\] == 0" " = 1" "element 4 not changed, == 4"
442 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"