Commit | Line | Data |
---|---|---|
7b6bb8da | 1 | # Copyright 2010, 2011 Free Software Foundation, Inc. |
ed41462c L |
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 3 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, see <http://www.gnu.org/licenses/>. | |
15 | ||
16 | if $tracelevel then { | |
17 | strace $tracelevel | |
18 | } | |
19 | ||
ed41462c L |
20 | |
21 | if { ![istarget i?86-*-linux*] && ![istarget x86_64-*-linux* ] } { | |
22 | verbose "Skipping system register gcore tests." | |
23 | return | |
24 | } | |
25 | ||
26 | set testfile "system-gcore" | |
27 | set srcfile gcore.c | |
28 | set binfile ${objdir}/${subdir}/${testfile} | |
29 | ||
30 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
31 | untested system-gcore.exp | |
32 | return -1 | |
33 | } | |
34 | ||
35 | # Start with a fresh gdb. | |
36 | ||
37 | gdb_exit | |
38 | gdb_start | |
39 | gdb_reinitialize_dir $srcdir/$subdir | |
40 | gdb_load ${binfile} | |
41 | ||
42 | # Does this gdb support gcore? | |
43 | send_gdb "help gcore\n" | |
44 | gdb_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 | ||
61 | if { ! [ runto_main ] } then { | |
62 | untested system-gcore.exp | |
63 | return -1 | |
64 | } | |
65 | ||
66 | proc capture_command_output { command prefix } { | |
67 | global gdb_prompt | |
68 | global expect_out | |
69 | ||
70 | set output_string "" | |
71 | gdb_test_multiple "$command" "capture_command_output for $command" { | |
72 | -re "${command}\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb_prompt $" { | |
73 | set output_string $expect_out(1,string) | |
74 | } | |
75 | } | |
76 | return $output_string | |
77 | } | |
78 | ||
79 | gdb_test "break terminal_func" "Breakpoint .* at .*${srcfile}, line .*" \ | |
80 | "set breakpoint at terminal_func" | |
81 | ||
82 | gdb_test "continue" "Breakpoint .* terminal_func.*" \ | |
83 | "continue to terminal_func" | |
84 | ||
85 | set print_prefix ".\[0123456789\]* = " | |
86 | ||
87 | set pre_corefile_backtrace [capture_command_output "backtrace" ""] | |
88 | set pre_corefile_regs [capture_command_output "info registers" ""] | |
89 | set pre_corefile_allregs [capture_command_output "info all-reg" ""] | |
90 | set pre_corefile_sysregs [capture_command_output "info reg system" ""] | |
91 | set pre_corefile_static_array \ | |
92 | [capture_command_output "print static_array" "$print_prefix"] | |
93 | set pre_corefile_uninit_array \ | |
94 | [capture_command_output "print un_initialized_array" "$print_prefix"] | |
95 | set pre_corefile_heap_string \ | |
96 | [capture_command_output "print heap_string" "$print_prefix"] | |
97 | set pre_corefile_local_array \ | |
98 | [capture_command_output "print array_func::local_array" "$print_prefix"] | |
99 | set pre_corefile_extern_array \ | |
100 | [capture_command_output "print extern_array" "$print_prefix"] | |
101 | ||
102 | set escapedfilename [string_to_regexp ${objdir}/${subdir}/gcore.test] | |
103 | ||
104 | set core_supported 0 | |
105 | gdb_test_multiple "gcore ${objdir}/${subdir}/gcore.test" \ | |
106 | "save a corefile" \ | |
107 | { | |
108 | -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" { | |
109 | pass "save a corefile" | |
110 | global core_supported | |
111 | set core_supported 1 | |
112 | } | |
113 | -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" { | |
114 | unsupported "save a corefile" | |
115 | global core_supported | |
116 | set core_supported 0 | |
117 | } | |
118 | } | |
119 | ||
120 | if {!$core_supported} { | |
121 | return -1 | |
122 | } | |
123 | ||
124 | # Now restart gdb and load the corefile. | |
125 | gdb_exit | |
126 | gdb_start | |
127 | gdb_reinitialize_dir $srcdir/$subdir | |
128 | gdb_load ${binfile} | |
129 | ||
130 | send_gdb "core ${objdir}/${subdir}/gcore.test\n" | |
131 | gdb_expect { | |
132 | -re ".* is not a core dump:.*$gdb_prompt $" { | |
133 | fail "re-load generated corefile (bad file format)" | |
134 | # No use proceeding from here. | |
135 | return; | |
136 | } | |
137 | -re ".*: No such file or directory.*$gdb_prompt $" { | |
138 | fail "re-load generated corefile (file not found)" | |
139 | # No use proceeding from here. | |
140 | return; | |
141 | } | |
142 | -re ".*Couldn't find .* registers in core file.*$gdb_prompt $" { | |
143 | fail "re-load generated corefile (incomplete note section)" | |
144 | } | |
145 | -re "Core was generated by .*$gdb_prompt $" { | |
146 | pass "re-load generated corefile" | |
147 | } | |
148 | -re ".*$gdb_prompt $" { | |
149 | fail "re-load generated corefile" | |
150 | } | |
151 | timeout { | |
152 | fail "re-load generated corefile (timeout)" | |
153 | } | |
154 | } | |
155 | ||
5fa290c1 DE |
156 | gdb_test_sequence "where" "where in corefile" { |
157 | "\[\r\n\]+#0 .* terminal_func \\(\\) at " | |
158 | "\[\r\n\]+#1 .* array_func \\(\\) at " | |
159 | "\[\r\n\]+#2 .* factorial_func \\(value=1\\) at " | |
160 | "\[\r\n\]+#3 .* factorial_func \\(value=2\\) at " | |
161 | "\[\r\n\]+#4 .* factorial_func \\(value=3\\) at " | |
162 | "\[\r\n\]+#5 .* factorial_func \\(value=4\\) at " | |
163 | "\[\r\n\]+#6 .* factorial_func \\(value=5\\) at " | |
164 | "\[\r\n\]+#7 .* factorial_func \\(value=6\\) at " | |
165 | "\[\r\n\]+#8 .* main \\(.*\\) at " | |
ed41462c L |
166 | } |
167 | ||
168 | set post_corefile_regs [capture_command_output "info registers" ""] | |
169 | if ![string compare $pre_corefile_regs $post_corefile_regs] then { | |
170 | pass "corefile restored general registers" | |
171 | } else { | |
172 | fail "corefile restored general registers" | |
173 | } | |
174 | ||
175 | set post_corefile_allregs [capture_command_output "info all-reg" ""] | |
176 | if ![string compare $pre_corefile_allregs $post_corefile_allregs] then { | |
177 | pass "corefile restored all registers" | |
178 | } else { | |
179 | fail "corefile restored all registers" | |
180 | } | |
181 | ||
182 | set post_corefile_sysregs [capture_command_output "info reg system" ""] | |
183 | if ![string compare $pre_corefile_sysregs $post_corefile_sysregs] then { | |
184 | pass "corefile restored system registers" | |
185 | } else { | |
186 | fail "corefile restored system registers" | |
187 | } | |
188 | ||
189 | set post_corefile_extern_array \ | |
190 | [capture_command_output "print extern_array" "$print_prefix"] | |
191 | if ![string compare $pre_corefile_extern_array $post_corefile_extern_array] { | |
192 | pass "corefile restored extern array" | |
193 | } else { | |
194 | fail "corefile restored extern array" | |
195 | } | |
196 | ||
197 | set post_corefile_static_array \ | |
198 | [capture_command_output "print static_array" "$print_prefix"] | |
199 | if ![string compare $pre_corefile_static_array $post_corefile_static_array] { | |
200 | pass "corefile restored static array" | |
201 | } else { | |
202 | fail "corefile restored static array" | |
203 | } | |
204 | ||
205 | set post_corefile_uninit_array \ | |
206 | [capture_command_output "print un_initialized_array" "$print_prefix"] | |
207 | if ![string compare $pre_corefile_uninit_array $post_corefile_uninit_array] { | |
208 | pass "corefile restored un-initialized array" | |
209 | } else { | |
210 | fail "corefile restored un-initialized array" | |
211 | } | |
212 | ||
213 | set post_corefile_heap_string \ | |
214 | [capture_command_output "print heap_string" "$print_prefix"] | |
215 | if ![string compare $pre_corefile_heap_string $post_corefile_heap_string] { | |
216 | pass "corefile restored heap array" | |
217 | } else { | |
218 | fail "corefile restored heap array" | |
219 | } | |
220 | ||
221 | set post_corefile_local_array \ | |
222 | [capture_command_output "print array_func::local_array" "$print_prefix"] | |
223 | if ![string compare $pre_corefile_local_array $post_corefile_local_array] { | |
224 | pass "corefile restored stack array" | |
225 | } else { | |
226 | fail "corefile restored stack array" | |
227 | } | |
228 | ||
229 | set post_corefile_backtrace [capture_command_output "backtrace" ""] | |
230 | if ![string compare $pre_corefile_backtrace $post_corefile_backtrace] { | |
231 | pass "corefile restored backtrace" | |
232 | } else { | |
233 | fail "corefile restored backtrace" | |
234 | } |