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