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