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