Commit | Line | Data |
---|---|---|
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 | ||
20 | if $tracelevel then { | |
21 | strace $tracelevel | |
22 | } | |
23 | ||
a911c360 MS |
24 | |
25 | set testfile "gcore" | |
26 | set srcfile ${testfile}.c | |
27 | set binfile ${objdir}/${subdir}/${testfile} | |
28 | ||
29 | if { [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 | ||
36 | gdb_exit | |
37 | gdb_start | |
38 | gdb_reinitialize_dir $srcdir/$subdir | |
39 | gdb_load ${binfile} | |
40 | ||
41 | # Does this gdb support gcore? | |
a76e022a | 42 | gdb_test_multiple "help gcore" "help gcore" { |
a911c360 MS |
43 | -re "Undefined command: .gcore.*$gdb_prompt $" { |
44 | # gcore command not supported -- nothing to test here. | |
45 | unsupported "gdb does not support gcore on this target" | |
46 | return -1; | |
47 | } | |
48 | -re "Save a core file .*$gdb_prompt $" { | |
49 | pass "help gcore" | |
50 | } | |
a911c360 MS |
51 | } |
52 | ||
3ad13771 | 53 | if { ! [ runto_main ] } then { |
b60f0898 JB |
54 | untested gcore.exp |
55 | return -1 | |
a911c360 MS |
56 | } |
57 | ||
58 | proc capture_command_output { command prefix } { | |
59 | global gdb_prompt | |
60 | global expect_out | |
61 | ||
62 | set output_string "" | |
db25f29d | 63 | gdb_test_multiple "$command" "capture_command_output for $command" { |
a911c360 MS |
64 | -re "${command}\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb_prompt $" { |
65 | set output_string $expect_out(1,string) | |
66 | } | |
a911c360 MS |
67 | } |
68 | return $output_string | |
69 | } | |
70 | ||
71 | gdb_test "break terminal_func" "Breakpoint .* at .*${srcfile}, line .*" \ | |
72 | "set breakpoint at terminal_func" | |
73 | ||
fda6ae12 | 74 | gdb_test "continue" "Breakpoint .* terminal_func.*" \ |
a911c360 MS |
75 | "continue to terminal_func" |
76 | ||
77 | set print_prefix ".\[0123456789\]* = " | |
78 | ||
79 | set pre_corefile_backtrace [capture_command_output "backtrace" ""] | |
80 | set pre_corefile_regs [capture_command_output "info registers" ""] | |
81 | set pre_corefile_allregs [capture_command_output "info all-reg" ""] | |
82 | set pre_corefile_static_array \ | |
83 | [capture_command_output "print static_array" "$print_prefix"] | |
84 | set pre_corefile_uninit_array \ | |
85 | [capture_command_output "print un_initialized_array" "$print_prefix"] | |
86 | set pre_corefile_heap_string \ | |
87 | [capture_command_output "print heap_string" "$print_prefix"] | |
88 | set pre_corefile_local_array \ | |
89 | [capture_command_output "print array_func::local_array" "$print_prefix"] | |
90 | set pre_corefile_extern_array \ | |
91 | [capture_command_output "print extern_array" "$print_prefix"] | |
92 | ||
e0f353ce EZ |
93 | set escapedfilename [string_to_regexp ${objdir}/${subdir}/gcore.test] |
94 | ||
09db0d03 | 95 | set core_supported 0 |
7d605576 DJ |
96 | gdb_test_multiple "gcore ${objdir}/${subdir}/gcore.test" \ |
97 | "save a corefile" \ | |
98 | { | |
99 | -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" { | |
100 | pass "save a corefile" | |
101 | global core_supported | |
102 | set core_supported 1 | |
103 | } | |
104 | -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" { | |
105 | unsupported "save a corefile" | |
106 | global core_supported | |
107 | set core_supported 0 | |
108 | } | |
109 | } | |
110 | ||
7d605576 DJ |
111 | if {!$core_supported} { |
112 | return -1 | |
113 | } | |
a911c360 MS |
114 | |
115 | # Now restart gdb and load the corefile. | |
116 | gdb_exit | |
117 | gdb_start | |
118 | gdb_reinitialize_dir $srcdir/$subdir | |
119 | gdb_load ${binfile} | |
120 | ||
a76e022a MS |
121 | gdb_test_multiple "core ${objdir}/${subdir}/gcore.test" \ |
122 | "re-load generated corefile" { | |
a911c360 MS |
123 | -re ".* is not a core dump:.*$gdb_prompt $" { |
124 | fail "re-load generated corefile (bad file format)" | |
125 | # No use proceeding from here. | |
126 | return; | |
127 | } | |
128 | -re ".*: No such file or directory.*$gdb_prompt $" { | |
129 | fail "re-load generated corefile (file not found)" | |
130 | # No use proceeding from here. | |
131 | return; | |
132 | } | |
133 | -re ".*Couldn't find .* registers in core file.*$gdb_prompt $" { | |
134 | fail "re-load generated corefile (incomplete note section)" | |
135 | } | |
136 | -re "Core was generated by .*$gdb_prompt $" { | |
137 | pass "re-load generated corefile" | |
138 | } | |
a911c360 MS |
139 | } |
140 | ||
141 | send_gdb "where\n" | |
142 | gdb_expect_list "where in corefile" ".*$gdb_prompt $" { | |
143 | ".*\[\r\n\]+#0 .* terminal_func \\(\\) at " | |
144 | ".*\[\r\n\]+#1 .* array_func \\(\\) at " | |
145 | ".*\[\r\n\]+#2 .* factorial_func \\(value=1\\) at " | |
146 | ".*\[\r\n\]+#3 .* factorial_func \\(value=2\\) at " | |
147 | ".*\[\r\n\]+#4 .* factorial_func \\(value=3\\) at " | |
148 | ".*\[\r\n\]+#5 .* factorial_func \\(value=4\\) at " | |
149 | ".*\[\r\n\]+#6 .* factorial_func \\(value=5\\) at " | |
150 | ".*\[\r\n\]+#7 .* factorial_func \\(value=6\\) at " | |
151 | ".*\[\r\n\]+#8 .* main \\(.*\\) at " | |
152 | } | |
153 | ||
154 | set post_corefile_regs [capture_command_output "info registers" ""] | |
155 | if ![string compare $pre_corefile_regs $post_corefile_regs] then { | |
156 | pass "corefile restored general registers" | |
157 | } else { | |
b082f199 | 158 | fail "corefile restored general registers" |
a911c360 MS |
159 | } |
160 | ||
161 | set post_corefile_allregs [capture_command_output "info all-reg" ""] | |
162 | if ![string compare $pre_corefile_allregs $post_corefile_allregs] then { | |
163 | pass "corefile restored all registers" | |
164 | } else { | |
b082f199 | 165 | fail "corefile restored all registers" |
a911c360 MS |
166 | } |
167 | ||
168 | set post_corefile_extern_array \ | |
169 | [capture_command_output "print extern_array" "$print_prefix"] | |
a911c360 MS |
170 | if ![string compare $pre_corefile_extern_array $post_corefile_extern_array] { |
171 | pass "corefile restored extern array" | |
172 | } else { | |
173 | fail "corefile restored extern array" | |
174 | } | |
175 | ||
176 | set post_corefile_static_array \ | |
177 | [capture_command_output "print static_array" "$print_prefix"] | |
a911c360 MS |
178 | if ![string compare $pre_corefile_static_array $post_corefile_static_array] { |
179 | pass "corefile restored static array" | |
180 | } else { | |
181 | fail "corefile restored static array" | |
182 | } | |
183 | ||
184 | set post_corefile_uninit_array \ | |
185 | [capture_command_output "print un_initialized_array" "$print_prefix"] | |
a911c360 MS |
186 | if ![string compare $pre_corefile_uninit_array $post_corefile_uninit_array] { |
187 | pass "corefile restored un-initialized array" | |
188 | } else { | |
189 | fail "corefile restored un-initialized array" | |
190 | } | |
191 | ||
192 | set post_corefile_heap_string \ | |
193 | [capture_command_output "print heap_string" "$print_prefix"] | |
a911c360 MS |
194 | if ![string compare $pre_corefile_heap_string $post_corefile_heap_string] { |
195 | pass "corefile restored heap array" | |
196 | } else { | |
197 | fail "corefile restored heap array" | |
198 | } | |
199 | ||
200 | set post_corefile_local_array \ | |
201 | [capture_command_output "print array_func::local_array" "$print_prefix"] | |
a911c360 MS |
202 | if ![string compare $pre_corefile_local_array $post_corefile_local_array] { |
203 | pass "corefile restored stack array" | |
204 | } else { | |
205 | fail "corefile restored stack array" | |
206 | } | |
207 | ||
208 | set post_corefile_backtrace [capture_command_output "backtrace" ""] | |
209 | if ![string compare $pre_corefile_backtrace $post_corefile_backtrace] { | |
210 | pass "corefile restored backtrace" | |
211 | } else { | |
212 | fail "corefile restored backtrace" | |
213 | } |