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