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