1 # Copyright 2002, 2004, 2007 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}] != "" } {
53 # Start with a fresh gdb.
57 gdb_reinitialize_dir $srcdir/$subdir
60 # Clean up any stale output files from previous test runs
62 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"
66 # Run target program until data structs are initialized.
68 if { ! [ runto checkpoint1 ] } then {
73 # Now generate some dump files.
75 proc make_dump_file { command msg } {
78 send_gdb "${command}\n"
80 -re ".*\[Ee\]rror.*$gdb_prompt $" { fail $msg }
81 -re ".*\[Ww\]arning.*$gdb_prompt $" { fail $msg }
82 -re ".*\[Uu\]ndefined .*$gdb_prompt $" { fail $msg }
83 -re ".*$gdb_prompt $" { pass $msg }
84 timeout { fail "$msg (timeout)" }
88 make_dump_file "dump val intarr1.bin intarray" \
89 "dump array as value, default"
91 make_dump_file "dump val intstr1.bin intstruct" \
92 "dump struct as value, default"
94 make_dump_file "dump bin val intarr1b.bin intarray" \
95 "dump array as value, binary"
97 make_dump_file "dump bin val intstr1b.bin intstruct" \
98 "dump struct as value, binary"
100 make_dump_file "dump srec val intarr1.srec intarray" \
101 "dump array as value, srec"
103 make_dump_file "dump srec val intstr1.srec intstruct" \
104 "dump struct as value, srec"
106 make_dump_file "dump ihex val intarr1.ihex intarray" \
107 "dump array as value, intel hex"
109 make_dump_file "dump ihex val intstr1.ihex intstruct" \
110 "dump struct as value, intel hex"
112 make_dump_file "dump tekhex val intarr1.tekhex intarray" \
113 "dump array as value, tekhex"
115 make_dump_file "dump tekhex val intstr1.tekhex intstruct" \
116 "dump struct as value, tekhex"
118 proc capture_value { expression args } {
123 if {[llength $args] > 0} {
124 # Convert $args into a simple string.
125 set test "[join $args]; capture $expression"
127 set test "capture $expression"
129 gdb_test_multiple "print ${expression}" "$test" {
130 -re "\\$\[0-9\]+ = (\[^\r\n\]+).*$gdb_prompt $" {
131 set output_string "$expect_out(1,string)"
134 -re "(Cannot access memory at address \[^\r\n\]+).*$gdb_prompt $" {
135 # Even a failed value is valid
136 set output_string "$expect_out(1,string)"
140 return $output_string
143 set array_start [capture_value "/x &intarray\[0\]"]
144 set array_end [capture_value "/x &intarray\[32\]"]
145 set struct_start [capture_value "/x &intstruct"]
146 set struct_end [capture_value "/x &intstruct + 1"]
148 set array_val [capture_value "intarray"]
149 set struct_val [capture_value "intstruct"]
151 make_dump_file "dump mem intarr2.bin $array_start $array_end" \
152 "dump array as memory, default"
154 make_dump_file "dump mem intstr2.bin $struct_start $struct_end" \
155 "dump struct as memory, default"
157 make_dump_file "dump bin mem intarr2b.bin $array_start $array_end" \
158 "dump array as memory, binary"
160 make_dump_file "dump bin mem intstr2b.bin $struct_start $struct_end" \
161 "dump struct as memory, binary"
163 make_dump_file "dump srec mem intarr2.srec $array_start $array_end" \
164 "dump array as memory, srec"
166 make_dump_file "dump srec mem intstr2.srec $struct_start $struct_end" \
167 "dump struct as memory, srec"
169 make_dump_file "dump ihex mem intarr2.ihex $array_start $array_end" \
170 "dump array as memory, ihex"
172 make_dump_file "dump ihex mem intstr2.ihex $struct_start $struct_end" \
173 "dump struct as memory, ihex"
175 make_dump_file "dump tekhex mem intarr2.tekhex $array_start $array_end" \
176 "dump array as memory, tekhex"
178 make_dump_file "dump tekhex mem intstr2.tekhex $struct_start $struct_end" \
179 "dump struct as memory, tekhex"
181 # test complex expressions
183 "dump srec mem intarr3.srec &intarray \(char *\) &intarray + sizeof intarray" \
184 "dump array as mem, srec, expressions"
187 # Now start a fresh gdb session, and reload the saved value files.
191 gdb_file_cmd ${binfile}
193 # Reload saved values one by one, and compare.
195 if { ![string compare $array_val \
196 [capture_value "intarray" "file binfile"]] } then {
197 fail "start with intarray un-initialized"
199 pass "start with intarray un-initialized"
202 if { ![string compare $struct_val \
203 [capture_value "intstruct" "file binfile"]] } then {
204 fail "start with intstruct un-initialized"
206 pass "start with intstruct un-initialized"
209 proc test_reload_saved_value { filename msg oldval newval } {
212 gdb_file_cmd $filename
213 if { ![string compare $oldval \
214 [capture_value $newval "$msg"]] } then {
215 pass "$msg; value restored ok"
217 fail "$msg; value restored ok"
221 proc test_restore_saved_value { restore_args msg oldval newval } {
224 gdb_test "restore $restore_args" \
226 "$msg; file restored ok"
227 if { ![string compare $oldval \
228 [capture_value $newval "$msg"]] } then {
229 pass "$msg; value restored ok"
231 fail "$msg; value restored ok"
235 # srec format can not be loaded for 64-bit-only platforms
236 if ![string compare $is64bitonly "no"] then {
237 test_reload_saved_value "intarr1.srec" "reload array as value, srec" \
238 $array_val "intarray"
239 test_reload_saved_value "intstr1.srec" "reload struct as value, srec" \
240 $struct_val "intstruct"
241 test_reload_saved_value "intarr2.srec" "reload array as memory, srec" \
242 $array_val "intarray"
243 test_reload_saved_value "intstr2.srec" "reload struct as memory, srec" \
244 $struct_val "intstruct"
247 # ihex format can not be loaded for 64-bit-only platforms
248 if ![string compare $is64bitonly "no"] then {
250 test_reload_saved_value "intarr1.ihex" "reload array as value, intel hex" \
251 $array_val "intarray"
252 test_reload_saved_value "intstr1.ihex" "reload struct as value, intel hex" \
253 $struct_val "intstruct"
254 test_reload_saved_value "intarr2.ihex" "reload array as memory, intel hex" \
255 $array_val "intarray"
256 test_reload_saved_value "intstr2.ihex" "reload struct as memory, intel hex" \
257 $struct_val "intstruct"
260 # tekhex format can not be loaded for 64-bit-only platforms
261 if ![string compare $is64bitonly "no"] then {
262 test_reload_saved_value "intarr1.tekhex" "reload array as value, tekhex" \
263 $array_val "intarray"
264 test_reload_saved_value "intstr1.tekhex" "reload struct as value, tekhex" \
265 $struct_val "intstruct"
266 test_reload_saved_value "intarr2.tekhex" "reload array as memory, tekhex" \
267 $array_val "intarray"
268 test_reload_saved_value "intstr2.tekhex" "reload struct as memory, tekhex" \
269 $struct_val "intstruct"
272 # Start a fresh gdb session
276 gdb_reinitialize_dir $srcdir/$subdir
280 if { ! [ runto_main ] } then {
285 if { ![string compare $array_val \
286 [capture_value "intarray" "load binfile"]] } then {
287 fail "start with intarray un-initialized, runto main"
289 pass "start with intarray un-initialized, runto main"
292 if { ![string compare $struct_val \
293 [capture_value "intstruct" "load binfile"]] } then {
294 fail "start with intstruct un-initialized, runto main"
296 pass "start with intstruct un-initialized, runto main"
299 if ![string compare $is64bitonly "no"] then {
300 test_restore_saved_value "intarr1.srec" "array as value, srec" \
301 $array_val "intarray"
303 test_restore_saved_value "intstr1.srec" "struct as value, srec" \
304 $struct_val "intstruct"
306 gdb_test "print zero_all ()" "void" "zero all"
308 test_restore_saved_value "intarr2.srec" "array as memory, srec" \
309 $array_val "intarray"
311 test_restore_saved_value "intstr2.srec" "struct as memory, srec" \
312 $struct_val "intstruct"
314 gdb_test "print zero_all ()" ""
316 test_restore_saved_value "intarr1.ihex" "array as value, ihex" \
317 $array_val "intarray"
319 test_restore_saved_value "intstr1.ihex" "struct as value, ihex" \
320 $struct_val "intstruct"
322 gdb_test "print zero_all ()" ""
324 test_restore_saved_value "intarr2.ihex" "array as memory, ihex" \
325 $array_val "intarray"
327 test_restore_saved_value "intstr2.ihex" "struct as memory, ihex" \
328 $struct_val "intstruct"
330 gdb_test "print zero_all ()" ""
332 test_restore_saved_value "intarr1.tekhex" "array as value, tekhex" \
333 $array_val "intarray"
335 test_restore_saved_value "intstr1.tekhex" "struct as value, tekhex" \
336 $struct_val "intstruct"
338 gdb_test "print zero_all ()" ""
340 test_restore_saved_value "intarr2.tekhex" "array as memory, tekhex" \
341 $array_val "intarray"
343 test_restore_saved_value "intstr2.tekhex" "struct as memory, tekhex" \
344 $struct_val "intstruct"
347 gdb_test "print zero_all ()" ""
349 test_restore_saved_value "intarr1.bin binary $array_start" \
350 "array as value, binary" \
351 $array_val "intarray"
353 test_restore_saved_value "intstr1.bin binary $struct_start" \
354 "struct as value, binary" \
355 $struct_val "intstruct"
357 gdb_test "print zero_all ()" ""
359 test_restore_saved_value "intarr2.bin binary $array_start" \
360 "array as memory, binary" \
361 $array_val "intarray"
363 test_restore_saved_value "intstr2.bin binary $struct_start" \
364 "struct as memory, binary" \
365 $struct_val "intstruct"
367 # test restore with offset.
369 set array2_start [capture_value "/x &intarray2\[0\]"]
370 set struct2_start [capture_value "/x &intstruct2"]
372 [capture_value "(char *) &intarray2 - (char *) &intarray"]
374 [capture_value "(char *) &intstruct2 - (char *) &intstruct"]
376 gdb_test "print zero_all ()" ""
379 if ![string compare $is64bitonly "no"] then {
380 test_restore_saved_value "intarr1.srec $array2_offset" \
382 $array_val "intarray2"
384 test_restore_saved_value "intstr1.srec $struct2_offset" \
385 "struct copy, srec" \
386 $struct_val "intstruct2"
388 gdb_test "print zero_all ()" ""
390 test_restore_saved_value "intarr1.ihex $array2_offset" \
392 $array_val "intarray2"
394 test_restore_saved_value "intstr1.ihex $struct2_offset" \
395 "struct copy, ihex" \
396 $struct_val "intstruct2"
398 gdb_test "print zero_all ()" ""
400 test_restore_saved_value "intarr1.tekhex $array2_offset" \
401 "array copy, tekhex" \
402 $array_val "intarray2"
404 test_restore_saved_value "intstr1.tekhex $struct2_offset" \
405 "struct copy, tekhex" \
406 $struct_val "intstruct2"
409 gdb_test "print zero_all ()" ""
411 test_restore_saved_value "intarr1.bin binary $array2_start" \
412 "array copy, binary" \
413 $array_val "intarray2"
415 test_restore_saved_value "intstr1.bin binary $struct2_start" \
416 "struct copy, binary" \
417 $struct_val "intstruct2"
420 # test restore with start/stop addresses.
422 # For this purpose, we will restore just the third element of the array,
423 # and check to see that adjacent elements are not modified.
425 # We will need the address and offset of the third and fourth elements.
428 set element3_start [capture_value "/x &intarray\[3\]"]
429 set element4_start [capture_value "/x &intarray\[4\]"]
430 set element3_offset \
431 [capture_value "/x (char *) &intarray\[3\] - (char *) &intarray\[0\]"]
432 set element4_offset \
433 [capture_value "/x (char *) &intarray\[4\] - (char *) &intarray\[0\]"]
435 if ![string compare $is64bitonly "no"] then {
436 gdb_test "print zero_all ()" ""
438 test_restore_saved_value "intarr1.srec 0 $element3_start $element4_start" \
439 "array partial, srec" 4 "intarray\[3\]"
441 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 1"
442 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 1"
444 gdb_test "print zero_all ()" ""
446 test_restore_saved_value "intarr1.ihex 0 $element3_start $element4_start" \
447 "array partial, ihex" 4 "intarray\[3\]"
449 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 2"
450 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 2"
452 gdb_test "print zero_all ()" ""
454 test_restore_saved_value "intarr1.tekhex 0 $element3_start $element4_start" \
455 "array partial, tekhex" 4 "intarray\[3\]"
457 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 3"
458 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 3"
461 gdb_test "print zero_all ()" ""
463 test_restore_saved_value \
464 "intarr1.bin binary $array_start $element3_offset $element4_offset" \
465 "array partial, binary" 4 "intarray\[3\]"
467 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 4"
468 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 4"
470 if ![string compare $is64bitonly "no"] then {
471 gdb_test "print zero_all ()" "" ""
473 # restore with expressions
474 test_restore_saved_value \
475 "intarr3.srec ${array2_start}-${array_start} &intarray\[3\] &intarray\[4\]" \
476 "array partial with expressions" 4 "intarray2\[3\]"
478 gdb_test "print intarray2\[2\] == 0" " = 1" "element 2 not changed, == 4"
479 gdb_test "print intarray2\[4\] == 0" " = 1" "element 4 not changed, == 4"
484 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"