1 # Copyright 2002-2004, 2007-2012 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file was written by Michael Snyder (msnyder@redhat.com)
17 # This is a test for the gdb command "generate-core-file".
21 set srcfile ${testfile}.c
22 set binfile ${objdir}/${subdir}/${testfile}
24 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
29 # Start with a fresh gdb.
33 gdb_reinitialize_dir $srcdir/$subdir
36 # Does this gdb support gcore?
37 gdb_test_multiple "help gcore" "help gcore" {
38 -re "Undefined command: .gcore.*$gdb_prompt $" {
39 # gcore command not supported -- nothing to test here.
40 unsupported "gdb does not support gcore on this target"
43 -re "Save a core file .*$gdb_prompt $" {
48 if { ! [ runto_main ] } then {
53 proc capture_command_output { command prefix } {
58 gdb_test_multiple "$command" "capture_command_output for $command" {
59 -re "${command}\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb_prompt $" {
60 set output_string $expect_out(1,string)
66 gdb_test "break terminal_func" "Breakpoint .* at .*${srcfile}, line .*" \
67 "set breakpoint at terminal_func"
69 gdb_test "continue" "Breakpoint .* terminal_func.*" \
70 "continue to terminal_func"
72 set print_prefix ".\[0123456789\]* = "
74 set pre_corefile_backtrace [capture_command_output "backtrace" ""]
75 set pre_corefile_regs [capture_command_output "info registers" ""]
76 set pre_corefile_allregs [capture_command_output "info all-reg" ""]
77 set pre_corefile_static_array \
78 [capture_command_output "print static_array" "$print_prefix"]
79 set pre_corefile_uninit_array \
80 [capture_command_output "print un_initialized_array" "$print_prefix"]
81 set pre_corefile_heap_string \
82 [capture_command_output "print heap_string" "$print_prefix"]
83 set pre_corefile_local_array \
84 [capture_command_output "print array_func::local_array" "$print_prefix"]
85 set pre_corefile_extern_array \
86 [capture_command_output "print extern_array" "$print_prefix"]
88 set escapedfilename [string_to_regexp ${objdir}/${subdir}/gcore.test]
91 gdb_test_multiple "gcore ${objdir}/${subdir}/gcore.test" \
94 -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
95 pass "save a corefile"
99 -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
100 unsupported "save a corefile"
101 global core_supported
106 if {!$core_supported} {
110 # Now restart gdb and load the corefile.
113 gdb_reinitialize_dir $srcdir/$subdir
116 gdb_test_multiple "core ${objdir}/${subdir}/gcore.test" \
117 "re-load generated corefile" {
118 -re ".* is not a core dump:.*$gdb_prompt $" {
119 fail "re-load generated corefile (bad file format)"
120 # No use proceeding from here.
123 -re ".*: No such file or directory.*$gdb_prompt $" {
124 fail "re-load generated corefile (file not found)"
125 # No use proceeding from here.
128 -re ".*Couldn't find .* registers in core file.*$gdb_prompt $" {
129 fail "re-load generated corefile (incomplete note section)"
131 -re "Core was generated by .*$gdb_prompt $" {
132 pass "re-load generated corefile"
136 gdb_test_sequence "where" "where in corefile" {
137 "\[\r\n\]+#0 .* terminal_func \\(\\) at "
138 "\[\r\n\]+#1 .* array_func \\(\\) at "
139 "\[\r\n\]+#2 .* factorial_func \\(value=1\\) at "
140 "\[\r\n\]+#3 .* factorial_func \\(value=2\\) at "
141 "\[\r\n\]+#4 .* factorial_func \\(value=3\\) at "
142 "\[\r\n\]+#5 .* factorial_func \\(value=4\\) at "
143 "\[\r\n\]+#6 .* factorial_func \\(value=5\\) at "
144 "\[\r\n\]+#7 .* factorial_func \\(value=6\\) at "
145 "\[\r\n\]+#8 .* main \\(.*\\) at "
148 set post_corefile_regs [capture_command_output "info registers" ""]
149 if ![string compare $pre_corefile_regs $post_corefile_regs] then {
150 pass "corefile restored general registers"
152 fail "corefile restored general registers"
155 set post_corefile_allregs [capture_command_output "info all-reg" ""]
156 if ![string compare $pre_corefile_allregs $post_corefile_allregs] then {
157 pass "corefile restored all registers"
159 fail "corefile restored all registers"
162 set post_corefile_extern_array \
163 [capture_command_output "print extern_array" "$print_prefix"]
164 if ![string compare $pre_corefile_extern_array $post_corefile_extern_array] {
165 pass "corefile restored extern array"
167 fail "corefile restored extern array"
170 set post_corefile_static_array \
171 [capture_command_output "print static_array" "$print_prefix"]
172 if ![string compare $pre_corefile_static_array $post_corefile_static_array] {
173 pass "corefile restored static array"
175 fail "corefile restored static array"
178 set post_corefile_uninit_array \
179 [capture_command_output "print un_initialized_array" "$print_prefix"]
180 if ![string compare $pre_corefile_uninit_array $post_corefile_uninit_array] {
181 pass "corefile restored un-initialized array"
183 fail "corefile restored un-initialized array"
186 set post_corefile_heap_string \
187 [capture_command_output "print heap_string" "$print_prefix"]
188 if ![string compare $pre_corefile_heap_string $post_corefile_heap_string] {
189 pass "corefile restored heap array"
191 fail "corefile restored heap array"
194 set post_corefile_local_array \
195 [capture_command_output "print array_func::local_array" "$print_prefix"]
196 if ![string compare $pre_corefile_local_array $post_corefile_local_array] {
197 pass "corefile restored stack array"
199 fail "corefile restored stack array"
202 set post_corefile_backtrace [capture_command_output "backtrace" ""]
203 if ![string compare $pre_corefile_backtrace $post_corefile_backtrace] {
204 pass "corefile restored backtrace"
206 fail "corefile restored backtrace"