2004-06-07 Randolph Chung <tausq@debian.org>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / bigcore.exp
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
44 if { [istarget "*-*-*bsd*"]
45 || [istarget "*-*-hpux*"]
46 || [istarget "*-*-solaris*"] } {
47 untested "Kernel lacks sparse corefile support (PR gdb/1551)"
48 return
49 }
50
51 set testfile "bigcore"
52 set srcfile ${testfile}.c
53 set binfile ${objdir}/${subdir}/${testfile}
54 set corefile ${objdir}/${subdir}/${testfile}.corefile
55
56 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
57 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
58 }
59
60 # Create a core file named "TESTFILE.corefile" rather than just
61 # "core", to avoid problems with sys admin types that like to
62 # regularly prune all files named "core" from the system.
63
64 # Some systems append "core" to the name of the program; others append
65 # the name of the program to "core"; still others (like Linux, as of
66 # May 2003) create cores named "core.PID". In the latter case, we
67 # could have many core files lying around, and it may be difficult to
68 # tell which one is ours, so let's run the program in a subdirectory.
69
70 set found 0
71 set coredir "${objdir}/${subdir}/coredir.[getpid]"
72 file mkdir $coredir
73 catch "system \"(cd ${coredir}; ${binfile}; true) >/dev/null 2>&1\""
74 set names [glob -nocomplain -directory $coredir *core*]
75 if {[llength $names] == 1} {
76 set file [file join $coredir [lindex $names 0]]
77 remote_exec build "mv $file $corefile"
78 set found 1
79 }
80
81 # Try to clean up after ourselves.
82 remote_file build delete [file join $coredir coremmap.data]
83 remote_exec build "rmdir $coredir"
84
85 if { $found == 0 } {
86 warning "can't generate a core file - core tests suppressed - check ulimit -c"
87 return 0
88 }
89
90 # Run GDB on the bigcore program up-to where it will dump core.
91
92 gdb_exit
93 gdb_start
94 gdb_reinitialize_dir $srcdir/$subdir
95 gdb_load ${binfile}
96 gdb_test "set print sevenbit-strings" "" \
97 "set print sevenbit-strings; ${testfile}"
98 gdb_test "set width 0" "" \
99 "set width 0; ${testfile}"
100 if { ![runto_main] } then {
101 gdb_suppress_tests;
102 }
103 set print_core_line [gdb_get_line_number "Dump core"]
104 gdb_test "tbreak $print_core_line"
105 gdb_test continue ".*print_string.*"
106 gdb_test next ".*0 = 0.*"
107
108 # Check that the corefile is plausibly large enough. We're trying to
109 # detect the case where the operating system has truncated the file
110 # just before signed wraparound. TCL, unfortunately, has a similar
111 # problem - so use catch. It can handle the "bad" size but not necessarily
112 # the "good" one. And we must use GDB for the comparison, similarly.
113
114 if {[catch {file size $corefile} core_size] == 0} {
115 set core_ok 0
116 gdb_test_multiple "print bytes_allocated < $core_size" "check core size" {
117 -re " = 1\r\n$gdb_prompt $" {
118 pass "check core size"
119 set core_ok 1
120 }
121 -re " = 0\r\n$gdb_prompt $" {
122 xfail "check core size (system does not support large corefiles)"
123 }
124 }
125 if {$core_ok == 0} {
126 return 0
127 }
128 }
129
130 # Traverse part of bigcore's linked list of memory chunks (forward or
131 # backward), saving each chunk's address.
132
133 proc extract_heap { dir } {
134 global gdb_prompt
135 global expect_out
136 set heap ""
137 set test "extract ${dir} heap"
138 set lim 0
139 gdb_test_multiple "print heap.${dir}" "$test" {
140 -re " = \\(struct list \\*\\) 0x0.*$gdb_prompt $" {
141 pass "$test"
142 }
143 -re " = \\(struct list \\*\\) (0x\[0-9a-f\]*).*$gdb_prompt $" {
144 set heap [concat $heap $expect_out(1,string)]
145 if { $lim >= 50 } {
146 pass "$test (stop at $lim)"
147 } else {
148 incr lim
149 send_gdb "print \$.${dir}\n"
150 exp_continue
151 }
152 }
153 -re ".*$gdb_prompt $" {
154 fail "$test (entry $lim)"
155 }
156 timeout {
157 fail "$test (timeout)"
158 }
159 }
160 return $heap;
161 }
162 set next_heap [extract_heap next]
163 set prev_heap [extract_heap prev]
164
165 # Now load up that core file
166
167 set test "load corefile"
168 gdb_test_multiple "core $corefile" "$test" {
169 -re "A program is being debugged already. Kill it. .y or n. " {
170 send_gdb "y\n"
171 exp_continue
172 }
173 -re "Core was generated by.*$gdb_prompt $" {
174 pass "$test"
175 }
176 }
177
178 # Finally, re-traverse bigcore's linked list, checking each chunk's
179 # address against the executable. Don't use gdb_test_multiple as want
180 # only one pass/fail. Don't use exp_continue as the regular
181 # expression involving $heap needs to be re-evaluated for each new
182 # response.
183
184 proc check_heap { dir heap } {
185 global gdb_prompt
186 set test "check ${dir} heap"
187 set ok 1
188 set lim 0
189 send_gdb "print heap.${dir}\n"
190 while { $ok } {
191 gdb_expect {
192 -re " = \\(struct list \\*\\) [lindex $heap $lim].*$gdb_prompt $" {
193 if { $lim >= [llength $heap] } {
194 pass "$test"
195 set ok 0
196 } else {
197 incr lim
198 send_gdb "print \$.${dir}\n"
199 }
200 }
201 -re ".*$gdb_prompt $" {
202 fail "$test (address [lindex $heap $lim])"
203 set ok 0
204 }
205 timeout {
206 fail "$test (timeout)"
207 set ok 0
208 }
209 }
210 }
211 }
212
213 check_heap next $next_heap
214 check_heap prev $prev_heap
This page took 0.039341 seconds and 4 git commands to generate.