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