]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/dump.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / dump.exp
1 # Copyright 2002, 2004, 2007 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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.
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 # This file was written by Michael Snyder (msnyder@redhat.com)
21 # This is a test for the gdb command "dump".
22
23 if $tracelevel then {
24 strace $tracelevel
25 }
26
27 set prms_id 0
28 set bug_id 0
29
30 set testfile "dump"
31
32 set srcfile ${testfile}.c
33 set binfile ${objdir}/${subdir}/${testfile}
34 set options {debug}
35
36 set is64bitonly "no"
37
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"
42 }
43
44 if {[istarget "ia64*-*-*"] || [istarget "hppa64-*-*"]} then {
45 set is64bitonly "yes"
46 }
47
48 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable ${options}] != "" } {
49 untested dump.exp
50 return -1
51 }
52
53 # Start with a fresh gdb.
54
55 gdb_exit
56 gdb_start
57 gdb_reinitialize_dir $srcdir/$subdir
58 gdb_load ${binfile}
59
60 # Clean up any stale output files from previous test runs
61
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"
63
64 # Test help (FIXME:)
65
66 # Run target program until data structs are initialized.
67
68 if { ! [ runto checkpoint1 ] } then {
69 untested dump.exp
70 return -1
71 }
72
73 # Now generate some dump files.
74
75 proc make_dump_file { command msg } {
76 global gdb_prompt
77
78 send_gdb "${command}\n"
79 gdb_expect {
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)" }
85 }
86 }
87
88 make_dump_file "dump val intarr1.bin intarray" \
89 "dump array as value, default"
90
91 make_dump_file "dump val intstr1.bin intstruct" \
92 "dump struct as value, default"
93
94 make_dump_file "dump bin val intarr1b.bin intarray" \
95 "dump array as value, binary"
96
97 make_dump_file "dump bin val intstr1b.bin intstruct" \
98 "dump struct as value, binary"
99
100 make_dump_file "dump srec val intarr1.srec intarray" \
101 "dump array as value, srec"
102
103 make_dump_file "dump srec val intstr1.srec intstruct" \
104 "dump struct as value, srec"
105
106 make_dump_file "dump ihex val intarr1.ihex intarray" \
107 "dump array as value, intel hex"
108
109 make_dump_file "dump ihex val intstr1.ihex intstruct" \
110 "dump struct as value, intel hex"
111
112 make_dump_file "dump tekhex val intarr1.tekhex intarray" \
113 "dump array as value, tekhex"
114
115 make_dump_file "dump tekhex val intstr1.tekhex intstruct" \
116 "dump struct as value, tekhex"
117
118 proc capture_value { expression args } {
119 global gdb_prompt
120 global expect_out
121
122 set output_string ""
123 if {[llength $args] > 0} {
124 # Convert $args into a simple string.
125 set test "[join $args]; capture $expression"
126 } {
127 set test "capture $expression"
128 }
129 gdb_test_multiple "print ${expression}" "$test" {
130 -re "\\$\[0-9\]+ = (\[^\r\n\]+).*$gdb_prompt $" {
131 set output_string "$expect_out(1,string)"
132 pass "$test"
133 }
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)"
137 pass "$test"
138 }
139 }
140 return $output_string
141 }
142
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"]
147
148 set array_val [capture_value "intarray"]
149 set struct_val [capture_value "intstruct"]
150
151 make_dump_file "dump mem intarr2.bin $array_start $array_end" \
152 "dump array as memory, default"
153
154 make_dump_file "dump mem intstr2.bin $struct_start $struct_end" \
155 "dump struct as memory, default"
156
157 make_dump_file "dump bin mem intarr2b.bin $array_start $array_end" \
158 "dump array as memory, binary"
159
160 make_dump_file "dump bin mem intstr2b.bin $struct_start $struct_end" \
161 "dump struct as memory, binary"
162
163 make_dump_file "dump srec mem intarr2.srec $array_start $array_end" \
164 "dump array as memory, srec"
165
166 make_dump_file "dump srec mem intstr2.srec $struct_start $struct_end" \
167 "dump struct as memory, srec"
168
169 make_dump_file "dump ihex mem intarr2.ihex $array_start $array_end" \
170 "dump array as memory, ihex"
171
172 make_dump_file "dump ihex mem intstr2.ihex $struct_start $struct_end" \
173 "dump struct as memory, ihex"
174
175 make_dump_file "dump tekhex mem intarr2.tekhex $array_start $array_end" \
176 "dump array as memory, tekhex"
177
178 make_dump_file "dump tekhex mem intstr2.tekhex $struct_start $struct_end" \
179 "dump struct as memory, tekhex"
180
181 # test complex expressions
182 make_dump_file \
183 "dump srec mem intarr3.srec &intarray \(char *\) &intarray + sizeof intarray" \
184 "dump array as mem, srec, expressions"
185
186
187 # Now start a fresh gdb session, and reload the saved value files.
188
189 gdb_exit
190 gdb_start
191 gdb_file_cmd ${binfile}
192
193 # Reload saved values one by one, and compare.
194
195 if { ![string compare $array_val \
196 [capture_value "intarray" "file binfile"]] } then {
197 fail "start with intarray un-initialized"
198 } else {
199 pass "start with intarray un-initialized"
200 }
201
202 if { ![string compare $struct_val \
203 [capture_value "intstruct" "file binfile"]] } then {
204 fail "start with intstruct un-initialized"
205 } else {
206 pass "start with intstruct un-initialized"
207 }
208
209 proc test_reload_saved_value { filename msg oldval newval } {
210 global gdb_prompt
211
212 gdb_file_cmd $filename
213 if { ![string compare $oldval \
214 [capture_value $newval "$msg"]] } then {
215 pass "$msg; value restored ok"
216 } else {
217 fail "$msg; value restored ok"
218 }
219 }
220
221 proc test_restore_saved_value { restore_args msg oldval newval } {
222 global gdb_prompt
223
224 gdb_test "restore $restore_args" \
225 "Restoring .*" \
226 "$msg; file restored ok"
227 if { ![string compare $oldval \
228 [capture_value $newval "$msg"]] } then {
229 pass "$msg; value restored ok"
230 } else {
231 fail "$msg; value restored ok"
232 }
233 }
234
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"
245 }
246
247 # ihex format can not be loaded for 64-bit-only platforms
248 if ![string compare $is64bitonly "no"] then {
249
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"
258 }
259
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"
270 }
271
272 # Start a fresh gdb session
273
274 gdb_exit
275 gdb_start
276 gdb_reinitialize_dir $srcdir/$subdir
277 gdb_load ${binfile}
278
279 # Run to main.
280 if { ! [ runto_main ] } then {
281 untested dump.exp
282 return -1
283 }
284
285 if { ![string compare $array_val \
286 [capture_value "intarray" "load binfile"]] } then {
287 fail "start with intarray un-initialized, runto main"
288 } else {
289 pass "start with intarray un-initialized, runto main"
290 }
291
292 if { ![string compare $struct_val \
293 [capture_value "intstruct" "load binfile"]] } then {
294 fail "start with intstruct un-initialized, runto main"
295 } else {
296 pass "start with intstruct un-initialized, runto main"
297 }
298
299 if ![string compare $is64bitonly "no"] then {
300 test_restore_saved_value "intarr1.srec" "array as value, srec" \
301 $array_val "intarray"
302
303 test_restore_saved_value "intstr1.srec" "struct as value, srec" \
304 $struct_val "intstruct"
305
306 gdb_test "print zero_all ()" "void" "zero all"
307
308 test_restore_saved_value "intarr2.srec" "array as memory, srec" \
309 $array_val "intarray"
310
311 test_restore_saved_value "intstr2.srec" "struct as memory, srec" \
312 $struct_val "intstruct"
313
314 gdb_test "print zero_all ()" ""
315
316 test_restore_saved_value "intarr1.ihex" "array as value, ihex" \
317 $array_val "intarray"
318
319 test_restore_saved_value "intstr1.ihex" "struct as value, ihex" \
320 $struct_val "intstruct"
321
322 gdb_test "print zero_all ()" ""
323
324 test_restore_saved_value "intarr2.ihex" "array as memory, ihex" \
325 $array_val "intarray"
326
327 test_restore_saved_value "intstr2.ihex" "struct as memory, ihex" \
328 $struct_val "intstruct"
329
330 gdb_test "print zero_all ()" ""
331
332 test_restore_saved_value "intarr1.tekhex" "array as value, tekhex" \
333 $array_val "intarray"
334
335 test_restore_saved_value "intstr1.tekhex" "struct as value, tekhex" \
336 $struct_val "intstruct"
337
338 gdb_test "print zero_all ()" ""
339
340 test_restore_saved_value "intarr2.tekhex" "array as memory, tekhex" \
341 $array_val "intarray"
342
343 test_restore_saved_value "intstr2.tekhex" "struct as memory, tekhex" \
344 $struct_val "intstruct"
345 }
346
347 gdb_test "print zero_all ()" ""
348
349 test_restore_saved_value "intarr1.bin binary $array_start" \
350 "array as value, binary" \
351 $array_val "intarray"
352
353 test_restore_saved_value "intstr1.bin binary $struct_start" \
354 "struct as value, binary" \
355 $struct_val "intstruct"
356
357 gdb_test "print zero_all ()" ""
358
359 test_restore_saved_value "intarr2.bin binary $array_start" \
360 "array as memory, binary" \
361 $array_val "intarray"
362
363 test_restore_saved_value "intstr2.bin binary $struct_start" \
364 "struct as memory, binary" \
365 $struct_val "intstruct"
366
367 # test restore with offset.
368
369 set array2_start [capture_value "/x &intarray2\[0\]"]
370 set struct2_start [capture_value "/x &intstruct2"]
371 set array2_offset \
372 [capture_value "(char *) &intarray2 - (char *) &intarray"]
373 set struct2_offset \
374 [capture_value "(char *) &intstruct2 - (char *) &intstruct"]
375
376 gdb_test "print zero_all ()" ""
377
378
379 if ![string compare $is64bitonly "no"] then {
380 test_restore_saved_value "intarr1.srec $array2_offset" \
381 "array copy, srec" \
382 $array_val "intarray2"
383
384 test_restore_saved_value "intstr1.srec $struct2_offset" \
385 "struct copy, srec" \
386 $struct_val "intstruct2"
387
388 gdb_test "print zero_all ()" ""
389
390 test_restore_saved_value "intarr1.ihex $array2_offset" \
391 "array copy, ihex" \
392 $array_val "intarray2"
393
394 test_restore_saved_value "intstr1.ihex $struct2_offset" \
395 "struct copy, ihex" \
396 $struct_val "intstruct2"
397
398 gdb_test "print zero_all ()" ""
399
400 test_restore_saved_value "intarr1.tekhex $array2_offset" \
401 "array copy, tekhex" \
402 $array_val "intarray2"
403
404 test_restore_saved_value "intstr1.tekhex $struct2_offset" \
405 "struct copy, tekhex" \
406 $struct_val "intstruct2"
407 }
408
409 gdb_test "print zero_all ()" ""
410
411 test_restore_saved_value "intarr1.bin binary $array2_start" \
412 "array copy, binary" \
413 $array_val "intarray2"
414
415 test_restore_saved_value "intstr1.bin binary $struct2_start" \
416 "struct copy, binary" \
417 $struct_val "intstruct2"
418
419 #
420 # test restore with start/stop addresses.
421 #
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.
424 #
425 # We will need the address and offset of the third and fourth elements.
426 #
427
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\]"]
434
435 if ![string compare $is64bitonly "no"] then {
436 gdb_test "print zero_all ()" ""
437
438 test_restore_saved_value "intarr1.srec 0 $element3_start $element4_start" \
439 "array partial, srec" 4 "intarray\[3\]"
440
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"
443
444 gdb_test "print zero_all ()" ""
445
446 test_restore_saved_value "intarr1.ihex 0 $element3_start $element4_start" \
447 "array partial, ihex" 4 "intarray\[3\]"
448
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"
451
452 gdb_test "print zero_all ()" ""
453
454 test_restore_saved_value "intarr1.tekhex 0 $element3_start $element4_start" \
455 "array partial, tekhex" 4 "intarray\[3\]"
456
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"
459 }
460
461 gdb_test "print zero_all ()" ""
462
463 test_restore_saved_value \
464 "intarr1.bin binary $array_start $element3_offset $element4_offset" \
465 "array partial, binary" 4 "intarray\[3\]"
466
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"
469
470 if ![string compare $is64bitonly "no"] then {
471 gdb_test "print zero_all ()" "" ""
472
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\]"
477
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"
480 }
481
482 # clean up files
483
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"