1# Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2007, 2008, 2# 2009, 2010, 2011 Free Software Foundation, Inc. 3 4# This program is free software; you can redistribute it and/or modify 5# it under the terms of the GNU General Public License as published by 6# the Free Software Foundation; either version 3 of the License, or 7# (at your option) any later version. 8# 9# This program is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13# 14# You should have received a copy of the GNU General Public License 15# along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17# This file was written by Fred Fish. (fnf@cygnus.com) 18 19if $tracelevel then { 20 strace $tracelevel 21} 22 23 24# are we on a target board 25if ![isnative] then { 26 return 27} 28 29set testfile "coremaker" 30set srcfile ${testfile}.c 31set binfile ${objdir}/${subdir}/${testfile} 32if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { 33 untested corefile.exp 34 return -1 35} 36 37# Create and source the file that provides information about the compiler 38# used to compile the test case. 39if [get_compiler_info ${binfile}] { 40 return -1; 41} 42 43set corefile [core_find $binfile {coremmap.data}] 44if {$corefile == ""} { 45 return 0 46} 47 48# Test that we can simply startup with a "-core=$corefile" command line arg 49# and recognize that the core file is a valid, usable core file. 50# To do this, we must shutdown the currently running gdb and restart 51# with the -core args. We can't use gdb_start because it looks for 52# the first gdb prompt, and the message we are looking for occurs 53# before the first prompt. 54# 55# Another problem is that on some systems (solaris for example), there 56# is apparently a limit on the length of a fully specified path to 57# the coremaker executable, at about 80 chars. For this case, consider 58# it a pass, but note that the program name is bad. 59 60gdb_exit 61if $verbose>1 then { 62 send_user "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS -core=$corefile\n" 63} 64 65set oldtimeout $timeout 66set timeout [expr "$timeout + 60"] 67verbose "Timeout is now $timeout seconds" 2 68eval "spawn $GDB $INTERNAL_GDBFLAGS $GDBFLAGS -core=$corefile" 69expect { 70 -re "Couldn't find .* registers in core file.*$gdb_prompt $" { 71 fail "args: -core=[file tail $corefile] (couldn't find regs)" 72 } 73 -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" { 74 pass "args: -core=[file tail $corefile]" 75 } 76 -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" { 77 pass "args: -core=[file tail $corefile] (with bad program name)" 78 } 79 -re ".*registers from core file: File in wrong format.* $" { 80 fail "args: -core=[file tail $corefile] (could not read registers from core file)" 81 } 82 -re ".*$gdb_prompt $" { fail "args: -core=[file tail $corefile]" } 83 timeout { fail "(timeout) starting with -core" } 84} 85 86 87# 88# Test that startup with both an executable file and -core argument. 89# See previous comments above, they are still applicable. 90# 91 92close; 93 94if $verbose>1 then { 95 send_user "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $binfile -core=$corefile\n" 96} 97 98 99eval "spawn $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $binfile -core=$corefile"; 100expect { 101 -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" { 102 pass "args: execfile -core=[file tail $corefile]" 103 } 104 -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" { 105 pass "args: execfile -core=[file tail $corefile] (with bad program name)" 106 } 107 -re ".*registers from core file: File in wrong format.* $" { 108 fail "args: execfile -core=[file tail $corefile] (could not read registers from core file)" 109 } 110 -re ".*$gdb_prompt $" { fail "args: execfile -core=[file tail $corefile]" } 111 timeout { fail "(timeout) starting with -core" } 112} 113set timeout $oldtimeout 114verbose "Timeout is now $timeout seconds" 2 115 116close; 117 118# Now restart normally. 119 120gdb_start 121gdb_reinitialize_dir $srcdir/$subdir 122gdb_load ${binfile} 123 124# Test basic corefile recognition via core-file command. 125 126gdb_test_multiple "core-file $corefile" "core-file command" { 127 -re ".* program is being debugged already.*y or n. $" { 128 # gdb_load may connect us to a gdbserver. 129 send_gdb "y\n" 130 exp_continue; 131 } 132 -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" { 133 pass "core-file command" 134 } 135 -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" { 136 pass "core-file command (with bad program name)" 137 } 138 -re ".*registers from core file: File in wrong format.* $" { 139 fail "core-file command (could not read registers from core file)" 140 } 141} 142 143# Test correct mapping of corefile sections by printing some variables. 144 145gdb_test "print coremaker_data" "\\\$$decimal = 202" 146gdb_test "print coremaker_bss" "\\\$$decimal = 10" 147gdb_test "print coremaker_ro" "\\\$$decimal = 201" 148 149gdb_test "print func2::coremaker_local" "\\\$$decimal = \\{0, 1, 2, 3, 4\\}" 150 151# Somehow we better test the ability to read the registers out of the core 152# file correctly. I don't think the other tests do this. 153 154gdb_test "bt" "abort.*func2.*func1.*main.*" "backtrace in corefile.exp" 155gdb_test "up" "#\[0-9\]* *\[0-9xa-fH'\]* in .* \\(.*\\).*" "up in corefile.exp" 156 157# Test ability to read mmap'd data 158 159gdb_test "x/8bd buf1" ".*:.*0.*1.*2.*3.*4.*5.*6.*7" "accessing original mmap data in core file" 160setup_xfail "*-*-sunos*" "*-*-ultrix*" "*-*-aix*" 161set test "accessing mmapped data in core file" 162gdb_test_multiple "x/8bd buf2" "$test" { 163 -re ".*:.*0.*1.*2.*3.*4.*5.*6.*7.*$gdb_prompt $" { 164 pass "$test" 165 } 166 -re "0x\[f\]*:.*Cannot access memory at address 0x\[f\]*.*$gdb_prompt $" { 167 fail "$test (mapping failed at runtime)" 168 } 169 -re "0x.*:.*Cannot access memory at address 0x.*$gdb_prompt $" { 170 fail "$test (mapping address not found in core file)" 171 } 172} 173 174# test reinit_frame_cache 175 176gdb_load ${binfile} 177gdb_test "up" "#\[0-9\]* *\[0-9xa-fH'\]* in .* \\(.*\\).*" "up in corefile.exp (reinit)" 178 179gdb_test "core" "No core file now." 180 181 182# Test a run (start) command will clear any loaded core file. 183 184gdb_test "core-file $corefile" "Core was generated by .*" "run: load core again" 185gdb_test "info files" "\r\nLocal core dump file:\r\n.*" "run: sanity check we see the core file" 186 187set test "run: with core" 188if [runto_main] { 189 pass $test 190} else { 191 fail $test 192} 193 194set test "run: core file is cleared" 195gdb_test_multiple "info files" $test { 196 -re "\r\nLocal core dump file:\r\n.*\r\n$gdb_prompt $" { 197 fail $test 198 } 199 -re "\r\n$gdb_prompt $" { 200 pass $test 201 } 202} 203 204set test "quit with a process" 205gdb_test_multiple "quit" $test { 206 -re "A debugging session is active.\r\n.*\r\nQuit anyway\\? \\(y or n\\) $" { 207 pass $test 208 gdb_test "n" {Not confirmed\.} "quit with processes: n" 209 } 210} 211 212gdb_exit 213 214# Verify there is no question if only a core file is loaded. 215 216gdb_start 217gdb_test "core-file $corefile" "Core was generated by .*" "no question: load core" 218 219set test "quit with a core file" 220gdb_test_multiple "quit" $test { 221 -re "A debugging session is active.\r\n.*\r\nQuit anyway\\? \\(y or n\\) $" { 222 fail $test 223 gdb_test "n" {Not confirmed\.} "quit with processes: n" 224 } 225 eof { 226 pass $test 227 } 228} 229 230gdb_exit 231 232# Test an attach command will clear any loaded core file. 233 234if ![is_remote target] { 235 set test "attach: spawn sleep" 236 set res [remote_spawn host "$binfile sleep"]; 237 if { $res < 0 || $res == "" } { 238 fail $test 239 return 240 } 241 set pid [exp_pid -i $res] 242 # We don't care whether the program is still in the startup phase when we 243 # attach. 244 245 gdb_start 246 247 gdb_test "core-file $corefile" "Core was generated by .*" "attach: load core again" 248 gdb_test "info files" "\r\nLocal core dump file:\r\n.*" "attach: sanity check we see the core file" 249 250 gdb_test "attach $pid" "Attaching to process $pid\r\n.*" "attach: with core" 251 252 set test "attach: core file is cleared" 253 gdb_test_multiple "info files" $test { 254 -re "\r\nLocal core dump file:\r\n.*\r\n$gdb_prompt $" { 255 fail $test 256 } 257 -re "\r\n$gdb_prompt $" { 258 pass $test 259 } 260 } 261 262 gdb_exit 263} 264