]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/dump.exp
Updated copyright notices for most files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / dump.exp
CommitLineData
9b254dd1 1# Copyright 2002, 2004, 2007, 2008 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
MS
15
16# Please email any bugs, comments, and/or additions to this file to:
17# bug-gdb@prep.ai.mit.edu
18
19# This file was written by Michael Snyder (msnyder@redhat.com)
20# This is a test for the gdb command "dump".
21
22if $tracelevel then {
23 strace $tracelevel
24}
25
26set prms_id 0
27set bug_id 0
28
29set testfile "dump"
30
31set srcfile ${testfile}.c
32set binfile ${objdir}/${subdir}/${testfile}
f6347e16 33set options {debug}
dd7dfd64 34
f31dfe3b 35set is64bitonly "no"
1ab80e5b 36set endian "auto"
f31dfe3b 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}] != "" } {
b60f0898
JB
49 untested dump.exp
50 return -1
dd7dfd64
MS
51}
52
53# Start with a fresh gdb.
54
55gdb_exit
56gdb_start
57gdb_reinitialize_dir $srcdir/$subdir
58gdb_load ${binfile}
59
60# Clean up any stale output files from previous test runs
61
62remote_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"
63
64# Test help (FIXME:)
65
66# Run target program until data structs are initialized.
67
68if { ! [ runto checkpoint1 ] } then {
b60f0898
JB
69 untested dump.exp
70 return -1
dd7dfd64
MS
71}
72
1ab80e5b
MR
73# Get the endianness for the later use with endianless formats.
74
75send_gdb "show endian\n"
76gdb_expect {
77 -re ".* (big|little) endian.*$gdb_prompt $" {
78 set endian $expect_out(1,string)
79 pass "endianness: $endian"
80 }
81 default {
82 fail "(timeout) getting target endianness"
83 }
84}
85
dd7dfd64
MS
86# Now generate some dump files.
87
88proc make_dump_file { command msg } {
89 global gdb_prompt
90
91 send_gdb "${command}\n"
92 gdb_expect {
93 -re ".*\[Ee\]rror.*$gdb_prompt $" { fail $msg }
94 -re ".*\[Ww\]arning.*$gdb_prompt $" { fail $msg }
95 -re ".*\[Uu\]ndefined .*$gdb_prompt $" { fail $msg }
96 -re ".*$gdb_prompt $" { pass $msg }
97 timeout { fail "$msg (timeout)" }
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
208send_gdb "set endian $endian\n"
209gdb_expect {
210 -re ".* (big|little) endian.*$gdb_prompt $" {
211 pass "setting $endian endianness"
212 }
213 default {
214 fail "(timeout) setting $endian endianness"
215 }
216}
217
dd7dfd64
MS
218# Reload saved values one by one, and compare.
219
8d394f98
AC
220if { ![string compare $array_val \
221 [capture_value "intarray" "file binfile"]] } then {
dd7dfd64
MS
222 fail "start with intarray un-initialized"
223} else {
224 pass "start with intarray un-initialized"
225}
226
8d394f98
AC
227if { ![string compare $struct_val \
228 [capture_value "intstruct" "file binfile"]] } then {
dd7dfd64
MS
229 fail "start with intstruct un-initialized"
230} else {
231 pass "start with intstruct un-initialized"
232}
233
234proc test_reload_saved_value { filename msg oldval newval } {
235 global gdb_prompt
236
237 gdb_file_cmd $filename
8d394f98
AC
238 if { ![string compare $oldval \
239 [capture_value $newval "$msg"]] } then {
240 pass "$msg; value restored ok"
dd7dfd64 241 } else {
8d394f98 242 fail "$msg; value restored ok"
dd7dfd64
MS
243 }
244}
245
246proc test_restore_saved_value { restore_args msg oldval newval } {
247 global gdb_prompt
248
249 gdb_test "restore $restore_args" \
8d394f98
AC
250 "Restoring .*" \
251 "$msg; file restored ok"
252 if { ![string compare $oldval \
253 [capture_value $newval "$msg"]] } then {
254 pass "$msg; value restored ok"
dd7dfd64 255 } else {
8d394f98 256 fail "$msg; value restored ok"
dd7dfd64
MS
257 }
258}
259
f31dfe3b
JJ
260# srec format can not be loaded for 64-bit-only platforms
261if ![string compare $is64bitonly "no"] then {
262 test_reload_saved_value "intarr1.srec" "reload array as value, srec" \
dd7dfd64 263 $array_val "intarray"
f31dfe3b 264 test_reload_saved_value "intstr1.srec" "reload struct as value, srec" \
dd7dfd64 265 $struct_val "intstruct"
f31dfe3b 266 test_reload_saved_value "intarr2.srec" "reload array as memory, srec" \
dd7dfd64 267 $array_val "intarray"
f31dfe3b 268 test_reload_saved_value "intstr2.srec" "reload struct as memory, srec" \
dd7dfd64 269 $struct_val "intstruct"
f31dfe3b
JJ
270}
271
272# ihex format can not be loaded for 64-bit-only platforms
273if ![string compare $is64bitonly "no"] then {
dd7dfd64 274
f31dfe3b 275 test_reload_saved_value "intarr1.ihex" "reload array as value, intel hex" \
dd7dfd64 276 $array_val "intarray"
f31dfe3b 277 test_reload_saved_value "intstr1.ihex" "reload struct as value, intel hex" \
dd7dfd64 278 $struct_val "intstruct"
f31dfe3b 279 test_reload_saved_value "intarr2.ihex" "reload array as memory, intel hex" \
dd7dfd64 280 $array_val "intarray"
f31dfe3b 281 test_reload_saved_value "intstr2.ihex" "reload struct as memory, intel hex" \
dd7dfd64 282 $struct_val "intstruct"
f31dfe3b 283}
dd7dfd64 284
f31dfe3b
JJ
285# tekhex format can not be loaded for 64-bit-only platforms
286if ![string compare $is64bitonly "no"] then {
287 test_reload_saved_value "intarr1.tekhex" "reload array as value, tekhex" \
dd7dfd64 288 $array_val "intarray"
f31dfe3b 289 test_reload_saved_value "intstr1.tekhex" "reload struct as value, tekhex" \
dd7dfd64 290 $struct_val "intstruct"
f31dfe3b 291 test_reload_saved_value "intarr2.tekhex" "reload array as memory, tekhex" \
dd7dfd64 292 $array_val "intarray"
f31dfe3b 293 test_reload_saved_value "intstr2.tekhex" "reload struct as memory, tekhex" \
dd7dfd64 294 $struct_val "intstruct"
f31dfe3b 295}
dd7dfd64
MS
296
297# Start a fresh gdb session
298
299gdb_exit
300gdb_start
301gdb_reinitialize_dir $srcdir/$subdir
302gdb_load ${binfile}
303
304# Run to main.
3ad13771 305if { ! [ runto_main ] } then {
b60f0898
JB
306 untested dump.exp
307 return -1
dd7dfd64
MS
308}
309
8d394f98
AC
310if { ![string compare $array_val \
311 [capture_value "intarray" "load binfile"]] } then {
dd7dfd64
MS
312 fail "start with intarray un-initialized, runto main"
313} else {
314 pass "start with intarray un-initialized, runto main"
315}
316
8d394f98
AC
317if { ![string compare $struct_val \
318 [capture_value "intstruct" "load binfile"]] } then {
dd7dfd64
MS
319 fail "start with intstruct un-initialized, runto main"
320} else {
321 pass "start with intstruct un-initialized, runto main"
322}
323
f31dfe3b
JJ
324if ![string compare $is64bitonly "no"] then {
325 test_restore_saved_value "intarr1.srec" "array as value, srec" \
dd7dfd64
MS
326 $array_val "intarray"
327
f31dfe3b 328 test_restore_saved_value "intstr1.srec" "struct as value, srec" \
dd7dfd64
MS
329 $struct_val "intstruct"
330
f31dfe3b 331 gdb_test "print zero_all ()" "void" "zero all"
dd7dfd64 332
f31dfe3b 333 test_restore_saved_value "intarr2.srec" "array as memory, srec" \
dd7dfd64
MS
334 $array_val "intarray"
335
f31dfe3b 336 test_restore_saved_value "intstr2.srec" "struct as memory, srec" \
dd7dfd64
MS
337 $struct_val "intstruct"
338
f31dfe3b 339 gdb_test "print zero_all ()" ""
dd7dfd64 340
f31dfe3b 341 test_restore_saved_value "intarr1.ihex" "array as value, ihex" \
dd7dfd64
MS
342 $array_val "intarray"
343
f31dfe3b 344 test_restore_saved_value "intstr1.ihex" "struct as value, ihex" \
dd7dfd64
MS
345 $struct_val "intstruct"
346
f31dfe3b 347 gdb_test "print zero_all ()" ""
dd7dfd64 348
f31dfe3b 349 test_restore_saved_value "intarr2.ihex" "array as memory, ihex" \
dd7dfd64
MS
350 $array_val "intarray"
351
f31dfe3b 352 test_restore_saved_value "intstr2.ihex" "struct as memory, ihex" \
dd7dfd64
MS
353 $struct_val "intstruct"
354
f31dfe3b 355 gdb_test "print zero_all ()" ""
dd7dfd64 356
f31dfe3b 357 test_restore_saved_value "intarr1.tekhex" "array as value, tekhex" \
dd7dfd64
MS
358 $array_val "intarray"
359
f31dfe3b 360 test_restore_saved_value "intstr1.tekhex" "struct as value, tekhex" \
dd7dfd64
MS
361 $struct_val "intstruct"
362
f31dfe3b 363 gdb_test "print zero_all ()" ""
dd7dfd64 364
f31dfe3b 365 test_restore_saved_value "intarr2.tekhex" "array as memory, tekhex" \
dd7dfd64
MS
366 $array_val "intarray"
367
f31dfe3b 368 test_restore_saved_value "intstr2.tekhex" "struct as memory, tekhex" \
dd7dfd64 369 $struct_val "intstruct"
f31dfe3b 370}
dd7dfd64
MS
371
372gdb_test "print zero_all ()" ""
373
374test_restore_saved_value "intarr1.bin binary $array_start" \
375 "array as value, binary" \
376 $array_val "intarray"
377
378test_restore_saved_value "intstr1.bin binary $struct_start" \
379 "struct as value, binary" \
380 $struct_val "intstruct"
381
382gdb_test "print zero_all ()" ""
383
384test_restore_saved_value "intarr2.bin binary $array_start" \
385 "array as memory, binary" \
386 $array_val "intarray"
387
388test_restore_saved_value "intstr2.bin binary $struct_start" \
389 "struct as memory, binary" \
390 $struct_val "intstruct"
391
392# test restore with offset.
393
394set array2_start [capture_value "/x &intarray2\[0\]"]
395set struct2_start [capture_value "/x &intstruct2"]
396set array2_offset \
2db536a1 397 [capture_value "(char *) &intarray2 - (char *) &intarray"]
dd7dfd64 398set struct2_offset \
2db536a1 399 [capture_value "(char *) &intstruct2 - (char *) &intstruct"]
dd7dfd64
MS
400
401gdb_test "print zero_all ()" ""
402
f31dfe3b
JJ
403
404if ![string compare $is64bitonly "no"] then {
405 test_restore_saved_value "intarr1.srec $array2_offset" \
dd7dfd64
MS
406 "array copy, srec" \
407 $array_val "intarray2"
408
f31dfe3b 409 test_restore_saved_value "intstr1.srec $struct2_offset" \
dd7dfd64
MS
410 "struct copy, srec" \
411 $struct_val "intstruct2"
412
f31dfe3b 413 gdb_test "print zero_all ()" ""
dd7dfd64 414
f31dfe3b 415 test_restore_saved_value "intarr1.ihex $array2_offset" \
dd7dfd64
MS
416 "array copy, ihex" \
417 $array_val "intarray2"
418
f31dfe3b 419 test_restore_saved_value "intstr1.ihex $struct2_offset" \
dd7dfd64
MS
420 "struct copy, ihex" \
421 $struct_val "intstruct2"
422
f31dfe3b 423 gdb_test "print zero_all ()" ""
dd7dfd64 424
f31dfe3b 425 test_restore_saved_value "intarr1.tekhex $array2_offset" \
dd7dfd64
MS
426 "array copy, tekhex" \
427 $array_val "intarray2"
428
f31dfe3b 429 test_restore_saved_value "intstr1.tekhex $struct2_offset" \
dd7dfd64
MS
430 "struct copy, tekhex" \
431 $struct_val "intstruct2"
f31dfe3b 432}
dd7dfd64
MS
433
434gdb_test "print zero_all ()" ""
435
436test_restore_saved_value "intarr1.bin binary $array2_start" \
437 "array copy, binary" \
438 $array_val "intarray2"
439
440test_restore_saved_value "intstr1.bin binary $struct2_start" \
441 "struct copy, binary" \
442 $struct_val "intstruct2"
443
444#
445# test restore with start/stop addresses.
446#
447# For this purpose, we will restore just the third element of the array,
448# and check to see that adjacent elements are not modified.
449#
450# We will need the address and offset of the third and fourth elements.
451#
452
453set element3_start [capture_value "/x &intarray\[3\]"]
454set element4_start [capture_value "/x &intarray\[4\]"]
455set element3_offset \
456 [capture_value "/x (char *) &intarray\[3\] - (char *) &intarray\[0\]"]
457set element4_offset \
458 [capture_value "/x (char *) &intarray\[4\] - (char *) &intarray\[0\]"]
459
f31dfe3b
JJ
460if ![string compare $is64bitonly "no"] then {
461 gdb_test "print zero_all ()" ""
dd7dfd64 462
f31dfe3b 463 test_restore_saved_value "intarr1.srec 0 $element3_start $element4_start" \
8d394f98 464 "array partial, srec" 4 "intarray\[3\]"
dd7dfd64 465
f31dfe3b
JJ
466 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 1"
467 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 1"
dd7dfd64 468
f31dfe3b 469 gdb_test "print zero_all ()" ""
dd7dfd64 470
f31dfe3b 471 test_restore_saved_value "intarr1.ihex 0 $element3_start $element4_start" \
8d394f98 472 "array partial, ihex" 4 "intarray\[3\]"
dd7dfd64 473
f31dfe3b
JJ
474 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 2"
475 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 2"
dd7dfd64 476
f31dfe3b 477 gdb_test "print zero_all ()" ""
dd7dfd64 478
f31dfe3b 479 test_restore_saved_value "intarr1.tekhex 0 $element3_start $element4_start" \
8d394f98 480 "array partial, tekhex" 4 "intarray\[3\]"
dd7dfd64 481
f31dfe3b
JJ
482 gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 3"
483 gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 3"
484}
dd7dfd64
MS
485
486gdb_test "print zero_all ()" ""
487
488test_restore_saved_value \
489 "intarr1.bin binary $array_start $element3_offset $element4_offset" \
8d394f98 490 "array partial, binary" 4 "intarray\[3\]"
dd7dfd64
MS
491
492gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 4"
493gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 4"
494
f31dfe3b
JJ
495if ![string compare $is64bitonly "no"] then {
496 gdb_test "print zero_all ()" "" ""
dd7dfd64 497
f31dfe3b
JJ
498 # restore with expressions
499 test_restore_saved_value \
dd7dfd64 500 "intarr3.srec ${array2_start}-${array_start} &intarray\[3\] &intarray\[4\]" \
8d394f98 501 "array partial with expressions" 4 "intarray2\[3\]"
dd7dfd64 502
f31dfe3b
JJ
503 gdb_test "print intarray2\[2\] == 0" " = 1" "element 2 not changed, == 4"
504 gdb_test "print intarray2\[4\] == 0" " = 1" "element 4 not changed, == 4"
505}
dd7dfd64
MS
506
507# clean up files
508
509remote_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"