1 # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2004
2 # Free Software Foundation, Inc.
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.
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.
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.
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
21 # This file is based on corefile.exp which was written by Fred
22 # Fish. (fnf@cygnus.com)
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.
35 untested "Remote system"
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
44 if { [istarget "*-*-*bsd*"]
45 || [istarget "*-*-hpux*"]
46 || [istarget "*-*-solaris*"] } {
47 untested "Kernel lacks sparse corefile support (PR gdb/1551)"
51 set testfile "bigcore"
52 set srcfile ${testfile}.c
53 set binfile ${objdir}/${subdir}/${testfile}
54 set corefile ${objdir}/${subdir}/${testfile}.corefile
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."
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.
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.
71 set coredir "${objdir}/${subdir}/coredir.[getpid]"
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"
81 # Try to clean up after ourselves.
82 remote_file build delete [file join $coredir coremmap.data]
83 remote_exec build "rmdir $coredir"
86 warning "can't generate a core file - core tests suppressed - check ulimit -c"
90 # Run GDB on the bigcore program up-to where it will dump core.
94 gdb_reinitialize_dir $srcdir/$subdir
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 {
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.*"
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.
114 if {[catch {file size $corefile} core_size] == 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"
121 -re " = 0\r\n$gdb_prompt $" {
122 xfail "check core size (system does not support large corefiles)"
130 # Traverse part of bigcore's linked list of memory chunks (forward or
131 # backward), saving each chunk's address.
133 proc extract_heap { dir } {
137 set test "extract ${dir} heap"
139 gdb_test_multiple "print heap.${dir}" "$test" {
140 -re " = \\(struct list \\*\\) 0x0.*$gdb_prompt $" {
143 -re " = \\(struct list \\*\\) (0x\[0-9a-f\]*).*$gdb_prompt $" {
144 set heap [concat $heap $expect_out(1,string)]
146 pass "$test (stop at $lim)"
149 send_gdb "print \$.${dir}\n"
153 -re ".*$gdb_prompt $" {
154 fail "$test (entry $lim)"
157 fail "$test (timeout)"
162 set next_heap [extract_heap next]
163 set prev_heap [extract_heap prev]
165 # Now load up that core file
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. " {
173 -re "Core was generated by.*$gdb_prompt $" {
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
184 proc check_heap { dir heap } {
186 set test "check ${dir} heap"
189 send_gdb "print heap.${dir}\n"
192 -re " = \\(struct list \\*\\) [lindex $heap $lim].*$gdb_prompt $" {
193 if { $lim >= [llength $heap] } {
198 send_gdb "print \$.${dir}\n"
201 -re ".*$gdb_prompt $" {
202 fail "$test (address [lindex $heap $lim])"
206 fail "$test (timeout)"
213 check_heap next $next_heap
214 check_heap prev $prev_heap