1 # Copyright
1992-2023 Free Software Foundation
, Inc.
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.
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.
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
/>.
16 # This file was written by Fred Fish.
(fnf@cygnus.com
)
19 # are we
on a target board
22 standard_testfile coremaker.c
24 if {[build_executable $testfile.exp $testfile $srcfile debug
] == -1} {
25 untested
"failed to compile"
29 #
Do not
delete coremap.data when calling core_find. This file is
30 # required
for GDB to find mmap
'd data in the "accessing read-only
31 # mmapped data in core file" test.
32 set corefile [core_find $binfile {}]
33 if {$corefile == ""} {
37 # Test that we can simply startup with a "-core=$corefile" command line arg
38 # and recognize that the core file is a valid, usable core file.
39 # To do this, we must shutdown the currently running gdb and restart
40 # with the -core args. We can't use gdb_start because it looks
for
41 # the first gdb prompt
, and the message we are looking
for occurs
42 # before the first prompt.
44 # Another problem is that
on some systems
(solaris
for example
), there
45 # is apparently a
limit on the length of a fully specified path to
46 # the corefile executable
, at about
80 chars.
For this case
, consider
47 # it a pass
, but note that the
program name is bad.
51 send_user
"Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS -core=$corefile\n"
54 set oldtimeout $timeout
55 set timeout
[expr
"$timeout + 60"]
56 verbose
"Timeout is now $timeout seconds" 2
57 eval
"spawn $GDB $INTERNAL_GDBFLAGS $GDBFLAGS -core=$corefile"
59 -re
"Couldn't find .* registers in core file.*$gdb_prompt $" {
60 fail
"args: -core=[file tail $corefile] (couldn't find regs)"
62 -re
"Core was generated by .*corefile.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
63 pass
"args: -core=[file tail $corefile]"
65 -re
"Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
66 pass
"args: -core=[file tail $corefile] (with bad program name)"
68 -re
".*registers from core file: File in wrong format.* $" {
69 fail
"args: -core=[file tail $corefile] (could not read registers from core file)"
71 -re
".*$gdb_prompt $" { fail "args: -core=[file tail $corefile]" }
72 timeout
{ fail
"(timeout) starting with -core" }
77 # Test that startup with both an executable file and
-core
argument.
78 # See previous comments above
, they are still applicable.
84 send_user
"Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $binfile -core=$corefile\n"
88 eval
"spawn $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $binfile -core=$corefile"
90 -re
"Core was generated by .*corefile.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
91 pass
"args: execfile -core=[file tail $corefile]"
93 -re
"Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
94 pass
"args: execfile -core=[file tail $corefile] (with bad program name)"
96 -re
".*registers from core file: File in wrong format.* $" {
97 fail
"args: execfile -core=[file tail $corefile] (could not read registers from core file)"
99 -re
".*$gdb_prompt $" { fail "args: execfile -core=[file tail $corefile]" }
100 timeout
{ fail
"(timeout) starting with -core" }
102 set timeout $oldtimeout
103 verbose
"Timeout is now $timeout seconds" 2
107 # Now restart normally.
110 gdb_reinitialize_dir $srcdir
/$subdir
113 # Test basic corefile recognition via core
-file command.
115 gdb_test_multiple
"core-file $corefile" "core-file command" {
116 -re
".* program is being debugged already.*y or n. $" {
117 # gdb_load may
connect us to a gdbserver.
121 -re
"Core was generated by .*corefile.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
122 pass
"core-file command"
124 -re
"Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
125 pass
"core-file command (with bad program name)"
127 -re
".*registers from core file: File in wrong format.* $" {
128 fail
"core-file command (could not read registers from core file)"
132 # Test correct mapping of corefile sections by printing some variables.
134 gdb_test
"print coremaker_data" "\\\$$decimal = 202"
135 gdb_test
"print coremaker_bss" "\\\$$decimal = 10"
136 gdb_test
"print coremaker_ro" "\\\$$decimal = 201"
138 gdb_test
"print func2::coremaker_local" "\\\$$decimal = \\{0, 1, 2, 3, 4\\}"
140 # Test the presence and the correct
values of $_exitsignal and
141 # $_exitcode variables. The corefile is generated with a SIGABRT
,
142 # which is
"6" in the Linux kernel.
144 gdb_test
"print \$_exitsignal" " = 6" \
145 "\$_exitsignal prints SIGABRT (6)"
147 gdb_test
"print \$_exitcode" " = void" \
148 "\$_exitcode is void"
150 # Somehow we better test the ability to read the registers out of the core
151 # file correctly. I don
't think the other tests do this.
153 gdb_test "bt" "abort.*func2.*func1.*main.*" "backtrace"
154 gdb_test "up" "#\[0-9\]* *(\[0-9xa-fH'\
]* in
)? .
* \\(.
*\\).
*" "up"
156 # Test ability to read mmap
'd data
158 gdb_test "x/8bd buf1" ".*:.*0.*1.*2.*3.*4.*5.*6.*7" "accessing original mmap data in core file"
159 setup_xfail "*-*-sunos*" "*-*-aix*"
160 set test "accessing mmapped data in core file"
161 gdb_test_multiple "x/8bd buf2" "$test" {
162 -re ".*:.*0.*1.*2.*3.*4.*5.*6.*7.*$gdb_prompt $" {
165 -re "0x\[f\]*:.*Cannot access memory at address 0x\[f\]*.*$gdb_prompt $" {
166 fail "$test (mapping failed at runtime)"
168 -re "0x.*:.*Cannot access memory at address 0x.*$gdb_prompt $" {
169 fail "$test (mapping address not found in core file)"
173 set test "accessing read-only mmapped data in core file"
174 gdb_test_multiple "x/8bd buf2ro" "$test" {
175 -re ".*:.*0.*1.*2.*3.*4.*5.*6.*7.*$gdb_prompt $" {
178 -re "0x\[f\]*:.*Cannot access memory at address 0x\[f\]*.*$gdb_prompt $" {
179 fail "$test (mapping failed at runtime)"
181 -re "0x.*:.*Cannot access memory at address 0x.*$gdb_prompt $" {
182 fail "$test (mapping address not found in core file)"
186 # Test ability to read anonymous and, more importantly, unwritten-to
189 if { ![istarget
*-linux
*] } {
192 gdb_test
"x/wx buf3" "$hex:\[ \t\]+0x00000000" \
193 "accessing anonymous, unwritten-to mmap data"
195 # test reinit_frame_cache
198 gdb_test
"up" "#\[0-9\]* *(\[0-9xa-fH'\]* in)? .* \\(.*\\).*" "up (reinit)"
200 gdb_test
"core" "No core file now."
202 # Test that we can unload the core with the
"detach" command.
204 proc_with_prefix corefile_detach
{} {
205 clean_restart $
::binfile
207 gdb_test
"core-file $::corefile" "Core was generated by .*" "load core"
208 gdb_test
"detach" "No core file now\\." "detach core"
213 # Test a run
(start
) command will clear
any loaded core file.
215 proc corefile_test_run
{} {
216 global corefile gdb_prompt
218 # This test is trying to check whether the
"run" command finds the
219 # default run target when already debugging a core
, so it would
220 # fail
on boards that
set auto
-connect-native
-target
off. Since
221 # there
's no real point in running the test but with the native
222 # target, it's easier to just skip elsewhere.
223 if {[target_info gdb_protocol
] != ""} {
227 clean_restart $
::binfile
229 gdb_test
"core-file $corefile" "Core was generated by .*" "run: load core again"
230 gdb_test
"info files" "\r\nLocal core dump file:\r\n.*" "run: sanity check we see the core file"
232 set test
"run: with core"
239 set test
"run: core file is cleared"
240 gdb_test_multiple
"info files" $test {
241 -re
"\r\nLocal core dump file:\r\n.*\r\n$gdb_prompt $" {
244 -re
"\r\n$gdb_prompt $" {
249 set test
"quit with a process"
250 gdb_test_multiple
"quit" $test {
251 -re
"A debugging session is active.\r\n.*\r\nQuit anyway\\? \\(y or n\\) $" {
253 gdb_test
"n" {Not confirmed\.} "quit with processes: n"
262 # Verify there is no question
if only a core file is loaded.
265 gdb_test
"core-file $corefile" "Core was generated by .*" "no question: load core"
267 set test
"quit with a core file"
268 gdb_test_multiple
"quit" $test {
269 -re
"A debugging session is active.\r\n.*\r\nQuit anyway\\? \\(y or n\\) $" {
271 gdb_test
"n" {Not confirmed\.} "quit with processes: n"
280 # Test an attach command will clear
any loaded core file.
282 proc corefile_test_attach
{} {
283 global binfile corefile gdb_prompt
285 # This test is checking whether the
"attach" command finds the
286 # default run target when already debugging a core
, so it would
287 # fail
on boards that
set auto
-connect-native
-target
off. Since
288 # there
's no real point in running the test but with the native
289 # target, it's easier to just skip elsewhere.
290 if {[target_info gdb_protocol
] != ""} {
294 if [can_spawn_for_attach
] {
295 set test
"attach: spawn sleep"
296 set res
[remote_spawn host
"$binfile sleep"]
297 if { $res
< 0 || $res
== "" } {
301 set pid
[exp_pid
-i $res
]
302 # We don
't care whether the program is still in the startup phase when we
307 gdb_test "core-file $corefile" "Core was generated by .*" "attach: load core again"
308 gdb_test "info files" "\r\nLocal core dump file:\r\n.*" "attach: sanity check we see the core file"
310 gdb_test "attach $pid" "Attaching to process $pid\r\n.*" "attach: with core"
312 set test "attach: core file is cleared"
313 gdb_test_multiple "info files" $test {
314 -re "\r\nLocal core dump file:\r\n.*\r\n$gdb_prompt $" {
317 -re "\r\n$gdb_prompt $" {
328 # Test warning-free core file load. E.g., a Linux vDSO used to
329 # trigger this warning:
330 # warning: Can't read pathname
for load map
: Input
/output error.
332 # When testing in a docker container using the AUFS storage driver
,
333 # the kernel places host paths in the core file
's NT_FILE note. XFAIL
334 # this case since these paths make no sense in the container.
336 clean_restart ${testfile}
338 set test "core-file warning-free"
339 gdb_test_multiple "core-file $corefile" $test {
340 -re "warning: Can\'t open file.*\/docker\/aufs\/.*\r\n$gdb_prompt $" {
343 -re "warning: .*\r\n.*\r\n$gdb_prompt $" {
346 -re "\r\n$gdb_prompt $" {