amd64-disp-step-avx.exp revision 1.1.1.4 1 1.1.1.4 christos # Copyright 2009-2024 Free Software Foundation, Inc.
2 1.1 christos
3 1.1 christos # This program is free software; you can redistribute it and/or modify
4 1.1 christos # it under the terms of the GNU General Public License as published by
5 1.1 christos # the Free Software Foundation; either version 3 of the License, or
6 1.1 christos # (at your option) any later version.
7 1.1 christos #
8 1.1 christos # This program is distributed in the hope that it will be useful,
9 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 1.1 christos # GNU General Public License for more details.
12 1.1 christos #
13 1.1 christos # You should have received a copy of the GNU General Public License
14 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 1.1 christos
16 1.1 christos # This file is part of the gdb testsuite.
17 1.1 christos
18 1.1 christos # Test displaced stepping over VEX-encoded RIP-relative AVX
19 1.1 christos # instructions.
20 1.1 christos
21 1.1.1.4 christos require is_x86_64_m64_target have_avx
22 1.1.1.3 christos
23 1.1 christos standard_testfile .S
24 1.1 christos
25 1.1.1.4 christos set options [list debug nopie]
26 1.1 christos if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} $options] } {
27 1.1 christos return -1
28 1.1 christos }
29 1.1 christos
30 1.1 christos # Get things started.
31 1.1 christos
32 1.1 christos gdb_test "set displaced-stepping on" ""
33 1.1 christos gdb_test "show displaced-stepping" ".* displaced stepping .* is on.*"
34 1.1 christos
35 1.1.1.3 christos if {![runto_main]} {
36 1.1 christos return 0
37 1.1 christos }
38 1.1 christos
39 1.1 christos # GDB picks a spare register from this list to hold the RIP-relative
40 1.1 christos # address.
41 1.1 christos set rip_regs { "rax" "rbx" "rcx" "rdx" "rbp" "rsi" "rdi" }
42 1.1 christos
43 1.1 christos # Assign VAL to all the RIP_REGS.
44 1.1 christos
45 1.1 christos proc set_regs { val } {
46 1.1 christos global gdb_prompt
47 1.1 christos global rip_regs
48 1.1 christos
49 1.1 christos foreach reg ${rip_regs} {
50 1.1 christos gdb_test_no_output "set \$${reg} = ${val}"
51 1.1 christos }
52 1.1 christos }
53 1.1 christos
54 1.1 christos # Verify all RIP_REGS print as HEX_VAL_RE in hex.
55 1.1 christos
56 1.1 christos proc verify_regs { hex_val_re } {
57 1.1 christos global rip_regs
58 1.1 christos
59 1.1 christos foreach reg ${rip_regs} {
60 1.1 christos gdb_test "p /x \$${reg}" " = ${hex_val_re}" "${reg} expected value"
61 1.1 christos }
62 1.1 christos }
63 1.1 christos
64 1.1 christos # Set a break at FUNC, which starts with a RIP-relative instruction
65 1.1 christos # that we want to displaced-step over, and then continue over the
66 1.1 christos # breakpoint, forcing a displaced-stepping sequence.
67 1.1 christos
68 1.1 christos proc disp_step_func { func } {
69 1.1 christos global srcfile
70 1.1 christos
71 1.1 christos set test_start_label "${func}"
72 1.1 christos set test_end_label "${func}_end"
73 1.1 christos
74 1.1 christos gdb_test "break ${test_start_label}" \
75 1.1.1.2 christos "Breakpoint.*at.* file .*$srcfile, line.*"
76 1.1 christos gdb_test "break ${test_end_label}" \
77 1.1.1.2 christos "Breakpoint.*at.* file .*$srcfile, line.*"
78 1.1 christos
79 1.1 christos gdb_test "continue" \
80 1.1 christos "Continuing.*Breakpoint.*, ${test_start_label} ().*" \
81 1.1 christos "continue to ${test_start_label}"
82 1.1 christos
83 1.1 christos # GDB picks a spare register to hold the RIP-relative address.
84 1.1 christos # Ensure the spare register value is restored properly (rax-rdi,
85 1.1 christos # sans rsp).
86 1.1 christos set value "0xdeadbeefd3adb33f"
87 1.1 christos set_regs $value
88 1.1 christos
89 1.1.1.2 christos # Turn "debug displaced" on to make sure a displaced step is actually
90 1.1.1.2 christos # executed, not an inline step.
91 1.1.1.2 christos gdb_test_no_output "set debug displaced on"
92 1.1.1.2 christos
93 1.1 christos gdb_test "continue" \
94 1.1.1.3 christos "Continuing.*prepared successfully .*Breakpoint.*, ${test_end_label} ().*" \
95 1.1 christos "continue to ${test_end_label}"
96 1.1 christos
97 1.1.1.2 christos gdb_test_no_output "set debug displaced off"
98 1.1.1.2 christos
99 1.1 christos verify_regs $value
100 1.1 christos }
101 1.1 christos
102 1.1 christos # Test a VEX2-encoded RIP-relative instruction.
103 1.1 christos with_test_prefix "vex2" {
104 1.1.1.4 christos # Initialize all XMM registers to 0.
105 1.1 christos for {set i 0 } { $i < 16 } { incr i } {
106 1.1.1.4 christos gdb_test_no_output "set \$xmm${i}.uint128 = 0" \
107 1.1.1.4 christos "xmm${i} set to zero"
108 1.1 christos }
109 1.1 christos
110 1.1 christos disp_step_func "test_rip_vex2"
111 1.1 christos
112 1.1 christos # Confirm the instruction's expected side effects. It should have
113 1.1 christos # modified xmm0.
114 1.1 christos gdb_test "p /x \$xmm0.uint128" " = 0x1122334455667788" \
115 1.1 christos "xmm0 has expected value after"
116 1.1 christos
117 1.1 christos # And all of the other XMM register should still be 0.
118 1.1 christos for {set i 1 } { $i < 16 } { incr i } {
119 1.1 christos gdb_test "p /x \$xmm${i}.uint128" " = 0x0" \
120 1.1 christos "xmm${i} has expected value after"
121 1.1 christos }
122 1.1 christos }
123 1.1 christos
124 1.1 christos # Test a VEX3-encoded RIP-relative instruction.
125 1.1 christos with_test_prefix "vex3" {
126 1.1 christos # This case writes to the 'var128' variable. Confirm the
127 1.1 christos # variable's value is what we believe it is before the AVX
128 1.1 christos # instruction runs.
129 1.1 christos gdb_test "p /x (unsigned long long \[2\]) var128" \
130 1.1 christos " = \\{0xaa55aa55aa55aa55, 0x55aa55aa55aa55aa\\}" \
131 1.1 christos "var128 has expected value before"
132 1.1 christos
133 1.1 christos # Run the AVX instruction.
134 1.1 christos disp_step_func "test_rip_vex3"
135 1.1 christos
136 1.1 christos # Confirm the instruction's expected side effects. It should have
137 1.1 christos # modifed the 'var128' variable.
138 1.1 christos gdb_test "p /x (unsigned long long \[2\]) var128" \
139 1.1 christos " = \\{0x1122334455667788, 0x0\\}" \
140 1.1 christos "var128 has expected value after"
141 1.1 christos }
142 1.1 christos
143 1.1 christos # Done, run program to exit.
144 1.1 christos gdb_continue_to_end "amd64-disp-step-avx"
145