Commit | Line | Data |
---|---|---|
ecd75fc8 | 1 | # Copyright 2002-2014 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 | 19 | |
289f9037 | 20 | standard_testfile |
a911c360 | 21 | |
289f9037 TT |
22 | if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} { |
23 | untested $testfile.exp | |
24 | return -1 | |
a911c360 MS |
25 | } |
26 | ||
a911c360 | 27 | # Does this gdb support gcore? |
a76e022a | 28 | gdb_test_multiple "help gcore" "help gcore" { |
a911c360 MS |
29 | -re "Undefined command: .gcore.*$gdb_prompt $" { |
30 | # gcore command not supported -- nothing to test here. | |
31 | unsupported "gdb does not support gcore on this target" | |
ae59b1da | 32 | return -1 |
a911c360 MS |
33 | } |
34 | -re "Save a core file .*$gdb_prompt $" { | |
35 | pass "help gcore" | |
36 | } | |
a911c360 MS |
37 | } |
38 | ||
3ad13771 | 39 | if { ! [ runto_main ] } then { |
b60f0898 JB |
40 | untested gcore.exp |
41 | return -1 | |
a911c360 MS |
42 | } |
43 | ||
44 | proc capture_command_output { command prefix } { | |
45 | global gdb_prompt | |
46 | global expect_out | |
47 | ||
48 | set output_string "" | |
db25f29d | 49 | gdb_test_multiple "$command" "capture_command_output for $command" { |
a911c360 MS |
50 | -re "${command}\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb_prompt $" { |
51 | set output_string $expect_out(1,string) | |
52 | } | |
a911c360 MS |
53 | } |
54 | return $output_string | |
55 | } | |
56 | ||
57 | gdb_test "break terminal_func" "Breakpoint .* at .*${srcfile}, line .*" \ | |
58 | "set breakpoint at terminal_func" | |
59 | ||
fda6ae12 | 60 | gdb_test "continue" "Breakpoint .* terminal_func.*" \ |
a911c360 MS |
61 | "continue to terminal_func" |
62 | ||
63 | set print_prefix ".\[0123456789\]* = " | |
64 | ||
65 | set pre_corefile_backtrace [capture_command_output "backtrace" ""] | |
66 | set pre_corefile_regs [capture_command_output "info registers" ""] | |
67 | set pre_corefile_allregs [capture_command_output "info all-reg" ""] | |
1f031429 | 68 | set pre_corefile_sysregs [capture_command_output "info reg system" ""] |
a911c360 MS |
69 | set pre_corefile_static_array \ |
70 | [capture_command_output "print static_array" "$print_prefix"] | |
71 | set pre_corefile_uninit_array \ | |
72 | [capture_command_output "print un_initialized_array" "$print_prefix"] | |
73 | set pre_corefile_heap_string \ | |
74 | [capture_command_output "print heap_string" "$print_prefix"] | |
75 | set pre_corefile_local_array \ | |
76 | [capture_command_output "print array_func::local_array" "$print_prefix"] | |
77 | set pre_corefile_extern_array \ | |
78 | [capture_command_output "print extern_array" "$print_prefix"] | |
79 | ||
289f9037 | 80 | set corefile [standard_output_file gcore.test] |
fac51dd9 | 81 | set core_supported [gdb_gcore_cmd "$corefile" "save a corefile"] |
7d605576 DJ |
82 | if {!$core_supported} { |
83 | return -1 | |
84 | } | |
a911c360 MS |
85 | |
86 | # Now restart gdb and load the corefile. | |
87 | gdb_exit | |
88 | gdb_start | |
89 | gdb_reinitialize_dir $srcdir/$subdir | |
90 | gdb_load ${binfile} | |
91 | ||
fac51dd9 DE |
92 | set core_loaded [gdb_core_cmd "$corefile" "re-load generated corefile"] |
93 | if { $core_loaded == -1 } { | |
94 | # No use proceeding from here. | |
95 | return | |
a911c360 MS |
96 | } |
97 | ||
5fa290c1 DE |
98 | gdb_test_sequence "where" "where in corefile" { |
99 | "\[\r\n\]+#0 .* terminal_func \\(\\) at " | |
100 | "\[\r\n\]+#1 .* array_func \\(\\) at " | |
101 | "\[\r\n\]+#2 .* factorial_func \\(value=1\\) at " | |
102 | "\[\r\n\]+#3 .* factorial_func \\(value=2\\) at " | |
103 | "\[\r\n\]+#4 .* factorial_func \\(value=3\\) at " | |
104 | "\[\r\n\]+#5 .* factorial_func \\(value=4\\) at " | |
105 | "\[\r\n\]+#6 .* factorial_func \\(value=5\\) at " | |
106 | "\[\r\n\]+#7 .* factorial_func \\(value=6\\) at " | |
107 | "\[\r\n\]+#8 .* main \\(.*\\) at " | |
a911c360 MS |
108 | } |
109 | ||
110 | set post_corefile_regs [capture_command_output "info registers" ""] | |
111 | if ![string compare $pre_corefile_regs $post_corefile_regs] then { | |
112 | pass "corefile restored general registers" | |
113 | } else { | |
b082f199 | 114 | fail "corefile restored general registers" |
a911c360 MS |
115 | } |
116 | ||
117 | set post_corefile_allregs [capture_command_output "info all-reg" ""] | |
118 | if ![string compare $pre_corefile_allregs $post_corefile_allregs] then { | |
119 | pass "corefile restored all registers" | |
120 | } else { | |
b082f199 | 121 | fail "corefile restored all registers" |
a911c360 MS |
122 | } |
123 | ||
1f031429 PA |
124 | set post_corefile_sysregs [capture_command_output "info reg system" ""] |
125 | if ![string compare $pre_corefile_sysregs $post_corefile_sysregs] then { | |
126 | pass "corefile restored system registers" | |
127 | } else { | |
128 | fail "corefile restored system registers" | |
129 | } | |
130 | ||
a911c360 MS |
131 | set post_corefile_extern_array \ |
132 | [capture_command_output "print extern_array" "$print_prefix"] | |
a911c360 MS |
133 | if ![string compare $pre_corefile_extern_array $post_corefile_extern_array] { |
134 | pass "corefile restored extern array" | |
135 | } else { | |
136 | fail "corefile restored extern array" | |
137 | } | |
138 | ||
139 | set post_corefile_static_array \ | |
140 | [capture_command_output "print static_array" "$print_prefix"] | |
a911c360 MS |
141 | if ![string compare $pre_corefile_static_array $post_corefile_static_array] { |
142 | pass "corefile restored static array" | |
143 | } else { | |
144 | fail "corefile restored static array" | |
145 | } | |
146 | ||
147 | set post_corefile_uninit_array \ | |
148 | [capture_command_output "print un_initialized_array" "$print_prefix"] | |
a911c360 MS |
149 | if ![string compare $pre_corefile_uninit_array $post_corefile_uninit_array] { |
150 | pass "corefile restored un-initialized array" | |
151 | } else { | |
152 | fail "corefile restored un-initialized array" | |
153 | } | |
154 | ||
155 | set post_corefile_heap_string \ | |
156 | [capture_command_output "print heap_string" "$print_prefix"] | |
a911c360 MS |
157 | if ![string compare $pre_corefile_heap_string $post_corefile_heap_string] { |
158 | pass "corefile restored heap array" | |
159 | } else { | |
160 | fail "corefile restored heap array" | |
161 | } | |
162 | ||
163 | set post_corefile_local_array \ | |
164 | [capture_command_output "print array_func::local_array" "$print_prefix"] | |
a911c360 MS |
165 | if ![string compare $pre_corefile_local_array $post_corefile_local_array] { |
166 | pass "corefile restored stack array" | |
167 | } else { | |
168 | fail "corefile restored stack array" | |
169 | } | |
170 | ||
171 | set post_corefile_backtrace [capture_command_output "backtrace" ""] | |
172 | if ![string compare $pre_corefile_backtrace $post_corefile_backtrace] { | |
173 | pass "corefile restored backtrace" | |
174 | } else { | |
175 | fail "corefile restored backtrace" | |
176 | } |