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