dump.exp revision 1.5 1 1.3 christos # Copyright 2002-2015 Free Software Foundation, Inc.
2 1.1 christos
3 1.1 christos # This program is free software; you can redistribute it and/or modify
4 1.1 christos # it under the terms of the GNU General Public License as published by
5 1.1 christos # the Free Software Foundation; either version 3 of the License, or
6 1.1 christos # (at your option) any later version.
7 1.1 christos #
8 1.1 christos # This program is distributed in the hope that it will be useful,
9 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 1.1 christos # GNU General Public License for more details.
12 1.1 christos #
13 1.1 christos # You should have received a copy of the GNU General Public License
14 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 1.1 christos
16 1.1 christos # This file was written by Michael Snyder (msnyder (at) redhat.com)
17 1.1 christos # This is a test for the gdb command "dump".
18 1.1 christos
19 1.1 christos
20 1.1 christos standard_testfile
21 1.1 christos
22 1.1 christos set options {debug}
23 1.1 christos
24 1.1 christos set is64bitonly "no"
25 1.1 christos set endian "auto"
26 1.1 christos
27 1.1 christos if [istarget "alpha*-*-*"] then {
28 1.1 christos # SREC etc cannot handle 64-bit addresses. Force the test
29 1.1 christos # program into the low 31 bits of the address space.
30 1.1 christos lappend options "additional_flags=-Wl,-taso"
31 1.1 christos }
32 1.1 christos
33 1.1 christos if {[istarget "spu*-*-*"]} then {
34 1.1 christos # The internal address format used for the combined Cell/B.E.
35 1.1 christos # debugger requires 64-bit.
36 1.1 christos set is64bitonly "yes"
37 1.1 christos }
38 1.1 christos
39 1.1 christos if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable ${options}] != "" } {
40 1.1 christos untested dump.exp
41 1.1 christos return -1
42 1.1 christos }
43 1.1 christos
44 1.1 christos # Start with a fresh gdb.
45 1.1 christos
46 1.1 christos gdb_exit
47 1.1 christos gdb_start
48 1.1 christos gdb_reinitialize_dir $srcdir/$subdir
49 1.1 christos
50 1.1 christos gdb_test "dump mem /dev/null 0x10 0x20" "Cannot access memory at address 0x10" \
51 1.1 christos "inaccessible memory is reported"
52 1.1 christos
53 1.1 christos gdb_load ${binfile}
54 1.1 christos
55 1.1 christos # Check the address of a variable. If it is bigger than 32-bit,
56 1.1 christos # assume our target has 64-bit addresses that are not supported by SREC,
57 1.1 christos # IHEX and TEKHEX. We skip those tests then.
58 1.1 christos set max_32bit_address "0xffffffff"
59 1.1 christos set data_address [get_hexadecimal_valueof "&intarray" 0x100000000]
60 1.1 christos if {${data_address} > ${max_32bit_address}} then {
61 1.1 christos set is64bitonly "yes"
62 1.1 christos }
63 1.1 christos
64 1.1 christos # Clean up any stale output files from previous test runs
65 1.1 christos
66 1.1 christos set filenames {}
67 1.1 christos set all_files {
68 1.1 christos intarr1.bin intarr1b.bin intarr1.ihex
69 1.5 christos intarr1.srec intarr1.tekhex intarr1.verilog
70 1.5 christos intarr2.bin intarr2b.bin intarr2.ihex
71 1.5 christos intarr2.srec intarr2.tekhex intarr2.verilog
72 1.5 christos intstr1.bin intstr1b.bin intstr1.ihex
73 1.5 christos intstr1.srec intstr1.tekhex intstr1.verilog
74 1.5 christos intstr2.bin intstr2b.bin intstr2.ihex
75 1.5 christos intstr2.srec intstr2.tekhex intstr2.verilog
76 1.5 christos intarr3.srec
77 1.1 christos }
78 1.1 christos
79 1.1 christos # This loop sets variables dynamically -- each name listed in
80 1.1 christos # $ALL_FILES is both a file name and a variable name.
81 1.1 christos foreach file $all_files {
82 1.1 christos if {[is_remote host]} {
83 1.1 christos set this_name $file
84 1.1 christos } else {
85 1.1 christos set this_name [standard_output_file $file]
86 1.1 christos }
87 1.1 christos
88 1.1 christos lappend filenames [set ${file} $this_name]
89 1.1 christos }
90 1.1 christos
91 1.1 christos remote_exec host "rm -f $filenames"
92 1.1 christos
93 1.1 christos # Test help (FIXME:)
94 1.1 christos
95 1.1 christos # Run target program until data structs are initialized.
96 1.1 christos
97 1.1 christos if { ! [ runto checkpoint1 ] } then {
98 1.1 christos untested dump.exp
99 1.1 christos return -1
100 1.1 christos }
101 1.1 christos
102 1.1 christos # Get the endianness for the later use with endianless formats.
103 1.1 christos
104 1.1 christos gdb_test_multiple "show endian" "show endian" {
105 1.1 christos -re ".* (big|little) endian.*$gdb_prompt $" {
106 1.1 christos set endian $expect_out(1,string)
107 1.1 christos pass "endianness: $endian"
108 1.1 christos }
109 1.1 christos }
110 1.1 christos
111 1.1 christos # Now generate some dump files.
112 1.1 christos
113 1.1 christos proc make_dump_file { command msg } {
114 1.1 christos global gdb_prompt
115 1.1 christos
116 1.1 christos gdb_test_multiple "${command}" "$msg" {
117 1.1 christos -re ".*\[Ee\]rror.*$gdb_prompt $" { fail $msg }
118 1.1 christos -re ".*\[Ww\]arning.*$gdb_prompt $" { fail $msg }
119 1.1 christos -re ".*\[Uu\]ndefined .*$gdb_prompt $" { fail $msg }
120 1.1 christos -re ".*$gdb_prompt $" { pass $msg }
121 1.1 christos }
122 1.1 christos }
123 1.1 christos
124 1.1 christos make_dump_file "dump val [set intarr1.bin] intarray" \
125 1.1 christos "dump array as value, default"
126 1.1 christos
127 1.1 christos make_dump_file "dump val [set intstr1.bin] intstruct" \
128 1.1 christos "dump struct as value, default"
129 1.1 christos
130 1.1 christos make_dump_file "dump bin val [set intarr1b.bin] intarray" \
131 1.1 christos "dump array as value, binary"
132 1.1 christos
133 1.1 christos make_dump_file "dump bin val [set intstr1b.bin] intstruct" \
134 1.1 christos "dump struct as value, binary"
135 1.1 christos
136 1.1 christos make_dump_file "dump srec val [set intarr1.srec] intarray" \
137 1.1 christos "dump array as value, srec"
138 1.1 christos
139 1.1 christos make_dump_file "dump srec val [set intstr1.srec] intstruct" \
140 1.1 christos "dump struct as value, srec"
141 1.1 christos
142 1.1 christos make_dump_file "dump ihex val [set intarr1.ihex] intarray" \
143 1.1 christos "dump array as value, intel hex"
144 1.1 christos
145 1.1 christos make_dump_file "dump ihex val [set intstr1.ihex] intstruct" \
146 1.1 christos "dump struct as value, intel hex"
147 1.1 christos
148 1.1 christos make_dump_file "dump tekhex val [set intarr1.tekhex] intarray" \
149 1.1 christos "dump array as value, tekhex"
150 1.1 christos
151 1.1 christos make_dump_file "dump tekhex val [set intstr1.tekhex] intstruct" \
152 1.1 christos "dump struct as value, tekhex"
153 1.1 christos
154 1.5 christos make_dump_file "dump verilog val [set intarr1.verilog] intarray" \
155 1.5 christos "dump array as value, intel hex"
156 1.5 christos
157 1.5 christos make_dump_file "dump verilog val [set intstr1.verilog] intstruct" \
158 1.5 christos "dump struct as value, intel hex"
159 1.5 christos
160 1.1 christos proc capture_value { expression args } {
161 1.1 christos global gdb_prompt
162 1.1 christos global expect_out
163 1.1 christos
164 1.1 christos set output_string ""
165 1.1 christos if {[llength $args] > 0} {
166 1.1 christos # Convert $args into a simple string and don't use EXPRESSION
167 1.1 christos # in the test name.
168 1.1 christos set test "[join $args]; capture"
169 1.1 christos } {
170 1.1 christos set test "capture $expression"
171 1.1 christos }
172 1.1 christos gdb_test_multiple "print ${expression}" "$test" {
173 1.1 christos -re "\\$\[0-9\]+ = (\[^\r\n\]+).*$gdb_prompt $" {
174 1.1 christos set output_string "$expect_out(1,string)"
175 1.1 christos pass "$test"
176 1.1 christos }
177 1.1 christos -re "(Cannot access memory at address \[^\r\n\]+).*$gdb_prompt $" {
178 1.1 christos # Even a failed value is valid
179 1.1 christos set output_string "$expect_out(1,string)"
180 1.1 christos pass "$test"
181 1.1 christos }
182 1.1 christos }
183 1.1 christos return $output_string
184 1.1 christos }
185 1.1 christos
186 1.1 christos # POINTER is a pointer and this proc captures the value of POINTER along
187 1.1 christos # with POINTER's type. For example, POINTER is "&intarray", this proc will
188 1.1 christos # call "p &intarray", capture "(int (*)[32]) 0x804a0e0", and return this
189 1.1 christos # string.
190 1.1 christos
191 1.1 christos proc capture_pointer_with_type { pointer } {
192 1.1 christos global gdb_prompt
193 1.1 christos global expect_out
194 1.1 christos
195 1.1 christos set test "capture type of pointer $pointer"
196 1.1 christos set output_string ""
197 1.1 christos gdb_test_multiple "p ${pointer}" $test {
198 1.1 christos -re "\\$\[0-9\]+ = .*$gdb_prompt $" {
199 1.1 christos # Expected output of "p ${pointer}" is like "$7 = (int (*)[32]) 0x804a0e0",
200 1.1 christos # and we want to extract "(int (*)[32]) 0x804a0e0" from it via
201 1.1 christos # following regexp.
202 1.1 christos if [regexp " \\(.*\\).* 0x\[0-9a-fA-F\]+" $expect_out(0,string) output_string] {
203 1.1 christos # OUTPUT_STRING is expected to be like "(int (*)[32]) 0x804a0e0".
204 1.1 christos pass "$test"
205 1.1 christos } else {
206 1.1 christos fail "$test"
207 1.1 christos }
208 1.1 christos }
209 1.1 christos }
210 1.1 christos
211 1.1 christos return $output_string
212 1.1 christos }
213 1.1 christos
214 1.1 christos set array_start [capture_value "/x &intarray\[0\]"]
215 1.1 christos set array_end [capture_value "/x &intarray\[32\]"]
216 1.1 christos set struct_start [capture_value "/x &intstruct"]
217 1.1 christos set struct_end [capture_value "/x &intstruct + 1"]
218 1.1 christos
219 1.1 christos set array_val [capture_value "intarray"]
220 1.1 christos set struct_val [capture_value "intstruct"]
221 1.1 christos
222 1.1 christos set array_ptr_type [capture_pointer_with_type "&intarray"]
223 1.1 christos set struct_ptr_type [capture_pointer_with_type "&intstruct"]
224 1.1 christos
225 1.1 christos make_dump_file "dump mem [set intarr2.bin] $array_start $array_end" \
226 1.1 christos "dump array as memory, default"
227 1.1 christos
228 1.1 christos make_dump_file "dump mem [set intstr2.bin] $struct_start $struct_end" \
229 1.1 christos "dump struct as memory, default"
230 1.1 christos
231 1.1 christos make_dump_file "dump bin mem [set intarr2b.bin] $array_start $array_end" \
232 1.1 christos "dump array as memory, binary"
233 1.1 christos
234 1.1 christos make_dump_file "dump bin mem [set intstr2b.bin] $struct_start $struct_end" \
235 1.1 christos "dump struct as memory, binary"
236 1.1 christos
237 1.1 christos make_dump_file "dump srec mem [set intarr2.srec] $array_start $array_end" \
238 1.1 christos "dump array as memory, srec"
239 1.1 christos
240 1.1 christos make_dump_file "dump srec mem [set intstr2.srec] $struct_start $struct_end" \
241 1.1 christos "dump struct as memory, srec"
242 1.1 christos
243 1.1 christos make_dump_file "dump ihex mem [set intarr2.ihex] $array_start $array_end" \
244 1.1 christos "dump array as memory, ihex"
245 1.1 christos
246 1.1 christos make_dump_file "dump ihex mem [set intstr2.ihex] $struct_start $struct_end" \
247 1.1 christos "dump struct as memory, ihex"
248 1.1 christos
249 1.1 christos make_dump_file "dump tekhex mem [set intarr2.tekhex] $array_start $array_end" \
250 1.1 christos "dump array as memory, tekhex"
251 1.1 christos
252 1.1 christos make_dump_file "dump tekhex mem [set intstr2.tekhex] $struct_start $struct_end" \
253 1.1 christos "dump struct as memory, tekhex"
254 1.1 christos
255 1.5 christos make_dump_file "dump verilog mem [set intarr2.verilog] $array_start $array_end" \
256 1.5 christos "dump array as memory, verilog"
257 1.5 christos
258 1.5 christos make_dump_file "dump verilog mem [set intstr2.verilog] $struct_start $struct_end" \
259 1.5 christos "dump struct as memory, verilog"
260 1.5 christos
261 1.1 christos # test complex expressions
262 1.1 christos make_dump_file \
263 1.1 christos "dump srec mem [set intarr3.srec] &intarray \(char *\) &intarray + sizeof intarray" \
264 1.1 christos "dump array as mem, srec, expressions"
265 1.1 christos
266 1.1 christos proc test_restore_saved_value { restore_args msg oldval newval } {
267 1.1 christos global gdb_prompt
268 1.1 christos
269 1.1 christos gdb_test "restore $restore_args" \
270 1.1 christos "Restoring .*" \
271 1.1 christos "$msg; file restored ok"
272 1.1 christos if { ![string compare $oldval \
273 1.1 christos [capture_value $newval "$msg"]] } then {
274 1.1 christos pass "$msg; value restored ok"
275 1.1 christos } else {
276 1.1 christos fail "$msg; value restored ok"
277 1.1 christos }
278 1.1 christos }
279 1.1 christos
280 1.1 christos if ![string compare $is64bitonly "no"] then {
281 1.1 christos
282 1.1 christos gdb_test "print zero_all ()" ".*"
283 1.1 christos
284 1.1 christos test_restore_saved_value "[set intarr1.srec]" "array as value, srec" \
285 1.1 christos $array_val "intarray"
286 1.1 christos
287 1.1 christos test_restore_saved_value "[set intstr1.srec]" "struct as value, srec" \
288 1.1 christos $struct_val "intstruct"
289 1.1 christos
290 1.1 christos gdb_test "print zero_all ()" "void" "zero all"
291 1.1 christos
292 1.1 christos test_restore_saved_value "[set intarr2.srec]" "array as memory, srec" \
293 1.1 christos $array_val "intarray"
294 1.1 christos
295 1.1 christos test_restore_saved_value "[set intstr2.srec]" "struct as memory, srec" \
296 1.1 christos $struct_val "intstruct"
297 1.1 christos
298 1.1 christos gdb_test "print zero_all ()" ".*"
299 1.1 christos
300 1.1 christos test_restore_saved_value "[set intarr1.ihex]" "array as value, ihex" \
301 1.1 christos $array_val "intarray"
302 1.1 christos
303 1.1 christos test_restore_saved_value "[set intstr1.ihex]" "struct as value, ihex" \
304 1.1 christos $struct_val "intstruct"
305 1.1 christos
306 1.1 christos gdb_test "print zero_all ()" ".*"
307 1.1 christos
308 1.1 christos test_restore_saved_value "[set intarr2.ihex]" "array as memory, ihex" \
309 1.1 christos $array_val "intarray"
310 1.1 christos
311 1.1 christos test_restore_saved_value "[set intstr2.ihex]" "struct as memory, ihex" \
312 1.1 christos $struct_val "intstruct"
313 1.1 christos
314 1.1 christos gdb_test "print zero_all ()" ".*"
315 1.1 christos
316 1.1 christos test_restore_saved_value "[set intarr1.tekhex]" "array as value, tekhex" \
317 1.1 christos $array_val "intarray"
318 1.1 christos
319 1.1 christos test_restore_saved_value "[set intstr1.tekhex]" "struct as value, tekhex" \
320 1.1 christos $struct_val "intstruct"
321 1.1 christos
322 1.1 christos gdb_test "print zero_all ()" ".*"
323 1.1 christos
324 1.1 christos test_restore_saved_value "[set intarr2.tekhex]" "array as memory, tekhex" \
325 1.1 christos $array_val "intarray"
326 1.1 christos
327 1.1 christos test_restore_saved_value "[set intstr2.tekhex]" "struct as memory, tekhex" \
328 1.1 christos $struct_val "intstruct"
329 1.1 christos }
330 1.1 christos
331 1.1 christos gdb_test "print zero_all ()" ".*"
332 1.1 christos
333 1.1 christos test_restore_saved_value "[set intarr1.bin] binary $array_start" \
334 1.1 christos "array as value, binary" \
335 1.1 christos $array_val "intarray"
336 1.1 christos
337 1.1 christos test_restore_saved_value "[set intstr1.bin] binary $struct_start" \
338 1.1 christos "struct as value, binary" \
339 1.1 christos $struct_val "intstruct"
340 1.1 christos
341 1.1 christos gdb_test "print zero_all ()" ".*"
342 1.1 christos
343 1.1 christos test_restore_saved_value "[set intarr2.bin] binary $array_start" \
344 1.1 christos "array as memory, binary" \
345 1.1 christos $array_val "intarray"
346 1.1 christos
347 1.1 christos test_restore_saved_value "[set intstr2.bin] binary $struct_start" \
348 1.1 christos "struct as memory, binary" \
349 1.1 christos $struct_val "intstruct"
350 1.1 christos
351 1.1 christos # test restore with offset.
352 1.1 christos
353 1.1 christos set array2_start [capture_value "/x &intarray2\[0\]"]
354 1.1 christos set struct2_start [capture_value "/x &intstruct2"]
355 1.1 christos set array2_offset \
356 1.1 christos [capture_value "(char *) &intarray2 - (char *) &intarray"]
357 1.1 christos set struct2_offset \
358 1.1 christos [capture_value "(char *) &intstruct2 - (char *) &intstruct"]
359 1.1 christos
360 1.1 christos gdb_test "print zero_all ()" ".*"
361 1.1 christos
362 1.1 christos
363 1.1 christos if ![string compare $is64bitonly "no"] then {
364 1.1 christos test_restore_saved_value "[set intarr1.srec] $array2_offset" \
365 1.1 christos "array copy, srec" \
366 1.1 christos $array_val "intarray2"
367 1.1 christos
368 1.1 christos test_restore_saved_value "[set intstr1.srec] $struct2_offset" \
369 1.1 christos "struct copy, srec" \
370 1.1 christos $struct_val "intstruct2"
371 1.1 christos
372 1.1 christos gdb_test "print zero_all ()" ".*"
373 1.1 christos
374 1.1 christos test_restore_saved_value "[set intarr1.ihex] $array2_offset" \
375 1.1 christos "array copy, ihex" \
376 1.1 christos $array_val "intarray2"
377 1.1 christos
378 1.1 christos test_restore_saved_value "[set intstr1.ihex] $struct2_offset" \
379 1.1 christos "struct copy, ihex" \
380 1.1 christos $struct_val "intstruct2"
381 1.1 christos
382 1.1 christos gdb_test "print zero_all ()" ".*"
383 1.1 christos
384 1.1 christos test_restore_saved_value "[set intarr1.tekhex] $array2_offset" \
385 1.1 christos "array copy, tekhex" \
386 1.1 christos $array_val "intarray2"
387 1.1 christos
388 1.1 christos test_restore_saved_value "[set intstr1.tekhex] $struct2_offset" \
389 1.1 christos "struct copy, tekhex" \
390 1.1 christos $struct_val "intstruct2"
391 1.1 christos }
392 1.1 christos
393 1.1 christos gdb_test "print zero_all ()" ".*"
394 1.1 christos
395 1.1 christos test_restore_saved_value "[set intarr1.bin] binary $array2_start" \
396 1.1 christos "array copy, binary" \
397 1.1 christos $array_val "intarray2"
398 1.1 christos
399 1.1 christos test_restore_saved_value "[set intstr1.bin] binary $struct2_start" \
400 1.1 christos "struct copy, binary" \
401 1.1 christos $struct_val "intstruct2"
402 1.1 christos
403 1.1 christos #
404 1.1 christos # test restore with start/stop addresses.
405 1.1 christos #
406 1.1 christos # For this purpose, we will restore just the third element of the array,
407 1.1 christos # and check to see that adjacent elements are not modified.
408 1.1 christos #
409 1.1 christos # We will need the address and offset of the third and fourth elements.
410 1.1 christos #
411 1.1 christos
412 1.1 christos set element3_start [capture_value "/x &intarray\[3\]"]
413 1.1 christos set element4_start [capture_value "/x &intarray\[4\]"]
414 1.1 christos set element3_offset \
415 1.1 christos [capture_value "/x (char *) &intarray\[3\] - (char *) &intarray\[0\]"]
416 1.1 christos set element4_offset \
417 1.1 christos [capture_value "/x (char *) &intarray\[4\] - (char *) &intarray\[0\]"]
418 1.1 christos
419 1.1 christos if ![string compare $is64bitonly "no"] then {
420 1.1 christos gdb_test "print zero_all ()" ".*"
421 1.1 christos
422 1.1 christos test_restore_saved_value "[set intarr1.srec] 0 $element3_start $element4_start" \
423 1.1 christos "array partial, srec" 4 "intarray\[3\]"
424 1.1 christos
425 1.1 christos gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 1"
426 1.1 christos gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 1"
427 1.1 christos
428 1.1 christos gdb_test "print zero_all ()" ".*"
429 1.1 christos
430 1.1 christos test_restore_saved_value "[set intarr1.ihex] 0 $element3_start $element4_start" \
431 1.1 christos "array partial, ihex" 4 "intarray\[3\]"
432 1.1 christos
433 1.1 christos gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 2"
434 1.1 christos gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 2"
435 1.1 christos
436 1.1 christos gdb_test "print zero_all ()" ".*"
437 1.1 christos
438 1.1 christos test_restore_saved_value "[set intarr1.tekhex] 0 $element3_start $element4_start" \
439 1.1 christos "array partial, tekhex" 4 "intarray\[3\]"
440 1.1 christos
441 1.1 christos gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 3"
442 1.1 christos gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 3"
443 1.1 christos }
444 1.1 christos
445 1.1 christos gdb_test "print zero_all ()" ".*"
446 1.1 christos
447 1.1 christos test_restore_saved_value \
448 1.1 christos "[set intarr1.bin] binary $array_start $element3_offset $element4_offset" \
449 1.1 christos "array partial, binary" 4 "intarray\[3\]"
450 1.1 christos
451 1.1 christos gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 4"
452 1.1 christos gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 4"
453 1.1 christos
454 1.1 christos if ![string compare $is64bitonly "no"] then {
455 1.1 christos gdb_test "print zero_all ()" ".*" ""
456 1.1 christos
457 1.1 christos # restore with expressions
458 1.1 christos test_restore_saved_value \
459 1.1 christos "[set intarr3.srec] (char*)${array2_start}-(char*)${array_start} &intarray\[3\] &intarray\[4\]" \
460 1.1 christos "array partial with expressions" 4 "intarray2\[3\]"
461 1.1 christos
462 1.1 christos gdb_test "print intarray2\[2\] == 0" " = 1" "element 2 not changed, == 4"
463 1.1 christos gdb_test "print intarray2\[4\] == 0" " = 1" "element 4 not changed, == 4"
464 1.1 christos }
465 1.1 christos
466 1.1 christos
467 1.1 christos # Now start a fresh gdb session, and reload the saved value files.
468 1.1 christos
469 1.1 christos gdb_exit
470 1.1 christos gdb_start
471 1.1 christos gdb_file_cmd ${binfile}
472 1.1 christos
473 1.1 christos # Now fix the endianness at the correct state.
474 1.1 christos
475 1.1 christos gdb_test_multiple "set endian $endian" "set endianness" {
476 1.1 christos -re ".* (big|little) endian.*$gdb_prompt $" {
477 1.1 christos pass "setting $endian endianness"
478 1.1 christos }
479 1.1 christos }
480 1.1 christos
481 1.1 christos # Reload saved values one by one, and compare.
482 1.1 christos
483 1.1 christos if { ![string compare $array_val \
484 1.1 christos [capture_value "intarray" "file binfile; intarray"]] } then {
485 1.1 christos fail "start with intarray un-initialized"
486 1.1 christos } else {
487 1.1 christos pass "start with intarray un-initialized"
488 1.1 christos }
489 1.1 christos
490 1.1 christos if { ![string compare $struct_val \
491 1.1 christos [capture_value "intstruct" "file binfile; intstruct"]] } then {
492 1.1 christos fail "start with intstruct un-initialized"
493 1.1 christos } else {
494 1.1 christos pass "start with intstruct un-initialized"
495 1.1 christos }
496 1.1 christos
497 1.1 christos proc test_reload_saved_value { filename msg oldval newval } {
498 1.1 christos global gdb_prompt
499 1.1 christos
500 1.1 christos gdb_file_cmd $filename
501 1.1 christos if { ![string compare $oldval \
502 1.1 christos [capture_value $newval "$msg"]] } then {
503 1.1 christos pass "$msg; value restored ok"
504 1.1 christos } else {
505 1.1 christos fail "$msg; value restored ok"
506 1.1 christos }
507 1.1 christos }
508 1.1 christos
509 1.1 christos # srec format can not be loaded for 64-bit-only platforms
510 1.1 christos if ![string compare $is64bitonly "no"] then {
511 1.1 christos test_reload_saved_value "[set intarr1.srec]" "reload array as value, srec" \
512 1.1 christos $array_val "\*$array_ptr_type"
513 1.1 christos test_reload_saved_value "[set intstr1.srec]" "reload struct as value, srec" \
514 1.1 christos $struct_val "\*$struct_ptr_type"
515 1.1 christos test_reload_saved_value "[set intarr2.srec]" "reload array as memory, srec" \
516 1.1 christos $array_val "\*$array_ptr_type"
517 1.1 christos test_reload_saved_value "[set intstr2.srec]" "reload struct as memory, srec" \
518 1.1 christos $struct_val "\*$struct_ptr_type"
519 1.1 christos }
520 1.1 christos
521 1.1 christos # ihex format can not be loaded for 64-bit-only platforms
522 1.1 christos if ![string compare $is64bitonly "no"] then {
523 1.1 christos
524 1.1 christos test_reload_saved_value "[set intarr1.ihex]" \
525 1.1 christos "reload array as value, intel hex" \
526 1.1 christos $array_val "\*$array_ptr_type"
527 1.1 christos test_reload_saved_value "[set intstr1.ihex]" \
528 1.1 christos "reload struct as value, intel hex" \
529 1.1 christos $struct_val "\*$struct_ptr_type"
530 1.1 christos test_reload_saved_value "[set intarr2.ihex]" \
531 1.1 christos "reload array as memory, intel hex" \
532 1.1 christos $array_val "\*$array_ptr_type"
533 1.1 christos test_reload_saved_value "[set intstr2.ihex]" \
534 1.1 christos "reload struct as memory, intel hex" \
535 1.1 christos $struct_val "\*$struct_ptr_type"
536 1.1 christos }
537 1.1 christos
538 1.1 christos # tekhex format can not be loaded for 64-bit-only platforms
539 1.1 christos if ![string compare $is64bitonly "no"] then {
540 1.1 christos test_reload_saved_value "[set intarr1.tekhex]" \
541 1.1 christos "reload array as value, tekhex" \
542 1.1 christos $array_val "\*$array_ptr_type"
543 1.1 christos test_reload_saved_value "[set intstr1.tekhex]" \
544 1.1 christos "reload struct as value, tekhex" \
545 1.1 christos $struct_val "\*$struct_ptr_type"
546 1.1 christos test_reload_saved_value "[set intarr2.tekhex]" \
547 1.1 christos "reload array as memory, tekhex" \
548 1.1 christos $array_val "\*$array_ptr_type"
549 1.1 christos test_reload_saved_value "[set intstr2.tekhex]" \
550 1.1 christos "reload struct as memory, tekhex" \
551 1.1 christos $struct_val "\*$struct_ptr_type"
552 1.1 christos }
553 1.1 christos
554 1.1 christos # clean up files
555 1.1 christos
556 1.1 christos remote_exec host "rm -f $filenames"
557