Allow making GDB not automatically connect to the native target.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / gcore.exp
1 # Copyright 2002-2014 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 standard_testfile
21
22 if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} {
23 untested $testfile.exp
24 return -1
25 }
26
27 # Does this gdb support gcore?
28 gdb_test_multiple "help gcore" "help gcore" {
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"
32 return -1
33 }
34 -re "Save a core file .*$gdb_prompt $" {
35 pass "help gcore"
36 }
37 }
38
39 if { ! [ runto_main ] } then {
40 untested gcore.exp
41 return -1
42 }
43
44 proc capture_command_output { command prefix } {
45 global gdb_prompt
46 global expect_out
47
48 set output_string ""
49 gdb_test_multiple "$command" "capture_command_output for $command" {
50 -re "${command}\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb_prompt $" {
51 set output_string $expect_out(1,string)
52 }
53 }
54 return $output_string
55 }
56
57 gdb_test "break terminal_func" "Breakpoint .* at .*${srcfile}, line .*" \
58 "set breakpoint at terminal_func"
59
60 gdb_test "continue" "Breakpoint .* terminal_func.*" \
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" ""]
68 set pre_corefile_sysregs [capture_command_output "info reg system" ""]
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
80 set corefile [standard_output_file gcore.test]
81 set core_supported [gdb_gcore_cmd "$corefile" "save a corefile"]
82 if {!$core_supported} {
83 return -1
84 }
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
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
96 }
97
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 "
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 {
114 fail "corefile restored general registers"
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 {
121 fail "corefile restored all registers"
122 }
123
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
131 set post_corefile_extern_array \
132 [capture_command_output "print extern_array" "$print_prefix"]
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"]
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"]
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"]
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"]
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 }
This page took 0.03332 seconds and 4 git commands to generate.