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