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