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