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