2002-02-13 Michael Snyder <msnyder@redhat.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / gcore.exp
CommitLineData
a911c360
MS
1# Copyright 2002 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 2 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, write to the Free Software
15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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 was written by Michael Snyder (msnyder@redhat.com)
21# This is a test for the gdb command "generate-core-file".
22
23if $tracelevel then {
24 strace $tracelevel
25}
26
27set prms_id 0
28set bug_id 0
29
30set testfile "gcore"
31set srcfile ${testfile}.c
32set binfile ${objdir}/${subdir}/${testfile}
33
34if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
35 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
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 gdb_suppress_entire_file "Run to main failed, so all tests in this file will automatically fail."
66}
67
68proc capture_command_output { command prefix } {
69 global gdb_prompt
70 global expect_out
71
72 set output_string ""
73 send_gdb "$command\n"
74 gdb_expect {
75 -re "${command}\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb_prompt $" {
76 set output_string $expect_out(1,string)
77 }
78 default {
79 fail "capture_command_output failed on $command."
80 }
81 }
82 return $output_string
83}
84
85gdb_test "break terminal_func" "Breakpoint .* at .*${srcfile}, line .*" \
86 "set breakpoint at terminal_func"
87
88gdb_test "continue" "Breakpoint .*, terminal_func.*" \
89 "continue to terminal_func"
90
91set print_prefix ".\[0123456789\]* = "
92
93set pre_corefile_backtrace [capture_command_output "backtrace" ""]
94set pre_corefile_regs [capture_command_output "info registers" ""]
95set pre_corefile_allregs [capture_command_output "info all-reg" ""]
96set pre_corefile_static_array \
97 [capture_command_output "print static_array" "$print_prefix"]
98set pre_corefile_uninit_array \
99 [capture_command_output "print un_initialized_array" "$print_prefix"]
100set pre_corefile_heap_string \
101 [capture_command_output "print heap_string" "$print_prefix"]
102set pre_corefile_local_array \
103 [capture_command_output "print array_func::local_array" "$print_prefix"]
104set pre_corefile_extern_array \
105 [capture_command_output "print extern_array" "$print_prefix"]
106
107gdb_test "gcore ${objdir}/${subdir}/gcore.test" \
108 "Saved corefile ${objdir}/${subdir}/gcore.test" \
109 "save a corefile"
110
111# Now restart gdb and load the corefile.
112gdb_exit
113gdb_start
114gdb_reinitialize_dir $srcdir/$subdir
115gdb_load ${binfile}
116
117send_gdb "core ${objdir}/${subdir}/gcore.test\n"
118gdb_expect {
119 -re ".* is not a core dump:.*$gdb_prompt $" {
120 fail "re-load generated corefile (bad file format)"
121 # No use proceeding from here.
122 return;
123 }
124 -re ".*: No such file or directory.*$gdb_prompt $" {
125 fail "re-load generated corefile (file not found)"
126 # No use proceeding from here.
127 return;
128 }
129 -re ".*Couldn't find .* registers in core file.*$gdb_prompt $" {
130 fail "re-load generated corefile (incomplete note section)"
131 }
132 -re "Core was generated by .*$gdb_prompt $" {
133 pass "re-load generated corefile"
134 }
135 -re ".*$gdb_prompt $" {
136 fail "re-load generated corefile"
137 }
138 timeout {
139 fail "re-load generated corefile (timeout)"
140 }
141}
142
143send_gdb "where\n"
144gdb_expect_list "where in corefile" ".*$gdb_prompt $" {
145 ".*\[\r\n\]+#0 .* terminal_func \\(\\) at "
146 ".*\[\r\n\]+#1 .* array_func \\(\\) at "
147 ".*\[\r\n\]+#2 .* factorial_func \\(value=1\\) at "
148 ".*\[\r\n\]+#3 .* factorial_func \\(value=2\\) at "
149 ".*\[\r\n\]+#4 .* factorial_func \\(value=3\\) at "
150 ".*\[\r\n\]+#5 .* factorial_func \\(value=4\\) at "
151 ".*\[\r\n\]+#6 .* factorial_func \\(value=5\\) at "
152 ".*\[\r\n\]+#7 .* factorial_func \\(value=6\\) at "
153 ".*\[\r\n\]+#8 .* main \\(.*\\) at "
154}
155
156set post_corefile_regs [capture_command_output "info registers" ""]
157if ![string compare $pre_corefile_regs $post_corefile_regs] then {
158 pass "corefile restored general registers"
159} else {
b082f199 160 fail "corefile restored general registers"
a911c360
MS
161}
162
163set post_corefile_allregs [capture_command_output "info all-reg" ""]
164if ![string compare $pre_corefile_allregs $post_corefile_allregs] then {
165 pass "corefile restored all registers"
166} else {
b082f199 167 fail "corefile restored all registers"
a911c360
MS
168}
169
170set post_corefile_extern_array \
171 [capture_command_output "print extern_array" "$print_prefix"]
172pass "extern_array = $post_corefile_extern_array"
173if ![string compare $pre_corefile_extern_array $post_corefile_extern_array] {
174 pass "corefile restored extern array"
175} else {
176 fail "corefile restored extern array"
177}
178
179set post_corefile_static_array \
180 [capture_command_output "print static_array" "$print_prefix"]
181pass "static_array = $post_corefile_static_array"
182if ![string compare $pre_corefile_static_array $post_corefile_static_array] {
183 pass "corefile restored static array"
184} else {
185 fail "corefile restored static array"
186}
187
188set post_corefile_uninit_array \
189 [capture_command_output "print un_initialized_array" "$print_prefix"]
190pass "uninit_array = $post_corefile_uninit_array"
191if ![string compare $pre_corefile_uninit_array $post_corefile_uninit_array] {
192 pass "corefile restored un-initialized array"
193} else {
194 fail "corefile restored un-initialized array"
195}
196
197set post_corefile_heap_string \
198 [capture_command_output "print heap_string" "$print_prefix"]
199pass "heap_string = $post_corefile_heap_string"
200if ![string compare $pre_corefile_heap_string $post_corefile_heap_string] {
201 pass "corefile restored heap array"
202} else {
203 fail "corefile restored heap array"
204}
205
206set post_corefile_local_array \
207 [capture_command_output "print array_func::local_array" "$print_prefix"]
208pass "local_array = $post_corefile_local_array"
209if ![string compare $pre_corefile_local_array $post_corefile_local_array] {
210 pass "corefile restored stack array"
211} else {
212 fail "corefile restored stack array"
213}
214
215set post_corefile_backtrace [capture_command_output "backtrace" ""]
216if ![string compare $pre_corefile_backtrace $post_corefile_backtrace] {
217 pass "corefile restored backtrace"
218} else {
219 fail "corefile restored backtrace"
220}
This page took 0.210133 seconds and 4 git commands to generate.