-# Copyright 2002, 2004, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+# Copyright 2002-2013 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
# This file was written by Michael Snyder (msnyder@redhat.com)
# This is a test for the gdb command "dump".
-if $tracelevel then {
- strace $tracelevel
-}
-
-set prms_id 0
-set bug_id 0
set testfile "dump"
# Get the endianness for the later use with endianless formats.
-send_gdb "show endian\n"
-gdb_expect {
+gdb_test_multiple "show endian" "show endian" {
-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.
proc make_dump_file { command msg } {
global gdb_prompt
- send_gdb "${command}\n"
- gdb_expect {
+ gdb_test_multiple "${command}" "$msg" {
-re ".*\[Ee\]rror.*$gdb_prompt $" { fail $msg }
-re ".*\[Ww\]arning.*$gdb_prompt $" { fail $msg }
-re ".*\[Uu\]ndefined .*$gdb_prompt $" { fail $msg }
- -re ".*$gdb_prompt $" { pass $msg }
- timeout { fail "$msg (timeout)" }
+ -re ".*$gdb_prompt $" { pass $msg }
}
}
return $output_string
}
+# POINTER is a pointer and this proc captures the value of POINTER along
+# with POINTER's type. For example, POINTER is "&intarray", this proc will
+# call "p &intarray", capture "(int (*)[32]) 0x804a0e0", and return this
+# string.
+
+proc capture_pointer_with_type { pointer } {
+ global gdb_prompt
+ global expect_out
+
+ set test "capture type of pointer $pointer"
+ set output_string ""
+ gdb_test_multiple "p ${pointer}" $test {
+ -re "\\$\[0-9\]+ = .*$gdb_prompt $" {
+ # Expected output of "p ${pointer}" is like "$7 = (int (*)[32]) 0x804a0e0",
+ # and we want to extract "(int (*)[32]) 0x804a0e0" from it via
+ # following regexp.
+ if [regexp " \\(.*\\).* 0x\[0-9a-fA-F\]+" $expect_out(0,string) output_string] {
+ # OUTPUT_STRING is expected to be like "(int (*)[32]) 0x804a0e0".
+ pass "$test"
+ } else {
+ fail "$test"
+ }
+ }
+ }
+
+ return $output_string
+}
+
set array_start [capture_value "/x &intarray\[0\]"]
set array_end [capture_value "/x &intarray\[32\]"]
set struct_start [capture_value "/x &intstruct"]
set array_val [capture_value "intarray"]
set struct_val [capture_value "intstruct"]
+set array_ptr_type [capture_pointer_with_type "&intarray"]
+set struct_ptr_type [capture_pointer_with_type "&intstruct"]
+
make_dump_file "dump mem intarr2.bin $array_start $array_end" \
"dump array as memory, default"
"dump srec mem intarr3.srec &intarray \(char *\) &intarray + sizeof intarray" \
"dump array as mem, srec, expressions"
-
-# Now start a fresh gdb session, and reload the saved value files.
-
-gdb_exit
-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" "file binfile"]] } then {
- fail "start with intarray un-initialized"
-} else {
- pass "start with intarray un-initialized"
-}
-
-if { ![string compare $struct_val \
- [capture_value "intstruct" "file binfile"]] } then {
- fail "start with intstruct un-initialized"
-} else {
- pass "start with intstruct un-initialized"
-}
-
-proc test_reload_saved_value { filename msg oldval newval } {
- global gdb_prompt
-
- gdb_file_cmd $filename
- if { ![string compare $oldval \
- [capture_value $newval "$msg"]] } then {
- pass "$msg; value restored ok"
- } else {
- fail "$msg; value restored ok"
- }
-}
-
proc test_restore_saved_value { restore_args msg oldval newval } {
global gdb_prompt
}
}
-# 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" \
- $struct_val "intstruct"
- 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" \
- $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" \
- $array_val "intarray"
- 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" \
- $array_val "intarray"
- test_reload_saved_value "intstr2.ihex" "reload struct as memory, intel hex" \
- $struct_val "intstruct"
-}
-
-# 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" \
- $struct_val "intstruct"
- 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" \
- $struct_val "intstruct"
-}
-
-# Start a fresh gdb session
-gdb_exit
-gdb_start
-gdb_reinitialize_dir $srcdir/$subdir
-gdb_load ${binfile}
+ gdb_test "print zero_all ()" ".*"
-# Run to main.
-if { ! [ runto_main ] } then {
- untested dump.exp
- return -1
-}
-
-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" "load binfile"]] } then {
- fail "start with intstruct un-initialized, runto main"
-} else {
- pass "start with intstruct un-initialized, runto main"
-}
-
-if ![string compare $is64bitonly "no"] then {
test_restore_saved_value "intarr1.srec" "array as value, srec" \
$array_val "intarray"
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" \
$array_val "intarray"
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" \
$array_val "intarray"
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" \
$array_val "intarray"
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" \
$array_val "intarray"
$struct_val "intstruct"
}
-gdb_test "print zero_all ()" ""
+gdb_test "print zero_all ()" ".*"
test_restore_saved_value "intarr1.bin binary $array_start" \
"array as value, binary" \
"struct as value, binary" \
$struct_val "intstruct"
-gdb_test "print zero_all ()" ""
+gdb_test "print zero_all ()" ".*"
test_restore_saved_value "intarr2.bin binary $array_start" \
"array as memory, binary" \
set struct2_offset \
[capture_value "(char *) &intstruct2 - (char *) &intstruct"]
-gdb_test "print zero_all ()" ""
+gdb_test "print zero_all ()" ".*"
if ![string compare $is64bitonly "no"] then {
"struct copy, srec" \
$struct_val "intstruct2"
- gdb_test "print zero_all ()" ""
+ gdb_test "print zero_all ()" ".*"
test_restore_saved_value "intarr1.ihex $array2_offset" \
"array copy, ihex" \
"struct copy, ihex" \
$struct_val "intstruct2"
- gdb_test "print zero_all ()" ""
+ gdb_test "print zero_all ()" ".*"
test_restore_saved_value "intarr1.tekhex $array2_offset" \
"array copy, tekhex" \
$struct_val "intstruct2"
}
-gdb_test "print zero_all ()" ""
+gdb_test "print zero_all ()" ".*"
test_restore_saved_value "intarr1.bin binary $array2_start" \
"array copy, binary" \
[capture_value "/x (char *) &intarray\[4\] - (char *) &intarray\[0\]"]
if ![string compare $is64bitonly "no"] then {
- gdb_test "print zero_all ()" ""
+ gdb_test "print zero_all ()" ".*"
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 zero_all ()" ""
+ gdb_test "print zero_all ()" ".*"
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 zero_all ()" ""
+ gdb_test "print zero_all ()" ".*"
test_restore_saved_value "intarr1.tekhex 0 $element3_start $element4_start" \
"array partial, tekhex" 4 "intarray\[3\]"
gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 3"
}
-gdb_test "print zero_all ()" ""
+gdb_test "print zero_all ()" ".*"
test_restore_saved_value \
"intarr1.bin binary $array_start $element3_offset $element4_offset" \
gdb_test "print intarray\[4\] == 0" " = 1" "element 4 not changed - 4"
if ![string compare $is64bitonly "no"] then {
- gdb_test "print zero_all ()" "" ""
+ gdb_test "print zero_all ()" ".*" ""
# restore with expressions
test_restore_saved_value \
gdb_test "print intarray2\[4\] == 0" " = 1" "element 4 not changed, == 4"
}
+
+# Now start a fresh gdb session, and reload the saved value files.
+
+gdb_exit
+gdb_start
+gdb_file_cmd ${binfile}
+
+# Now fix the endianness at the correct state.
+
+gdb_test_multiple "set endian $endian" "set endianness" {
+ -re ".* (big|little) endian.*$gdb_prompt $" {
+ pass "setting $endian endianness"
+ }
+}
+
+# Reload saved values one by one, and compare.
+
+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" "file binfile"]] } then {
+ fail "start with intstruct un-initialized"
+} else {
+ pass "start with intstruct un-initialized"
+}
+
+proc test_reload_saved_value { filename msg oldval newval } {
+ global gdb_prompt
+
+ gdb_file_cmd $filename
+ if { ![string compare $oldval \
+ [capture_value $newval "$msg"]] } then {
+ pass "$msg; value restored ok"
+ } else {
+ fail "$msg; value restored ok"
+ }
+}
+
+# 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 "\*$array_ptr_type"
+ test_reload_saved_value "intstr1.srec" "reload struct as value, srec" \
+ $struct_val "\*$struct_ptr_type"
+ test_reload_saved_value "intarr2.srec" "reload array as memory, srec" \
+ $array_val "\*$array_ptr_type"
+ test_reload_saved_value "intstr2.srec" "reload struct as memory, srec" \
+ $struct_val "\*$struct_ptr_type"
+}
+
+# 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" \
+ $array_val "\*$array_ptr_type"
+ test_reload_saved_value "intstr1.ihex" "reload struct as value, intel hex" \
+ $struct_val "\*$struct_ptr_type"
+ test_reload_saved_value "intarr2.ihex" "reload array as memory, intel hex" \
+ $array_val "\*$array_ptr_type"
+ test_reload_saved_value "intstr2.ihex" "reload struct as memory, intel hex" \
+ $struct_val "\*$struct_ptr_type"
+}
+
+# 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 "\*$array_ptr_type"
+ test_reload_saved_value "intstr1.tekhex" "reload struct as value, tekhex" \
+ $struct_val "\*$struct_ptr_type"
+ test_reload_saved_value "intarr2.tekhex" "reload array as memory, tekhex" \
+ $array_val "\*$array_ptr_type"
+ test_reload_saved_value "intstr2.tekhex" "reload struct as memory, tekhex" \
+ $struct_val "\*$struct_ptr_type"
+}
+
# 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"