22b46cef87881b210d4a18e740f2d9ea96cedcbe
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / gcore.exp
1 # Copyright 2002-2021 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 "failed to prepare" $testfile $srcfile debug]} {
23 return -1
24 }
25
26 if { ! [ runto_main ] } then {
27 untested "couldn't run to main"
28 return -1
29 }
30
31 gdb_test "break terminal_func" "Breakpoint .* at .*${srcfile}, line .*" \
32 "set breakpoint at terminal_func"
33
34 gdb_test "continue" "Breakpoint .* terminal_func.*" \
35 "continue to terminal_func"
36
37 set print_prefix ".\[0123456789\]* = "
38
39 set pre_corefile_backtrace [capture_command_output "backtrace" ""]
40 set pre_corefile_regs [capture_command_output "info registers" ""]
41 set pre_corefile_allregs [capture_command_output "info all-reg" ""]
42 set pre_corefile_sysregs [capture_command_output "info reg system" ""]
43 set pre_corefile_static_array \
44 [capture_command_output "print static_array" "$print_prefix"]
45 set pre_corefile_uninit_array \
46 [capture_command_output "print un_initialized_array" "$print_prefix"]
47 set pre_corefile_heap_string \
48 [capture_command_output "print heap_string" "$print_prefix"]
49 set pre_corefile_local_array \
50 [capture_command_output "print array_func::local_array" "$print_prefix"]
51 set pre_corefile_extern_array \
52 [capture_command_output "print extern_array" "$print_prefix"]
53
54 set corefile [standard_output_file gcore.test]
55 set core_supported [gdb_gcore_cmd "$corefile" "save a corefile"]
56 if {!$core_supported} {
57 return -1
58 }
59
60 # Now restart gdb and load the corefile.
61 gdb_exit
62 gdb_start
63 gdb_reinitialize_dir $srcdir/$subdir
64 gdb_load ${binfile}
65
66 set core_loaded [gdb_core_cmd "$corefile" "re-load generated corefile"]
67 if { $core_loaded == -1 } {
68 # No use proceeding from here.
69 return
70 }
71
72 gdb_test_sequence "where" "where in corefile" {
73 "\[\r\n\]+#0 .* terminal_func \\(\\) at "
74 "\[\r\n\]+#1 .* array_func \\(\\) at "
75 "\[\r\n\]+#2 .* factorial_func \\(value=1\\) at "
76 "\[\r\n\]+#3 .* factorial_func \\(value=2\\) at "
77 "\[\r\n\]+#4 .* factorial_func \\(value=3\\) at "
78 "\[\r\n\]+#5 .* factorial_func \\(value=4\\) at "
79 "\[\r\n\]+#6 .* factorial_func \\(value=5\\) at "
80 "\[\r\n\]+#7 .* factorial_func \\(value=6\\) at "
81 "\[\r\n\]+#8 .* main \\(.*\\) at "
82 }
83
84 set post_corefile_regs [capture_command_output "info registers" ""]
85 if ![string compare $pre_corefile_regs $post_corefile_regs] then {
86 pass "corefile restored general registers"
87 } else {
88 fail "corefile restored general registers"
89 }
90
91 set post_corefile_allregs [capture_command_output "info all-reg" ""]
92 if ![string compare $pre_corefile_allregs $post_corefile_allregs] then {
93 pass "corefile restored all registers"
94 } else {
95 fail "corefile restored all registers"
96 }
97
98 set post_corefile_sysregs [capture_command_output "info reg system" ""]
99 if ![string compare $pre_corefile_sysregs $post_corefile_sysregs] then {
100 pass "corefile restored system registers"
101 } else {
102 fail "corefile restored system registers"
103 }
104
105 set post_corefile_extern_array \
106 [capture_command_output "print extern_array" "$print_prefix"]
107 if ![string compare $pre_corefile_extern_array $post_corefile_extern_array] {
108 pass "corefile restored extern array"
109 } else {
110 fail "corefile restored extern array"
111 }
112
113 set post_corefile_static_array \
114 [capture_command_output "print static_array" "$print_prefix"]
115 if ![string compare $pre_corefile_static_array $post_corefile_static_array] {
116 pass "corefile restored static array"
117 } else {
118 fail "corefile restored static array"
119 }
120
121 set post_corefile_uninit_array \
122 [capture_command_output "print un_initialized_array" "$print_prefix"]
123 if ![string compare $pre_corefile_uninit_array $post_corefile_uninit_array] {
124 pass "corefile restored un-initialized array"
125 } else {
126 fail "corefile restored un-initialized array"
127 }
128
129 set post_corefile_heap_string \
130 [capture_command_output "print heap_string" "$print_prefix"]
131 if ![string compare $pre_corefile_heap_string $post_corefile_heap_string] {
132 pass "corefile restored heap array"
133 } else {
134 fail "corefile restored heap array"
135 }
136
137 set post_corefile_local_array \
138 [capture_command_output "print array_func::local_array" "$print_prefix"]
139 if ![string compare $pre_corefile_local_array $post_corefile_local_array] {
140 pass "corefile restored stack array"
141 } else {
142 fail "corefile restored stack array"
143 }
144
145 set post_corefile_backtrace [capture_command_output "backtrace" ""]
146 if ![string compare $pre_corefile_backtrace $post_corefile_backtrace] {
147 pass "corefile restored backtrace"
148 } else {
149 fail "corefile restored backtrace"
150 }
This page took 0.048841 seconds and 3 git commands to generate.