* gdb.base/completion.exp: Recognize the more detailed error
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / dump.exp
CommitLineData
dd7dfd64
MS
1
2# This program is free software; you can redistribute it and/or modify
3# it under the terms of the GNU General Public License as published by
4# the Free Software Foundation; either version 2 of the License, or
5# (at your option) any later version.
6#
7# This program is distributed in the hope that it will be useful,
8# but WITHOUT ANY WARRANTY; without even the implied warranty of
9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10# GNU General Public License for more details.
11#
12# You should have received a copy of the GNU General Public License
13# along with this program; if not, write to the Free Software
14# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15
16# Please email any bugs, comments, and/or additions to this file to:
17# bug-gdb@prep.ai.mit.edu
18
19# This file was written by Michael Snyder (msnyder@redhat.com)
20# This is a test for the gdb command "dump".
21
22if $tracelevel then {
23 strace $tracelevel
24}
25
26set prms_id 0
27set bug_id 0
28
29set testfile "dump"
30
31set srcfile ${testfile}.c
32set binfile ${objdir}/${subdir}/${testfile}
33
34if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
35 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
36}
37
38# Start with a fresh gdb.
39
40gdb_exit
41gdb_start
42gdb_reinitialize_dir $srcdir/$subdir
43gdb_load ${binfile}
44
45# Clean up any stale output files from previous test runs
46
47remote_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"
48
49# Test help (FIXME:)
50
51# Run target program until data structs are initialized.
52
53if { ! [ runto checkpoint1 ] } then {
54 gdb_suppress_entire_file "Program failed to run, so all tests in this file will automatically fail."
55}
56
57# Now generate some dump files.
58
59proc make_dump_file { command msg } {
60 global gdb_prompt
61
62 send_gdb "${command}\n"
63 gdb_expect {
64 -re ".*\[Ee\]rror.*$gdb_prompt $" { fail $msg }
65 -re ".*\[Ww\]arning.*$gdb_prompt $" { fail $msg }
66 -re ".*\[Uu\]ndefined .*$gdb_prompt $" { fail $msg }
67 -re ".*$gdb_prompt $" { pass $msg }
68 timeout { fail "$msg (timeout)" }
69 }
70}
71
72make_dump_file "dump val intarr1.bin intarray" \
73 "dump array as value, default"
74
75make_dump_file "dump val intstr1.bin intstruct" \
76 "dump struct as value, default"
77
78make_dump_file "dump bin val intarr1b.bin intarray" \
79 "dump array as value, binary"
80
81make_dump_file "dump bin val intstr1b.bin intstruct" \
82 "dump struct as value, binary"
83
84make_dump_file "dump srec val intarr1.srec intarray" \
85 "dump array as value, srec"
86
87make_dump_file "dump srec val intstr1.srec intstruct" \
88 "dump struct as value, srec"
89
90make_dump_file "dump ihex val intarr1.ihex intarray" \
91 "dump array as value, intel hex"
92
93make_dump_file "dump ihex val intstr1.ihex intstruct" \
94 "dump struct as value, intel hex"
95
96make_dump_file "dump tekhex val intarr1.tekhex intarray" \
97 "dump array as value, tekhex"
98
99make_dump_file "dump tekhex val intstr1.tekhex intstruct" \
100 "dump struct as value, tekhex"
101
102proc capture_value { expression } {
103 global gdb_prompt
104 global expect_out
105
106 set output_string ""
107 send_gdb "print ${expression}\n"
108 gdb_expect {
109 -re ".*\[\r\n\]+.\[0123456789\]+ = (\[^\r\n\]+).*$gdb_prompt $" {
110 set output_string $expect_out(1,string)
111 }
112 default {
113 fail "capture_value failed on $expression."
114 }
115 }
116 return $output_string
117}
118
119set array_start [capture_value "/x &intarray\[0\]"]
120set array_end [capture_value "/x &intarray\[32\]"]
121set struct_start [capture_value "/x &intstruct"]
122set struct_end [capture_value "/x &intstruct + 1"]
123
124set array_val [capture_value "intarray"]
125set struct_val [capture_value "intstruct"]
126
127make_dump_file "dump mem intarr2.bin $array_start $array_end" \
128 "dump array as memory, default"
129
130make_dump_file "dump mem intstr2.bin $struct_start $struct_end" \
131 "dump struct as memory, default"
132
133make_dump_file "dump bin mem intarr2b.bin $array_start $array_end" \
134 "dump array as memory, binary"
135
136make_dump_file "dump bin mem intstr2b.bin $struct_start $struct_end" \
137 "dump struct as memory, binary"
138
139make_dump_file "dump srec mem intarr2.srec $array_start $array_end" \
140 "dump array as memory, srec"
141
142make_dump_file "dump srec mem intstr2.srec $struct_start $struct_end" \
143 "dump struct as memory, srec"
144
145make_dump_file "dump ihex mem intarr2.ihex $array_start $array_end" \
146 "dump array as memory, ihex"
147
148make_dump_file "dump ihex mem intstr2.ihex $struct_start $struct_end" \
149 "dump struct as memory, ihex"
150
151make_dump_file "dump tekhex mem intarr2.tekhex $array_start $array_end" \
152 "dump array as memory, tekhex"
153
154make_dump_file "dump tekhex mem intstr2.tekhex $struct_start $struct_end" \
155 "dump struct as memory, tekhex"
156
157# test complex expressions
158make_dump_file \
159 "dump srec mem intarr3.srec &intarray \(char *\) &intarray + sizeof intarray" \
160 "dump array as mem, srec, expressions"
161
162
163# Now start a fresh gdb session, and reload the saved value files.
164
165gdb_exit
166gdb_start
167gdb_file_cmd ${binfile}
168
169# Reload saved values one by one, and compare.
170
171if { ![string compare $array_val [capture_value "intarray"]] } then {
172 fail "start with intarray un-initialized"
173} else {
174 pass "start with intarray un-initialized"
175}
176
177if { ![string compare $struct_val [capture_value "intstruct"]] } then {
178 fail "start with intstruct un-initialized"
179} else {
180 pass "start with intstruct un-initialized"
181}
182
183proc test_reload_saved_value { filename msg oldval newval } {
184 global gdb_prompt
185
186 gdb_file_cmd $filename
187 if { ![string compare $oldval [capture_value $newval]] } then {
188 pass $msg
189 } else {
190 fail $msg
191 }
192}
193
194proc test_restore_saved_value { restore_args msg oldval newval } {
195 global gdb_prompt
196
197 gdb_test "restore $restore_args" \
198 "Restoring .*" \
199 "Restore command, $msg"
200
201 if { ![string compare $oldval [capture_value $newval]] } then {
202 pass "Restored value, $msg"
203 } else {
204 fail "Restored value, $msg"
205 }
206}
207
208test_reload_saved_value "intarr1.srec" "reload array as value, srec" \
209 $array_val "intarray"
210test_reload_saved_value "intstr1.srec" "reload struct as value, srec" \
211 $struct_val "intstruct"
212test_reload_saved_value "intarr2.srec" "reload array as memory, srec" \
213 $array_val "intarray"
214test_reload_saved_value "intstr2.srec" "reload struct as memory, srec" \
215 $struct_val "intstruct"
216
217test_reload_saved_value "intarr1.ihex" "reload array as value, intel hex" \
218 $array_val "intarray"
219test_reload_saved_value "intstr1.ihex" "reload struct as value, intel hex" \
220 $struct_val "intstruct"
221test_reload_saved_value "intarr2.ihex" "reload array as memory, intel hex" \
222 $array_val "intarray"
223test_reload_saved_value "intstr2.ihex" "reload struct as memory, intel hex" \
224 $struct_val "intstruct"
225
226test_reload_saved_value "intarr1.tekhex" "reload array as value, tekhex" \
227 $array_val "intarray"
228test_reload_saved_value "intstr1.tekhex" "reload struct as value, tekhex" \
229 $struct_val "intstruct"
230test_reload_saved_value "intarr2.tekhex" "reload array as memory, tekhex" \
231 $array_val "intarray"
232test_reload_saved_value "intstr2.tekhex" "reload struct as memory, tekhex" \
233 $struct_val "intstruct"
234
235# Start a fresh gdb session
236
237gdb_exit
238gdb_start
239gdb_reinitialize_dir $srcdir/$subdir
240gdb_load ${binfile}
241
242# Run to main.
243if { ! [ runto main ] } then {
244 gdb_suppress_entire_file "Program failed to run, so remaining tests in this file will automatically fail."
245}
246
247if { ![string compare $array_val [capture_value "intarray"]] } then {
248 fail "start with intarray un-initialized, runto main"
249} else {
250 pass "start with intarray un-initialized, runto main"
251}
252
253if { ![string compare $struct_val [capture_value "intstruct"]] } then {
254 fail "start with intstruct un-initialized, runto main"
255} else {
256 pass "start with intstruct un-initialized, runto main"
257}
258
259test_restore_saved_value "intarr1.srec" "array as value, srec" \
260 $array_val "intarray"
261
262test_restore_saved_value "intstr1.srec" "struct as value, srec" \
263 $struct_val "intstruct"
264
265gdb_test "print zero_all ()" "void" "zero all"
266
267test_restore_saved_value "intarr2.srec" "array as memory, srec" \
268 $array_val "intarray"
269
270test_restore_saved_value "intstr2.srec" "struct as memory, srec" \
271 $struct_val "intstruct"
272
273gdb_test "print zero_all ()" ""
274
275test_restore_saved_value "intarr1.ihex" "array as value, ihex" \
276 $array_val "intarray"
277
278test_restore_saved_value "intstr1.ihex" "struct as value, ihex" \
279 $struct_val "intstruct"
280
281gdb_test "print zero_all ()" ""
282
283test_restore_saved_value "intarr2.ihex" "array as memory, ihex" \
284 $array_val "intarray"
285
286test_restore_saved_value "intstr2.ihex" "struct as memory, ihex" \
287 $struct_val "intstruct"
288
289gdb_test "print zero_all ()" ""
290
291test_restore_saved_value "intarr1.tekhex" "array as value, tekhex" \
292 $array_val "intarray"
293
294test_restore_saved_value "intstr1.tekhex" "struct as value, tekhex" \
295 $struct_val "intstruct"
296
297gdb_test "print zero_all ()" ""
298
299test_restore_saved_value "intarr2.tekhex" "array as memory, tekhex" \
300 $array_val "intarray"
301
302test_restore_saved_value "intstr2.tekhex" "struct as memory, tekhex" \
303 $struct_val "intstruct"
304
305gdb_test "print zero_all ()" ""
306
307test_restore_saved_value "intarr1.bin binary $array_start" \
308 "array as value, binary" \
309 $array_val "intarray"
310
311test_restore_saved_value "intstr1.bin binary $struct_start" \
312 "struct as value, binary" \
313 $struct_val "intstruct"
314
315gdb_test "print zero_all ()" ""
316
317test_restore_saved_value "intarr2.bin binary $array_start" \
318 "array as memory, binary" \
319 $array_val "intarray"
320
321test_restore_saved_value "intstr2.bin binary $struct_start" \
322 "struct as memory, binary" \
323 $struct_val "intstruct"
324
325# test restore with offset.
326
327set array2_start [capture_value "/x &intarray2\[0\]"]
328set struct2_start [capture_value "/x &intstruct2"]
329set array2_offset \
330 [capture_value "/x (char *) &intarray2 - (char *) &intarray"]
331set struct2_offset \
332 [capture_value "/x (char *) &intstruct2 - (char *) &intstruct"]
333
334gdb_test "print zero_all ()" ""
335
336test_restore_saved_value "intarr1.srec $array2_offset" \
337 "array copy, srec" \
338 $array_val "intarray2"
339
340test_restore_saved_value "intstr1.srec $struct2_offset" \
341 "struct copy, srec" \
342 $struct_val "intstruct2"
343
344gdb_test "print zero_all ()" ""
345
346test_restore_saved_value "intarr1.ihex $array2_offset" \
347 "array copy, ihex" \
348 $array_val "intarray2"
349
350test_restore_saved_value "intstr1.ihex $struct2_offset" \
351 "struct copy, ihex" \
352 $struct_val "intstruct2"
353
354gdb_test "print zero_all ()" ""
355
356test_restore_saved_value "intarr1.tekhex $array2_offset" \
357 "array copy, tekhex" \
358 $array_val "intarray2"
359
360test_restore_saved_value "intstr1.tekhex $struct2_offset" \
361 "struct copy, tekhex" \
362 $struct_val "intstruct2"
363
364gdb_test "print zero_all ()" ""
365
366test_restore_saved_value "intarr1.bin binary $array2_start" \
367 "array copy, binary" \
368 $array_val "intarray2"
369
370test_restore_saved_value "intstr1.bin binary $struct2_start" \
371 "struct copy, binary" \
372 $struct_val "intstruct2"
373
374#
375# test restore with start/stop addresses.
376#
377# For this purpose, we will restore just the third element of the array,
378# and check to see that adjacent elements are not modified.
379#
380# We will need the address and offset of the third and fourth elements.
381#
382
383set element3_start [capture_value "/x &intarray\[3\]"]
384set element4_start [capture_value "/x &intarray\[4\]"]
385set element3_offset \
386 [capture_value "/x (char *) &intarray\[3\] - (char *) &intarray\[0\]"]
387set element4_offset \
388 [capture_value "/x (char *) &intarray\[4\] - (char *) &intarray\[0\]"]
389
390gdb_test "print zero_all ()" ""
391
392test_restore_saved_value "intarr1.srec 0 $element3_start $element4_start" \
393 "array partial, srec" \
394 [capture_value "4"] "intarray\[3\]"
395
396gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 1"
397gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 1"
398
399gdb_test "print zero_all ()" ""
400
401test_restore_saved_value "intarr1.ihex 0 $element3_start $element4_start" \
402 "array partial, ihex" \
403 [capture_value "4"] "intarray\[3\]"
404
405gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 2"
406gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 2"
407
408gdb_test "print zero_all ()" ""
409
410test_restore_saved_value "intarr1.tekhex 0 $element3_start $element4_start" \
411 "array partial, tekhex" \
412 [capture_value "4"] "intarray\[3\]"
413
414gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 3"
415gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 3"
416
417gdb_test "print zero_all ()" ""
418
419test_restore_saved_value \
420 "intarr1.bin binary $array_start $element3_offset $element4_offset" \
421 "array partial, binary" \
422 [capture_value "4"] "intarray\[3\]"
423
424gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 4"
425gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 4"
426
427gdb_test "print zero_all ()" "" ""
428
429# restore with expressions
430test_restore_saved_value \
431 "intarr3.srec ${array2_start}-${array_start} &intarray\[3\] &intarray\[4\]" \
432 "array partial with expressions" \
433 [capture_value "4"] "intarray2\[3\]"
434
435gdb_test "print intarray2\[2\] == 0" " = 1" "element 2 not changed, == 4"
436gdb_test "print intarray2\[4\] == 0" " = 1" "element 4 not changed, == 4"
437
438
439# clean up files
440
441remote_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"
442
This page took 0.058099 seconds and 4 git commands to generate.