]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/corefile.exp
[gdb/testsuite] Fix gdb.base/corefile.exp with glibc 2.35
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / corefile.exp
CommitLineData
4a94e368 1# Copyright 1992-2022 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
65a33d75 20if {![isnative]} {
c906108c
SS
21 return
22}
23
f76495c8 24standard_testfile coremaker.c
c906108c 25
f76495c8 26if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} {
5b362f04 27 untested "failed to compile"
f76495c8
TT
28 return -1
29}
30
f9e233c9
KB
31# Do not delete coremap.data when calling core_find. This file is
32# required for GDB to find mmap'd data in the "accessing read-only
33# mmapped data in core file" test.
34set corefile [core_find $binfile {}]
37aeb5df 35if {$corefile == ""} {
e9ecd949 36 return 0
c906108c
SS
37}
38
37aeb5df 39# Test that we can simply startup with a "-core=$corefile" command line arg
c906108c
SS
40# and recognize that the core file is a valid, usable core file.
41# To do this, we must shutdown the currently running gdb and restart
42# with the -core args. We can't use gdb_start because it looks for
43# the first gdb prompt, and the message we are looking for occurs
6b8ce727 44# before the first prompt.
c906108c
SS
45#
46# Another problem is that on some systems (solaris for example), there
47# is apparently a limit on the length of a fully specified path to
f76495c8 48# the corefile executable, at about 80 chars. For this case, consider
c906108c
SS
49# it a pass, but note that the program name is bad.
50
51gdb_exit
65a33d75 52if {$verbose>1} {
37aeb5df 53 send_user "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS -core=$corefile\n"
c906108c
SS
54}
55
56set oldtimeout $timeout
57set timeout [expr "$timeout + 60"]
58verbose "Timeout is now $timeout seconds" 2
37aeb5df 59eval "spawn $GDB $INTERNAL_GDBFLAGS $GDBFLAGS -core=$corefile"
c906108c 60expect {
b9891b29 61 -re "Couldn't find .* registers in core file.*$gdb_prompt $" {
37aeb5df 62 fail "args: -core=[file tail $corefile] (couldn't find regs)"
b9891b29 63 }
f76495c8 64 -re "Core was generated by .*corefile.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
37aeb5df 65 pass "args: -core=[file tail $corefile]"
c906108c
SS
66 }
67 -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
37aeb5df 68 pass "args: -core=[file tail $corefile] (with bad program name)"
c906108c
SS
69 }
70 -re ".*registers from core file: File in wrong format.* $" {
37aeb5df 71 fail "args: -core=[file tail $corefile] (could not read registers from core file)"
c906108c 72 }
37aeb5df 73 -re ".*$gdb_prompt $" { fail "args: -core=[file tail $corefile]" }
c906108c
SS
74 timeout { fail "(timeout) starting with -core" }
75}
76
77
78#
79# Test that startup with both an executable file and -core argument.
80# See previous comments above, they are still applicable.
81#
82
4ec70201 83close
c906108c 84
65a33d75 85if {$verbose>1} {
37aeb5df 86 send_user "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $binfile -core=$corefile\n"
c906108c
SS
87}
88
89
4ec70201 90eval "spawn $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $binfile -core=$corefile"
c906108c 91expect {
f76495c8 92 -re "Core was generated by .*corefile.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
37aeb5df 93 pass "args: execfile -core=[file tail $corefile]"
c906108c
SS
94 }
95 -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
37aeb5df 96 pass "args: execfile -core=[file tail $corefile] (with bad program name)"
c906108c
SS
97 }
98 -re ".*registers from core file: File in wrong format.* $" {
37aeb5df 99 fail "args: execfile -core=[file tail $corefile] (could not read registers from core file)"
c906108c 100 }
37aeb5df 101 -re ".*$gdb_prompt $" { fail "args: execfile -core=[file tail $corefile]" }
c906108c
SS
102 timeout { fail "(timeout) starting with -core" }
103}
104set timeout $oldtimeout
105verbose "Timeout is now $timeout seconds" 2
106
4ec70201 107close
c906108c
SS
108
109# Now restart normally.
110
111gdb_start
112gdb_reinitialize_dir $srcdir/$subdir
113gdb_load ${binfile}
114
115# Test basic corefile recognition via core-file command.
116
ad3986f0 117gdb_test_multiple "core-file $corefile" "core-file command" {
958a4e4c
MS
118 -re ".* program is being debugged already.*y or n. $" {
119 # gdb_load may connect us to a gdbserver.
120 send_gdb "y\n"
4ec70201 121 exp_continue
958a4e4c 122 }
f76495c8 123 -re "Core was generated by .*corefile.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
c906108c
SS
124 pass "core-file command"
125 }
126 -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
127 pass "core-file command (with bad program name)"
128 }
129 -re ".*registers from core file: File in wrong format.* $" {
130 fail "core-file command (could not read registers from core file)"
131 }
c906108c
SS
132}
133
134# Test correct mapping of corefile sections by printing some variables.
135
136gdb_test "print coremaker_data" "\\\$$decimal = 202"
137gdb_test "print coremaker_bss" "\\\$$decimal = 10"
138gdb_test "print coremaker_ro" "\\\$$decimal = 201"
139
d85da69f 140gdb_test "print func2::coremaker_local" "\\\$$decimal = \\{0, 1, 2, 3, 4\\}"
c906108c 141
0c557179
SDJ
142# Test the presence and the correct values of $_exitsignal and
143# $_exitcode variables. The corefile is generated with a SIGABRT,
144# which is "6" in the Linux kernel.
145
146gdb_test "print \$_exitsignal" " = 6" \
147 "\$_exitsignal prints SIGABRT (6)"
148
149gdb_test "print \$_exitcode" " = void" \
150 "\$_exitcode is void"
151
c906108c
SS
152# Somehow we better test the ability to read the registers out of the core
153# file correctly. I don't think the other tests do this.
154
2939f92a 155gdb_test "bt" "abort.*func2.*func1.*main.*" "backtrace"
e64ddcc6 156gdb_test "up" "#\[0-9\]* *(\[0-9xa-fH'\]* in)? .* \\(.*\\).*" "up"
c906108c
SS
157
158# Test ability to read mmap'd data
159
160gdb_test "x/8bd buf1" ".*:.*0.*1.*2.*3.*4.*5.*6.*7" "accessing original mmap data in core file"
09dd9a69 161setup_xfail "*-*-sunos*" "*-*-aix*"
90d59e34
AC
162set test "accessing mmapped data in core file"
163gdb_test_multiple "x/8bd buf2" "$test" {
c906108c 164 -re ".*:.*0.*1.*2.*3.*4.*5.*6.*7.*$gdb_prompt $" {
90d59e34 165 pass "$test"
c906108c 166 }
f9e233c9
KB
167 -re "0x\[f\]*:.*Cannot access memory at address 0x\[f\]*.*$gdb_prompt $" {
168 fail "$test (mapping failed at runtime)"
169 }
170 -re "0x.*:.*Cannot access memory at address 0x.*$gdb_prompt $" {
171 fail "$test (mapping address not found in core file)"
172 }
173}
174
175set test "accessing read-only mmapped data in core file"
176gdb_test_multiple "x/8bd buf2ro" "$test" {
177 -re ".*:.*0.*1.*2.*3.*4.*5.*6.*7.*$gdb_prompt $" {
178 pass "$test"
179 }
c906108c 180 -re "0x\[f\]*:.*Cannot access memory at address 0x\[f\]*.*$gdb_prompt $" {
90d59e34 181 fail "$test (mapping failed at runtime)"
c906108c
SS
182 }
183 -re "0x.*:.*Cannot access memory at address 0x.*$gdb_prompt $" {
90d59e34 184 fail "$test (mapping address not found in core file)"
c906108c
SS
185 }
186}
187
94c265d7
KB
188# Test ability to read anonymous and, more importantly, unwritten-to
189# mmap'd data.
190
191if { ![istarget *-linux*] } {
192 setup_xfail "*-*-*"
193}
194gdb_test "x/wx buf3" "$hex:\[ \t\]+0x00000000" \
195 "accessing anonymous, unwritten-to mmap data"
196
c906108c
SS
197# test reinit_frame_cache
198
199gdb_load ${binfile}
e64ddcc6 200gdb_test "up" "#\[0-9\]* *(\[0-9xa-fH'\]* in)? .* \\(.*\\).*" "up (reinit)"
c906108c
SS
201
202gdb_test "core" "No core file now."
c0edd9ed 203
5d067f3d
PA
204# Test that we can unload the core with the "detach" command.
205
206proc_with_prefix corefile_detach {} {
207 clean_restart $::binfile
208
209 gdb_test "core-file $::corefile" "Core was generated by .*" "load core"
210 gdb_test "detach" "No core file now\\." "detach core"
211}
212
213corefile_detach
c0edd9ed
JK
214
215# Test a run (start) command will clear any loaded core file.
216
b3ccfe11
TT
217proc corefile_test_run {} {
218 global corefile gdb_prompt
219
df479dc6
PA
220 # This test is trying to check whether the "run" command finds the
221 # default run target when already debugging a core, so it would
222 # fail on boards that set auto-connect-native-target off. Since
223 # there's no real point in running the test but with the native
224 # target, it's easier to just skip elsewhere.
225 if {[target_info gdb_protocol] != ""} {
226 return
227 }
228
5d067f3d
PA
229 clean_restart $::binfile
230
b3ccfe11
TT
231 gdb_test "core-file $corefile" "Core was generated by .*" "run: load core again"
232 gdb_test "info files" "\r\nLocal core dump file:\r\n.*" "run: sanity check we see the core file"
c0edd9ed 233
b3ccfe11
TT
234 set test "run: with core"
235 if [runto_main] {
236 pass $test
237 } else {
c0edd9ed
JK
238 fail $test
239 }
b3ccfe11
TT
240
241 set test "run: core file is cleared"
242 gdb_test_multiple "info files" $test {
243 -re "\r\nLocal core dump file:\r\n.*\r\n$gdb_prompt $" {
244 fail $test
245 }
246 -re "\r\n$gdb_prompt $" {
247 pass $test
248 }
c0edd9ed 249 }
c0edd9ed 250
b3ccfe11
TT
251 set test "quit with a process"
252 gdb_test_multiple "quit" $test {
253 -re "A debugging session is active.\r\n.*\r\nQuit anyway\\? \\(y or n\\) $" {
254 pass $test
255 gdb_test "n" {Not confirmed\.} "quit with processes: n"
256 }
cd2effb2 257 }
b3ccfe11
TT
258
259 gdb_exit
cd2effb2
JK
260}
261
b3ccfe11 262corefile_test_run
c0edd9ed 263
cd2effb2
JK
264# Verify there is no question if only a core file is loaded.
265
266gdb_start
267gdb_test "core-file $corefile" "Core was generated by .*" "no question: load core"
268
269set test "quit with a core file"
270gdb_test_multiple "quit" $test {
271 -re "A debugging session is active.\r\n.*\r\nQuit anyway\\? \\(y or n\\) $" {
272 fail $test
273 gdb_test "n" {Not confirmed\.} "quit with processes: n"
274 }
275 eof {
276 pass $test
277 }
278}
279
280gdb_exit
c0edd9ed
JK
281
282# Test an attach command will clear any loaded core file.
283
329ea579 284proc corefile_test_attach {} {
b3ccfe11 285 global binfile corefile gdb_prompt
c0edd9ed 286
df479dc6
PA
287 # This test is checking whether the "attach" command finds the
288 # default run target when already debugging a core, so it would
289 # fail on boards that set auto-connect-native-target off. Since
290 # there's no real point in running the test but with the native
291 # target, it's easier to just skip elsewhere.
292 if {[target_info gdb_protocol] != ""} {
293 return
294 }
295
296 if [can_spawn_for_attach] {
b3ccfe11
TT
297 set test "attach: spawn sleep"
298 set res [remote_spawn host "$binfile sleep"]
299 if { $res < 0 || $res == "" } {
300 fail $test
301 return
302 }
303 set pid [exp_pid -i $res]
304 # We don't care whether the program is still in the startup phase when we
305 # attach.
c0edd9ed 306
b3ccfe11 307 gdb_start
c0edd9ed 308
b3ccfe11
TT
309 gdb_test "core-file $corefile" "Core was generated by .*" "attach: load core again"
310 gdb_test "info files" "\r\nLocal core dump file:\r\n.*" "attach: sanity check we see the core file"
311
312 gdb_test "attach $pid" "Attaching to process $pid\r\n.*" "attach: with core"
313
314 set test "attach: core file is cleared"
315 gdb_test_multiple "info files" $test {
316 -re "\r\nLocal core dump file:\r\n.*\r\n$gdb_prompt $" {
317 fail $test
318 }
319 -re "\r\n$gdb_prompt $" {
320 pass $test
321 }
c0edd9ed 322 }
c0edd9ed 323
b3ccfe11
TT
324 gdb_exit
325 }
c0edd9ed 326}
7d760051 327
b3ccfe11
TT
328corefile_test_attach
329
7d760051
UW
330# Test warning-free core file load. E.g., a Linux vDSO used to
331# trigger this warning:
332# warning: Can't read pathname for load map: Input/output error.
efe24f05
KB
333#
334# When testing in a docker container using the AUFS storage driver,
335# the kernel places host paths in the core file's NT_FILE note. XFAIL
336# this case since these paths make no sense in the container.
7d760051
UW
337
338clean_restart ${testfile}
339
340set test "core-file warning-free"
341gdb_test_multiple "core-file $corefile" $test {
efe24f05
KB
342 -re "warning: Can\'t open file.*\/docker\/aufs\/.*\r\n$gdb_prompt $" {
343 xfail $test
344 }
7d760051
UW
345 -re "warning: .*\r\n.*\r\n$gdb_prompt $" {
346 fail $test
347 }
348 -re "\r\n$gdb_prompt $" {
349 pass $test
350 }
351}