test suite update - gdb.base/[cd]
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / gcore.exp
CommitLineData
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
20set testfile "gcore"
21set srcfile ${testfile}.c
22set binfile ${objdir}/${subdir}/${testfile}
23
24if { [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
31gdb_exit
32gdb_start
33gdb_reinitialize_dir $srcdir/$subdir
34gdb_load ${binfile}
35
36# Does this gdb support gcore?
a76e022a 37gdb_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"
ae59b1da 41 return -1
a911c360
MS
42 }
43 -re "Save a core file .*$gdb_prompt $" {
44 pass "help gcore"
45 }
a911c360
MS
46}
47
3ad13771 48if { ! [ runto_main ] } then {
b60f0898
JB
49 untested gcore.exp
50 return -1
a911c360
MS
51}
52
53proc 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
66gdb_test "break terminal_func" "Breakpoint .* at .*${srcfile}, line .*" \
67 "set breakpoint at terminal_func"
68
fda6ae12 69gdb_test "continue" "Breakpoint .* terminal_func.*" \
a911c360
MS
70 "continue to terminal_func"
71
72set print_prefix ".\[0123456789\]* = "
73
74set pre_corefile_backtrace [capture_command_output "backtrace" ""]
75set pre_corefile_regs [capture_command_output "info registers" ""]
76set pre_corefile_allregs [capture_command_output "info all-reg" ""]
1f031429 77set pre_corefile_sysregs [capture_command_output "info reg system" ""]
a911c360
MS
78set pre_corefile_static_array \
79 [capture_command_output "print static_array" "$print_prefix"]
80set pre_corefile_uninit_array \
81 [capture_command_output "print un_initialized_array" "$print_prefix"]
82set pre_corefile_heap_string \
83 [capture_command_output "print heap_string" "$print_prefix"]
84set pre_corefile_local_array \
85 [capture_command_output "print array_func::local_array" "$print_prefix"]
86set pre_corefile_extern_array \
87 [capture_command_output "print extern_array" "$print_prefix"]
88
fac51dd9
DE
89set corefile "${objdir}/${subdir}/gcore.test"
90set core_supported [gdb_gcore_cmd "$corefile" "save a corefile"]
7d605576
DJ
91if {!$core_supported} {
92 return -1
93}
a911c360
MS
94
95# Now restart gdb and load the corefile.
96gdb_exit
97gdb_start
98gdb_reinitialize_dir $srcdir/$subdir
99gdb_load ${binfile}
100
fac51dd9
DE
101set core_loaded [gdb_core_cmd "$corefile" "re-load generated corefile"]
102if { $core_loaded == -1 } {
103 # No use proceeding from here.
104 return
a911c360
MS
105}
106
5fa290c1
DE
107gdb_test_sequence "where" "where in corefile" {
108 "\[\r\n\]+#0 .* terminal_func \\(\\) at "
109 "\[\r\n\]+#1 .* array_func \\(\\) at "
110 "\[\r\n\]+#2 .* factorial_func \\(value=1\\) at "
111 "\[\r\n\]+#3 .* factorial_func \\(value=2\\) at "
112 "\[\r\n\]+#4 .* factorial_func \\(value=3\\) at "
113 "\[\r\n\]+#5 .* factorial_func \\(value=4\\) at "
114 "\[\r\n\]+#6 .* factorial_func \\(value=5\\) at "
115 "\[\r\n\]+#7 .* factorial_func \\(value=6\\) at "
116 "\[\r\n\]+#8 .* main \\(.*\\) at "
a911c360
MS
117}
118
119set post_corefile_regs [capture_command_output "info registers" ""]
120if ![string compare $pre_corefile_regs $post_corefile_regs] then {
121 pass "corefile restored general registers"
122} else {
b082f199 123 fail "corefile restored general registers"
a911c360
MS
124}
125
126set post_corefile_allregs [capture_command_output "info all-reg" ""]
127if ![string compare $pre_corefile_allregs $post_corefile_allregs] then {
128 pass "corefile restored all registers"
129} else {
b082f199 130 fail "corefile restored all registers"
a911c360
MS
131}
132
1f031429
PA
133set post_corefile_sysregs [capture_command_output "info reg system" ""]
134if ![string compare $pre_corefile_sysregs $post_corefile_sysregs] then {
135 pass "corefile restored system registers"
136} else {
137 fail "corefile restored system registers"
138}
139
a911c360
MS
140set post_corefile_extern_array \
141 [capture_command_output "print extern_array" "$print_prefix"]
a911c360
MS
142if ![string compare $pre_corefile_extern_array $post_corefile_extern_array] {
143 pass "corefile restored extern array"
144} else {
145 fail "corefile restored extern array"
146}
147
148set post_corefile_static_array \
149 [capture_command_output "print static_array" "$print_prefix"]
a911c360
MS
150if ![string compare $pre_corefile_static_array $post_corefile_static_array] {
151 pass "corefile restored static array"
152} else {
153 fail "corefile restored static array"
154}
155
156set post_corefile_uninit_array \
157 [capture_command_output "print un_initialized_array" "$print_prefix"]
a911c360
MS
158if ![string compare $pre_corefile_uninit_array $post_corefile_uninit_array] {
159 pass "corefile restored un-initialized array"
160} else {
161 fail "corefile restored un-initialized array"
162}
163
164set post_corefile_heap_string \
165 [capture_command_output "print heap_string" "$print_prefix"]
a911c360
MS
166if ![string compare $pre_corefile_heap_string $post_corefile_heap_string] {
167 pass "corefile restored heap array"
168} else {
169 fail "corefile restored heap array"
170}
171
172set post_corefile_local_array \
173 [capture_command_output "print array_func::local_array" "$print_prefix"]
a911c360
MS
174if ![string compare $pre_corefile_local_array $post_corefile_local_array] {
175 pass "corefile restored stack array"
176} else {
177 fail "corefile restored stack array"
178}
179
180set post_corefile_backtrace [capture_command_output "backtrace" ""]
181if ![string compare $pre_corefile_backtrace $post_corefile_backtrace] {
182 pass "corefile restored backtrace"
183} else {
184 fail "corefile restored backtrace"
185}
This page took 1.150909 seconds and 4 git commands to generate.