]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/bigcore.exp
* gdb.base/bigcore.exp: Bail out on *BSD instead of only NetBSD.
[thirdparty/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 untested "Kernel lacks sparse corefile support (PR gdb/1551)"
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 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
56 }
57
58 # Create a core file named "TESTFILE.corefile" rather than just
59 # "core", to avoid problems with sys admin types that like to
60 # regularly prune all files named "core" from the system.
61
62 # Some systems append "core" to the name of the program; others append
63 # the name of the program to "core"; still others (like Linux, as of
64 # May 2003) create cores named "core.PID". In the latter case, we
65 # could have many core files lying around, and it may be difficult to
66 # tell which one is ours, so let's run the program in a subdirectory.
67
68 set found 0
69 set coredir "${objdir}/${subdir}/coredir.[getpid]"
70 file mkdir $coredir
71 catch "system \"(cd ${coredir}; ${binfile}; true) >/dev/null 2>&1\""
72 set names [glob -nocomplain -directory $coredir *core*]
73 if {[llength $names] == 1} {
74 set file [file join $coredir [lindex $names 0]]
75 remote_exec build "mv $file $corefile"
76 set found 1
77 }
78
79 # Try to clean up after ourselves.
80 remote_file build delete [file join $coredir coremmap.data]
81 remote_exec build "rmdir $coredir"
82
83 if { $found == 0 } {
84 warning "can't generate a core file - core tests suppressed - check ulimit -c"
85 return 0
86 }
87
88 # Run GDB on the bigcore program up-to where it will dump core.
89
90 gdb_exit
91 gdb_start
92 gdb_reinitialize_dir $srcdir/$subdir
93 gdb_load ${binfile}
94 gdb_test "set print sevenbit-strings" "" \
95 "set print sevenbit-strings; ${testfile}"
96 gdb_test "set width 0" "" \
97 "set width 0; ${testfile}"
98 if { ![runto_main] } then {
99 gdb_suppress_tests;
100 }
101 set print_core_line [gdb_get_line_number "Dump core"]
102 gdb_test "tbreak $print_core_line"
103 gdb_test continue ".*print_string.*"
104 gdb_test next ".*0 = 0.*"
105
106 # Traverse part of bigcore's linked list of memory chunks (forward or
107 # backward), saving each chunk's address. I don't know why but
108 # expect_out didn't work with gdb_test_multiple.
109
110 proc extract_heap { dir } {
111 global gdb_prompt
112 global expect_out
113 set heap ""
114 set test "extract ${dir} heap"
115 set lim 0
116 send_gdb "print heap.${dir}\n"
117 gdb_expect {
118 -re " = \\(struct list \\*\\) 0x0.*$gdb_prompt $" {
119 pass "$test"
120 }
121 -re " = \\(struct list \\*\\) (0x\[0-9a-f\]*).*$gdb_prompt $" {
122 set heap [concat $heap $expect_out(1,string)]
123 if { $lim >= 50 } {
124 pass "$test (stop at $lim)"
125 } else {
126 incr lim
127 send_gdb "print \$.${dir}\n"
128 exp_continue
129 }
130 }
131 -re ".*$gdb_prompt $" {
132 fail "$test (entry $lim)"
133 }
134 timeout {
135 fail "$test (timeout)"
136 }
137 }
138 return $heap;
139 }
140 set next_heap [extract_heap next]
141 set prev_heap [extract_heap prev]
142
143 # Now load up that core file
144
145 set test "load corefile"
146 gdb_test_multiple "core $corefile" "$test" {
147 -re "A program is being debugged already. Kill it. .y or n. " {
148 send_gdb "y\n"
149 exp_continue
150 }
151 -re "Core was generated by.*$gdb_prompt $" {
152 pass "$test"
153 }
154 }
155
156 # Finally, re-traverse bigcore's linked list, checking each chunk's
157 # address against the executable. Don't use gdb_test_multiple as want
158 # only one pass/fail. Don't use exp_continue as the regular
159 # expression involving $heap needs to be re-evaluated for each new
160 # response.
161
162 proc check_heap { dir heap } {
163 global gdb_prompt
164 set test "check ${dir} heap"
165 set ok 1
166 set lim 0
167 send_gdb "print heap.${dir}\n"
168 while { $ok } {
169 gdb_expect {
170 -re " = \\(struct list \\*\\) [lindex $heap $lim].*$gdb_prompt $" {
171 if { $lim >= [llength $heap] } {
172 pass "$test"
173 set ok 0
174 } else {
175 incr lim
176 send_gdb "print \$.${dir}\n"
177 }
178 }
179 -re ".*$gdb_prompt $" {
180 fail "$test (address [lindex $heap $lim])"
181 set ok 0
182 }
183 timeout {
184 fail "$test (timeout)"
185 set ok 0
186 }
187 }
188 }
189 }
190
191 check_heap next $next_heap
192 check_heap prev $prev_heap