* lib/gdb.exp (gdb_test): Between $pattern and $prompt, expect
[binutils-gdb.git] / gdb / testsuite / gdb.base / corefile.exp
1 # Copyright (C) 1992, 1993, 1994, 1995 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 2 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, write to the Free Software
15 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 # This file was written by Fred Fish. (fnf@cygnus.com)
21
22 if $tracelevel then {
23 strace $tracelevel
24 }
25
26 set prms_id 0
27 set bug_id 0
28
29 # are we on a target board
30 if ![isnative] then {
31 warning "corefile test case can't run on a target system"
32 return
33 }
34
35
36 set binfile "coremaker"
37 set srcfile $binfile.c
38
39 if ![file exists $objdir/$subdir/$binfile] then {
40 perror "$objdir/$subdir/$binfile does not exist."
41 return 0
42 }
43
44 if ![file exists $objdir/$subdir/corefile] then {
45 # Create a core file named "corefile" rather than just "core", to
46 # avoid problems with sys admin types that like to regularly prune all
47 # files named "core" from the system.
48 #
49 # Some systems append "core" to the name of the program; others append
50 # the name of the program to "core".
51
52 catch "system \"cd $objdir/$subdir; ./$binfile\""
53 if [file exists $objdir/$subdir/core] then {
54 catch "exec mv $objdir/$subdir/core $objdir/$subdir/corefile"
55 } elseif [file exists $objdir/$subdir/core.$binfile] {
56 catch "exec mv $objdir/$subdir/core.$binfile $objdir/$subdir/corefile"
57 } elseif [file exists $objdir/$subdir/$binfile.core] {
58 catch "exec mv $objdir/$subdir/$binfile.core $objdir/$subdir/corefile"
59 }
60 }
61
62 #
63 # Test that we can simply startup with a "-core=corefile" command line arg
64 # and recognize that the core file is a valid, usable core file.
65 # To do this, we must shutdown the currently running gdb and restart
66 # with the -core args. We can't use gdb_start because it looks for
67 # the first gdb prompt, and the message we are looking for occurs
68 # before the first prompt. Also, we can't include GDBFLAGS because
69 # if it is empty, this confuses gdb with an empty argument that it
70 # grumbles about (said grumbling currently being ignored in gdb_start).
71 # **FIXME**
72 #
73
74 gdb_exit
75 if $verbose>1 then {
76 send_user "Spawning $GDB -nw $GDBFLAGS -core=$objdir/$subdir/corefile\n"
77 }
78
79 # The RS/6000 gdb doesn't know how to extract the file name and
80 # terminating signal from the core file, so all these tests are
81 # expected to fail.
82
83 setup_xfail "rs6000-*-*"
84 set oldtimeout $timeout
85 set timeout [expr "$timeout + 60"]
86 eval "spawn $GDB -nw $GDBFLAGS -core=$objdir/$subdir/corefile"
87 expect {
88 -re "Core was generated by .*coremaker.*\r
89 \#0 .*\(\).*\r
90 $prompt $" { pass "args: -core=corefile" }
91 -re ".*$prompt $" { fail "args: -core=corefile" }
92 timeout { fail "(timeout) starting with -core" }
93 }
94
95
96 #
97 # Test that startup with both an executable file and -core argument.
98 # See previous comments above, they are still applicable.
99 #
100
101 gdb_exit
102 if $verbose>1 then {
103 send_user "Spawning $GDB -nw $GDBFLAGS $objdir/$subdir/$binfile -core=$objdir/$subdir/corefile\n"
104 }
105
106
107 setup_xfail "rs6000-*-*"
108 # This fails in p3, but not in devo.
109 spawn $GDB -nw $GDBFLAGS $objdir/$subdir/$binfile -core=$objdir/$subdir/corefile
110 expect {
111 -re "Core was generated by .*coremaker.*\r
112 \#0 .*\(\).*\r
113 $prompt $" { pass "args: execfile -core=corefile" }
114 -re ".*$prompt $" { fail "args: execfile -core=corefile" }
115 timeout { fail "(timeout) starting with -core" }
116 }
117 set timeout $oldtimeout
118
119
120 # Now restart normally.
121
122 gdb_exit
123 gdb_start
124 gdb_reinitialize_dir $srcdir/$subdir
125 gdb_load $objdir/$subdir/$binfile
126
127 # Test basic corefile recognition via core-file command.
128
129 setup_xfail "rs6000-*-*"
130 send "core-file $objdir/$subdir/corefile\n"
131 expect {
132 -re "Core was generated by .*coremaker.*\r
133 \#0 .*\(\).*\r
134 $prompt $" { pass "core-file command" }
135 -re ".*$prompt $" { fail "core-file command" }
136 timeout { fail "(timeout) core-file command" }
137 }
138
139 # test reinit_frame_cache
140
141 gdb_load $objdir/$subdir/$binfile
142 setup_xfail "*-*-*"
143 gdb_test "up" "#\[0-9\]* *\[0-9xa-fH'\]* in .* \\(\\)"
144
145 gdb_test "core" "No core file now."