]>
Commit | Line | Data |
---|---|---|
2d822687 AC |
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 | ||
15f7b60e MK |
44 | if { [istarget "*-*-*bsd*"] |
45 | || [istarget "*-*-hpux*"] | |
46 | || [istarget "*-*-solaris*"] } { | |
2d822687 AC |
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 | # Traverse part of bigcore's linked list of memory chunks (forward or | |
109 | # backward), saving each chunk's address. I don't know why but | |
110 | # expect_out didn't work with gdb_test_multiple. | |
111 | ||
112 | proc extract_heap { dir } { | |
113 | global gdb_prompt | |
114 | global expect_out | |
115 | set heap "" | |
116 | set test "extract ${dir} heap" | |
117 | set lim 0 | |
118 | send_gdb "print heap.${dir}\n" | |
119 | gdb_expect { | |
120 | -re " = \\(struct list \\*\\) 0x0.*$gdb_prompt $" { | |
121 | pass "$test" | |
122 | } | |
123 | -re " = \\(struct list \\*\\) (0x\[0-9a-f\]*).*$gdb_prompt $" { | |
124 | set heap [concat $heap $expect_out(1,string)] | |
125 | if { $lim >= 50 } { | |
126 | pass "$test (stop at $lim)" | |
127 | } else { | |
128 | incr lim | |
129 | send_gdb "print \$.${dir}\n" | |
130 | exp_continue | |
131 | } | |
132 | } | |
133 | -re ".*$gdb_prompt $" { | |
134 | fail "$test (entry $lim)" | |
135 | } | |
136 | timeout { | |
137 | fail "$test (timeout)" | |
138 | } | |
139 | } | |
140 | return $heap; | |
141 | } | |
142 | set next_heap [extract_heap next] | |
143 | set prev_heap [extract_heap prev] | |
144 | ||
145 | # Now load up that core file | |
146 | ||
147 | set test "load corefile" | |
148 | gdb_test_multiple "core $corefile" "$test" { | |
149 | -re "A program is being debugged already. Kill it. .y or n. " { | |
150 | send_gdb "y\n" | |
151 | exp_continue | |
152 | } | |
153 | -re "Core was generated by.*$gdb_prompt $" { | |
154 | pass "$test" | |
155 | } | |
156 | } | |
157 | ||
158 | # Finally, re-traverse bigcore's linked list, checking each chunk's | |
159 | # address against the executable. Don't use gdb_test_multiple as want | |
160 | # only one pass/fail. Don't use exp_continue as the regular | |
161 | # expression involving $heap needs to be re-evaluated for each new | |
162 | # response. | |
163 | ||
164 | proc check_heap { dir heap } { | |
165 | global gdb_prompt | |
166 | set test "check ${dir} heap" | |
167 | set ok 1 | |
168 | set lim 0 | |
169 | send_gdb "print heap.${dir}\n" | |
170 | while { $ok } { | |
171 | gdb_expect { | |
172 | -re " = \\(struct list \\*\\) [lindex $heap $lim].*$gdb_prompt $" { | |
173 | if { $lim >= [llength $heap] } { | |
174 | pass "$test" | |
175 | set ok 0 | |
176 | } else { | |
177 | incr lim | |
178 | send_gdb "print \$.${dir}\n" | |
179 | } | |
180 | } | |
181 | -re ".*$gdb_prompt $" { | |
182 | fail "$test (address [lindex $heap $lim])" | |
183 | set ok 0 | |
184 | } | |
185 | timeout { | |
186 | fail "$test (timeout)" | |
187 | set ok 0 | |
188 | } | |
189 | } | |
190 | } | |
191 | } | |
192 | ||
193 | check_heap next $next_heap | |
194 | check_heap prev $prev_heap |