• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/gdb/gdb/testsuite/gdb.base/
1# Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2004, 2005,
2# 2007 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 3 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, see <http://www.gnu.org/licenses/>.
16
17# Please email any bugs, comments, and/or additions to this file to:
18# bug-gdb@prep.ai.mit.edu
19
20# This file is based on corefile.exp which was written by Fred
21# Fish. (fnf@cygnus.com)
22
23if $tracelevel then {
24	strace $tracelevel
25}
26
27set prms_id 0
28set bug_id 0
29
30# Are we on a target board?  As of 2004-02-12, GDB didn't have a
31# mechanism that would let it efficiently access a remote corefile.
32
33if ![isnative] then {
34    untested "Remote system"
35    return
36}
37
38# Can the system run this test (in particular support sparse
39# corefiles)?  On systems that lack sparse corefile support this test
40# consumes too many resources - gigabytes worth of disk space and and
41# I/O bandwith.
42
43if { [istarget "*-*-*bsd*"]
44     || [istarget "*-*-hpux*"]
45     || [istarget "*-*-solaris*"]
46     || [istarget "*-*-cygwin*"] } {
47    untested "Kernel lacks sparse corefile support (PR gdb/1551)"
48    return
49}
50
51# This testcase causes too much stress (in terms of memory usage)
52# on certain systems...
53if { [istarget "*-*-*irix*"] } {
54    untested "Testcase too stressful for this system"
55    return
56}
57
58set testfile "bigcore"
59set srcfile ${testfile}.c
60set binfile ${objdir}/${subdir}/${testfile}
61set corefile ${objdir}/${subdir}/${testfile}.corefile
62
63if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
64     untested bigcore.exp
65     return -1
66}
67
68# Run GDB on the bigcore program up-to where it will dump core.
69
70gdb_exit
71gdb_start
72gdb_reinitialize_dir $srcdir/$subdir
73gdb_load ${binfile}
74gdb_test "set print sevenbit-strings" "" \
75	"set print sevenbit-strings; ${testfile}"
76gdb_test "set width 0" "" \
77	"set width 0; ${testfile}"
78if { ![runto_main] } then {
79    gdb_suppress_tests;
80}
81set print_core_line [gdb_get_line_number "Dump core"]
82gdb_test "tbreak $print_core_line"
83gdb_test continue ".*print_string.*"
84gdb_test next ".*0 = 0.*"
85
86# Traverse part of bigcore's linked list of memory chunks (forward or
87# backward), saving each chunk's address.
88
89proc extract_heap { dir } {
90    global gdb_prompt
91    global expect_out
92    set heap ""
93    set test "extract ${dir} heap"
94    set lim 0
95    gdb_test_multiple "print heap.${dir}" "$test" {
96	-re " = \\(struct list \\*\\) 0x0.*$gdb_prompt $" {
97	    pass "$test"
98	}
99	-re " = \\(struct list \\*\\) (0x\[0-9a-f\]*).*$gdb_prompt $" {
100	    set heap [concat $heap $expect_out(1,string)]
101	    if { $lim >= 50 } {
102		pass "$test (stop at $lim)"
103	    } else {
104		incr lim
105		send_gdb "print \$.${dir}\n"
106		exp_continue
107	    }
108	}
109	-re ".*$gdb_prompt $" {
110	    fail "$test (entry $lim)"
111	}
112	timeout {
113	    fail "$test (timeout)"
114	}
115    }
116    return $heap;
117}
118set next_heap [extract_heap next]
119set prev_heap [extract_heap prev]
120
121# Save the total allocated size within GDB so that we can check
122# the core size later.
123gdb_test "set \$bytes_allocated = bytes_allocated" "" "save heap size"
124
125# Now create a core dump
126
127# Rename the core file to "TESTFILE.corefile" rather than just "core",
128# to avoid problems with sys admin types that like to regularly prune
129# all files named "core" from the system.
130
131# Some systems append "core" to the name of the program; others append
132# the name of the program to "core"; still others (like Linux, as of
133# May 2003) create cores named "core.PID".
134
135# Save the process ID.  Some systems dump the core into core.PID.
136set test "grab pid"
137gdb_test_multiple "info program" $test {
138    -re "child process (\[0-9\]+).*$gdb_prompt $" {
139	set inferior_pid $expect_out(1,string)
140	pass $test
141    }
142    -re "$gdb_prompt $" {
143	set inferior_pid unknown
144	pass $test
145    }
146}
147
148# Dump core using SIGABRT
149set oldtimeout $timeout
150set timeout 600
151gdb_test "signal SIGABRT" "Program terminated with signal SIGABRT, .*"
152
153# Find the corefile
154set file ""
155foreach pat [list core.${inferior_pid} ${testfile}.core core] {
156    set names [glob -nocomplain $pat]
157    if {[llength $names] == 1} {
158	set file [lindex $names 0]
159	remote_exec build "mv $file $corefile"
160	break
161    }
162}
163
164if { $file == "" } {
165    untested "Can't generate a core file"
166    return 0
167}
168
169# Check that the corefile is plausibly large enough.  We're trying to
170# detect the case where the operating system has truncated the file
171# just before signed wraparound.  TCL, unfortunately, has a similar
172# problem - so use catch.  It can handle the "bad" size but not
173# necessarily the "good" one.  And we must use GDB for the comparison,
174# similarly.
175
176if {[catch {file size $corefile} core_size] == 0} {
177    set core_ok 0
178    gdb_test_multiple "print \$bytes_allocated < $core_size" "check core size" {
179	-re " = 1\r\n$gdb_prompt $" {
180	    pass "check core size"
181	    set core_ok 1
182	}
183	-re " = 0\r\n$gdb_prompt $" {
184	    pass "check core size"
185	    set core_ok 0
186	}
187    }
188} {
189    # Probably failed due to the TCL build having problems with very
190    # large values.  Since GDB uses a 64-bit off_t (when possible) it
191    # shouldn't have this problem.  Assume that things are going to
192    # work.  Without this assumption the test is skiped on systems
193    # (such as i386 GNU/Linux with patched kernel) which do pass.
194    pass "check core size"
195    set core_ok 1
196}
197if {! $core_ok} {
198    untested "check core size (system does not support large corefiles)"
199    return 0
200}
201
202# Now load up that core file
203
204set test "load corefile"
205gdb_test_multiple "core $corefile" "$test" {
206    -re "A program is being debugged already.  Kill it. .y or n. " {
207	send_gdb "y\n"
208	exp_continue
209    }
210    -re "Core was generated by.*$gdb_prompt $" {
211	pass "$test"
212    }
213}
214
215# Finally, re-traverse bigcore's linked list, checking each chunk's
216# address against the executable.  Don't use gdb_test_multiple as want
217# only one pass/fail.  Don't use exp_continue as the regular
218# expression involving $heap needs to be re-evaluated for each new
219# response.
220
221proc check_heap { dir heap } {
222    global gdb_prompt
223    set test "check ${dir} heap"
224    set ok 1
225    set lim 0
226    send_gdb "print heap.${dir}\n"
227    while { $ok } {
228	gdb_expect {
229	    -re " = \\(struct list \\*\\) [lindex $heap $lim].*$gdb_prompt $" {
230		if { $lim >= [llength $heap] } {
231		    pass "$test"
232		    set ok 0
233		} else {
234		    incr lim
235		    send_gdb "print \$.${dir}\n"
236		}
237	    }
238	    -re ".*$gdb_prompt $" {
239		fail "$test (address [lindex $heap $lim])"
240		set ok 0
241	    }
242	    timeout {
243		fail "$test (timeout)"
244		set ok 0
245	    }
246	}
247    }
248}
249
250check_heap next $next_heap
251check_heap prev $prev_heap
252