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