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