* top.c (print_gdb_version): Update copyright year.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / corefile.exp
1 # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2007, 2008
2 # Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 # This file was written by Fred Fish. (fnf@cygnus.com)
18
19 if $tracelevel then {
20 strace $tracelevel
21 }
22
23 set prms_id 0
24 set bug_id 0
25
26 # are we on a target board
27 if ![isnative] then {
28 return
29 }
30
31 set testfile "coremaker"
32 set srcfile ${testfile}.c
33 set binfile ${objdir}/${subdir}/${testfile}
34 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
35 untested corefile.exp
36 return -1
37 }
38
39 # Create and source the file that provides information about the compiler
40 # used to compile the test case.
41 if [get_compiler_info ${binfile}] {
42 return -1;
43 }
44
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 # Arbitrarily try setting the core size limit to "unlimited" since
50 # this does not hurt on systems where the command does not work and
51 # allows us to generate a core on systems where it does.
52 #
53 # Some systems append "core" to the name of the program; others append
54 # the name of the program to "core"; still others (like Linux, as of
55 # May 2003) create cores named "core.PID". In the latter case, we
56 # could have many core files lying around, and it may be difficult to
57 # tell which one is ours, so let's run the program in a subdirectory.
58 set found 0
59 set coredir "${objdir}/${subdir}/coredir.[getpid]"
60 file mkdir $coredir
61 catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile}; true) >/dev/null 2>&1\""
62 # remote_exec host "${binfile}"
63 foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
64 if [remote_file build exists $i] {
65 remote_exec build "mv $i ${objdir}/${subdir}/corefile"
66 set found 1
67 }
68 }
69 # Check for "core.PID".
70 if { $found == 0 } {
71 set names [glob -nocomplain -directory $coredir core.*]
72 if {[llength $names] == 1} {
73 set corefile [file join $coredir [lindex $names 0]]
74 remote_exec build "mv $corefile ${objdir}/${subdir}/corefile"
75 set found 1
76 }
77 }
78 if { $found == 0 } {
79 # The braindamaged HPUX shell quits after the ulimit -c above
80 # without executing ${binfile}. So we try again without the
81 # ulimit here if we didn't find a core file above.
82 # Oh, I should mention that any "braindamaged" non-Unix system has
83 # the same problem. I like the cd bit too, it's really neat'n stuff.
84 catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\""
85 foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" {
86 if [remote_file build exists $i] {
87 remote_exec build "mv $i ${objdir}/${subdir}/corefile"
88 set found 1
89 }
90 }
91 }
92
93 # Try to clean up after ourselves.
94 remote_file build delete [file join $coredir coremmap.data]
95 remote_exec build "rmdir $coredir"
96
97 if { $found == 0 } {
98 warning "can't generate a core file - core tests suppressed - check ulimit -c"
99 return 0
100 }
101
102 #
103 # Test that we can simply startup with a "-core=corefile" command line arg
104 # and recognize that the core file is a valid, usable core file.
105 # To do this, we must shutdown the currently running gdb and restart
106 # with the -core args. We can't use gdb_start because it looks for
107 # the first gdb prompt, and the message we are looking for occurs
108 # before the first prompt.
109 #
110 # Another problem is that on some systems (solaris for example), there
111 # is apparently a limit on the length of a fully specified path to
112 # the coremaker executable, at about 80 chars. For this case, consider
113 # it a pass, but note that the program name is bad.
114
115 gdb_exit
116 if $verbose>1 then {
117 send_user "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS -core=$objdir/$subdir/corefile\n"
118 }
119
120 set oldtimeout $timeout
121 set timeout [expr "$timeout + 60"]
122 verbose "Timeout is now $timeout seconds" 2
123 eval "spawn $GDB $INTERNAL_GDBFLAGS $GDBFLAGS -core=$objdir/$subdir/corefile"
124 expect {
125 -re "Couldn't find .* registers in core file.*$gdb_prompt $" {
126 fail "args: -core=corefile (couldn't find regs)"
127 }
128 -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
129 pass "args: -core=corefile"
130 }
131 -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
132 pass "args: -core=corefile (with bad program name)"
133 }
134 -re ".*registers from core file: File in wrong format.* $" {
135 fail "args: -core=corefile (could not read registers from core file)"
136 }
137 -re ".*$gdb_prompt $" { fail "args: -core=corefile" }
138 timeout { fail "(timeout) starting with -core" }
139 }
140
141
142 #
143 # Test that startup with both an executable file and -core argument.
144 # See previous comments above, they are still applicable.
145 #
146
147 close;
148
149 if $verbose>1 then {
150 send_user "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $binfile -core=$objdir/$subdir/corefile\n"
151 }
152
153
154 eval "spawn $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $binfile -core=$objdir/$subdir/corefile";
155 expect {
156 -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
157 pass "args: execfile -core=corefile"
158 }
159 -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
160 pass "args: execfile -core=corefile (with bad program name)"
161 }
162 -re ".*registers from core file: File in wrong format.* $" {
163 fail "args: execfile -core=corefile (could not read registers from core file)"
164 }
165 -re ".*$gdb_prompt $" { fail "args: execfile -core=corefile" }
166 timeout { fail "(timeout) starting with -core" }
167 }
168 set timeout $oldtimeout
169 verbose "Timeout is now $timeout seconds" 2
170
171 close;
172
173 # Now restart normally.
174
175 gdb_start
176 gdb_reinitialize_dir $srcdir/$subdir
177 gdb_load ${binfile}
178
179 # Test basic corefile recognition via core-file command.
180
181 send_gdb "core-file $objdir/$subdir/corefile\n"
182 gdb_expect {
183 -re ".* program is being debugged already.*y or n. $" {
184 # gdb_load may connect us to a gdbserver.
185 send_gdb "y\n"
186 exp_continue;
187 }
188 -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
189 pass "core-file command"
190 }
191 -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
192 pass "core-file command (with bad program name)"
193 }
194 -re ".*registers from core file: File in wrong format.* $" {
195 fail "core-file command (could not read registers from core file)"
196 }
197 -re ".*$gdb_prompt $" { fail "core-file command" }
198 timeout { fail "(timeout) core-file command" }
199 }
200
201 # Test correct mapping of corefile sections by printing some variables.
202
203 gdb_test "print coremaker_data" "\\\$$decimal = 202"
204 gdb_test "print coremaker_bss" "\\\$$decimal = 10"
205 gdb_test "print coremaker_ro" "\\\$$decimal = 201"
206
207 gdb_test "print func2::coremaker_local" "\\\$$decimal = \\{0, 1, 2, 3, 4\\}"
208
209 # Somehow we better test the ability to read the registers out of the core
210 # file correctly. I don't think the other tests do this.
211
212 gdb_test "bt" "abort.*func2.*func1.*main.*" "backtrace in corefile.exp"
213 gdb_test "up" "#\[0-9\]* *\[0-9xa-fH'\]* in .* \\(.*\\).*" "up in corefile.exp"
214
215 # Test ability to read mmap'd data
216
217 gdb_test "x/8bd buf1" ".*:.*0.*1.*2.*3.*4.*5.*6.*7" "accessing original mmap data in core file"
218 setup_xfail "*-*-sunos*" "*-*-ultrix*" "*-*-aix*"
219 set test "accessing mmapped data in core file"
220 gdb_test_multiple "x/8bd buf2" "$test" {
221 -re ".*:.*0.*1.*2.*3.*4.*5.*6.*7.*$gdb_prompt $" {
222 pass "$test"
223 }
224 -re "0x\[f\]*:.*Cannot access memory at address 0x\[f\]*.*$gdb_prompt $" {
225 fail "$test (mapping failed at runtime)"
226 }
227 -re "0x.*:.*Cannot access memory at address 0x.*$gdb_prompt $" {
228 fail "$test (mapping address not found in core file)"
229 }
230 }
231
232 # test reinit_frame_cache
233
234 gdb_load ${binfile}
235 gdb_test "up" "#\[0-9\]* *\[0-9xa-fH'\]* in .* \\(.*\\).*" "up in corefile.exp (reinit)"
236
237 gdb_test "core" "No core file now."
This page took 0.081995 seconds and 5 git commands to generate.