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