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