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