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