ChangeLog:
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / corefile.exp
CommitLineData
0fb0cc75
JB
1# Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2007, 2008,
2# 2009 Free Software Foundation, Inc.
c906108c
SS
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
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
c906108c 7# (at your option) any later version.
e22f8b7c 8#
c906108c
SS
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.
e22f8b7c 13#
c906108c 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 16
c906108c
SS
17# This file was written by Fred Fish. (fnf@cygnus.com)
18
19if $tracelevel then {
20 strace $tracelevel
21}
22
23set prms_id 0
24set bug_id 0
25
26# are we on a target board
27if ![isnative] then {
28 return
29}
30
31set testfile "coremaker"
32set srcfile ${testfile}.c
33set binfile ${objdir}/${subdir}/${testfile}
34if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
b60f0898
JB
35 untested corefile.exp
36 return -1
c906108c
SS
37}
38
39# Create and source the file that provides information about the compiler
40# used to compile the test case.
41if [get_compiler_info ${binfile}] {
42 return -1;
43}
44
45# Create a core file named "corefile" rather than just "core", to
46# avoid problems with sys admin types that like to regularly prune all
47# files named "core" from the system.
48#
49# Arbitrarily try setting the core size limit to "unlimited" since
50# this does not hurt on systems where the command does not work and
51# allows us to generate a core on systems where it does.
52#
53# Some systems append "core" to the name of the program; others append
e9ecd949
JB
54# the name of the program to "core"; still others (like Linux, as of
55# May 2003) create cores named "core.PID". In the latter case, we
56# could have many core files lying around, and it may be difficult to
57# tell which one is ours, so let's run the program in a subdirectory.
c906108c 58set found 0
e9ecd949
JB
59set coredir "${objdir}/${subdir}/coredir.[getpid]"
60file mkdir $coredir
61catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile}; true) >/dev/null 2>&1\""
c906108c 62# remote_exec host "${binfile}"
e9ecd949 63foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
c906108c
SS
64 if [remote_file build exists $i] {
65 remote_exec build "mv $i ${objdir}/${subdir}/corefile"
66 set found 1
67 }
68}
e9ecd949
JB
69# Check for "core.PID".
70if { $found == 0 } {
71 set names [glob -nocomplain -directory $coredir core.*]
72 if {[llength $names] == 1} {
73 set corefile [file join $coredir [lindex $names 0]]
74 remote_exec build "mv $corefile ${objdir}/${subdir}/corefile"
75 set found 1
76 }
77}
c906108c
SS
78if { $found == 0 } {
79 # The braindamaged HPUX shell quits after the ulimit -c above
80 # without executing ${binfile}. So we try again without the
81 # ulimit here if we didn't find a core file above.
82 # Oh, I should mention that any "braindamaged" non-Unix system has
83 # the same problem. I like the cd bit too, it's really neat'n stuff.
84 catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\""
85 foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" {
86 if [remote_file build exists $i] {
87 remote_exec build "mv $i ${objdir}/${subdir}/corefile"
88 set found 1
89 }
90 }
e9ecd949
JB
91}
92
93# Try to clean up after ourselves.
94remote_file build delete [file join $coredir coremmap.data]
95remote_exec build "rmdir $coredir"
c906108c 96
e9ecd949
JB
97if { $found == 0 } {
98 warning "can't generate a core file - core tests suppressed - check ulimit -c"
99 return 0
c906108c
SS
100}
101
102#
103# Test that we can simply startup with a "-core=corefile" command line arg
104# and recognize that the core file is a valid, usable core file.
105# To do this, we must shutdown the currently running gdb and restart
106# with the -core args. We can't use gdb_start because it looks for
107# the first gdb prompt, and the message we are looking for occurs
6b8ce727 108# before the first prompt.
c906108c
SS
109#
110# Another problem is that on some systems (solaris for example), there
111# is apparently a limit on the length of a fully specified path to
112# the coremaker executable, at about 80 chars. For this case, consider
113# it a pass, but note that the program name is bad.
114
115gdb_exit
116if $verbose>1 then {
6b8ce727 117 send_user "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS -core=$objdir/$subdir/corefile\n"
c906108c
SS
118}
119
120set oldtimeout $timeout
121set timeout [expr "$timeout + 60"]
122verbose "Timeout is now $timeout seconds" 2
6b8ce727 123eval "spawn $GDB $INTERNAL_GDBFLAGS $GDBFLAGS -core=$objdir/$subdir/corefile"
c906108c 124expect {
b9891b29
JB
125 -re "Couldn't find .* registers in core file.*$gdb_prompt $" {
126 fail "args: -core=corefile (couldn't find regs)"
127 }
c906108c
SS
128 -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
129 pass "args: -core=corefile"
130 }
131 -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
132 pass "args: -core=corefile (with bad program name)"
133 }
134 -re ".*registers from core file: File in wrong format.* $" {
135 fail "args: -core=corefile (could not read registers from core file)"
136 }
137 -re ".*$gdb_prompt $" { fail "args: -core=corefile" }
138 timeout { fail "(timeout) starting with -core" }
139}
140
141
142#
143# Test that startup with both an executable file and -core argument.
144# See previous comments above, they are still applicable.
145#
146
147close;
148
149if $verbose>1 then {
6b8ce727 150 send_user "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $binfile -core=$objdir/$subdir/corefile\n"
c906108c
SS
151}
152
153
6b8ce727 154eval "spawn $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $binfile -core=$objdir/$subdir/corefile";
c906108c
SS
155expect {
156 -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
157 pass "args: execfile -core=corefile"
158 }
159 -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
160 pass "args: execfile -core=corefile (with bad program name)"
161 }
162 -re ".*registers from core file: File in wrong format.* $" {
163 fail "args: execfile -core=corefile (could not read registers from core file)"
164 }
165 -re ".*$gdb_prompt $" { fail "args: execfile -core=corefile" }
166 timeout { fail "(timeout) starting with -core" }
167}
168set timeout $oldtimeout
169verbose "Timeout is now $timeout seconds" 2
170
171close;
172
173# Now restart normally.
174
175gdb_start
176gdb_reinitialize_dir $srcdir/$subdir
177gdb_load ${binfile}
178
179# Test basic corefile recognition via core-file command.
180
181send_gdb "core-file $objdir/$subdir/corefile\n"
182gdb_expect {
958a4e4c
MS
183 -re ".* program is being debugged already.*y or n. $" {
184 # gdb_load may connect us to a gdbserver.
185 send_gdb "y\n"
186 exp_continue;
187 }
c906108c
SS
188 -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
189 pass "core-file command"
190 }
191 -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
192 pass "core-file command (with bad program name)"
193 }
194 -re ".*registers from core file: File in wrong format.* $" {
195 fail "core-file command (could not read registers from core file)"
196 }
197 -re ".*$gdb_prompt $" { fail "core-file command" }
198 timeout { fail "(timeout) core-file command" }
199}
200
201# Test correct mapping of corefile sections by printing some variables.
202
203gdb_test "print coremaker_data" "\\\$$decimal = 202"
204gdb_test "print coremaker_bss" "\\\$$decimal = 10"
205gdb_test "print coremaker_ro" "\\\$$decimal = 201"
206
d85da69f 207gdb_test "print func2::coremaker_local" "\\\$$decimal = \\{0, 1, 2, 3, 4\\}"
c906108c
SS
208
209# Somehow we better test the ability to read the registers out of the core
210# file correctly. I don't think the other tests do this.
211
212gdb_test "bt" "abort.*func2.*func1.*main.*" "backtrace in corefile.exp"
d4f3574e 213gdb_test "up" "#\[0-9\]* *\[0-9xa-fH'\]* in .* \\(.*\\).*" "up in corefile.exp"
c906108c
SS
214
215# Test ability to read mmap'd data
216
217gdb_test "x/8bd buf1" ".*:.*0.*1.*2.*3.*4.*5.*6.*7" "accessing original mmap data in core file"
218setup_xfail "*-*-sunos*" "*-*-ultrix*" "*-*-aix*"
90d59e34
AC
219set test "accessing mmapped data in core file"
220gdb_test_multiple "x/8bd buf2" "$test" {
c906108c 221 -re ".*:.*0.*1.*2.*3.*4.*5.*6.*7.*$gdb_prompt $" {
90d59e34 222 pass "$test"
c906108c
SS
223 }
224 -re "0x\[f\]*:.*Cannot access memory at address 0x\[f\]*.*$gdb_prompt $" {
90d59e34 225 fail "$test (mapping failed at runtime)"
c906108c
SS
226 }
227 -re "0x.*:.*Cannot access memory at address 0x.*$gdb_prompt $" {
90d59e34 228 fail "$test (mapping address not found in core file)"
c906108c
SS
229 }
230}
231
232# test reinit_frame_cache
233
234gdb_load ${binfile}
9a01813a 235gdb_test "up" "#\[0-9\]* *\[0-9xa-fH'\]* in .* \\(.*\\).*" "up in corefile.exp (reinit)"
c906108c
SS
236
237gdb_test "core" "No core file now."
This page took 0.981851 seconds and 4 git commands to generate.