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