]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.arch/amd64-disp-step-avx.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.arch / amd64-disp-step-avx.exp
CommitLineData
213516ef 1# Copyright 2009-2023 Free Software Foundation, Inc.
50a1fdd5
PA
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 is part of the gdb testsuite.
17
18# Test displaced stepping over VEX-encoded RIP-relative AVX
19# instructions.
20
21if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
22 verbose "Skipping x86_64 displaced stepping tests."
23 return
24}
25
10f3fbec
TV
26if { ![have_avx] } {
27 verbose "Skipping x86_64 displaced stepping tests."
28 return
29}
30
50a1fdd5
PA
31standard_testfile .S
32
376be529
AB
33set options [list debug \
34 additional_flags=-static \
35 additional_flags=-nostartfiles]
36if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} $options] } {
50a1fdd5
PA
37 return -1
38}
39
40# Get things started.
41
42gdb_test "set displaced-stepping on" ""
43gdb_test "show displaced-stepping" ".* displaced stepping .* is on.*"
44
75b6f386 45if {![runto_main]} {
50a1fdd5
PA
46 return 0
47}
48
49# GDB picks a spare register from this list to hold the RIP-relative
50# address.
51set rip_regs { "rax" "rbx" "rcx" "rdx" "rbp" "rsi" "rdi" }
52
53# Assign VAL to all the RIP_REGS.
54
55proc set_regs { val } {
56 global gdb_prompt
57 global rip_regs
58
59 foreach reg ${rip_regs} {
60 gdb_test_no_output "set \$${reg} = ${val}"
61 }
62}
63
64# Verify all RIP_REGS print as HEX_VAL_RE in hex.
65
66proc verify_regs { hex_val_re } {
67 global rip_regs
68
69 foreach reg ${rip_regs} {
70 gdb_test "p /x \$${reg}" " = ${hex_val_re}" "${reg} expected value"
71 }
72}
73
74# Set a break at FUNC, which starts with a RIP-relative instruction
75# that we want to displaced-step over, and then continue over the
76# breakpoint, forcing a displaced-stepping sequence.
77
78proc disp_step_func { func } {
79 global srcfile
80
81 set test_start_label "${func}"
82 set test_end_label "${func}_end"
83
84 gdb_test "break ${test_start_label}" \
d1e36019 85 "Breakpoint.*at.* file .*$srcfile, line.*"
50a1fdd5 86 gdb_test "break ${test_end_label}" \
d1e36019 87 "Breakpoint.*at.* file .*$srcfile, line.*"
50a1fdd5
PA
88
89 gdb_test "continue" \
90 "Continuing.*Breakpoint.*, ${test_start_label} ().*" \
91 "continue to ${test_start_label}"
92
93 # GDB picks a spare register to hold the RIP-relative address.
94 # Ensure the spare register value is restored properly (rax-rdi,
95 # sans rsp).
96 set value "0xdeadbeefd3adb33f"
97 set_regs $value
98
40310f30
SM
99 # Turn "debug displaced" on to make sure a displaced step is actually
100 # executed, not an inline step.
101 gdb_test_no_output "set debug displaced on"
102
50a1fdd5 103 gdb_test "continue" \
187b041e 104 "Continuing.*prepared successfully .*Breakpoint.*, ${test_end_label} ().*" \
50a1fdd5
PA
105 "continue to ${test_end_label}"
106
40310f30
SM
107 gdb_test_no_output "set debug displaced off"
108
50a1fdd5
PA
109 verify_regs $value
110}
111
112# Test a VEX2-encoded RIP-relative instruction.
113with_test_prefix "vex2" {
376be529
AB
114 # This test writes to the 'xmm0' register. As the test is
115 # statically linked, we know that the XMM registers should all
116 # have the default value of 0 at this point in time. We're about
117 # to run an AVX instruction that will modify $xmm0, but lets first
118 # confirm that all XMM registers are 0.
119 for {set i 0 } { $i < 16 } { incr i } {
120 gdb_test "p /x \$xmm${i}.uint128" " = 0x0" \
121 "xmm${i} has expected value before"
122 }
50a1fdd5
PA
123
124 disp_step_func "test_rip_vex2"
125
126 # Confirm the instruction's expected side effects. It should have
127 # modified xmm0.
128 gdb_test "p /x \$xmm0.uint128" " = 0x1122334455667788" \
129 "xmm0 has expected value after"
376be529
AB
130
131 # And all of the other XMM register should still be 0.
132 for {set i 1 } { $i < 16 } { incr i } {
133 gdb_test "p /x \$xmm${i}.uint128" " = 0x0" \
134 "xmm${i} has expected value after"
135 }
50a1fdd5
PA
136}
137
138# Test a VEX3-encoded RIP-relative instruction.
139with_test_prefix "vex3" {
140 # This case writes to the 'var128' variable. Confirm the
141 # variable's value is what we believe it is before the AVX
142 # instruction runs.
143 gdb_test "p /x (unsigned long long \[2\]) var128" \
144 " = \\{0xaa55aa55aa55aa55, 0x55aa55aa55aa55aa\\}" \
145 "var128 has expected value before"
146
147 # Run the AVX instruction.
148 disp_step_func "test_rip_vex3"
149
150 # Confirm the instruction's expected side effects. It should have
151 # modifed the 'var128' variable.
152 gdb_test "p /x (unsigned long long \[2\]) var128" \
153 " = \\{0x1122334455667788, 0x0\\}" \
154 "var128 has expected value after"
155}
156
157# Done, run program to exit.
158gdb_continue_to_end "amd64-disp-step-avx"