Commit | Line | Data |
---|---|---|
28e7fd62 | 1 | # Copyright 2002-2013 Free Software Foundation, Inc. |
a911c360 MS |
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 | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
a911c360 | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
a911c360 MS |
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. | |
e22f8b7c | 12 | # |
a911c360 | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
a911c360 | 15 | |
a911c360 MS |
16 | # This file was written by Michael Snyder (msnyder@redhat.com) |
17 | # This is a test for the gdb command "generate-core-file". | |
18 | ||
a911c360 MS |
19 | |
20 | set testfile "gcore" | |
21 | set srcfile ${testfile}.c | |
22 | set binfile ${objdir}/${subdir}/${testfile} | |
23 | ||
24 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
b60f0898 JB |
25 | untested gcore.exp |
26 | return -1 | |
a911c360 MS |
27 | } |
28 | ||
29 | # Start with a fresh gdb. | |
30 | ||
31 | gdb_exit | |
32 | gdb_start | |
33 | gdb_reinitialize_dir $srcdir/$subdir | |
34 | gdb_load ${binfile} | |
35 | ||
36 | # Does this gdb support gcore? | |
a76e022a | 37 | gdb_test_multiple "help gcore" "help gcore" { |
a911c360 MS |
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" | |
41 | return -1; | |
42 | } | |
43 | -re "Save a core file .*$gdb_prompt $" { | |
44 | pass "help gcore" | |
45 | } | |
a911c360 MS |
46 | } |
47 | ||
3ad13771 | 48 | if { ! [ runto_main ] } then { |
b60f0898 JB |
49 | untested gcore.exp |
50 | return -1 | |
a911c360 MS |
51 | } |
52 | ||
53 | proc capture_command_output { command prefix } { | |
54 | global gdb_prompt | |
55 | global expect_out | |
56 | ||
57 | set output_string "" | |
db25f29d | 58 | gdb_test_multiple "$command" "capture_command_output for $command" { |
a911c360 MS |
59 | -re "${command}\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb_prompt $" { |
60 | set output_string $expect_out(1,string) | |
61 | } | |
a911c360 MS |
62 | } |
63 | return $output_string | |
64 | } | |
65 | ||
66 | gdb_test "break terminal_func" "Breakpoint .* at .*${srcfile}, line .*" \ | |
67 | "set breakpoint at terminal_func" | |
68 | ||
fda6ae12 | 69 | gdb_test "continue" "Breakpoint .* terminal_func.*" \ |
a911c360 MS |
70 | "continue to terminal_func" |
71 | ||
72 | set print_prefix ".\[0123456789\]* = " | |
73 | ||
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"] | |
87 | ||
2d338fa9 TT |
88 | set core_supported [gdb_gcore_cmd "${objdir}/${subdir}/gcore.test" \ |
89 | "save a corefile"] | |
7d605576 DJ |
90 | if {!$core_supported} { |
91 | return -1 | |
92 | } | |
a911c360 MS |
93 | |
94 | # Now restart gdb and load the corefile. | |
95 | gdb_exit | |
96 | gdb_start | |
97 | gdb_reinitialize_dir $srcdir/$subdir | |
98 | gdb_load ${binfile} | |
99 | ||
a76e022a MS |
100 | gdb_test_multiple "core ${objdir}/${subdir}/gcore.test" \ |
101 | "re-load generated corefile" { | |
a911c360 MS |
102 | -re ".* is not a core dump:.*$gdb_prompt $" { |
103 | fail "re-load generated corefile (bad file format)" | |
104 | # No use proceeding from here. | |
105 | return; | |
106 | } | |
107 | -re ".*: No such file or directory.*$gdb_prompt $" { | |
108 | fail "re-load generated corefile (file not found)" | |
109 | # No use proceeding from here. | |
110 | return; | |
111 | } | |
112 | -re ".*Couldn't find .* registers in core file.*$gdb_prompt $" { | |
113 | fail "re-load generated corefile (incomplete note section)" | |
114 | } | |
115 | -re "Core was generated by .*$gdb_prompt $" { | |
116 | pass "re-load generated corefile" | |
117 | } | |
a911c360 MS |
118 | } |
119 | ||
5fa290c1 DE |
120 | gdb_test_sequence "where" "where in corefile" { |
121 | "\[\r\n\]+#0 .* terminal_func \\(\\) at " | |
122 | "\[\r\n\]+#1 .* array_func \\(\\) at " | |
123 | "\[\r\n\]+#2 .* factorial_func \\(value=1\\) at " | |
124 | "\[\r\n\]+#3 .* factorial_func \\(value=2\\) at " | |
125 | "\[\r\n\]+#4 .* factorial_func \\(value=3\\) at " | |
126 | "\[\r\n\]+#5 .* factorial_func \\(value=4\\) at " | |
127 | "\[\r\n\]+#6 .* factorial_func \\(value=5\\) at " | |
128 | "\[\r\n\]+#7 .* factorial_func \\(value=6\\) at " | |
129 | "\[\r\n\]+#8 .* main \\(.*\\) at " | |
a911c360 MS |
130 | } |
131 | ||
132 | set post_corefile_regs [capture_command_output "info registers" ""] | |
133 | if ![string compare $pre_corefile_regs $post_corefile_regs] then { | |
134 | pass "corefile restored general registers" | |
135 | } else { | |
b082f199 | 136 | fail "corefile restored general registers" |
a911c360 MS |
137 | } |
138 | ||
139 | set post_corefile_allregs [capture_command_output "info all-reg" ""] | |
140 | if ![string compare $pre_corefile_allregs $post_corefile_allregs] then { | |
141 | pass "corefile restored all registers" | |
142 | } else { | |
b082f199 | 143 | fail "corefile restored all registers" |
a911c360 MS |
144 | } |
145 | ||
146 | set post_corefile_extern_array \ | |
147 | [capture_command_output "print extern_array" "$print_prefix"] | |
a911c360 MS |
148 | if ![string compare $pre_corefile_extern_array $post_corefile_extern_array] { |
149 | pass "corefile restored extern array" | |
150 | } else { | |
151 | fail "corefile restored extern array" | |
152 | } | |
153 | ||
154 | set post_corefile_static_array \ | |
155 | [capture_command_output "print static_array" "$print_prefix"] | |
a911c360 MS |
156 | if ![string compare $pre_corefile_static_array $post_corefile_static_array] { |
157 | pass "corefile restored static array" | |
158 | } else { | |
159 | fail "corefile restored static array" | |
160 | } | |
161 | ||
162 | set post_corefile_uninit_array \ | |
163 | [capture_command_output "print un_initialized_array" "$print_prefix"] | |
a911c360 MS |
164 | if ![string compare $pre_corefile_uninit_array $post_corefile_uninit_array] { |
165 | pass "corefile restored un-initialized array" | |
166 | } else { | |
167 | fail "corefile restored un-initialized array" | |
168 | } | |
169 | ||
170 | set post_corefile_heap_string \ | |
171 | [capture_command_output "print heap_string" "$print_prefix"] | |
a911c360 MS |
172 | if ![string compare $pre_corefile_heap_string $post_corefile_heap_string] { |
173 | pass "corefile restored heap array" | |
174 | } else { | |
175 | fail "corefile restored heap array" | |
176 | } | |
177 | ||
178 | set post_corefile_local_array \ | |
179 | [capture_command_output "print array_func::local_array" "$print_prefix"] | |
a911c360 MS |
180 | if ![string compare $pre_corefile_local_array $post_corefile_local_array] { |
181 | pass "corefile restored stack array" | |
182 | } else { | |
183 | fail "corefile restored stack array" | |
184 | } | |
185 | ||
186 | set post_corefile_backtrace [capture_command_output "backtrace" ""] | |
187 | if ![string compare $pre_corefile_backtrace $post_corefile_backtrace] { | |
188 | pass "corefile restored backtrace" | |
189 | } else { | |
190 | fail "corefile restored backtrace" | |
191 | } |