]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.arch/i386-mpx-call.exp
[gdb/testsuite] Fix regexp in gdb.threads/stepi-over-clone.exp
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.arch / i386-mpx-call.exp
CommitLineData
1d506c26 1# Copyright (C) 2017-2024 Free Software Foundation, Inc.
4a612d6f
WT
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
c7ccb471 17require {is_any_target "i?86-*-*" "x86_64-*-*"}
4a612d6f
WT
18
19standard_testfile
20
73c06197 21require supports_mpx_check_pointer_bounds have_mpx
3f94e588 22
4a612d6f
WT
23set comp_flags "-mmpx -fcheck-pointer-bounds -I${srcdir}/../nat"
24
25if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
26 [list debug additional_flags=${comp_flags}]] } {
27 return -1
28}
29
30if ![runto_main] {
4a612d6f
WT
31 return -1
32}
33
346e7e19
TV
34set bounds_table 0
35gdb_test_multiple "disassemble upper" "" {
36 -re -wrap "bndldx.*" {
37 set bounds_table 1
38 }
39 -re -wrap "" {
40 }
41}
42
4a612d6f
WT
43# Convenience for returning from an inferior call that causes a BND violation.
44#
45gdb_test_no_output "set confirm off"
46
47# Convenience variable.
48#
49set bound_reg " = \\\{lbound = $hex, ubound = $hex\\\}.*"
50set int_braw_reg " = \\\{lbound = 0x0, ubound_raw = 0x0\\\}.*"
51set bndcfg_reg " = \\\{raw = $hex, config = \\\{base = $hex, reserved = $hex,\
52 preserved = $hex, enabled = $hex\\\}\\\}"
53set bndstatus_reg " = \\\{raw = $hex, status = \\\{bde = $hex,\
54 error = $hex\\\}\\\}"
55set u_fault [multi_line "Program received signal SIGSEGV, Segmentation fault" \
56 "Upper bound violation while accessing address $hex" \
57 "Bounds: \\\[lower = $hex, upper = $hex\\\]"]
58
59
60# Simplify the tests below.
61#
62proc sanity_check_bndregs {arglist} {
63
64 global int_braw_reg
65
66 foreach a $arglist {
67 gdb_test "p /x $a" "$int_braw_reg"\
68 "$a"
69 }
70}
71
72# Set bnd register to have no access to memory.
73#
74proc remove_memory_access {reg} {
75 global hex
76
77 sanity_check_bndregs {"\$bnd0raw" "\$bnd1raw" "\$bnd2raw" "\$bnd3raw"}
78
79 gdb_test "p /x $reg.lbound = $reg.ubound" "= $hex"\
80 "$reg lower bound set"
81 gdb_test "p /x $reg.ubound = 0" " = 0x0"\
82 "$reg upper bound set"
83}
84
85
86# Prepare convenience variables for bndconfig and status
87# for posterior comparison.
88#
89proc prepare_bndcfg_bndstatus {} {
90
91 global bndcfg_reg
92 global bndstatus_reg
93
94 gdb_test "p /x \$temp_bndcfgu = \$bndcfgu" "$bndcfg_reg"\
95 "bndcfgu should not change"
96
97 gdb_test "p /x \$temp_bndstatus = \$bndstatus" "$bndstatus_reg"\
98 "bndstatus should not change"
99}
100
101# Compare values set for convenience variables and actual values of bndconfig
102# and bndstatus registers.
103#
104proc compare_bndstatus_with_convenience {} {
105
106 gdb_test "p \$temp_bndcfgu == \$bndcfgu" "= 1"\
107 "bndcfgu compare before and after"
108 gdb_test "p \$temp_bndstatus == \$bndstatus" "= 1"\
109 "bndstatus compare before and after"
110}
111
112# Perform an inferior call defined in func.
113#
114proc perform_a_call {func} {
115
116 global inf_call_stopped
117 global gdb_prompt
118
119 gdb_test "p /x $func" [multi_line "The program being debugged\
120 stopped while in a function called from GDB." \
121 "Evaluation of the expression containing the\
122 function.*" \
123 ] "inferior call stopped"
124}
125
126# Perform an inferior call defined in func.
127#
128proc check_bound_violation {parm parm_type is_positive} {
129
346e7e19
TV
130 global u_fault bounds_table
131
132 set have_bnd_violation 0
133 gdb_test_multiple "continue" "continue to a bnd violation" {
134 -re -wrap "Continuing\." {
135 if { $bounds_table } {
136 pass $gdb_test_name
137 } else {
138 fail $gdb_test_name
139 }
140 }
141 -re -wrap "$u_fault.*" {
142 pass $gdb_test_name
143 set have_bnd_violation 1
144 }
145 }
146 if { ! $have_bnd_violation } {
147 return
148 }
4a612d6f
WT
149
150 set message "access only one position"
151 if {$is_positive == 1} {
152 gdb_test "p (((void *)\$_siginfo._sifields._sigfault.si_addr\
153 - (void*)$parm))/sizeof($parm_type) == 1"\
154 " = 1" $message
155 } else {
156 gdb_test "p ((void*)$parm\
157 - (void *)\$_siginfo._sifields._sigfault.si_addr)\
158 /sizeof($parm_type) == 1"\
159 " = 1" $message
160 }
161 gdb_test "return" "\\\#.*main.*i386-mpx-call\\\.c:.*" "return from the fault"
162}
163
164
165# Start testing!
166#
167
168# Set up for stopping in the middle of main for calling a function in the
169# inferior.
170#
171set break "bkpt 1."
172gdb_breakpoint [gdb_get_line_number "${break}"]
173gdb_continue_to_breakpoint "${break}" ".*${break}.*"
174
175
176# Consistency:
177# default run execution of call should succeed without violations.
178#
179with_test_prefix "default_run" {
180
181 gdb_test "p \$keep_bnd0_value=\$bnd0" $bound_reg\
182 "store bnd0 register in a convenience variable"
183
184 gdb_test "p /x upper (a, b, c, d, 0)" " = $hex"\
185 "default inferior call"
186
187 gdb_test "p ((\$bnd0.lbound==\$keep_bnd0_value.lbound) &&\
188 (\$bnd0.ubound==\$keep_bnd0_value.ubound))" "= 1" \
189 "bnd register value after and before call"
190}
191
192# Consistency: Examine bnd registers values before and after the call.
193#
194#
195with_test_prefix "verify_default_values" {
196
197 prepare_bndcfg_bndstatus
198
199 gdb_breakpoint "*upper"
200 perform_a_call "upper (a, b, c, d, 1)"
201
202 sanity_check_bndregs {"\$bnd0raw" "\$bnd1raw" "\$bnd2raw" "\$bnd3raw"}
203
204 compare_bndstatus_with_convenience
205
206 gdb_test_multiple "continue" "inferior call test" {
207 -re ".*Continuing.\r\n$gdb_prompt " {
208 pass "inferior call performed"
209 }
210 }
211}
212
213# Examine: Cause an upper bound violation changing BND0.
214#
215#
216with_test_prefix "upper_bnd0" {
217
218 prepare_bndcfg_bndstatus
219
220 gdb_breakpoint "*upper"
221 perform_a_call "upper (a, b, c, d, 1)"
222
223 remove_memory_access "\$bnd0"
224
225 compare_bndstatus_with_convenience
226
227 check_bound_violation "a" "int" 1
228}
229
230# Examine: Cause an upper bound violation changing BND1.
231#
232#
233with_test_prefix "upper_bnd1" {
234
235 prepare_bndcfg_bndstatus
236
237 gdb_breakpoint "*upper"
238 perform_a_call "upper (a, b, c, d, 1)"
239
240 remove_memory_access "\$bnd1"
241
242 compare_bndstatus_with_convenience
243
244 check_bound_violation "b" "int" 1
245}
246
247# Examine: Cause an upper bound violation changing BND2.
248#
249#
250with_test_prefix "upper_bnd2" {
251
252 prepare_bndcfg_bndstatus
253
254 gdb_breakpoint "*upper"
255 perform_a_call "upper (a, b, c, d, 1)"
256
257 remove_memory_access "\$bnd2"
258
259 compare_bndstatus_with_convenience
260
261 check_bound_violation "c" "int" 1
262}
263
264# Examine: Cause an upper bound violation changing BND3.
265#
266#
267with_test_prefix "upper_bnd3" {
268 prepare_bndcfg_bndstatus
269
270 gdb_breakpoint "*upper"
271 perform_a_call "upper (a, b, c, d, 1)"
272
273 remove_memory_access "\$bnd3"
274
275 compare_bndstatus_with_convenience
276
277 check_bound_violation "d" "int" 1
278}
279
280# Examine: Cause a lower bound violation changing BND0.
281#
282#
283with_test_prefix "lower_bnd0" {
284
285 prepare_bndcfg_bndstatus
286
287 gdb_breakpoint "*lower"
288 perform_a_call "lower (a, b, c, d, 1)"
289
290 remove_memory_access "\$bnd0"
291
292 compare_bndstatus_with_convenience
293
294 check_bound_violation "a" "int" 0
295}
296
297# Examine: Cause a lower bound violation changing BND1.
298#
299#
300with_test_prefix "lower_bnd1" {
301
302 prepare_bndcfg_bndstatus
303
304 gdb_breakpoint "*lower"
305 perform_a_call "lower (a, b, c, d, 1)"
306
307 remove_memory_access "\$bnd1"
308
309 compare_bndstatus_with_convenience
310
311 check_bound_violation "b" "int" 0
312}
313
314# Examine: Cause a lower bound violation changing BND2.
315#
316#
317with_test_prefix "lower_bnd2" {
318
319 prepare_bndcfg_bndstatus
320
321 gdb_breakpoint "*lower"
322 perform_a_call "lower (a, b, c, d, 1)"
323
324 remove_memory_access "\$bnd2"
325
326 compare_bndstatus_with_convenience
327
328 check_bound_violation "c" "int" 0
329}
330
331# Examine: Cause a lower bound violation changing BND3.
332#
333#
334with_test_prefix "lower_bnd3" {
335
336 prepare_bndcfg_bndstatus
337
338 gdb_breakpoint "*lower"
339 perform_a_call "lower (a, b, c, d, 1)"
340
341 remove_memory_access "\$bnd3"
342
343 compare_bndstatus_with_convenience
344
345 check_bound_violation "d" "int" 0
346}
347
348# Examine: String causing a upper bound violation changing BND0.
349#
350#
351with_test_prefix "chars_up" {
352
353 prepare_bndcfg_bndstatus
354
355 gdb_breakpoint "*char_upper"
356 perform_a_call "char_upper (hello, 1)"
357
358 remove_memory_access "\$bnd0"
359
360 compare_bndstatus_with_convenience
361
362 check_bound_violation "str" "char" 1
363}
364
365
366# Examine: String causing an lower bound violation changing BND0.
367#
368#
369with_test_prefix "chars_low" {
370
371 prepare_bndcfg_bndstatus
372
373 gdb_breakpoint "*char_lower"
374 perform_a_call "char_lower (hello, 1)"
375
376 remove_memory_access "\$bnd0"
377
378 compare_bndstatus_with_convenience
379
380 check_bound_violation "str" "char" 0
381}
382
383# Examine: String causing an lower bound violation changing BND0.
384#
385#
386with_test_prefix "chars_low_adhoc_parm" {
387
388 prepare_bndcfg_bndstatus
389
390 gdb_breakpoint "*char_lower"
391 perform_a_call "char_lower (\"tryme\", 1)"
392
393 remove_memory_access "\$bnd0"
394
395 compare_bndstatus_with_convenience
396
397 check_bound_violation "str" "char" 0
398}