]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/corefile2.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / corefile2.exp
1 # Copyright 2020-2024 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 # Tests of core file memory accesses when mmap() has been used to
17 # create a "hole" of zeroes over pre-existing memory regions. See
18 # coremaker2.c for details.
19
20 # are we on a target board
21 require isnative
22
23 # Some of these tests will only work on GNU/Linux due to the
24 # fact that Linux core files includes a section describing
25 # memory address to file mappings. We'll use set_up_xfail for the
26 # affected tests. As other targets become supported, the condition
27 # can be changed accordingly.
28
29 set xfail 0
30 if { ![istarget *-linux*] } {
31 set xfail 1
32 }
33
34 standard_testfile coremaker2.c
35
36 if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} {
37 untested "failed to compile"
38 return -1
39 }
40
41 set corefile [core_find $binfile {}]
42 if {$corefile == ""} {
43 return 0
44 }
45
46 gdb_start
47 gdb_reinitialize_dir $srcdir/$subdir
48 gdb_load ${binfile}
49
50 # Attempt to load the core file.
51
52 gdb_test_multiple "core-file $corefile" "core-file command" {
53 -re ".* program is being debugged already.*y or n. $" {
54 # gdb_load may connect us to a gdbserver.
55 send_gdb "y\n"
56 exp_continue
57 }
58 -re "Core was generated by .*corefile.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
59 pass "core-file command"
60 }
61 -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
62 pass "core-file command (with bad program name)"
63 }
64 -re ".*registers from core file: File in wrong format.* $" {
65 fail "core-file command (could not read registers from core file)"
66 }
67 }
68
69 # Perform the "interesting" tests which check the contents of certain
70 # memory regions.
71
72 proc do_tests { } {
73 global xfail
74
75 # Check contents of beginning of buf_rw and buf_ro.
76
77 gdb_test {print/x buf_rw[0]@4} {\{0x6b, 0x6b, 0x6b, 0x6b\}}
78 gdb_test {print/x buf_ro[0]@4} {\{0xc5, 0xc5, 0xc5, 0xc5\}}
79
80 # Check for correct contents at beginning of mbuf_rw and mbuf_ro.
81
82 gdb_test {print/x mbuf_rw[0]@4} {\{0x0, 0x0, 0x0, 0x0\}}
83
84 if { $xfail } { setup_xfail "*-*-*" }
85 gdb_test {print/x mbuf_ro[0]@4} {\{0x0, 0x0, 0x0, 0x0\}}
86
87 # Check contents of mbuf_rw and mbuf_ro at the end of these regions.
88
89 gdb_test {print/x mbuf_rw[pagesize-4]@4} {\{0x0, 0x0, 0x0, 0x0\}}
90
91 if { $xfail } { setup_xfail "*-*-*" }
92 gdb_test {print/x mbuf_ro[pagesize-4]@4} {\{0x0, 0x0, 0x0, 0x0\}}
93
94 # Check contents of mbuf_rw and mbuf_ro, right before the hole,
95 # overlapping into the beginning of these mmap'd regions.
96
97 gdb_test {print/x mbuf_rw[-3]@6} {\{0x6b, 0x6b, 0x6b, 0x0, 0x0, 0x0\}}
98
99 if { $xfail } { setup_xfail "*-*-*" }
100 gdb_test {print/x mbuf_ro[-3]@6} {\{0xc5, 0xc5, 0xc5, 0x0, 0x0, 0x0\}}
101
102 # Likewise, at the end of the mbuf_rw and mbuf_ro, with overlap.
103
104 # If this test FAILs, it's probably a genuine bug unrelated to whether
105 # the core file includes a section describing memory address to file
106 # mappings or not. (So don't xfail it!)
107 gdb_test {print/x mbuf_rw[pagesize-3]@6} {\{0x0, 0x0, 0x0, 0x6b, 0x6b, 0x6b\}}
108
109 if { $xfail } { setup_xfail "*-*-*" }
110 gdb_test {print/x mbuf_ro[pagesize-3]@6} {\{0x0, 0x0, 0x0, 0xc5, 0xc5, 0xc5\}}
111
112 # Check contents of (what should be) buf_rw and buf_ro immediately after
113 # mbuf_rw and mbuf_ro holes.
114
115 gdb_test {print/x mbuf_rw[pagesize]@4} {\{0x6b, 0x6b, 0x6b, 0x6b\}}
116 gdb_test {print/x mbuf_ro[pagesize]@4} {\{0xc5, 0xc5, 0xc5, 0xc5\}}
117
118 # Check contents at ends of buf_rw and buf_rw.
119
120 gdb_test {print/x buf_rw[sizeof(buf_rw)-4]@4} {\{0x6b, 0x6b, 0x6b, 0x6b\}}
121 gdb_test {print/x buf_ro[sizeof(buf_ro)-4]@4} {\{0xc5, 0xc5, 0xc5, 0xc5\}}
122 }
123
124 # Run tests with kernel-produced core file.
125
126 with_test_prefix "kernel core" {
127 do_tests
128 }
129
130 # Verify that "maint print core-file-backed-mappings" exists and does
131 # not crash GDB. If it produces any output at all, make sure that
132 # that output at least mentions binfile.
133
134 set test "maint print core-file-backed-mappings"
135 gdb_test_multiple $test "" {
136 -re ".*$binfile.*$gdb_prompt $" {
137 pass $test
138 }
139 -re "^$test\[\r\n\]*$gdb_prompt $" {
140 pass "$test (no output)"
141 }
142 }
143
144 # Test again with executable renamed during loading of core file.
145
146 with_test_prefix "renamed binfile" {
147 # Don't load $binfile in this call to clean_restart. (BFD will
148 # complain that $binfile has disappeared after the rename if it's
149 # loaded first.)
150 clean_restart
151
152 # Rename $binfile so that it won't be found during loading of
153 # the core file.
154 set hide_binfile [standard_output_file "${testfile}.hide"]
155 remote_exec host "mv -f $binfile $hide_binfile"
156
157 # Load core file - check that a warning is printed.
158 global xfail
159 if { $xfail } { setup_xfail "*-*-*" }
160 gdb_test "core-file $corefile" \
161 "warning: Can't open file.*during.* note processing.*Core was generated by .*\#0 .*\(\)" \
162 "load core file without having first loaded binfile"
163
164 # Restore $binfile and then load it.
165 remote_exec host "mv -f $hide_binfile $binfile"
166 gdb_load ${binfile}
167
168 do_tests
169 }
170
171 # Restart and run to the abort call.
172
173 clean_restart $binfile
174
175 if {![runto_main]} {
176 return
177 }
178
179 gdb_breakpoint [gdb_get_line_number "abort"]
180 gdb_continue_to_breakpoint "at abort"
181
182 # Do not execute abort call; instead, invoke gcore command to make a
183 # gdb-produced core file.
184
185 set corefile [standard_output_file gcore.test]
186 set core_supported [gdb_gcore_cmd "$corefile" "save a corefile"]
187 if {!$core_supported} {
188 return
189 }
190
191 # maint print-core-file-backed-mappings shouldn't produce any output
192 # when not debugging a core file.
193
194 gdb_test_no_output "maint print core-file-backed-mappings" \
195 "maint print core-file-backed-mapping with no core file"
196
197 clean_restart $binfile
198
199 set core_loaded [gdb_core_cmd "$corefile" "re-load generated corefile"]
200 if { $core_loaded == -1 } {
201 # No use proceeding from here.
202 return
203 }
204
205 # Run tests using gcore-produced core file.
206
207 with_test_prefix "gcore core" {
208 do_tests
209 }