]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/corefile.exp
Copyright year update in most files of the GDB Project.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / corefile.exp
1 # Copyright 1992-2000, 2007-2012 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 if $tracelevel then {
19 strace $tracelevel
20 }
21
22
23 # are we on a target board
24 if ![isnative] then {
25 return
26 }
27
28 set testfile "coremaker"
29 set srcfile ${testfile}.c
30 set binfile ${objdir}/${subdir}/${testfile}
31 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
32 untested corefile.exp
33 return -1
34 }
35
36 # Create and source the file that provides information about the compiler
37 # used to compile the test case.
38 if [get_compiler_info ${binfile}] {
39 return -1;
40 }
41
42 set corefile [core_find $binfile {coremmap.data}]
43 if {$corefile == ""} {
44 return 0
45 }
46
47 # Test that we can simply startup with a "-core=$corefile" command line arg
48 # and recognize that the core file is a valid, usable core file.
49 # To do this, we must shutdown the currently running gdb and restart
50 # with the -core args. We can't use gdb_start because it looks for
51 # the first gdb prompt, and the message we are looking for occurs
52 # before the first prompt.
53 #
54 # Another problem is that on some systems (solaris for example), there
55 # is apparently a limit on the length of a fully specified path to
56 # the coremaker executable, at about 80 chars. For this case, consider
57 # it a pass, but note that the program name is bad.
58
59 gdb_exit
60 if $verbose>1 then {
61 send_user "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS -core=$corefile\n"
62 }
63
64 set oldtimeout $timeout
65 set timeout [expr "$timeout + 60"]
66 verbose "Timeout is now $timeout seconds" 2
67 eval "spawn $GDB $INTERNAL_GDBFLAGS $GDBFLAGS -core=$corefile"
68 expect {
69 -re "Couldn't find .* registers in core file.*$gdb_prompt $" {
70 fail "args: -core=[file tail $corefile] (couldn't find regs)"
71 }
72 -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
73 pass "args: -core=[file tail $corefile]"
74 }
75 -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
76 pass "args: -core=[file tail $corefile] (with bad program name)"
77 }
78 -re ".*registers from core file: File in wrong format.* $" {
79 fail "args: -core=[file tail $corefile] (could not read registers from core file)"
80 }
81 -re ".*$gdb_prompt $" { fail "args: -core=[file tail $corefile]" }
82 timeout { fail "(timeout) starting with -core" }
83 }
84
85
86 #
87 # Test that startup with both an executable file and -core argument.
88 # See previous comments above, they are still applicable.
89 #
90
91 close;
92
93 if $verbose>1 then {
94 send_user "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $binfile -core=$corefile\n"
95 }
96
97
98 eval "spawn $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $binfile -core=$corefile";
99 expect {
100 -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
101 pass "args: execfile -core=[file tail $corefile]"
102 }
103 -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
104 pass "args: execfile -core=[file tail $corefile] (with bad program name)"
105 }
106 -re ".*registers from core file: File in wrong format.* $" {
107 fail "args: execfile -core=[file tail $corefile] (could not read registers from core file)"
108 }
109 -re ".*$gdb_prompt $" { fail "args: execfile -core=[file tail $corefile]" }
110 timeout { fail "(timeout) starting with -core" }
111 }
112 set timeout $oldtimeout
113 verbose "Timeout is now $timeout seconds" 2
114
115 close;
116
117 # Now restart normally.
118
119 gdb_start
120 gdb_reinitialize_dir $srcdir/$subdir
121 gdb_load ${binfile}
122
123 # Test basic corefile recognition via core-file command.
124
125 gdb_test_multiple "core-file $corefile" "core-file command" {
126 -re ".* program is being debugged already.*y or n. $" {
127 # gdb_load may connect us to a gdbserver.
128 send_gdb "y\n"
129 exp_continue;
130 }
131 -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
132 pass "core-file command"
133 }
134 -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
135 pass "core-file command (with bad program name)"
136 }
137 -re ".*registers from core file: File in wrong format.* $" {
138 fail "core-file command (could not read registers from core file)"
139 }
140 }
141
142 # Test correct mapping of corefile sections by printing some variables.
143
144 gdb_test "print coremaker_data" "\\\$$decimal = 202"
145 gdb_test "print coremaker_bss" "\\\$$decimal = 10"
146 gdb_test "print coremaker_ro" "\\\$$decimal = 201"
147
148 gdb_test "print func2::coremaker_local" "\\\$$decimal = \\{0, 1, 2, 3, 4\\}"
149
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.
152
153 gdb_test "bt" "abort.*func2.*func1.*main.*" "backtrace in corefile.exp"
154 gdb_test "up" "#\[0-9\]* *\[0-9xa-fH'\]* in .* \\(.*\\).*" "up in corefile.exp"
155
156 # Test ability to read mmap'd data
157
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*" "*-*-ultrix*" "*-*-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 $" {
163 pass "$test"
164 }
165 -re "0x\[f\]*:.*Cannot access memory at address 0x\[f\]*.*$gdb_prompt $" {
166 fail "$test (mapping failed at runtime)"
167 }
168 -re "0x.*:.*Cannot access memory at address 0x.*$gdb_prompt $" {
169 fail "$test (mapping address not found in core file)"
170 }
171 }
172
173 # test reinit_frame_cache
174
175 gdb_load ${binfile}
176 gdb_test "up" "#\[0-9\]* *\[0-9xa-fH'\]* in .* \\(.*\\).*" "up in corefile.exp (reinit)"
177
178 gdb_test "core" "No core file now."
179
180
181 # Test a run (start) command will clear any loaded core file.
182
183 gdb_test "core-file $corefile" "Core was generated by .*" "run: load core again"
184 gdb_test "info files" "\r\nLocal core dump file:\r\n.*" "run: sanity check we see the core file"
185
186 set test "run: with core"
187 if [runto_main] {
188 pass $test
189 } else {
190 fail $test
191 }
192
193 set test "run: core file is cleared"
194 gdb_test_multiple "info files" $test {
195 -re "\r\nLocal core dump file:\r\n.*\r\n$gdb_prompt $" {
196 fail $test
197 }
198 -re "\r\n$gdb_prompt $" {
199 pass $test
200 }
201 }
202
203 set test "quit with a process"
204 gdb_test_multiple "quit" $test {
205 -re "A debugging session is active.\r\n.*\r\nQuit anyway\\? \\(y or n\\) $" {
206 pass $test
207 gdb_test "n" {Not confirmed\.} "quit with processes: n"
208 }
209 }
210
211 gdb_exit
212
213 # Verify there is no question if only a core file is loaded.
214
215 gdb_start
216 gdb_test "core-file $corefile" "Core was generated by .*" "no question: load core"
217
218 set test "quit with a core file"
219 gdb_test_multiple "quit" $test {
220 -re "A debugging session is active.\r\n.*\r\nQuit anyway\\? \\(y or n\\) $" {
221 fail $test
222 gdb_test "n" {Not confirmed\.} "quit with processes: n"
223 }
224 eof {
225 pass $test
226 }
227 }
228
229 gdb_exit
230
231 # Test an attach command will clear any loaded core file.
232
233 if ![is_remote target] {
234 set test "attach: spawn sleep"
235 set res [remote_spawn host "$binfile sleep"];
236 if { $res < 0 || $res == "" } {
237 fail $test
238 return
239 }
240 set pid [exp_pid -i $res]
241 # We don't care whether the program is still in the startup phase when we
242 # attach.
243
244 gdb_start
245
246 gdb_test "core-file $corefile" "Core was generated by .*" "attach: load core again"
247 gdb_test "info files" "\r\nLocal core dump file:\r\n.*" "attach: sanity check we see the core file"
248
249 gdb_test "attach $pid" "Attaching to process $pid\r\n.*" "attach: with core"
250
251 set test "attach: core file is cleared"
252 gdb_test_multiple "info files" $test {
253 -re "\r\nLocal core dump file:\r\n.*\r\n$gdb_prompt $" {
254 fail $test
255 }
256 -re "\r\n$gdb_prompt $" {
257 pass $test
258 }
259 }
260
261 gdb_exit
262 }