1 # Copyright 2009-2017 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file is part of the gdb testsuite.
18 # Test displaced stepping over VEX-encoded RIP-relative AVX
21 if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
22 verbose "Skipping x86_64 displaced stepping tests."
28 set additional_flags "-Wa,-g"
30 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
31 [list debug $additional_flags]] } {
37 gdb_test "set displaced-stepping on" ""
38 gdb_test "show displaced-stepping" ".* displaced stepping .* is on.*"
40 if ![runto_main] then {
41 fail "can't run to main"
45 # GDB picks a spare register from this list to hold the RIP-relative
47 set rip_regs { "rax" "rbx" "rcx" "rdx" "rbp" "rsi" "rdi" }
49 # Assign VAL to all the RIP_REGS.
51 proc set_regs { val } {
55 foreach reg ${rip_regs} {
56 gdb_test_no_output "set \$${reg} = ${val}"
60 # Verify all RIP_REGS print as HEX_VAL_RE in hex.
62 proc verify_regs { hex_val_re } {
65 foreach reg ${rip_regs} {
66 gdb_test "p /x \$${reg}" " = ${hex_val_re}" "${reg} expected value"
70 # Set a break at FUNC, which starts with a RIP-relative instruction
71 # that we want to displaced-step over, and then continue over the
72 # breakpoint, forcing a displaced-stepping sequence.
74 proc disp_step_func { func } {
77 set test_start_label "${func}"
78 set test_end_label "${func}_end"
80 gdb_test "break ${test_start_label}" \
81 "Breakpoint.*at.* file .*$srcfile, line.*" \
82 "break ${test_start_label}"
83 gdb_test "break ${test_end_label}" \
84 "Breakpoint.*at.* file .*$srcfile, line.*" \
85 "break ${test_end_label}"
88 "Continuing.*Breakpoint.*, ${test_start_label} ().*" \
89 "continue to ${test_start_label}"
91 # GDB picks a spare register to hold the RIP-relative address.
92 # Ensure the spare register value is restored properly (rax-rdi,
94 set value "0xdeadbeefd3adb33f"
98 "Continuing.*Breakpoint.*, ${test_end_label} ().*" \
99 "continue to ${test_end_label}"
104 # Test a VEX2-encoded RIP-relative instruction.
105 with_test_prefix "vex2" {
106 # This case writes to the 'xmm0' register. Confirm the register's
107 # value is what we believe it is before the AVX instruction runs.
108 gdb_test "p /x \$xmm0.uint128" " = 0x0" \
109 "xmm0 has expected value before"
111 disp_step_func "test_rip_vex2"
113 # Confirm the instruction's expected side effects. It should have
115 gdb_test "p /x \$xmm0.uint128" " = 0x1122334455667788" \
116 "xmm0 has expected value after"
119 # Test a VEX3-encoded RIP-relative instruction.
120 with_test_prefix "vex3" {
121 # This case writes to the 'var128' variable. Confirm the
122 # variable's value is what we believe it is before the AVX
124 gdb_test "p /x (unsigned long long \[2\]) var128" \
125 " = \\{0xaa55aa55aa55aa55, 0x55aa55aa55aa55aa\\}" \
126 "var128 has expected value before"
128 # Run the AVX instruction.
129 disp_step_func "test_rip_vex3"
131 # Confirm the instruction's expected side effects. It should have
132 # modifed the 'var128' variable.
133 gdb_test "p /x (unsigned long long \[2\]) var128" \
134 " = \\{0x1122334455667788, 0x0\\}" \
135 "var128 has expected value after"
138 # Done, run program to exit.
139 gdb_continue_to_end "amd64-disp-step-avx"