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