Commit | Line | Data |
---|---|---|
6aba47ca | 1 | # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2004, 2005, |
4c38e0a4 | 2 | # 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
2d822687 AC |
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 |
2d822687 | 7 | # (at your option) any later version. |
e22f8b7c | 8 | # |
2d822687 AC |
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 | # |
2d822687 | 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/>. |
2d822687 | 16 | |
2d822687 AC |
17 | # This file is based on corefile.exp which was written by Fred |
18 | # Fish. (fnf@cygnus.com) | |
19 | ||
20 | if $tracelevel then { | |
21 | strace $tracelevel | |
22 | } | |
23 | ||
2d822687 AC |
24 | |
25 | # Are we on a target board? As of 2004-02-12, GDB didn't have a | |
26 | # mechanism that would let it efficiently access a remote corefile. | |
27 | ||
28 | if ![isnative] then { | |
29 | untested "Remote system" | |
30 | return | |
31 | } | |
32 | ||
33 | # Can the system run this test (in particular support sparse | |
34 | # corefiles)? On systems that lack sparse corefile support this test | |
35 | # consumes too many resources - gigabytes worth of disk space and and | |
36 | # I/O bandwith. | |
37 | ||
15f7b60e MK |
38 | if { [istarget "*-*-*bsd*"] |
39 | || [istarget "*-*-hpux*"] | |
cc984116 | 40 | || [istarget "*-*-solaris*"] |
af589bd0 | 41 | || [istarget "*-*-darwin*"] |
cc984116 | 42 | || [istarget "*-*-cygwin*"] } { |
2d822687 AC |
43 | untested "Kernel lacks sparse corefile support (PR gdb/1551)" |
44 | return | |
45 | } | |
46 | ||
eac69dca JB |
47 | # This testcase causes too much stress (in terms of memory usage) |
48 | # on certain systems... | |
49 | if { [istarget "*-*-*irix*"] } { | |
50 | untested "Testcase too stressful for this system" | |
51 | return | |
52 | } | |
53 | ||
2d822687 AC |
54 | set testfile "bigcore" |
55 | set srcfile ${testfile}.c | |
56 | set binfile ${objdir}/${subdir}/${testfile} | |
57 | set corefile ${objdir}/${subdir}/${testfile}.corefile | |
58 | ||
59 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
b60f0898 JB |
60 | untested bigcore.exp |
61 | return -1 | |
2d822687 AC |
62 | } |
63 | ||
2d822687 AC |
64 | # Run GDB on the bigcore program up-to where it will dump core. |
65 | ||
66 | gdb_exit | |
67 | gdb_start | |
68 | gdb_reinitialize_dir $srcdir/$subdir | |
69 | gdb_load ${binfile} | |
70 | gdb_test "set print sevenbit-strings" "" \ | |
71 | "set print sevenbit-strings; ${testfile}" | |
72 | gdb_test "set width 0" "" \ | |
73 | "set width 0; ${testfile}" | |
74 | if { ![runto_main] } then { | |
75 | gdb_suppress_tests; | |
76 | } | |
77 | set print_core_line [gdb_get_line_number "Dump core"] | |
78 | gdb_test "tbreak $print_core_line" | |
79 | gdb_test continue ".*print_string.*" | |
80 | gdb_test next ".*0 = 0.*" | |
81 | ||
82 | # Traverse part of bigcore's linked list of memory chunks (forward or | |
bf08c2a1 | 83 | # backward), saving each chunk's address. |
2d822687 AC |
84 | |
85 | proc extract_heap { dir } { | |
86 | global gdb_prompt | |
87 | global expect_out | |
88 | set heap "" | |
89 | set test "extract ${dir} heap" | |
90 | set lim 0 | |
bf08c2a1 | 91 | gdb_test_multiple "print heap.${dir}" "$test" { |
2d822687 AC |
92 | -re " = \\(struct list \\*\\) 0x0.*$gdb_prompt $" { |
93 | pass "$test" | |
94 | } | |
95 | -re " = \\(struct list \\*\\) (0x\[0-9a-f\]*).*$gdb_prompt $" { | |
96 | set heap [concat $heap $expect_out(1,string)] | |
6a53b2ec | 97 | if { $lim >= 200 } { |
2d822687 AC |
98 | pass "$test (stop at $lim)" |
99 | } else { | |
100 | incr lim | |
101 | send_gdb "print \$.${dir}\n" | |
102 | exp_continue | |
103 | } | |
104 | } | |
105 | -re ".*$gdb_prompt $" { | |
106 | fail "$test (entry $lim)" | |
107 | } | |
108 | timeout { | |
109 | fail "$test (timeout)" | |
110 | } | |
111 | } | |
112 | return $heap; | |
113 | } | |
114 | set next_heap [extract_heap next] | |
115 | set prev_heap [extract_heap prev] | |
116 | ||
26585198 DJ |
117 | # Save the total allocated size within GDB so that we can check |
118 | # the core size later. | |
119 | gdb_test "set \$bytes_allocated = bytes_allocated" "" "save heap size" | |
120 | ||
4bb3667f AC |
121 | # Now create a core dump |
122 | ||
123 | # Rename the core file to "TESTFILE.corefile" rather than just "core", | |
124 | # to avoid problems with sys admin types that like to regularly prune | |
125 | # all files named "core" from the system. | |
126 | ||
127 | # Some systems append "core" to the name of the program; others append | |
128 | # the name of the program to "core"; still others (like Linux, as of | |
129 | # May 2003) create cores named "core.PID". | |
130 | ||
131 | # Save the process ID. Some systems dump the core into core.PID. | |
132 | set test "grab pid" | |
133 | gdb_test_multiple "info program" $test { | |
134 | -re "child process (\[0-9\]+).*$gdb_prompt $" { | |
135 | set inferior_pid $expect_out(1,string) | |
136 | pass $test | |
137 | } | |
138 | -re "$gdb_prompt $" { | |
139 | set inferior_pid unknown | |
140 | pass $test | |
141 | } | |
142 | } | |
143 | ||
144 | # Dump core using SIGABRT | |
145 | set oldtimeout $timeout | |
146 | set timeout 600 | |
147 | gdb_test "signal SIGABRT" "Program terminated with signal SIGABRT, .*" | |
c593ac0e | 148 | set timeout $oldtimeout |
4bb3667f AC |
149 | |
150 | # Find the corefile | |
151 | set file "" | |
152 | foreach pat [list core.${inferior_pid} ${testfile}.core core] { | |
153 | set names [glob -nocomplain $pat] | |
154 | if {[llength $names] == 1} { | |
155 | set file [lindex $names 0] | |
156 | remote_exec build "mv $file $corefile" | |
157 | break | |
158 | } | |
159 | } | |
160 | ||
161 | if { $file == "" } { | |
162 | untested "Can't generate a core file" | |
163 | return 0 | |
164 | } | |
165 | ||
166 | # Check that the corefile is plausibly large enough. We're trying to | |
167 | # detect the case where the operating system has truncated the file | |
168 | # just before signed wraparound. TCL, unfortunately, has a similar | |
169 | # problem - so use catch. It can handle the "bad" size but not | |
170 | # necessarily the "good" one. And we must use GDB for the comparison, | |
171 | # similarly. | |
172 | ||
4bb3667f | 173 | if {[catch {file size $corefile} core_size] == 0} { |
3c0edcdc | 174 | set core_ok 0 |
26585198 | 175 | gdb_test_multiple "print \$bytes_allocated < $core_size" "check core size" { |
4bb3667f AC |
176 | -re " = 1\r\n$gdb_prompt $" { |
177 | pass "check core size" | |
178 | set core_ok 1 | |
179 | } | |
26585198 DJ |
180 | -re " = 0\r\n$gdb_prompt $" { |
181 | pass "check core size" | |
182 | set core_ok 0 | |
183 | } | |
4bb3667f | 184 | } |
3c0edcdc AC |
185 | } { |
186 | # Probably failed due to the TCL build having problems with very | |
187 | # large values. Since GDB uses a 64-bit off_t (when possible) it | |
188 | # shouldn't have this problem. Assume that things are going to | |
189 | # work. Without this assumption the test is skiped on systems | |
190 | # (such as i386 GNU/Linux with patched kernel) which do pass. | |
191 | pass "check core size" | |
192 | set core_ok 1 | |
4bb3667f | 193 | } |
3c0edcdc | 194 | if {! $core_ok} { |
4bb3667f AC |
195 | untested "check core size (system does not support large corefiles)" |
196 | return 0 | |
197 | } | |
198 | ||
2d822687 AC |
199 | # Now load up that core file |
200 | ||
201 | set test "load corefile" | |
202 | gdb_test_multiple "core $corefile" "$test" { | |
203 | -re "A program is being debugged already. Kill it. .y or n. " { | |
204 | send_gdb "y\n" | |
205 | exp_continue | |
206 | } | |
207 | -re "Core was generated by.*$gdb_prompt $" { | |
208 | pass "$test" | |
209 | } | |
210 | } | |
211 | ||
212 | # Finally, re-traverse bigcore's linked list, checking each chunk's | |
213 | # address against the executable. Don't use gdb_test_multiple as want | |
214 | # only one pass/fail. Don't use exp_continue as the regular | |
215 | # expression involving $heap needs to be re-evaluated for each new | |
216 | # response. | |
217 | ||
218 | proc check_heap { dir heap } { | |
219 | global gdb_prompt | |
220 | set test "check ${dir} heap" | |
221 | set ok 1 | |
222 | set lim 0 | |
223 | send_gdb "print heap.${dir}\n" | |
224 | while { $ok } { | |
225 | gdb_expect { | |
226 | -re " = \\(struct list \\*\\) [lindex $heap $lim].*$gdb_prompt $" { | |
227 | if { $lim >= [llength $heap] } { | |
228 | pass "$test" | |
229 | set ok 0 | |
230 | } else { | |
231 | incr lim | |
232 | send_gdb "print \$.${dir}\n" | |
233 | } | |
234 | } | |
235 | -re ".*$gdb_prompt $" { | |
236 | fail "$test (address [lindex $heap $lim])" | |
237 | set ok 0 | |
238 | } | |
239 | timeout { | |
240 | fail "$test (timeout)" | |
241 | set ok 0 | |
242 | } | |
243 | } | |
244 | } | |
245 | } | |
246 | ||
247 | check_heap next $next_heap | |
248 | check_heap prev $prev_heap |