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