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