gdb:
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / dump.exp
CommitLineData
4c38e0a4 1# Copyright 2002, 2004, 2007, 2008, 2009, 2010 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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
dd7dfd64 6# (at your option) any later version.
e22f8b7c 7#
dd7dfd64
MS
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.
e22f8b7c 12#
dd7dfd64 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
dd7dfd64 15
dd7dfd64
MS
16# This file was written by Michael Snyder (msnyder@redhat.com)
17# This is a test for the gdb command "dump".
18
19if $tracelevel then {
20 strace $tracelevel
21}
22
dd7dfd64
MS
23
24set testfile "dump"
25
26set srcfile ${testfile}.c
27set binfile ${objdir}/${subdir}/${testfile}
f6347e16 28set options {debug}
dd7dfd64 29
f31dfe3b 30set is64bitonly "no"
1ab80e5b 31set endian "auto"
f31dfe3b 32
f6347e16
RH
33if [istarget "alpha*-*-*"] then {
34 # SREC etc cannot handle 64-bit addresses. Force the test
35 # program into the low 31 bits of the address space.
36 lappend options "additional_flags=-Wl,-taso"
37}
38
8f07f25a 39if {[istarget "ia64*-*-*"] || [istarget "hppa64-*-*"]} then {
f31dfe3b
JJ
40 set is64bitonly "yes"
41}
42
1fac167a
UW
43if {[istarget "spu*-*-*"]} then {
44 # The internal address format used for the combined Cell/B.E.
45 # debugger requires 64-bit.
46 set is64bitonly "yes"
47}
48
f6347e16 49if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable ${options}] != "" } {
b60f0898
JB
50 untested dump.exp
51 return -1
dd7dfd64
MS
52}
53
54# Start with a fresh gdb.
55
56gdb_exit
57gdb_start
58gdb_reinitialize_dir $srcdir/$subdir
c0ac0ec7
JK
59
60gdb_test "dump mem /dev/null 0x10 0x20" "Cannot access memory at address 0x10" \
61 "inaccessible memory is reported"
62
dd7dfd64
MS
63gdb_load ${binfile}
64
65# Clean up any stale output files from previous test runs
66
67remote_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"
68
69# Test help (FIXME:)
70
71# Run target program until data structs are initialized.
72
73if { ! [ runto checkpoint1 ] } then {
b60f0898
JB
74 untested dump.exp
75 return -1
dd7dfd64
MS
76}
77
1ab80e5b
MR
78# Get the endianness for the later use with endianless formats.
79
a76e022a 80gdb_test_multiple "show endian" "show endian" {
1ab80e5b
MR
81 -re ".* (big|little) endian.*$gdb_prompt $" {
82 set endian $expect_out(1,string)
83 pass "endianness: $endian"
84 }
1ab80e5b
MR
85}
86
dd7dfd64
MS
87# Now generate some dump files.
88
89proc make_dump_file { command msg } {
90 global gdb_prompt
91
a76e022a 92 gdb_test_multiple "${command}" "$msg" {
dd7dfd64
MS
93 -re ".*\[Ee\]rror.*$gdb_prompt $" { fail $msg }
94 -re ".*\[Ww\]arning.*$gdb_prompt $" { fail $msg }
95 -re ".*\[Uu\]ndefined .*$gdb_prompt $" { fail $msg }
a76e022a 96 -re ".*$gdb_prompt $" { pass $msg }
dd7dfd64
MS
97 }
98}
99
100make_dump_file "dump val intarr1.bin intarray" \
101 "dump array as value, default"
102
103make_dump_file "dump val intstr1.bin intstruct" \
104 "dump struct as value, default"
105
106make_dump_file "dump bin val intarr1b.bin intarray" \
107 "dump array as value, binary"
108
109make_dump_file "dump bin val intstr1b.bin intstruct" \
110 "dump struct as value, binary"
111
112make_dump_file "dump srec val intarr1.srec intarray" \
113 "dump array as value, srec"
114
115make_dump_file "dump srec val intstr1.srec intstruct" \
116 "dump struct as value, srec"
117
118make_dump_file "dump ihex val intarr1.ihex intarray" \
119 "dump array as value, intel hex"
120
121make_dump_file "dump ihex val intstr1.ihex intstruct" \
122 "dump struct as value, intel hex"
123
124make_dump_file "dump tekhex val intarr1.tekhex intarray" \
125 "dump array as value, tekhex"
126
127make_dump_file "dump tekhex val intstr1.tekhex intstruct" \
128 "dump struct as value, tekhex"
129
8d394f98 130proc capture_value { expression args } {
dd7dfd64
MS
131 global gdb_prompt
132 global expect_out
133
134 set output_string ""
8d394f98
AC
135 if {[llength $args] > 0} {
136 # Convert $args into a simple string.
137 set test "[join $args]; capture $expression"
138 } {
139 set test "capture $expression"
140 }
141 gdb_test_multiple "print ${expression}" "$test" {
142 -re "\\$\[0-9\]+ = (\[^\r\n\]+).*$gdb_prompt $" {
143 set output_string "$expect_out(1,string)"
144 pass "$test"
dd7dfd64 145 }
8d394f98
AC
146 -re "(Cannot access memory at address \[^\r\n\]+).*$gdb_prompt $" {
147 # Even a failed value is valid
148 set output_string "$expect_out(1,string)"
149 pass "$test"
dd7dfd64
MS
150 }
151 }
152 return $output_string
153}
154
155set array_start [capture_value "/x &intarray\[0\]"]
156set array_end [capture_value "/x &intarray\[32\]"]
157set struct_start [capture_value "/x &intstruct"]
158set struct_end [capture_value "/x &intstruct + 1"]
159
160set array_val [capture_value "intarray"]
161set struct_val [capture_value "intstruct"]
162
163make_dump_file "dump mem intarr2.bin $array_start $array_end" \
164 "dump array as memory, default"
165
166make_dump_file "dump mem intstr2.bin $struct_start $struct_end" \
167 "dump struct as memory, default"
168
169make_dump_file "dump bin mem intarr2b.bin $array_start $array_end" \
170 "dump array as memory, binary"
171
172make_dump_file "dump bin mem intstr2b.bin $struct_start $struct_end" \
173 "dump struct as memory, binary"
174
175make_dump_file "dump srec mem intarr2.srec $array_start $array_end" \
176 "dump array as memory, srec"
177
178make_dump_file "dump srec mem intstr2.srec $struct_start $struct_end" \
179 "dump struct as memory, srec"
180
181make_dump_file "dump ihex mem intarr2.ihex $array_start $array_end" \
182 "dump array as memory, ihex"
183
184make_dump_file "dump ihex mem intstr2.ihex $struct_start $struct_end" \
185 "dump struct as memory, ihex"
186
187make_dump_file "dump tekhex mem intarr2.tekhex $array_start $array_end" \
188 "dump array as memory, tekhex"
189
190make_dump_file "dump tekhex mem intstr2.tekhex $struct_start $struct_end" \
191 "dump struct as memory, tekhex"
192
193# test complex expressions
194make_dump_file \
195 "dump srec mem intarr3.srec &intarray \(char *\) &intarray + sizeof intarray" \
196 "dump array as mem, srec, expressions"
197
198
199# Now start a fresh gdb session, and reload the saved value files.
200
201gdb_exit
202gdb_start
203gdb_file_cmd ${binfile}
204
1ab80e5b
MR
205# Now fix the endianness at the correct state.
206
a76e022a 207gdb_test_multiple "set endian $endian" "set endianness" {
1ab80e5b
MR
208 -re ".* (big|little) endian.*$gdb_prompt $" {
209 pass "setting $endian endianness"
210 }
1ab80e5b
MR
211}
212
dd7dfd64
MS
213# Reload saved values one by one, and compare.
214
8d394f98
AC
215if { ![string compare $array_val \
216 [capture_value "intarray" "file binfile"]] } then {
dd7dfd64
MS
217 fail "start with intarray un-initialized"
218} else {
219 pass "start with intarray un-initialized"
220}
221
8d394f98
AC
222if { ![string compare $struct_val \
223 [capture_value "intstruct" "file binfile"]] } then {
dd7dfd64
MS
224 fail "start with intstruct un-initialized"
225} else {
226 pass "start with intstruct un-initialized"
227}
228
229proc test_reload_saved_value { filename msg oldval newval } {
230 global gdb_prompt
231
232 gdb_file_cmd $filename
8d394f98
AC
233 if { ![string compare $oldval \
234 [capture_value $newval "$msg"]] } then {
235 pass "$msg; value restored ok"
dd7dfd64 236 } else {
8d394f98 237 fail "$msg; value restored ok"
dd7dfd64
MS
238 }
239}
240
241proc test_restore_saved_value { restore_args msg oldval newval } {
242 global gdb_prompt
243
244 gdb_test "restore $restore_args" \
8d394f98
AC
245 "Restoring .*" \
246 "$msg; file restored ok"
247 if { ![string compare $oldval \
248 [capture_value $newval "$msg"]] } then {
249 pass "$msg; value restored ok"
dd7dfd64 250 } else {
8d394f98 251 fail "$msg; value restored ok"
dd7dfd64
MS
252 }
253}
254
f31dfe3b
JJ
255# srec format can not be loaded for 64-bit-only platforms
256if ![string compare $is64bitonly "no"] then {
257 test_reload_saved_value "intarr1.srec" "reload array as value, srec" \
dd7dfd64 258 $array_val "intarray"
f31dfe3b 259 test_reload_saved_value "intstr1.srec" "reload struct as value, srec" \
dd7dfd64 260 $struct_val "intstruct"
f31dfe3b 261 test_reload_saved_value "intarr2.srec" "reload array as memory, srec" \
dd7dfd64 262 $array_val "intarray"
f31dfe3b 263 test_reload_saved_value "intstr2.srec" "reload struct as memory, srec" \
dd7dfd64 264 $struct_val "intstruct"
f31dfe3b
JJ
265}
266
267# ihex format can not be loaded for 64-bit-only platforms
268if ![string compare $is64bitonly "no"] then {
dd7dfd64 269
f31dfe3b 270 test_reload_saved_value "intarr1.ihex" "reload array as value, intel hex" \
dd7dfd64 271 $array_val "intarray"
f31dfe3b 272 test_reload_saved_value "intstr1.ihex" "reload struct as value, intel hex" \
dd7dfd64 273 $struct_val "intstruct"
f31dfe3b 274 test_reload_saved_value "intarr2.ihex" "reload array as memory, intel hex" \
dd7dfd64 275 $array_val "intarray"
f31dfe3b 276 test_reload_saved_value "intstr2.ihex" "reload struct as memory, intel hex" \
dd7dfd64 277 $struct_val "intstruct"
f31dfe3b 278}
dd7dfd64 279
f31dfe3b
JJ
280# tekhex format can not be loaded for 64-bit-only platforms
281if ![string compare $is64bitonly "no"] then {
282 test_reload_saved_value "intarr1.tekhex" "reload array as value, tekhex" \
dd7dfd64 283 $array_val "intarray"
f31dfe3b 284 test_reload_saved_value "intstr1.tekhex" "reload struct as value, tekhex" \
dd7dfd64 285 $struct_val "intstruct"
f31dfe3b 286 test_reload_saved_value "intarr2.tekhex" "reload array as memory, tekhex" \
dd7dfd64 287 $array_val "intarray"
f31dfe3b 288 test_reload_saved_value "intstr2.tekhex" "reload struct as memory, tekhex" \
dd7dfd64 289 $struct_val "intstruct"
f31dfe3b 290}
dd7dfd64
MS
291
292# Start a fresh gdb session
293
294gdb_exit
295gdb_start
296gdb_reinitialize_dir $srcdir/$subdir
297gdb_load ${binfile}
298
299# Run to main.
3ad13771 300if { ! [ runto_main ] } then {
b60f0898
JB
301 untested dump.exp
302 return -1
dd7dfd64
MS
303}
304
8d394f98
AC
305if { ![string compare $array_val \
306 [capture_value "intarray" "load binfile"]] } then {
dd7dfd64
MS
307 fail "start with intarray un-initialized, runto main"
308} else {
309 pass "start with intarray un-initialized, runto main"
310}
311
8d394f98
AC
312if { ![string compare $struct_val \
313 [capture_value "intstruct" "load binfile"]] } then {
dd7dfd64
MS
314 fail "start with intstruct un-initialized, runto main"
315} else {
316 pass "start with intstruct un-initialized, runto main"
317}
318
f31dfe3b
JJ
319if ![string compare $is64bitonly "no"] then {
320 test_restore_saved_value "intarr1.srec" "array as value, srec" \
dd7dfd64
MS
321 $array_val "intarray"
322
f31dfe3b 323 test_restore_saved_value "intstr1.srec" "struct as value, srec" \
dd7dfd64
MS
324 $struct_val "intstruct"
325
f31dfe3b 326 gdb_test "print zero_all ()" "void" "zero all"
dd7dfd64 327
f31dfe3b 328 test_restore_saved_value "intarr2.srec" "array as memory, srec" \
dd7dfd64
MS
329 $array_val "intarray"
330
f31dfe3b 331 test_restore_saved_value "intstr2.srec" "struct as memory, srec" \
dd7dfd64
MS
332 $struct_val "intstruct"
333
f6978de9 334 gdb_test "print zero_all ()" ".*"
dd7dfd64 335
f31dfe3b 336 test_restore_saved_value "intarr1.ihex" "array as value, ihex" \
dd7dfd64
MS
337 $array_val "intarray"
338
f31dfe3b 339 test_restore_saved_value "intstr1.ihex" "struct as value, ihex" \
dd7dfd64
MS
340 $struct_val "intstruct"
341
f6978de9 342 gdb_test "print zero_all ()" ".*"
dd7dfd64 343
f31dfe3b 344 test_restore_saved_value "intarr2.ihex" "array as memory, ihex" \
dd7dfd64
MS
345 $array_val "intarray"
346
f31dfe3b 347 test_restore_saved_value "intstr2.ihex" "struct as memory, ihex" \
dd7dfd64
MS
348 $struct_val "intstruct"
349
f6978de9 350 gdb_test "print zero_all ()" ".*"
dd7dfd64 351
f31dfe3b 352 test_restore_saved_value "intarr1.tekhex" "array as value, tekhex" \
dd7dfd64
MS
353 $array_val "intarray"
354
f31dfe3b 355 test_restore_saved_value "intstr1.tekhex" "struct as value, tekhex" \
dd7dfd64
MS
356 $struct_val "intstruct"
357
f6978de9 358 gdb_test "print zero_all ()" ".*"
dd7dfd64 359
f31dfe3b 360 test_restore_saved_value "intarr2.tekhex" "array as memory, tekhex" \
dd7dfd64
MS
361 $array_val "intarray"
362
f31dfe3b 363 test_restore_saved_value "intstr2.tekhex" "struct as memory, tekhex" \
dd7dfd64 364 $struct_val "intstruct"
f31dfe3b 365}
dd7dfd64 366
f6978de9 367gdb_test "print zero_all ()" ".*"
dd7dfd64
MS
368
369test_restore_saved_value "intarr1.bin binary $array_start" \
370 "array as value, binary" \
371 $array_val "intarray"
372
373test_restore_saved_value "intstr1.bin binary $struct_start" \
374 "struct as value, binary" \
375 $struct_val "intstruct"
376
f6978de9 377gdb_test "print zero_all ()" ".*"
dd7dfd64
MS
378
379test_restore_saved_value "intarr2.bin binary $array_start" \
380 "array as memory, binary" \
381 $array_val "intarray"
382
383test_restore_saved_value "intstr2.bin binary $struct_start" \
384 "struct as memory, binary" \
385 $struct_val "intstruct"
386
387# test restore with offset.
388
389set array2_start [capture_value "/x &intarray2\[0\]"]
390set struct2_start [capture_value "/x &intstruct2"]
391set array2_offset \
2db536a1 392 [capture_value "(char *) &intarray2 - (char *) &intarray"]
dd7dfd64 393set struct2_offset \
2db536a1 394 [capture_value "(char *) &intstruct2 - (char *) &intstruct"]
dd7dfd64 395
f6978de9 396gdb_test "print zero_all ()" ".*"
dd7dfd64 397
f31dfe3b
JJ
398
399if ![string compare $is64bitonly "no"] then {
400 test_restore_saved_value "intarr1.srec $array2_offset" \
dd7dfd64
MS
401 "array copy, srec" \
402 $array_val "intarray2"
403
f31dfe3b 404 test_restore_saved_value "intstr1.srec $struct2_offset" \
dd7dfd64
MS
405 "struct copy, srec" \
406 $struct_val "intstruct2"
407
f6978de9 408 gdb_test "print zero_all ()" ".*"
dd7dfd64 409
f31dfe3b 410 test_restore_saved_value "intarr1.ihex $array2_offset" \
dd7dfd64
MS
411 "array copy, ihex" \
412 $array_val "intarray2"
413
f31dfe3b 414 test_restore_saved_value "intstr1.ihex $struct2_offset" \
dd7dfd64
MS
415 "struct copy, ihex" \
416 $struct_val "intstruct2"
417
f6978de9 418 gdb_test "print zero_all ()" ".*"
dd7dfd64 419
f31dfe3b 420 test_restore_saved_value "intarr1.tekhex $array2_offset" \
dd7dfd64
MS
421 "array copy, tekhex" \
422 $array_val "intarray2"
423
f31dfe3b 424 test_restore_saved_value "intstr1.tekhex $struct2_offset" \
dd7dfd64
MS
425 "struct copy, tekhex" \
426 $struct_val "intstruct2"
f31dfe3b 427}
dd7dfd64 428
f6978de9 429gdb_test "print zero_all ()" ".*"
dd7dfd64
MS
430
431test_restore_saved_value "intarr1.bin binary $array2_start" \
432 "array copy, binary" \
433 $array_val "intarray2"
434
435test_restore_saved_value "intstr1.bin binary $struct2_start" \
436 "struct copy, binary" \
437 $struct_val "intstruct2"
438
439#
440# test restore with start/stop addresses.
441#
442# For this purpose, we will restore just the third element of the array,
443# and check to see that adjacent elements are not modified.
444#
445# We will need the address and offset of the third and fourth elements.
446#
447
448set element3_start [capture_value "/x &intarray\[3\]"]
449set element4_start [capture_value "/x &intarray\[4\]"]
450set element3_offset \
451 [capture_value "/x (char *) &intarray\[3\] - (char *) &intarray\[0\]"]
452set element4_offset \
453 [capture_value "/x (char *) &intarray\[4\] - (char *) &intarray\[0\]"]
454
f31dfe3b 455if ![string compare $is64bitonly "no"] then {
f6978de9 456 gdb_test "print zero_all ()" ".*"
dd7dfd64 457
f31dfe3b 458 test_restore_saved_value "intarr1.srec 0 $element3_start $element4_start" \
8d394f98 459 "array partial, srec" 4 "intarray\[3\]"
dd7dfd64 460
f31dfe3b
JJ
461 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 1"
462 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 1"
dd7dfd64 463
f6978de9 464 gdb_test "print zero_all ()" ".*"
dd7dfd64 465
f31dfe3b 466 test_restore_saved_value "intarr1.ihex 0 $element3_start $element4_start" \
8d394f98 467 "array partial, ihex" 4 "intarray\[3\]"
dd7dfd64 468
f31dfe3b
JJ
469 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 2"
470 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 2"
dd7dfd64 471
f6978de9 472 gdb_test "print zero_all ()" ".*"
dd7dfd64 473
f31dfe3b 474 test_restore_saved_value "intarr1.tekhex 0 $element3_start $element4_start" \
8d394f98 475 "array partial, tekhex" 4 "intarray\[3\]"
dd7dfd64 476
f31dfe3b
JJ
477 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 3"
478 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 3"
479}
dd7dfd64 480
f6978de9 481gdb_test "print zero_all ()" ".*"
dd7dfd64
MS
482
483test_restore_saved_value \
484 "intarr1.bin binary $array_start $element3_offset $element4_offset" \
8d394f98 485 "array partial, binary" 4 "intarray\[3\]"
dd7dfd64
MS
486
487gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 4"
488gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 4"
489
f31dfe3b 490if ![string compare $is64bitonly "no"] then {
de7ff789 491 gdb_test "print zero_all ()" ".*" ""
dd7dfd64 492
f31dfe3b
JJ
493 # restore with expressions
494 test_restore_saved_value \
f29c0325 495 "intarr3.srec (char*)${array2_start}-(char*)${array_start} &intarray\[3\] &intarray\[4\]" \
8d394f98 496 "array partial with expressions" 4 "intarray2\[3\]"
dd7dfd64 497
f31dfe3b
JJ
498 gdb_test "print intarray2\[2\] == 0" " = 1" "element 2 not changed, == 4"
499 gdb_test "print intarray2\[4\] == 0" " = 1" "element 4 not changed, == 4"
500}
dd7dfd64
MS
501
502# clean up files
503
504remote_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.852516 seconds and 4 git commands to generate.