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