-# Copyright 2002 Free Software Foundation, Inc.
+# Copyright 2002, 2004, 2007 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
set srcfile ${testfile}.c
set binfile ${objdir}/${subdir}/${testfile}
+set options {debug}
-if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
- gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+set is64bitonly "no"
+set endian "auto"
+
+if [istarget "alpha*-*-*"] then {
+ # SREC etc cannot handle 64-bit addresses. Force the test
+ # program into the low 31 bits of the address space.
+ lappend options "additional_flags=-Wl,-taso"
+}
+
+if {[istarget "ia64*-*-*"] || [istarget "hppa64-*-*"]} then {
+ set is64bitonly "yes"
+}
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable ${options}] != "" } {
+ untested dump.exp
+ return -1
}
# Start with a fresh gdb.
# Run target program until data structs are initialized.
if { ! [ runto checkpoint1 ] } then {
- gdb_suppress_entire_file "Program failed to run, so all tests in this file will automatically fail."
+ untested dump.exp
+ return -1
+}
+
+# Get the endianness for the later use with endianless formats.
+
+send_gdb "show endian\n"
+gdb_expect {
+ -re ".* (big|little) endian.*$gdb_prompt $" {
+ set endian $expect_out(1,string)
+ pass "endianness: $endian"
+ }
+ default {
+ fail "(timeout) getting target endianness"
+ }
}
# Now generate some dump files.
make_dump_file "dump tekhex val intstr1.tekhex intstruct" \
"dump struct as value, tekhex"
-proc capture_value { expression } {
+proc capture_value { expression args } {
global gdb_prompt
global expect_out
set output_string ""
- send_gdb "print ${expression}\n"
- gdb_expect {
- -re ".*\[\r\n\]+.\[0123456789\]+ = (\[^\r\n\]+).*$gdb_prompt $" {
- set output_string $expect_out(1,string)
+ if {[llength $args] > 0} {
+ # Convert $args into a simple string.
+ set test "[join $args]; capture $expression"
+ } {
+ set test "capture $expression"
+ }
+ gdb_test_multiple "print ${expression}" "$test" {
+ -re "\\$\[0-9\]+ = (\[^\r\n\]+).*$gdb_prompt $" {
+ set output_string "$expect_out(1,string)"
+ pass "$test"
}
- default {
- fail "capture_value failed on $expression."
+ -re "(Cannot access memory at address \[^\r\n\]+).*$gdb_prompt $" {
+ # Even a failed value is valid
+ set output_string "$expect_out(1,string)"
+ pass "$test"
}
}
return $output_string
gdb_start
gdb_file_cmd ${binfile}
+# Now fix the endianness at the correct state.
+
+send_gdb "set endian $endian\n"
+gdb_expect {
+ -re ".* (big|little) endian.*$gdb_prompt $" {
+ pass "setting $endian endianness"
+ }
+ default {
+ fail "(timeout) setting $endian endianness"
+ }
+}
+
# Reload saved values one by one, and compare.
-if { ![string compare $array_val [capture_value "intarray"]] } then {
+if { ![string compare $array_val \
+ [capture_value "intarray" "file binfile"]] } then {
fail "start with intarray un-initialized"
} else {
pass "start with intarray un-initialized"
}
-if { ![string compare $struct_val [capture_value "intstruct"]] } then {
+if { ![string compare $struct_val \
+ [capture_value "intstruct" "file binfile"]] } then {
fail "start with intstruct un-initialized"
} else {
pass "start with intstruct un-initialized"
global gdb_prompt
gdb_file_cmd $filename
- if { ![string compare $oldval [capture_value $newval]] } then {
- pass $msg
+ if { ![string compare $oldval \
+ [capture_value $newval "$msg"]] } then {
+ pass "$msg; value restored ok"
} else {
- fail $msg
+ fail "$msg; value restored ok"
}
}
global gdb_prompt
gdb_test "restore $restore_args" \
- "Restoring .*" \
- "Restore command, $msg"
-
- if { ![string compare $oldval [capture_value $newval]] } then {
- pass "Restored value, $msg"
+ "Restoring .*" \
+ "$msg; file restored ok"
+ if { ![string compare $oldval \
+ [capture_value $newval "$msg"]] } then {
+ pass "$msg; value restored ok"
} else {
- fail "Restored value, $msg"
+ fail "$msg; value restored ok"
}
}
-test_reload_saved_value "intarr1.srec" "reload array as value, srec" \
+# srec format can not be loaded for 64-bit-only platforms
+if ![string compare $is64bitonly "no"] then {
+ test_reload_saved_value "intarr1.srec" "reload array as value, srec" \
$array_val "intarray"
-test_reload_saved_value "intstr1.srec" "reload struct as value, srec" \
+ test_reload_saved_value "intstr1.srec" "reload struct as value, srec" \
$struct_val "intstruct"
-test_reload_saved_value "intarr2.srec" "reload array as memory, srec" \
+ test_reload_saved_value "intarr2.srec" "reload array as memory, srec" \
$array_val "intarray"
-test_reload_saved_value "intstr2.srec" "reload struct as memory, srec" \
+ test_reload_saved_value "intstr2.srec" "reload struct as memory, srec" \
$struct_val "intstruct"
+}
+
+# ihex format can not be loaded for 64-bit-only platforms
+if ![string compare $is64bitonly "no"] then {
-test_reload_saved_value "intarr1.ihex" "reload array as value, intel hex" \
+ test_reload_saved_value "intarr1.ihex" "reload array as value, intel hex" \
$array_val "intarray"
-test_reload_saved_value "intstr1.ihex" "reload struct as value, intel hex" \
+ test_reload_saved_value "intstr1.ihex" "reload struct as value, intel hex" \
$struct_val "intstruct"
-test_reload_saved_value "intarr2.ihex" "reload array as memory, intel hex" \
+ test_reload_saved_value "intarr2.ihex" "reload array as memory, intel hex" \
$array_val "intarray"
-test_reload_saved_value "intstr2.ihex" "reload struct as memory, intel hex" \
+ test_reload_saved_value "intstr2.ihex" "reload struct as memory, intel hex" \
$struct_val "intstruct"
+}
-test_reload_saved_value "intarr1.tekhex" "reload array as value, tekhex" \
+# tekhex format can not be loaded for 64-bit-only platforms
+if ![string compare $is64bitonly "no"] then {
+ test_reload_saved_value "intarr1.tekhex" "reload array as value, tekhex" \
$array_val "intarray"
-test_reload_saved_value "intstr1.tekhex" "reload struct as value, tekhex" \
+ test_reload_saved_value "intstr1.tekhex" "reload struct as value, tekhex" \
$struct_val "intstruct"
-test_reload_saved_value "intarr2.tekhex" "reload array as memory, tekhex" \
+ test_reload_saved_value "intarr2.tekhex" "reload array as memory, tekhex" \
$array_val "intarray"
-test_reload_saved_value "intstr2.tekhex" "reload struct as memory, tekhex" \
+ test_reload_saved_value "intstr2.tekhex" "reload struct as memory, tekhex" \
$struct_val "intstruct"
+}
# Start a fresh gdb session
gdb_load ${binfile}
# Run to main.
-if { ! [ runto main ] } then {
- gdb_suppress_entire_file "Program failed to run, so remaining tests in this file will automatically fail."
+if { ! [ runto_main ] } then {
+ untested dump.exp
+ return -1
}
-if { ![string compare $array_val [capture_value "intarray"]] } then {
+if { ![string compare $array_val \
+ [capture_value "intarray" "load binfile"]] } then {
fail "start with intarray un-initialized, runto main"
} else {
pass "start with intarray un-initialized, runto main"
}
-if { ![string compare $struct_val [capture_value "intstruct"]] } then {
+if { ![string compare $struct_val \
+ [capture_value "intstruct" "load binfile"]] } then {
fail "start with intstruct un-initialized, runto main"
} else {
pass "start with intstruct un-initialized, runto main"
}
-test_restore_saved_value "intarr1.srec" "array as value, srec" \
+if ![string compare $is64bitonly "no"] then {
+ test_restore_saved_value "intarr1.srec" "array as value, srec" \
$array_val "intarray"
-test_restore_saved_value "intstr1.srec" "struct as value, srec" \
+ test_restore_saved_value "intstr1.srec" "struct as value, srec" \
$struct_val "intstruct"
-gdb_test "print zero_all ()" "void" "zero all"
+ gdb_test "print zero_all ()" "void" "zero all"
-test_restore_saved_value "intarr2.srec" "array as memory, srec" \
+ test_restore_saved_value "intarr2.srec" "array as memory, srec" \
$array_val "intarray"
-test_restore_saved_value "intstr2.srec" "struct as memory, srec" \
+ test_restore_saved_value "intstr2.srec" "struct as memory, srec" \
$struct_val "intstruct"
-gdb_test "print zero_all ()" ""
+ gdb_test "print zero_all ()" ""
-test_restore_saved_value "intarr1.ihex" "array as value, ihex" \
+ test_restore_saved_value "intarr1.ihex" "array as value, ihex" \
$array_val "intarray"
-test_restore_saved_value "intstr1.ihex" "struct as value, ihex" \
+ test_restore_saved_value "intstr1.ihex" "struct as value, ihex" \
$struct_val "intstruct"
-gdb_test "print zero_all ()" ""
+ gdb_test "print zero_all ()" ""
-test_restore_saved_value "intarr2.ihex" "array as memory, ihex" \
+ test_restore_saved_value "intarr2.ihex" "array as memory, ihex" \
$array_val "intarray"
-test_restore_saved_value "intstr2.ihex" "struct as memory, ihex" \
+ test_restore_saved_value "intstr2.ihex" "struct as memory, ihex" \
$struct_val "intstruct"
-gdb_test "print zero_all ()" ""
+ gdb_test "print zero_all ()" ""
-test_restore_saved_value "intarr1.tekhex" "array as value, tekhex" \
+ test_restore_saved_value "intarr1.tekhex" "array as value, tekhex" \
$array_val "intarray"
-test_restore_saved_value "intstr1.tekhex" "struct as value, tekhex" \
+ test_restore_saved_value "intstr1.tekhex" "struct as value, tekhex" \
$struct_val "intstruct"
-gdb_test "print zero_all ()" ""
+ gdb_test "print zero_all ()" ""
-test_restore_saved_value "intarr2.tekhex" "array as memory, tekhex" \
+ test_restore_saved_value "intarr2.tekhex" "array as memory, tekhex" \
$array_val "intarray"
-test_restore_saved_value "intstr2.tekhex" "struct as memory, tekhex" \
+ test_restore_saved_value "intstr2.tekhex" "struct as memory, tekhex" \
$struct_val "intstruct"
+}
gdb_test "print zero_all ()" ""
set array2_start [capture_value "/x &intarray2\[0\]"]
set struct2_start [capture_value "/x &intstruct2"]
set array2_offset \
- [capture_value "/x (char *) &intarray2 - (char *) &intarray"]
+ [capture_value "(char *) &intarray2 - (char *) &intarray"]
set struct2_offset \
- [capture_value "/x (char *) &intstruct2 - (char *) &intstruct"]
+ [capture_value "(char *) &intstruct2 - (char *) &intstruct"]
gdb_test "print zero_all ()" ""
-test_restore_saved_value "intarr1.srec $array2_offset" \
+
+if ![string compare $is64bitonly "no"] then {
+ test_restore_saved_value "intarr1.srec $array2_offset" \
"array copy, srec" \
$array_val "intarray2"
-test_restore_saved_value "intstr1.srec $struct2_offset" \
+ test_restore_saved_value "intstr1.srec $struct2_offset" \
"struct copy, srec" \
$struct_val "intstruct2"
-gdb_test "print zero_all ()" ""
+ gdb_test "print zero_all ()" ""
-test_restore_saved_value "intarr1.ihex $array2_offset" \
+ test_restore_saved_value "intarr1.ihex $array2_offset" \
"array copy, ihex" \
$array_val "intarray2"
-test_restore_saved_value "intstr1.ihex $struct2_offset" \
+ test_restore_saved_value "intstr1.ihex $struct2_offset" \
"struct copy, ihex" \
$struct_val "intstruct2"
-gdb_test "print zero_all ()" ""
+ gdb_test "print zero_all ()" ""
-test_restore_saved_value "intarr1.tekhex $array2_offset" \
+ test_restore_saved_value "intarr1.tekhex $array2_offset" \
"array copy, tekhex" \
$array_val "intarray2"
-test_restore_saved_value "intstr1.tekhex $struct2_offset" \
+ test_restore_saved_value "intstr1.tekhex $struct2_offset" \
"struct copy, tekhex" \
$struct_val "intstruct2"
+}
gdb_test "print zero_all ()" ""
set element4_offset \
[capture_value "/x (char *) &intarray\[4\] - (char *) &intarray\[0\]"]
-gdb_test "print zero_all ()" ""
+if ![string compare $is64bitonly "no"] then {
+ gdb_test "print zero_all ()" ""
-test_restore_saved_value "intarr1.srec 0 $element3_start $element4_start" \
- "array partial, srec" \
- [capture_value "4"] "intarray\[3\]"
+ test_restore_saved_value "intarr1.srec 0 $element3_start $element4_start" \
+ "array partial, srec" 4 "intarray\[3\]"
-gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 1"
-gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 1"
+ gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 1"
+ gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 1"
-gdb_test "print zero_all ()" ""
+ gdb_test "print zero_all ()" ""
-test_restore_saved_value "intarr1.ihex 0 $element3_start $element4_start" \
- "array partial, ihex" \
- [capture_value "4"] "intarray\[3\]"
+ test_restore_saved_value "intarr1.ihex 0 $element3_start $element4_start" \
+ "array partial, ihex" 4 "intarray\[3\]"
-gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 2"
-gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 2"
+ gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 2"
+ gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 2"
-gdb_test "print zero_all ()" ""
+ gdb_test "print zero_all ()" ""
-test_restore_saved_value "intarr1.tekhex 0 $element3_start $element4_start" \
- "array partial, tekhex" \
- [capture_value "4"] "intarray\[3\]"
+ test_restore_saved_value "intarr1.tekhex 0 $element3_start $element4_start" \
+ "array partial, tekhex" 4 "intarray\[3\]"
-gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 3"
-gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 3"
+ gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 3"
+ gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 3"
+}
gdb_test "print zero_all ()" ""
test_restore_saved_value \
"intarr1.bin binary $array_start $element3_offset $element4_offset" \
- "array partial, binary" \
- [capture_value "4"] "intarray\[3\]"
+ "array partial, binary" 4 "intarray\[3\]"
gdb_test "print intarray\[2\] == 0" " = 1" "element 2 not changed - 4"
gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 4"
-gdb_test "print zero_all ()" "" ""
+if ![string compare $is64bitonly "no"] then {
+ gdb_test "print zero_all ()" "" ""
-# restore with expressions
-test_restore_saved_value \
+ # restore with expressions
+ test_restore_saved_value \
"intarr3.srec ${array2_start}-${array_start} &intarray\[3\] &intarray\[4\]" \
- "array partial with expressions" \
- [capture_value "4"] "intarray2\[3\]"
-
-gdb_test "print intarray2\[2\] == 0" " = 1" "element 2 not changed, == 4"
-gdb_test "print intarray2\[4\] == 0" " = 1" "element 4 not changed, == 4"
+ "array partial with expressions" 4 "intarray2\[3\]"
+ gdb_test "print intarray2\[2\] == 0" " = 1" "element 2 not changed, == 4"
+ gdb_test "print intarray2\[4\] == 0" " = 1" "element 4 not changed, == 4"
+}
# clean up files
remote_exec build "rm -f intarr1.bin intarr1b.bin intarr1.ihex intarr1.srec intarr1.tekhex intarr2.bin intarr2b.bin intarr2.ihex intarr2.srec intarr2.tekhex intstr1.bin intstr1b.bin intstr1.ihex intstr1.srec intstr1.tekhex intstr2.bin intstr2b.bin intstr2.ihex intstr2.srec intstr2.tekhex intarr3.srec"
-