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