• 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 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16# Please email any bugs, comments, and/or additions to this file to:
17# bug-gdb@prep.ai.mit.edu
18
19# This file was written by Michael Snyder (msnyder@redhat.com)
20# This is a test for the gdb command "generate-core-file".
21
22if $tracelevel then {
23	strace $tracelevel
24}
25
26set prms_id 0
27set bug_id 0
28
29set testfile "gcore"
30set srcfile  ${testfile}.c
31set binfile  ${objdir}/${subdir}/${testfile}
32
33if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
34     untested gcore.exp
35     return -1
36}
37
38# Start with a fresh gdb.
39
40gdb_exit
41gdb_start
42gdb_reinitialize_dir $srcdir/$subdir
43gdb_load ${binfile}
44
45# Does this gdb support gcore?
46send_gdb "help gcore\n"
47gdb_expect {
48    -re "Undefined command: .gcore.*$gdb_prompt $" {
49	# gcore command not supported -- nothing to test here.
50	unsupported "gdb does not support gcore on this target"
51	return -1;
52    }
53    -re "Save a core file .*$gdb_prompt $" {
54	pass "help gcore"
55    }
56    -re ".*$gdb_prompt $" {
57	fail "help gcore"
58    }
59    timeout {
60	fail "help gcore (timeout)"
61    }
62}
63
64if { ! [ runto_main ] } then {
65    untested gcore.exp
66    return -1
67}
68
69proc capture_command_output { command prefix } {
70    global gdb_prompt
71    global expect_out
72
73    set output_string ""
74    send_gdb "$command\n"
75    gdb_expect {
76	-re "${command}\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb_prompt $" {
77	    set output_string $expect_out(1,string)
78	}
79	default {
80	    fail "capture_command_output failed on $command."
81	}
82    }
83    return $output_string
84}
85
86gdb_test "break terminal_func" "Breakpoint .* at .*${srcfile}, line .*" \
87	"set breakpoint at terminal_func"
88
89gdb_test "continue" "Breakpoint .* terminal_func.*" \
90	"continue to terminal_func"
91
92set print_prefix ".\[0123456789\]* = "
93
94set pre_corefile_backtrace [capture_command_output "backtrace" ""]
95set pre_corefile_regs [capture_command_output "info registers" ""]
96set pre_corefile_allregs [capture_command_output "info all-reg" ""]
97set pre_corefile_static_array \
98	[capture_command_output "print static_array" "$print_prefix"]
99set pre_corefile_uninit_array \
100	[capture_command_output "print un_initialized_array" "$print_prefix"]
101set pre_corefile_heap_string \
102	[capture_command_output "print heap_string" "$print_prefix"]
103set pre_corefile_local_array \
104	[capture_command_output "print array_func::local_array" "$print_prefix"]
105set pre_corefile_extern_array \
106	[capture_command_output "print extern_array" "$print_prefix"]
107
108set escapedfilename [string_to_regexp ${objdir}/${subdir}/gcore.test]
109
110set core_supported 0
111gdb_test_multiple "gcore ${objdir}/${subdir}/gcore.test" \
112	"save a corefile" \
113{
114  -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
115    pass "save a corefile"
116    global core_supported
117    set core_supported 1
118  }
119  -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
120    unsupported "save a corefile"
121    global core_supported
122    set core_supported 0
123  }
124}
125
126if {!$core_supported} {
127  return -1
128}
129
130# Now restart gdb and load the corefile.
131gdb_exit
132gdb_start
133gdb_reinitialize_dir $srcdir/$subdir
134gdb_load ${binfile}
135
136send_gdb "core ${objdir}/${subdir}/gcore.test\n"
137gdb_expect {
138    -re ".* is not a core dump:.*$gdb_prompt $" {
139	fail "re-load generated corefile (bad file format)"
140	# No use proceeding from here.
141	return;
142    }
143    -re ".*: No such file or directory.*$gdb_prompt $" {
144	fail "re-load generated corefile (file not found)"
145	# No use proceeding from here.
146	return;
147    }
148    -re ".*Couldn't find .* registers in core file.*$gdb_prompt $" {
149	fail "re-load generated corefile (incomplete note section)"
150    }
151    -re "Core was generated by .*$gdb_prompt $" {
152	pass "re-load generated corefile"
153    }
154    -re ".*$gdb_prompt $" {
155	fail "re-load generated corefile"
156    }
157    timeout {
158	fail "re-load generated corefile (timeout)"
159    }
160}
161
162send_gdb "where\n"
163gdb_expect_list "where in corefile" ".*$gdb_prompt $" {
164    ".*\[\r\n\]+#0 .* terminal_func \\(\\) at "
165    ".*\[\r\n\]+#1 .* array_func \\(\\) at "
166    ".*\[\r\n\]+#2 .* factorial_func \\(value=1\\) at "
167    ".*\[\r\n\]+#3 .* factorial_func \\(value=2\\) at "
168    ".*\[\r\n\]+#4 .* factorial_func \\(value=3\\) at "
169    ".*\[\r\n\]+#5 .* factorial_func \\(value=4\\) at "
170    ".*\[\r\n\]+#6 .* factorial_func \\(value=5\\) at "
171    ".*\[\r\n\]+#7 .* factorial_func \\(value=6\\) at "
172    ".*\[\r\n\]+#8 .* main \\(.*\\) at "
173}
174
175set post_corefile_regs [capture_command_output "info registers" ""]
176if ![string compare $pre_corefile_regs $post_corefile_regs] then {
177    pass "corefile restored general registers"
178} else {
179    fail "corefile restored general registers"
180}
181
182set post_corefile_allregs [capture_command_output "info all-reg" ""]
183if ![string compare $pre_corefile_allregs $post_corefile_allregs] then {
184    pass "corefile restored all registers"
185} else {
186    fail "corefile restored all registers"
187}
188
189set post_corefile_extern_array \
190	[capture_command_output "print extern_array" "$print_prefix"]
191if ![string compare $pre_corefile_extern_array $post_corefile_extern_array]  {
192    pass "corefile restored extern array"
193} else {
194    fail "corefile restored extern array"
195}
196
197set post_corefile_static_array \
198	[capture_command_output "print static_array" "$print_prefix"]
199if ![string compare $pre_corefile_static_array $post_corefile_static_array]  {
200    pass "corefile restored static array"
201} else {
202    fail "corefile restored static array"
203}
204
205set post_corefile_uninit_array \
206	[capture_command_output "print un_initialized_array" "$print_prefix"]
207if ![string compare $pre_corefile_uninit_array $post_corefile_uninit_array]  {
208    pass "corefile restored un-initialized array"
209} else {
210    fail "corefile restored un-initialized array"
211}
212
213set post_corefile_heap_string \
214	[capture_command_output "print heap_string" "$print_prefix"]
215if ![string compare $pre_corefile_heap_string $post_corefile_heap_string]  {
216    pass "corefile restored heap array"
217} else {
218    fail "corefile restored heap array"
219}
220
221set post_corefile_local_array \
222	[capture_command_output "print array_func::local_array" "$print_prefix"]
223if ![string compare $pre_corefile_local_array $post_corefile_local_array]  {
224    pass "corefile restored stack array"
225} else {
226    fail "corefile restored stack array"
227}
228
229set post_corefile_backtrace [capture_command_output "backtrace" ""]
230if ![string compare $pre_corefile_backtrace $post_corefile_backtrace]  {
231    pass "corefile restored backtrace"
232} else {
233    fail "corefile restored backtrace"
234}
235