* gdb.base/dump.exp [alpha*-*-*]: Add -taso linker switch.
[external/binutils.git] / gdb / testsuite / gdb.base / dump.exp
1 # Copyright 2002 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 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"
40 }
41
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."
44 }
45
46 # Start with a fresh gdb.
47
48 gdb_exit
49 gdb_start
50 gdb_reinitialize_dir $srcdir/$subdir
51 gdb_load ${binfile}
52
53 # Clean up any stale output files from previous test runs
54
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"
56
57 # Test help (FIXME:)
58
59 # Run target program until data structs are initialized.
60
61 if { ! [ runto checkpoint1 ] } then {
62     gdb_suppress_entire_file "Program failed to run, so all tests in this file will automatically fail."
63 }
64
65 # Now generate some dump files.
66
67 proc make_dump_file { command msg } {
68   global gdb_prompt
69
70     send_gdb "${command}\n"
71     gdb_expect {
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)" }
77     }
78 }
79
80 make_dump_file "dump val intarr1.bin intarray" \
81         "dump array as value, default"
82
83 make_dump_file "dump val intstr1.bin intstruct" \
84         "dump struct as value, default"
85
86 make_dump_file "dump bin val intarr1b.bin intarray" \
87         "dump array as value, binary"
88
89 make_dump_file "dump bin val intstr1b.bin intstruct" \
90         "dump struct as value, binary"
91
92 make_dump_file "dump srec val intarr1.srec intarray" \
93         "dump array as value, srec"
94
95 make_dump_file "dump srec val intstr1.srec intstruct" \
96         "dump struct as value, srec"
97
98 make_dump_file "dump ihex val intarr1.ihex intarray" \
99         "dump array as value, intel hex"
100
101 make_dump_file "dump ihex val intstr1.ihex intstruct" \
102         "dump struct as value, intel hex"
103
104 make_dump_file "dump tekhex val intarr1.tekhex intarray" \
105         "dump array as value, tekhex"
106
107 make_dump_file "dump tekhex val intstr1.tekhex intstruct" \
108         "dump struct as value, tekhex"
109
110 proc capture_value { expression } {
111     global gdb_prompt
112     global expect_out
113
114     set output_string ""
115     send_gdb "print ${expression}\n"
116     gdb_expect {
117         -re ".*\[\r\n\]+.\[0123456789\]+ = (\[^\r\n\]+).*$gdb_prompt $" {
118             set output_string $expect_out(1,string)
119         }
120         default {
121             fail "capture_value failed on $expression."
122         }
123     }
124     return $output_string
125 }
126
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"]
131
132 set array_val    [capture_value "intarray"]
133 set struct_val   [capture_value "intstruct"]
134
135 make_dump_file "dump mem intarr2.bin $array_start $array_end" \
136         "dump array as memory, default"
137
138 make_dump_file "dump  mem intstr2.bin $struct_start $struct_end" \
139         "dump struct as memory, default"
140
141 make_dump_file "dump bin mem intarr2b.bin $array_start $array_end" \
142         "dump array as memory, binary"
143
144 make_dump_file "dump bin mem intstr2b.bin $struct_start $struct_end" \
145         "dump struct as memory, binary"
146
147 make_dump_file "dump srec mem intarr2.srec $array_start $array_end" \
148         "dump array as memory, srec"
149
150 make_dump_file "dump srec mem intstr2.srec $struct_start $struct_end" \
151         "dump struct as memory, srec"
152
153 make_dump_file "dump ihex mem intarr2.ihex $array_start $array_end" \
154         "dump array as memory, ihex"
155
156 make_dump_file "dump ihex mem intstr2.ihex $struct_start $struct_end" \
157         "dump struct as memory, ihex"
158
159 make_dump_file "dump tekhex mem intarr2.tekhex $array_start $array_end" \
160         "dump array as memory, tekhex"
161
162 make_dump_file "dump tekhex mem intstr2.tekhex $struct_start $struct_end" \
163         "dump struct as memory, tekhex"
164
165 # test complex expressions
166 make_dump_file \
167         "dump srec mem intarr3.srec &intarray \(char *\) &intarray + sizeof intarray" \
168         "dump array as mem, srec, expressions"
169
170
171 # Now start a fresh gdb session, and reload the saved value files.
172
173 gdb_exit
174 gdb_start
175 gdb_file_cmd ${binfile}
176
177 # Reload saved values one by one, and compare.
178
179 if { ![string compare $array_val [capture_value "intarray"]] } then {
180     fail "start with intarray un-initialized"
181 } else {
182     pass "start with intarray un-initialized"
183 }
184
185 if { ![string compare $struct_val [capture_value "intstruct"]] } then {
186     fail "start with intstruct un-initialized"
187 } else {
188     pass "start with intstruct un-initialized"
189 }
190
191 proc test_reload_saved_value { filename msg oldval newval } {
192     global gdb_prompt
193     
194     gdb_file_cmd $filename
195     if { ![string compare $oldval [capture_value $newval]] } then { 
196         pass $msg 
197     } else {
198         fail $msg 
199     }
200 }
201
202 proc test_restore_saved_value { restore_args msg oldval newval } {
203     global gdb_prompt
204     
205     gdb_test "restore $restore_args" \
206             "Restoring .*" \
207             "Restore command, $msg"
208
209     if { ![string compare $oldval [capture_value $newval]] } then { 
210         pass "Restored value, $msg"
211     } else {
212         fail "Restored value, $msg"
213     }
214 }
215
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"
224
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"
233
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"
242
243 # Start a fresh gdb session
244
245 gdb_exit
246 gdb_start
247 gdb_reinitialize_dir $srcdir/$subdir
248 gdb_load ${binfile}
249
250 # Run to main.
251 if { ! [ runto main ] } then {
252     gdb_suppress_entire_file "Program failed to run, so remaining tests in this file will automatically fail."
253 }
254
255 if { ![string compare $array_val [capture_value "intarray"]] } then {
256     fail "start with intarray un-initialized, runto main"
257 } else {
258     pass "start with intarray un-initialized, runto main"
259 }
260
261 if { ![string compare $struct_val [capture_value "intstruct"]] } then {
262     fail "start with intstruct un-initialized, runto main"
263 } else {
264     pass "start with intstruct un-initialized, runto main"
265 }
266
267 test_restore_saved_value "intarr1.srec" "array as value, srec" \
268         $array_val "intarray"
269
270 test_restore_saved_value "intstr1.srec" "struct as value, srec" \
271         $struct_val "intstruct"
272
273 gdb_test "print zero_all ()" "void" "zero all"
274
275 test_restore_saved_value "intarr2.srec" "array as memory, srec" \
276         $array_val "intarray"
277
278 test_restore_saved_value "intstr2.srec" "struct as memory, srec" \
279         $struct_val "intstruct"
280
281 gdb_test "print zero_all ()" ""
282
283 test_restore_saved_value "intarr1.ihex" "array as value, ihex" \
284         $array_val "intarray"
285
286 test_restore_saved_value "intstr1.ihex" "struct as value, ihex" \
287         $struct_val "intstruct"
288
289 gdb_test "print zero_all ()" ""
290
291 test_restore_saved_value "intarr2.ihex" "array as memory, ihex" \
292         $array_val "intarray"
293
294 test_restore_saved_value "intstr2.ihex" "struct as memory, ihex" \
295         $struct_val "intstruct"
296
297 gdb_test "print zero_all ()" ""
298
299 test_restore_saved_value "intarr1.tekhex" "array as value, tekhex" \
300         $array_val "intarray"
301
302 test_restore_saved_value "intstr1.tekhex" "struct as value, tekhex" \
303         $struct_val "intstruct"
304
305 gdb_test "print zero_all ()" ""
306
307 test_restore_saved_value "intarr2.tekhex" "array as memory, tekhex" \
308         $array_val "intarray"
309
310 test_restore_saved_value "intstr2.tekhex" "struct as memory, tekhex" \
311         $struct_val "intstruct"
312
313 gdb_test "print zero_all ()" ""
314
315 test_restore_saved_value "intarr1.bin binary $array_start" \
316         "array as value, binary" \
317         $array_val "intarray"
318
319 test_restore_saved_value "intstr1.bin binary $struct_start" \
320         "struct as value, binary" \
321         $struct_val "intstruct"
322
323 gdb_test "print zero_all ()" ""
324
325 test_restore_saved_value "intarr2.bin binary $array_start" \
326         "array as memory, binary" \
327         $array_val "intarray"
328
329 test_restore_saved_value "intstr2.bin binary $struct_start" \
330         "struct as memory, binary" \
331         $struct_val "intstruct"
332
333 # test restore with offset.
334
335 set array2_start   [capture_value "/x &intarray2\[0\]"]
336 set struct2_start  [capture_value "/x &intstruct2"]
337 set array2_offset  \
338         [capture_value "/x (char *) &intarray2 - (char *) &intarray"]
339 set struct2_offset \
340         [capture_value "/x (char *) &intstruct2 - (char *) &intstruct"]
341
342 gdb_test "print zero_all ()" ""
343
344 test_restore_saved_value "intarr1.srec $array2_offset" \
345         "array copy, srec" \
346         $array_val "intarray2"
347
348 test_restore_saved_value "intstr1.srec $struct2_offset" \
349         "struct copy, srec" \
350         $struct_val "intstruct2"
351
352 gdb_test "print zero_all ()" ""
353
354 test_restore_saved_value "intarr1.ihex $array2_offset" \
355         "array copy, ihex" \
356         $array_val "intarray2"
357
358 test_restore_saved_value "intstr1.ihex $struct2_offset" \
359         "struct copy, ihex" \
360         $struct_val "intstruct2"
361
362 gdb_test "print zero_all ()" ""
363
364 test_restore_saved_value "intarr1.tekhex $array2_offset" \
365         "array copy, tekhex" \
366         $array_val "intarray2"
367
368 test_restore_saved_value "intstr1.tekhex $struct2_offset" \
369         "struct copy, tekhex" \
370         $struct_val "intstruct2"
371
372 gdb_test "print zero_all ()" ""
373
374 test_restore_saved_value "intarr1.bin binary $array2_start" \
375         "array copy, binary" \
376         $array_val "intarray2"
377
378 test_restore_saved_value "intstr1.bin binary $struct2_start" \
379         "struct copy, binary" \
380         $struct_val "intstruct2"
381
382 #
383 # test restore with start/stop addresses.
384 #
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.
387 #
388 # We will need the address and offset of the third and fourth elements.
389 #
390
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\]"]
397
398 gdb_test "print zero_all ()" ""
399
400 test_restore_saved_value "intarr1.srec 0 $element3_start $element4_start" \
401         "array partial, srec" \
402         [capture_value "4"] "intarray\[3\]"
403
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"
406
407 gdb_test "print zero_all ()" ""
408
409 test_restore_saved_value "intarr1.ihex 0 $element3_start $element4_start" \
410         "array partial, ihex" \
411         [capture_value "4"] "intarray\[3\]"
412
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"
415
416 gdb_test "print zero_all ()" ""
417
418 test_restore_saved_value "intarr1.tekhex 0 $element3_start $element4_start" \
419         "array partial, tekhex" \
420         [capture_value "4"] "intarray\[3\]"
421
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"
424
425 gdb_test "print zero_all ()" ""
426
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\]"
431
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"
434
435 gdb_test "print zero_all ()" "" ""
436
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\]"
442
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"
445
446
447 # clean up files
448
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"
450