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