* lib/gdb.exp (gdb_core_cmd): New function.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / gcore.exp
1 # Copyright 2002-2013 Free Software Foundation, Inc.
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
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
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.
12 #
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/>.
15
16 # This file was written by Michael Snyder (msnyder@redhat.com)
17 # This is a test for the gdb command "generate-core-file".
18
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}] != "" } {
25 untested gcore.exp
26 return -1
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?
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"
41 return -1
42 }
43 -re "Save a core file .*$gdb_prompt $" {
44 pass "help gcore"
45 }
46 }
47
48 if { ! [ runto_main ] } then {
49 untested gcore.exp
50 return -1
51 }
52
53 proc capture_command_output { command prefix } {
54 global gdb_prompt
55 global expect_out
56
57 set output_string ""
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)
61 }
62 }
63 return $output_string
64 }
65
66 gdb_test "break terminal_func" "Breakpoint .* at .*${srcfile}, line .*" \
67 "set breakpoint at terminal_func"
68
69 gdb_test "continue" "Breakpoint .* terminal_func.*" \
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
88 set corefile "${objdir}/${subdir}/gcore.test"
89 set core_supported [gdb_gcore_cmd "$corefile" "save a corefile"]
90 if {!$core_supported} {
91 return -1
92 }
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
100 set core_loaded [gdb_core_cmd "$corefile" "re-load generated corefile"]
101 if { $core_loaded == -1 } {
102 # No use proceeding from here.
103 return
104 }
105
106 gdb_test_sequence "where" "where in corefile" {
107 "\[\r\n\]+#0 .* terminal_func \\(\\) at "
108 "\[\r\n\]+#1 .* array_func \\(\\) at "
109 "\[\r\n\]+#2 .* factorial_func \\(value=1\\) at "
110 "\[\r\n\]+#3 .* factorial_func \\(value=2\\) at "
111 "\[\r\n\]+#4 .* factorial_func \\(value=3\\) at "
112 "\[\r\n\]+#5 .* factorial_func \\(value=4\\) at "
113 "\[\r\n\]+#6 .* factorial_func \\(value=5\\) at "
114 "\[\r\n\]+#7 .* factorial_func \\(value=6\\) at "
115 "\[\r\n\]+#8 .* main \\(.*\\) at "
116 }
117
118 set post_corefile_regs [capture_command_output "info registers" ""]
119 if ![string compare $pre_corefile_regs $post_corefile_regs] then {
120 pass "corefile restored general registers"
121 } else {
122 fail "corefile restored general registers"
123 }
124
125 set post_corefile_allregs [capture_command_output "info all-reg" ""]
126 if ![string compare $pre_corefile_allregs $post_corefile_allregs] then {
127 pass "corefile restored all registers"
128 } else {
129 fail "corefile restored all registers"
130 }
131
132 set post_corefile_extern_array \
133 [capture_command_output "print extern_array" "$print_prefix"]
134 if ![string compare $pre_corefile_extern_array $post_corefile_extern_array] {
135 pass "corefile restored extern array"
136 } else {
137 fail "corefile restored extern array"
138 }
139
140 set post_corefile_static_array \
141 [capture_command_output "print static_array" "$print_prefix"]
142 if ![string compare $pre_corefile_static_array $post_corefile_static_array] {
143 pass "corefile restored static array"
144 } else {
145 fail "corefile restored static array"
146 }
147
148 set post_corefile_uninit_array \
149 [capture_command_output "print un_initialized_array" "$print_prefix"]
150 if ![string compare $pre_corefile_uninit_array $post_corefile_uninit_array] {
151 pass "corefile restored un-initialized array"
152 } else {
153 fail "corefile restored un-initialized array"
154 }
155
156 set post_corefile_heap_string \
157 [capture_command_output "print heap_string" "$print_prefix"]
158 if ![string compare $pre_corefile_heap_string $post_corefile_heap_string] {
159 pass "corefile restored heap array"
160 } else {
161 fail "corefile restored heap array"
162 }
163
164 set post_corefile_local_array \
165 [capture_command_output "print array_func::local_array" "$print_prefix"]
166 if ![string compare $pre_corefile_local_array $post_corefile_local_array] {
167 pass "corefile restored stack array"
168 } else {
169 fail "corefile restored stack array"
170 }
171
172 set post_corefile_backtrace [capture_command_output "backtrace" ""]
173 if ![string compare $pre_corefile_backtrace $post_corefile_backtrace] {
174 pass "corefile restored backtrace"
175 } else {
176 fail "corefile restored backtrace"
177 }
This page took 0.047212 seconds and 5 git commands to generate.