Commit | Line | Data |
---|---|---|
3ad13771 | 1 | # Copyright 2002, 2003, 2004 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 | |
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 | 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 | ||
40 | gdb_exit | |
41 | gdb_start | |
42 | gdb_reinitialize_dir $srcdir/$subdir | |
43 | gdb_load ${binfile} | |
44 | ||
45 | # Does this gdb support gcore? | |
46 | send_gdb "help gcore\n" | |
47 | gdb_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 | ||
3ad13771 | 64 | if { ! [ runto_main ] } then { |
a911c360 MS |
65 | gdb_suppress_entire_file "Run to main failed, so all tests in this file will automatically fail." |
66 | } | |
67 | ||
68 | proc 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 | ||
85 | gdb_test "break terminal_func" "Breakpoint .* at .*${srcfile}, line .*" \ | |
86 | "set breakpoint at terminal_func" | |
87 | ||
fda6ae12 | 88 | gdb_test "continue" "Breakpoint .* terminal_func.*" \ |
a911c360 MS |
89 | "continue to terminal_func" |
90 | ||
91 | set print_prefix ".\[0123456789\]* = " | |
92 | ||
93 | set pre_corefile_backtrace [capture_command_output "backtrace" ""] | |
94 | set pre_corefile_regs [capture_command_output "info registers" ""] | |
95 | set pre_corefile_allregs [capture_command_output "info all-reg" ""] | |
96 | set pre_corefile_static_array \ | |
97 | [capture_command_output "print static_array" "$print_prefix"] | |
98 | set pre_corefile_uninit_array \ | |
99 | [capture_command_output "print un_initialized_array" "$print_prefix"] | |
100 | set pre_corefile_heap_string \ | |
101 | [capture_command_output "print heap_string" "$print_prefix"] | |
102 | set pre_corefile_local_array \ | |
103 | [capture_command_output "print array_func::local_array" "$print_prefix"] | |
104 | set pre_corefile_extern_array \ | |
105 | [capture_command_output "print extern_array" "$print_prefix"] | |
106 | ||
e0f353ce EZ |
107 | set escapedfilename [string_to_regexp ${objdir}/${subdir}/gcore.test] |
108 | ||
7d605576 DJ |
109 | gdb_test_multiple "gcore ${objdir}/${subdir}/gcore.test" \ |
110 | "save a corefile" \ | |
111 | { | |
112 | -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" { | |
113 | pass "save a corefile" | |
114 | global core_supported | |
115 | set core_supported 1 | |
116 | } | |
117 | -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" { | |
118 | unsupported "save a corefile" | |
119 | global core_supported | |
120 | set core_supported 0 | |
121 | } | |
122 | } | |
123 | ||
124 | global core_supported | |
125 | if {!$core_supported} { | |
126 | return -1 | |
127 | } | |
a911c360 MS |
128 | |
129 | # Now restart gdb and load the corefile. | |
130 | gdb_exit | |
131 | gdb_start | |
132 | gdb_reinitialize_dir $srcdir/$subdir | |
133 | gdb_load ${binfile} | |
134 | ||
135 | send_gdb "core ${objdir}/${subdir}/gcore.test\n" | |
136 | gdb_expect { | |
137 | -re ".* is not a core dump:.*$gdb_prompt $" { | |
138 | fail "re-load generated corefile (bad file format)" | |
139 | # No use proceeding from here. | |
140 | return; | |
141 | } | |
142 | -re ".*: No such file or directory.*$gdb_prompt $" { | |
143 | fail "re-load generated corefile (file not found)" | |
144 | # No use proceeding from here. | |
145 | return; | |
146 | } | |
147 | -re ".*Couldn't find .* registers in core file.*$gdb_prompt $" { | |
148 | fail "re-load generated corefile (incomplete note section)" | |
149 | } | |
150 | -re "Core was generated by .*$gdb_prompt $" { | |
151 | pass "re-load generated corefile" | |
152 | } | |
153 | -re ".*$gdb_prompt $" { | |
154 | fail "re-load generated corefile" | |
155 | } | |
156 | timeout { | |
157 | fail "re-load generated corefile (timeout)" | |
158 | } | |
159 | } | |
160 | ||
161 | send_gdb "where\n" | |
162 | gdb_expect_list "where in corefile" ".*$gdb_prompt $" { | |
163 | ".*\[\r\n\]+#0 .* terminal_func \\(\\) at " | |
164 | ".*\[\r\n\]+#1 .* array_func \\(\\) at " | |
165 | ".*\[\r\n\]+#2 .* factorial_func \\(value=1\\) at " | |
166 | ".*\[\r\n\]+#3 .* factorial_func \\(value=2\\) at " | |
167 | ".*\[\r\n\]+#4 .* factorial_func \\(value=3\\) at " | |
168 | ".*\[\r\n\]+#5 .* factorial_func \\(value=4\\) at " | |
169 | ".*\[\r\n\]+#6 .* factorial_func \\(value=5\\) at " | |
170 | ".*\[\r\n\]+#7 .* factorial_func \\(value=6\\) at " | |
171 | ".*\[\r\n\]+#8 .* main \\(.*\\) at " | |
172 | } | |
173 | ||
174 | set post_corefile_regs [capture_command_output "info registers" ""] | |
175 | if ![string compare $pre_corefile_regs $post_corefile_regs] then { | |
176 | pass "corefile restored general registers" | |
177 | } else { | |
b082f199 | 178 | fail "corefile restored general registers" |
a911c360 MS |
179 | } |
180 | ||
181 | set post_corefile_allregs [capture_command_output "info all-reg" ""] | |
182 | if ![string compare $pre_corefile_allregs $post_corefile_allregs] then { | |
183 | pass "corefile restored all registers" | |
184 | } else { | |
b082f199 | 185 | fail "corefile restored all registers" |
a911c360 MS |
186 | } |
187 | ||
188 | set post_corefile_extern_array \ | |
189 | [capture_command_output "print extern_array" "$print_prefix"] | |
a911c360 MS |
190 | if ![string compare $pre_corefile_extern_array $post_corefile_extern_array] { |
191 | pass "corefile restored extern array" | |
192 | } else { | |
193 | fail "corefile restored extern array" | |
194 | } | |
195 | ||
196 | set post_corefile_static_array \ | |
197 | [capture_command_output "print static_array" "$print_prefix"] | |
a911c360 MS |
198 | if ![string compare $pre_corefile_static_array $post_corefile_static_array] { |
199 | pass "corefile restored static array" | |
200 | } else { | |
201 | fail "corefile restored static array" | |
202 | } | |
203 | ||
204 | set post_corefile_uninit_array \ | |
205 | [capture_command_output "print un_initialized_array" "$print_prefix"] | |
a911c360 MS |
206 | if ![string compare $pre_corefile_uninit_array $post_corefile_uninit_array] { |
207 | pass "corefile restored un-initialized array" | |
208 | } else { | |
209 | fail "corefile restored un-initialized array" | |
210 | } | |
211 | ||
212 | set post_corefile_heap_string \ | |
213 | [capture_command_output "print heap_string" "$print_prefix"] | |
a911c360 MS |
214 | if ![string compare $pre_corefile_heap_string $post_corefile_heap_string] { |
215 | pass "corefile restored heap array" | |
216 | } else { | |
217 | fail "corefile restored heap array" | |
218 | } | |
219 | ||
220 | set post_corefile_local_array \ | |
221 | [capture_command_output "print array_func::local_array" "$print_prefix"] | |
a911c360 MS |
222 | if ![string compare $pre_corefile_local_array $post_corefile_local_array] { |
223 | pass "corefile restored stack array" | |
224 | } else { | |
225 | fail "corefile restored stack array" | |
226 | } | |
227 | ||
228 | set post_corefile_backtrace [capture_command_output "backtrace" ""] | |
229 | if ![string compare $pre_corefile_backtrace $post_corefile_backtrace] { | |
230 | pass "corefile restored backtrace" | |
231 | } else { | |
232 | fail "corefile restored backtrace" | |
233 | } |