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