Reviewed and approved by Daniel Jacobowitz <drow@false.org>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / dump.exp
CommitLineData
3ad13771 1# Copyright 2002, 2004 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
8f07f25a 44if {[istarget "ia64*-*-*"] || [istarget "hppa64-*-*"]} then {
f31dfe3b
JJ
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
8d394f98 116proc capture_value { expression args } {
dd7dfd64
MS
117 global gdb_prompt
118 global expect_out
119
120 set output_string ""
8d394f98
AC
121 if {[llength $args] > 0} {
122 # Convert $args into a simple string.
123 set test "[join $args]; capture $expression"
124 } {
125 set test "capture $expression"
126 }
127 gdb_test_multiple "print ${expression}" "$test" {
128 -re "\\$\[0-9\]+ = (\[^\r\n\]+).*$gdb_prompt $" {
129 set output_string "$expect_out(1,string)"
130 pass "$test"
dd7dfd64 131 }
8d394f98
AC
132 -re "(Cannot access memory at address \[^\r\n\]+).*$gdb_prompt $" {
133 # Even a failed value is valid
134 set output_string "$expect_out(1,string)"
135 pass "$test"
dd7dfd64
MS
136 }
137 }
138 return $output_string
139}
140
141set array_start [capture_value "/x &intarray\[0\]"]
142set array_end [capture_value "/x &intarray\[32\]"]
143set struct_start [capture_value "/x &intstruct"]
144set struct_end [capture_value "/x &intstruct + 1"]
145
146set array_val [capture_value "intarray"]
147set struct_val [capture_value "intstruct"]
148
149make_dump_file "dump mem intarr2.bin $array_start $array_end" \
150 "dump array as memory, default"
151
152make_dump_file "dump mem intstr2.bin $struct_start $struct_end" \
153 "dump struct as memory, default"
154
155make_dump_file "dump bin mem intarr2b.bin $array_start $array_end" \
156 "dump array as memory, binary"
157
158make_dump_file "dump bin mem intstr2b.bin $struct_start $struct_end" \
159 "dump struct as memory, binary"
160
161make_dump_file "dump srec mem intarr2.srec $array_start $array_end" \
162 "dump array as memory, srec"
163
164make_dump_file "dump srec mem intstr2.srec $struct_start $struct_end" \
165 "dump struct as memory, srec"
166
167make_dump_file "dump ihex mem intarr2.ihex $array_start $array_end" \
168 "dump array as memory, ihex"
169
170make_dump_file "dump ihex mem intstr2.ihex $struct_start $struct_end" \
171 "dump struct as memory, ihex"
172
173make_dump_file "dump tekhex mem intarr2.tekhex $array_start $array_end" \
174 "dump array as memory, tekhex"
175
176make_dump_file "dump tekhex mem intstr2.tekhex $struct_start $struct_end" \
177 "dump struct as memory, tekhex"
178
179# test complex expressions
180make_dump_file \
181 "dump srec mem intarr3.srec &intarray \(char *\) &intarray + sizeof intarray" \
182 "dump array as mem, srec, expressions"
183
184
185# Now start a fresh gdb session, and reload the saved value files.
186
187gdb_exit
188gdb_start
189gdb_file_cmd ${binfile}
190
191# Reload saved values one by one, and compare.
192
8d394f98
AC
193if { ![string compare $array_val \
194 [capture_value "intarray" "file binfile"]] } then {
dd7dfd64
MS
195 fail "start with intarray un-initialized"
196} else {
197 pass "start with intarray un-initialized"
198}
199
8d394f98
AC
200if { ![string compare $struct_val \
201 [capture_value "intstruct" "file binfile"]] } then {
dd7dfd64
MS
202 fail "start with intstruct un-initialized"
203} else {
204 pass "start with intstruct un-initialized"
205}
206
207proc test_reload_saved_value { filename msg oldval newval } {
208 global gdb_prompt
209
210 gdb_file_cmd $filename
8d394f98
AC
211 if { ![string compare $oldval \
212 [capture_value $newval "$msg"]] } then {
213 pass "$msg; value restored ok"
dd7dfd64 214 } else {
8d394f98 215 fail "$msg; value restored ok"
dd7dfd64
MS
216 }
217}
218
219proc test_restore_saved_value { restore_args msg oldval newval } {
220 global gdb_prompt
221
222 gdb_test "restore $restore_args" \
8d394f98
AC
223 "Restoring .*" \
224 "$msg; file restored ok"
225 if { ![string compare $oldval \
226 [capture_value $newval "$msg"]] } then {
227 pass "$msg; value restored ok"
dd7dfd64 228 } else {
8d394f98 229 fail "$msg; value restored ok"
dd7dfd64
MS
230 }
231}
232
f31dfe3b
JJ
233# srec format can not be loaded for 64-bit-only platforms
234if ![string compare $is64bitonly "no"] then {
235 test_reload_saved_value "intarr1.srec" "reload array as value, srec" \
dd7dfd64 236 $array_val "intarray"
f31dfe3b 237 test_reload_saved_value "intstr1.srec" "reload struct as value, srec" \
dd7dfd64 238 $struct_val "intstruct"
f31dfe3b 239 test_reload_saved_value "intarr2.srec" "reload array as memory, srec" \
dd7dfd64 240 $array_val "intarray"
f31dfe3b 241 test_reload_saved_value "intstr2.srec" "reload struct as memory, srec" \
dd7dfd64 242 $struct_val "intstruct"
f31dfe3b
JJ
243}
244
245# ihex format can not be loaded for 64-bit-only platforms
246if ![string compare $is64bitonly "no"] then {
dd7dfd64 247
f31dfe3b 248 test_reload_saved_value "intarr1.ihex" "reload array as value, intel hex" \
dd7dfd64 249 $array_val "intarray"
f31dfe3b 250 test_reload_saved_value "intstr1.ihex" "reload struct as value, intel hex" \
dd7dfd64 251 $struct_val "intstruct"
f31dfe3b 252 test_reload_saved_value "intarr2.ihex" "reload array as memory, intel hex" \
dd7dfd64 253 $array_val "intarray"
f31dfe3b 254 test_reload_saved_value "intstr2.ihex" "reload struct as memory, intel hex" \
dd7dfd64 255 $struct_val "intstruct"
f31dfe3b 256}
dd7dfd64 257
f31dfe3b
JJ
258# tekhex format can not be loaded for 64-bit-only platforms
259if ![string compare $is64bitonly "no"] then {
260 test_reload_saved_value "intarr1.tekhex" "reload array as value, tekhex" \
dd7dfd64 261 $array_val "intarray"
f31dfe3b 262 test_reload_saved_value "intstr1.tekhex" "reload struct as value, tekhex" \
dd7dfd64 263 $struct_val "intstruct"
f31dfe3b 264 test_reload_saved_value "intarr2.tekhex" "reload array as memory, tekhex" \
dd7dfd64 265 $array_val "intarray"
f31dfe3b 266 test_reload_saved_value "intstr2.tekhex" "reload struct as memory, tekhex" \
dd7dfd64 267 $struct_val "intstruct"
f31dfe3b 268}
dd7dfd64
MS
269
270# Start a fresh gdb session
271
272gdb_exit
273gdb_start
274gdb_reinitialize_dir $srcdir/$subdir
275gdb_load ${binfile}
276
277# Run to main.
3ad13771 278if { ! [ runto_main ] } then {
dd7dfd64
MS
279 gdb_suppress_entire_file "Program failed to run, so remaining tests in this file will automatically fail."
280}
281
8d394f98
AC
282if { ![string compare $array_val \
283 [capture_value "intarray" "load binfile"]] } then {
dd7dfd64
MS
284 fail "start with intarray un-initialized, runto main"
285} else {
286 pass "start with intarray un-initialized, runto main"
287}
288
8d394f98
AC
289if { ![string compare $struct_val \
290 [capture_value "intstruct" "load binfile"]] } then {
dd7dfd64
MS
291 fail "start with intstruct un-initialized, runto main"
292} else {
293 pass "start with intstruct un-initialized, runto main"
294}
295
f31dfe3b
JJ
296if ![string compare $is64bitonly "no"] then {
297 test_restore_saved_value "intarr1.srec" "array as value, srec" \
dd7dfd64
MS
298 $array_val "intarray"
299
f31dfe3b 300 test_restore_saved_value "intstr1.srec" "struct as value, srec" \
dd7dfd64
MS
301 $struct_val "intstruct"
302
f31dfe3b 303 gdb_test "print zero_all ()" "void" "zero all"
dd7dfd64 304
f31dfe3b 305 test_restore_saved_value "intarr2.srec" "array as memory, srec" \
dd7dfd64
MS
306 $array_val "intarray"
307
f31dfe3b 308 test_restore_saved_value "intstr2.srec" "struct as memory, srec" \
dd7dfd64
MS
309 $struct_val "intstruct"
310
f31dfe3b 311 gdb_test "print zero_all ()" ""
dd7dfd64 312
f31dfe3b 313 test_restore_saved_value "intarr1.ihex" "array as value, ihex" \
dd7dfd64
MS
314 $array_val "intarray"
315
f31dfe3b 316 test_restore_saved_value "intstr1.ihex" "struct as value, ihex" \
dd7dfd64
MS
317 $struct_val "intstruct"
318
f31dfe3b 319 gdb_test "print zero_all ()" ""
dd7dfd64 320
f31dfe3b 321 test_restore_saved_value "intarr2.ihex" "array as memory, ihex" \
dd7dfd64
MS
322 $array_val "intarray"
323
f31dfe3b 324 test_restore_saved_value "intstr2.ihex" "struct as memory, ihex" \
dd7dfd64
MS
325 $struct_val "intstruct"
326
f31dfe3b 327 gdb_test "print zero_all ()" ""
dd7dfd64 328
f31dfe3b 329 test_restore_saved_value "intarr1.tekhex" "array as value, tekhex" \
dd7dfd64
MS
330 $array_val "intarray"
331
f31dfe3b 332 test_restore_saved_value "intstr1.tekhex" "struct as value, tekhex" \
dd7dfd64
MS
333 $struct_val "intstruct"
334
f31dfe3b 335 gdb_test "print zero_all ()" ""
dd7dfd64 336
f31dfe3b 337 test_restore_saved_value "intarr2.tekhex" "array as memory, tekhex" \
dd7dfd64
MS
338 $array_val "intarray"
339
f31dfe3b 340 test_restore_saved_value "intstr2.tekhex" "struct as memory, tekhex" \
dd7dfd64 341 $struct_val "intstruct"
f31dfe3b 342}
dd7dfd64
MS
343
344gdb_test "print zero_all ()" ""
345
346test_restore_saved_value "intarr1.bin binary $array_start" \
347 "array as value, binary" \
348 $array_val "intarray"
349
350test_restore_saved_value "intstr1.bin binary $struct_start" \
351 "struct as value, binary" \
352 $struct_val "intstruct"
353
354gdb_test "print zero_all ()" ""
355
356test_restore_saved_value "intarr2.bin binary $array_start" \
357 "array as memory, binary" \
358 $array_val "intarray"
359
360test_restore_saved_value "intstr2.bin binary $struct_start" \
361 "struct as memory, binary" \
362 $struct_val "intstruct"
363
364# test restore with offset.
365
366set array2_start [capture_value "/x &intarray2\[0\]"]
367set struct2_start [capture_value "/x &intstruct2"]
368set array2_offset \
2db536a1 369 [capture_value "(char *) &intarray2 - (char *) &intarray"]
dd7dfd64 370set struct2_offset \
2db536a1 371 [capture_value "(char *) &intstruct2 - (char *) &intstruct"]
dd7dfd64
MS
372
373gdb_test "print zero_all ()" ""
374
f31dfe3b
JJ
375
376if ![string compare $is64bitonly "no"] then {
377 test_restore_saved_value "intarr1.srec $array2_offset" \
dd7dfd64
MS
378 "array copy, srec" \
379 $array_val "intarray2"
380
f31dfe3b 381 test_restore_saved_value "intstr1.srec $struct2_offset" \
dd7dfd64
MS
382 "struct copy, srec" \
383 $struct_val "intstruct2"
384
f31dfe3b 385 gdb_test "print zero_all ()" ""
dd7dfd64 386
f31dfe3b 387 test_restore_saved_value "intarr1.ihex $array2_offset" \
dd7dfd64
MS
388 "array copy, ihex" \
389 $array_val "intarray2"
390
f31dfe3b 391 test_restore_saved_value "intstr1.ihex $struct2_offset" \
dd7dfd64
MS
392 "struct copy, ihex" \
393 $struct_val "intstruct2"
394
f31dfe3b 395 gdb_test "print zero_all ()" ""
dd7dfd64 396
f31dfe3b 397 test_restore_saved_value "intarr1.tekhex $array2_offset" \
dd7dfd64
MS
398 "array copy, tekhex" \
399 $array_val "intarray2"
400
f31dfe3b 401 test_restore_saved_value "intstr1.tekhex $struct2_offset" \
dd7dfd64
MS
402 "struct copy, tekhex" \
403 $struct_val "intstruct2"
f31dfe3b 404}
dd7dfd64
MS
405
406gdb_test "print zero_all ()" ""
407
408test_restore_saved_value "intarr1.bin binary $array2_start" \
409 "array copy, binary" \
410 $array_val "intarray2"
411
412test_restore_saved_value "intstr1.bin binary $struct2_start" \
413 "struct copy, binary" \
414 $struct_val "intstruct2"
415
416#
417# test restore with start/stop addresses.
418#
419# For this purpose, we will restore just the third element of the array,
420# and check to see that adjacent elements are not modified.
421#
422# We will need the address and offset of the third and fourth elements.
423#
424
425set element3_start [capture_value "/x &intarray\[3\]"]
426set element4_start [capture_value "/x &intarray\[4\]"]
427set element3_offset \
428 [capture_value "/x (char *) &intarray\[3\] - (char *) &intarray\[0\]"]
429set element4_offset \
430 [capture_value "/x (char *) &intarray\[4\] - (char *) &intarray\[0\]"]
431
f31dfe3b
JJ
432if ![string compare $is64bitonly "no"] then {
433 gdb_test "print zero_all ()" ""
dd7dfd64 434
f31dfe3b 435 test_restore_saved_value "intarr1.srec 0 $element3_start $element4_start" \
8d394f98 436 "array partial, srec" 4 "intarray\[3\]"
dd7dfd64 437
f31dfe3b
JJ
438 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 1"
439 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 1"
dd7dfd64 440
f31dfe3b 441 gdb_test "print zero_all ()" ""
dd7dfd64 442
f31dfe3b 443 test_restore_saved_value "intarr1.ihex 0 $element3_start $element4_start" \
8d394f98 444 "array partial, ihex" 4 "intarray\[3\]"
dd7dfd64 445
f31dfe3b
JJ
446 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 2"
447 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 2"
dd7dfd64 448
f31dfe3b 449 gdb_test "print zero_all ()" ""
dd7dfd64 450
f31dfe3b 451 test_restore_saved_value "intarr1.tekhex 0 $element3_start $element4_start" \
8d394f98 452 "array partial, tekhex" 4 "intarray\[3\]"
dd7dfd64 453
f31dfe3b
JJ
454 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 3"
455 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 3"
456}
dd7dfd64
MS
457
458gdb_test "print zero_all ()" ""
459
460test_restore_saved_value \
461 "intarr1.bin binary $array_start $element3_offset $element4_offset" \
8d394f98 462 "array partial, binary" 4 "intarray\[3\]"
dd7dfd64
MS
463
464gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 4"
465gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 4"
466
f31dfe3b
JJ
467if ![string compare $is64bitonly "no"] then {
468 gdb_test "print zero_all ()" "" ""
dd7dfd64 469
f31dfe3b
JJ
470 # restore with expressions
471 test_restore_saved_value \
dd7dfd64 472 "intarr3.srec ${array2_start}-${array_start} &intarray\[3\] &intarray\[4\]" \
8d394f98 473 "array partial with expressions" 4 "intarray2\[3\]"
dd7dfd64 474
f31dfe3b
JJ
475 gdb_test "print intarray2\[2\] == 0" " = 1" "element 2 not changed, == 4"
476 gdb_test "print intarray2\[4\] == 0" " = 1" "element 4 not changed, == 4"
477}
dd7dfd64
MS
478
479# clean up files
480
481remote_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"
This page took 0.473356 seconds and 4 git commands to generate.