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