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