1 # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2007, 2008,
2 # 2009, 2010, 2011 Free Software Foundation, Inc.
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.
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.
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/>.
17 # This file was written by Fred Fish. (fnf@cygnus.com)
24 # are we on a target board
29 set testfile "coremaker"
30 set srcfile ${testfile}.c
31 set binfile ${objdir}/${subdir}/${testfile}
32 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
37 # Create and source the file that provides information about the compiler
38 # used to compile the test case.
39 if [get_compiler_info ${binfile}] {
43 set corefile [core_find $binfile {coremmap.data}]
44 if {$corefile == ""} {
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.
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.
62 send_user "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS -core=$corefile\n"
65 set oldtimeout $timeout
66 set timeout [expr "$timeout + 60"]
67 verbose "Timeout is now $timeout seconds" 2
68 eval "spawn $GDB $INTERNAL_GDBFLAGS $GDBFLAGS -core=$corefile"
70 -re "Couldn't find .* registers in core file.*$gdb_prompt $" {
71 fail "args: -core=[file tail $corefile] (couldn't find regs)"
73 -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
74 pass "args: -core=[file tail $corefile]"
76 -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
77 pass "args: -core=[file tail $corefile] (with bad program name)"
79 -re ".*registers from core file: File in wrong format.* $" {
80 fail "args: -core=[file tail $corefile] (could not read registers from core file)"
82 -re ".*$gdb_prompt $" { fail "args: -core=[file tail $corefile]" }
83 timeout { fail "(timeout) starting with -core" }
88 # Test that startup with both an executable file and -core argument.
89 # See previous comments above, they are still applicable.
95 send_user "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $binfile -core=$corefile\n"
99 eval "spawn $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $binfile -core=$corefile";
101 -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
102 pass "args: execfile -core=[file tail $corefile]"
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)"
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)"
110 -re ".*$gdb_prompt $" { fail "args: execfile -core=[file tail $corefile]" }
111 timeout { fail "(timeout) starting with -core" }
113 set timeout $oldtimeout
114 verbose "Timeout is now $timeout seconds" 2
118 # Now restart normally.
121 gdb_reinitialize_dir $srcdir/$subdir
124 # Test basic corefile recognition via core-file command.
126 gdb_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.
132 -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
133 pass "core-file command"
135 -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
136 pass "core-file command (with bad program name)"
138 -re ".*registers from core file: File in wrong format.* $" {
139 fail "core-file command (could not read registers from core file)"
143 # Test correct mapping of corefile sections by printing some variables.
145 gdb_test "print coremaker_data" "\\\$$decimal = 202"
146 gdb_test "print coremaker_bss" "\\\$$decimal = 10"
147 gdb_test "print coremaker_ro" "\\\$$decimal = 201"
149 gdb_test "print func2::coremaker_local" "\\\$$decimal = \\{0, 1, 2, 3, 4\\}"
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.
154 gdb_test "bt" "abort.*func2.*func1.*main.*" "backtrace in corefile.exp"
155 gdb_test "up" "#\[0-9\]* *\[0-9xa-fH'\]* in .* \\(.*\\).*" "up in corefile.exp"
157 # Test ability to read mmap'd data
159 gdb_test "x/8bd buf1" ".*:.*0.*1.*2.*3.*4.*5.*6.*7" "accessing original mmap data in core file"
160 setup_xfail "*-*-sunos*" "*-*-ultrix*" "*-*-aix*"
161 set test "accessing mmapped data in core file"
162 gdb_test_multiple "x/8bd buf2" "$test" {
163 -re ".*:.*0.*1.*2.*3.*4.*5.*6.*7.*$gdb_prompt $" {
166 -re "0x\[f\]*:.*Cannot access memory at address 0x\[f\]*.*$gdb_prompt $" {
167 fail "$test (mapping failed at runtime)"
169 -re "0x.*:.*Cannot access memory at address 0x.*$gdb_prompt $" {
170 fail "$test (mapping address not found in core file)"
174 # test reinit_frame_cache
177 gdb_test "up" "#\[0-9\]* *\[0-9xa-fH'\]* in .* \\(.*\\).*" "up in corefile.exp (reinit)"
179 gdb_test "core" "No core file now."
182 # Test a run (start) command will clear any loaded core file.
184 gdb_test "core-file $corefile" "Core was generated by .*" "run: load core again"
185 gdb_test "info files" "\r\nLocal core dump file:\r\n.*" "run: sanity check we see the core file"
187 set test "run: with core"
194 set test "run: core file is cleared"
195 gdb_test_multiple "info files" $test {
196 -re "\r\nLocal core dump file:\r\n.*\r\n$gdb_prompt $" {
199 -re "\r\n$gdb_prompt $" {
204 set test "quit with a process"
205 gdb_test_multiple "quit" $test {
206 -re "A debugging session is active.\r\n.*\r\nQuit anyway\\? \\(y or n\\) $" {
208 gdb_test "n" {Not confirmed\.} "quit with processes: n"
214 # Verify there is no question if only a core file is loaded.
217 gdb_test "core-file $corefile" "Core was generated by .*" "no question: load core"
219 set test "quit with a core file"
220 gdb_test_multiple "quit" $test {
221 -re "A debugging session is active.\r\n.*\r\nQuit anyway\\? \\(y or n\\) $" {
223 gdb_test "n" {Not confirmed\.} "quit with processes: n"
232 # Test an attach command will clear any loaded core file.
234 if ![is_remote target] {
235 set test "attach: spawn sleep"
236 set res [remote_spawn host "$binfile sleep"];
237 if { $res < 0 || $res == "" } {
241 set pid [exp_pid -i $res]
242 # We don't care whether the program is still in the startup phase when we
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"
250 gdb_test "attach $pid" "Attaching to process $pid\r\n.*" "attach: with core"
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 $" {
257 -re "\r\n$gdb_prompt $" {