]>
Commit | Line | Data |
---|---|---|
2d822687 AC |
1 | # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2004 |
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 2 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, write to the Free Software | |
16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 | ||
18 | # Please email any bugs, comments, and/or additions to this file to: | |
19 | # bug-gdb@prep.ai.mit.edu | |
20 | ||
21 | # This file is based on corefile.exp which was written by Fred | |
22 | # Fish. (fnf@cygnus.com) | |
23 | ||
24 | if $tracelevel then { | |
25 | strace $tracelevel | |
26 | } | |
27 | ||
28 | set prms_id 0 | |
29 | set bug_id 0 | |
30 | ||
31 | # Are we on a target board? As of 2004-02-12, GDB didn't have a | |
32 | # mechanism that would let it efficiently access a remote corefile. | |
33 | ||
34 | if ![isnative] then { | |
35 | untested "Remote system" | |
36 | return | |
37 | } | |
38 | ||
39 | # Can the system run this test (in particular support sparse | |
40 | # corefiles)? On systems that lack sparse corefile support this test | |
41 | # consumes too many resources - gigabytes worth of disk space and and | |
42 | # I/O bandwith. | |
43 | ||
15f7b60e MK |
44 | if { [istarget "*-*-*bsd*"] |
45 | || [istarget "*-*-hpux*"] | |
cc984116 CV |
46 | || [istarget "*-*-solaris*"] |
47 | || [istarget "*-*-cygwin*"] } { | |
2d822687 AC |
48 | untested "Kernel lacks sparse corefile support (PR gdb/1551)" |
49 | return | |
50 | } | |
51 | ||
eac69dca JB |
52 | # This testcase causes too much stress (in terms of memory usage) |
53 | # on certain systems... | |
54 | if { [istarget "*-*-*irix*"] } { | |
55 | untested "Testcase too stressful for this system" | |
56 | return | |
57 | } | |
58 | ||
2d822687 AC |
59 | set testfile "bigcore" |
60 | set srcfile ${testfile}.c | |
61 | set binfile ${objdir}/${subdir}/${testfile} | |
62 | set corefile ${objdir}/${subdir}/${testfile}.corefile | |
63 | ||
64 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
65 | gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." | |
66 | } | |
67 | ||
2d822687 AC |
68 | # Run GDB on the bigcore program up-to where it will dump core. |
69 | ||
70 | gdb_exit | |
71 | gdb_start | |
72 | gdb_reinitialize_dir $srcdir/$subdir | |
73 | gdb_load ${binfile} | |
74 | gdb_test "set print sevenbit-strings" "" \ | |
75 | "set print sevenbit-strings; ${testfile}" | |
76 | gdb_test "set width 0" "" \ | |
77 | "set width 0; ${testfile}" | |
78 | if { ![runto_main] } then { | |
79 | gdb_suppress_tests; | |
80 | } | |
81 | set print_core_line [gdb_get_line_number "Dump core"] | |
82 | gdb_test "tbreak $print_core_line" | |
83 | gdb_test continue ".*print_string.*" | |
84 | gdb_test next ".*0 = 0.*" | |
85 | ||
86 | # Traverse part of bigcore's linked list of memory chunks (forward or | |
bf08c2a1 | 87 | # backward), saving each chunk's address. |
2d822687 AC |
88 | |
89 | proc extract_heap { dir } { | |
90 | global gdb_prompt | |
91 | global expect_out | |
92 | set heap "" | |
93 | set test "extract ${dir} heap" | |
94 | set lim 0 | |
bf08c2a1 | 95 | gdb_test_multiple "print heap.${dir}" "$test" { |
2d822687 AC |
96 | -re " = \\(struct list \\*\\) 0x0.*$gdb_prompt $" { |
97 | pass "$test" | |
98 | } | |
99 | -re " = \\(struct list \\*\\) (0x\[0-9a-f\]*).*$gdb_prompt $" { | |
100 | set heap [concat $heap $expect_out(1,string)] | |
101 | if { $lim >= 50 } { | |
102 | pass "$test (stop at $lim)" | |
103 | } else { | |
104 | incr lim | |
105 | send_gdb "print \$.${dir}\n" | |
106 | exp_continue | |
107 | } | |
108 | } | |
109 | -re ".*$gdb_prompt $" { | |
110 | fail "$test (entry $lim)" | |
111 | } | |
112 | timeout { | |
113 | fail "$test (timeout)" | |
114 | } | |
115 | } | |
116 | return $heap; | |
117 | } | |
118 | set next_heap [extract_heap next] | |
119 | set prev_heap [extract_heap prev] | |
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, .*" | |
148 | ||
149 | # Find the corefile | |
150 | set file "" | |
151 | foreach pat [list core.${inferior_pid} ${testfile}.core core] { | |
152 | set names [glob -nocomplain $pat] | |
153 | if {[llength $names] == 1} { | |
154 | set file [lindex $names 0] | |
155 | remote_exec build "mv $file $corefile" | |
156 | break | |
157 | } | |
158 | } | |
159 | ||
160 | if { $file == "" } { | |
161 | untested "Can't generate a core file" | |
162 | return 0 | |
163 | } | |
164 | ||
165 | # Check that the corefile is plausibly large enough. We're trying to | |
166 | # detect the case where the operating system has truncated the file | |
167 | # just before signed wraparound. TCL, unfortunately, has a similar | |
168 | # problem - so use catch. It can handle the "bad" size but not | |
169 | # necessarily the "good" one. And we must use GDB for the comparison, | |
170 | # similarly. | |
171 | ||
172 | set core_ok 0 | |
173 | if {[catch {file size $corefile} core_size] == 0} { | |
174 | gdb_test_multiple "print bytes_allocated < $core_size" "check core size" { | |
175 | -re " = 1\r\n$gdb_prompt $" { | |
176 | pass "check core size" | |
177 | set core_ok 1 | |
178 | } | |
179 | } | |
180 | } | |
181 | if {$core_ok == 0} { | |
182 | untested "check core size (system does not support large corefiles)" | |
183 | return 0 | |
184 | } | |
185 | ||
2d822687 AC |
186 | # Now load up that core file |
187 | ||
188 | set test "load corefile" | |
189 | gdb_test_multiple "core $corefile" "$test" { | |
190 | -re "A program is being debugged already. Kill it. .y or n. " { | |
191 | send_gdb "y\n" | |
192 | exp_continue | |
193 | } | |
194 | -re "Core was generated by.*$gdb_prompt $" { | |
195 | pass "$test" | |
196 | } | |
197 | } | |
198 | ||
199 | # Finally, re-traverse bigcore's linked list, checking each chunk's | |
200 | # address against the executable. Don't use gdb_test_multiple as want | |
201 | # only one pass/fail. Don't use exp_continue as the regular | |
202 | # expression involving $heap needs to be re-evaluated for each new | |
203 | # response. | |
204 | ||
205 | proc check_heap { dir heap } { | |
206 | global gdb_prompt | |
207 | set test "check ${dir} heap" | |
208 | set ok 1 | |
209 | set lim 0 | |
210 | send_gdb "print heap.${dir}\n" | |
211 | while { $ok } { | |
212 | gdb_expect { | |
213 | -re " = \\(struct list \\*\\) [lindex $heap $lim].*$gdb_prompt $" { | |
214 | if { $lim >= [llength $heap] } { | |
215 | pass "$test" | |
216 | set ok 0 | |
217 | } else { | |
218 | incr lim | |
219 | send_gdb "print \$.${dir}\n" | |
220 | } | |
221 | } | |
222 | -re ".*$gdb_prompt $" { | |
223 | fail "$test (address [lindex $heap $lim])" | |
224 | set ok 0 | |
225 | } | |
226 | timeout { | |
227 | fail "$test (timeout)" | |
228 | set ok 0 | |
229 | } | |
230 | } | |
231 | } | |
232 | } | |
233 | ||
234 | check_heap next $next_heap | |
235 | check_heap prev $prev_heap |