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