]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/gcore.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / gcore.exp
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 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
23 if $tracelevel then {
24 strace $tracelevel
25 }
26
27 set prms_id 0
28 set bug_id 0
29
30 set testfile "gcore"
31 set srcfile ${testfile}.c
32 set binfile ${objdir}/${subdir}/${testfile}
33
34 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
35 untested gcore.exp
36 return -1
37 }
38
39 # Start with a fresh gdb.
40
41 gdb_exit
42 gdb_start
43 gdb_reinitialize_dir $srcdir/$subdir
44 gdb_load ${binfile}
45
46 # Does this gdb support gcore?
47 send_gdb "help gcore\n"
48 gdb_expect {
49 -re "Undefined command: .gcore.*$gdb_prompt $" {
50 # gcore command not supported -- nothing to test here.
51 unsupported "gdb does not support gcore on this target"
52 return -1;
53 }
54 -re "Save a core file .*$gdb_prompt $" {
55 pass "help gcore"
56 }
57 -re ".*$gdb_prompt $" {
58 fail "help gcore"
59 }
60 timeout {
61 fail "help gcore (timeout)"
62 }
63 }
64
65 if { ! [ runto_main ] } then {
66 untested gcore.exp
67 return -1
68 }
69
70 proc capture_command_output { command prefix } {
71 global gdb_prompt
72 global expect_out
73
74 set output_string ""
75 send_gdb "$command\n"
76 gdb_expect {
77 -re "${command}\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb_prompt $" {
78 set output_string $expect_out(1,string)
79 }
80 default {
81 fail "capture_command_output failed on $command."
82 }
83 }
84 return $output_string
85 }
86
87 gdb_test "break terminal_func" "Breakpoint .* at .*${srcfile}, line .*" \
88 "set breakpoint at terminal_func"
89
90 gdb_test "continue" "Breakpoint .* terminal_func.*" \
91 "continue to terminal_func"
92
93 set print_prefix ".\[0123456789\]* = "
94
95 set pre_corefile_backtrace [capture_command_output "backtrace" ""]
96 set pre_corefile_regs [capture_command_output "info registers" ""]
97 set pre_corefile_allregs [capture_command_output "info all-reg" ""]
98 set pre_corefile_static_array \
99 [capture_command_output "print static_array" "$print_prefix"]
100 set pre_corefile_uninit_array \
101 [capture_command_output "print un_initialized_array" "$print_prefix"]
102 set pre_corefile_heap_string \
103 [capture_command_output "print heap_string" "$print_prefix"]
104 set pre_corefile_local_array \
105 [capture_command_output "print array_func::local_array" "$print_prefix"]
106 set pre_corefile_extern_array \
107 [capture_command_output "print extern_array" "$print_prefix"]
108
109 set escapedfilename [string_to_regexp ${objdir}/${subdir}/gcore.test]
110
111 gdb_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
126 global core_supported
127 if {!$core_supported} {
128 return -1
129 }
130
131 # Now restart gdb and load the corefile.
132 gdb_exit
133 gdb_start
134 gdb_reinitialize_dir $srcdir/$subdir
135 gdb_load ${binfile}
136
137 send_gdb "core ${objdir}/${subdir}/gcore.test\n"
138 gdb_expect {
139 -re ".* is not a core dump:.*$gdb_prompt $" {
140 fail "re-load generated corefile (bad file format)"
141 # No use proceeding from here.
142 return;
143 }
144 -re ".*: No such file or directory.*$gdb_prompt $" {
145 fail "re-load generated corefile (file not found)"
146 # No use proceeding from here.
147 return;
148 }
149 -re ".*Couldn't find .* registers in core file.*$gdb_prompt $" {
150 fail "re-load generated corefile (incomplete note section)"
151 }
152 -re "Core was generated by .*$gdb_prompt $" {
153 pass "re-load generated corefile"
154 }
155 -re ".*$gdb_prompt $" {
156 fail "re-load generated corefile"
157 }
158 timeout {
159 fail "re-load generated corefile (timeout)"
160 }
161 }
162
163 send_gdb "where\n"
164 gdb_expect_list "where in corefile" ".*$gdb_prompt $" {
165 ".*\[\r\n\]+#0 .* terminal_func \\(\\) at "
166 ".*\[\r\n\]+#1 .* array_func \\(\\) at "
167 ".*\[\r\n\]+#2 .* factorial_func \\(value=1\\) at "
168 ".*\[\r\n\]+#3 .* factorial_func \\(value=2\\) at "
169 ".*\[\r\n\]+#4 .* factorial_func \\(value=3\\) at "
170 ".*\[\r\n\]+#5 .* factorial_func \\(value=4\\) at "
171 ".*\[\r\n\]+#6 .* factorial_func \\(value=5\\) at "
172 ".*\[\r\n\]+#7 .* factorial_func \\(value=6\\) at "
173 ".*\[\r\n\]+#8 .* main \\(.*\\) at "
174 }
175
176 set post_corefile_regs [capture_command_output "info registers" ""]
177 if ![string compare $pre_corefile_regs $post_corefile_regs] then {
178 pass "corefile restored general registers"
179 } else {
180 fail "corefile restored general registers"
181 }
182
183 set post_corefile_allregs [capture_command_output "info all-reg" ""]
184 if ![string compare $pre_corefile_allregs $post_corefile_allregs] then {
185 pass "corefile restored all registers"
186 } else {
187 fail "corefile restored all registers"
188 }
189
190 set post_corefile_extern_array \
191 [capture_command_output "print extern_array" "$print_prefix"]
192 if ![string compare $pre_corefile_extern_array $post_corefile_extern_array] {
193 pass "corefile restored extern array"
194 } else {
195 fail "corefile restored extern array"
196 }
197
198 set post_corefile_static_array \
199 [capture_command_output "print static_array" "$print_prefix"]
200 if ![string compare $pre_corefile_static_array $post_corefile_static_array] {
201 pass "corefile restored static array"
202 } else {
203 fail "corefile restored static array"
204 }
205
206 set post_corefile_uninit_array \
207 [capture_command_output "print un_initialized_array" "$print_prefix"]
208 if ![string compare $pre_corefile_uninit_array $post_corefile_uninit_array] {
209 pass "corefile restored un-initialized array"
210 } else {
211 fail "corefile restored un-initialized array"
212 }
213
214 set post_corefile_heap_string \
215 [capture_command_output "print heap_string" "$print_prefix"]
216 if ![string compare $pre_corefile_heap_string $post_corefile_heap_string] {
217 pass "corefile restored heap array"
218 } else {
219 fail "corefile restored heap array"
220 }
221
222 set post_corefile_local_array \
223 [capture_command_output "print array_func::local_array" "$print_prefix"]
224 if ![string compare $pre_corefile_local_array $post_corefile_local_array] {
225 pass "corefile restored stack array"
226 } else {
227 fail "corefile restored stack array"
228 }
229
230 set post_corefile_backtrace [capture_command_output "backtrace" ""]
231 if ![string compare $pre_corefile_backtrace $post_corefile_backtrace] {
232 pass "corefile restored backtrace"
233 } else {
234 fail "corefile restored backtrace"
235 }