1# Copyright 2009-2019 Free Software Foundation, Inc. 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 amd64 displaced stepping. 19 20 21if { ![istarget x86_64-*-* ] || ![is_lp64_target] } { 22 verbose "Skipping x86_64 displaced stepping tests." 23 return 24} 25 26set newline "\[\r\n\]*" 27 28set opts {debug nopie} 29standard_testfile .S 30 31if { [prepare_for_testing "failed to prepare" $testfile $srcfile $opts] } { 32 return -1 33} 34 35gdb_test "set displaced-stepping on" "" 36gdb_test "show displaced-stepping" ".* displaced stepping .* is on.*" 37 38if ![runto_main] then { 39 fail "can't run to main" 40 return 0 41} 42 43########################################## 44 45# Test call/ret. 46 47gdb_test "break test_call" \ 48 "Breakpoint.*at.* file .*$srcfile, line.*" \ 49 "break test_call" 50gdb_test "break test_call_end" \ 51 "Breakpoint.*at.* file .*$srcfile, line.*" \ 52 "break test_call_end" 53 54gdb_test "break test_ret" \ 55 "Breakpoint.*at.* file .*$srcfile, line.*" \ 56 "break test_ret" 57gdb_test "break test_ret_end" \ 58 "Breakpoint.*at.* file .*$srcfile, line.*" \ 59 "break test_ret_end" 60 61gdb_test "continue" \ 62 "Continuing.*Breakpoint.*, test_call ().*" \ 63 "continue to test_call" 64gdb_test "continue" \ 65 "Continuing.*Breakpoint.*, test_call_end ().*" \ 66 "continue to test_call_end" 67 68gdb_test "continue" \ 69 "Continuing.*Breakpoint.*, test_ret ().*" \ 70 "continue to test_ret" 71gdb_test "continue" \ 72 "Continuing.*Breakpoint.*, test_ret_end ().*" \ 73 "continue to test_ret_end" 74 75########################################## 76 77# Test abs-jmp/rep-ret. 78 79gdb_test "break test_abs_jmp" \ 80 "Breakpoint.*at.* file .*$srcfile, line.*" \ 81 "break test_abs_jmp" 82gdb_test "break test_abs_jmp_end" \ 83 "Breakpoint.*at.* file .*$srcfile, line.*" \ 84 "break test_abs_jmp_end" 85 86gdb_test "break test_rep_ret" \ 87 "Breakpoint.*at.* file .*$srcfile, line.*" \ 88 "break test_rep_ret" 89gdb_test "break test_rep_ret_end" \ 90 "Breakpoint.*at.* file .*$srcfile, line.*" \ 91 "break test_rep_ret_end" 92 93gdb_test "continue" \ 94 "Continuing.*Breakpoint.*, test_abs_jmp ().*" \ 95 "continue to test_abs_jmp" 96gdb_test "continue" \ 97 "Continuing.*Breakpoint.*, test_abs_jmp_end ().*" \ 98 "continue to test_abs_jmp_end" 99 100gdb_test "continue" \ 101 "Continuing.*Breakpoint.*, test_rep_ret ().*" \ 102 "continue to test_rep_ret" 103gdb_test "continue" \ 104 "Continuing.*Breakpoint.*, test_rep_ret_end ().*" \ 105 "continue to test_rep_ret_end" 106 107########################################## 108 109# Test syscall. 110 111gdb_test "break test_syscall" \ 112 "Breakpoint.*at.* file .*$srcfile, line.*" \ 113 "break test_syscall" 114gdb_test "break test_syscall_end" \ 115 "Breakpoint.*at.* file .*$srcfile, line.*" \ 116 "break test_syscall_end" 117 118gdb_test "continue" \ 119 "Continuing.*Breakpoint.*, test_syscall ().*" \ 120 "continue to test_syscall" 121gdb_test "continue" \ 122 "Continuing.*Breakpoint.*, test_syscall_end ().*" \ 123 "continue to test_syscall_end" 124 125########################################## 126 127# int3 (with prefixes) 128# These don't occur in normal code, but gdb should still DTRT. 129 130gdb_test "break test_int3" \ 131 "Breakpoint.*at.* file .*$srcfile, line.*" \ 132 "break test_int3" 133gdb_test "break test_int3_end" \ 134 "Breakpoint.*at.* file .*$srcfile, line.*" \ 135 "break test_int3_end" 136 137gdb_test "continue" \ 138 "Continuing.*Breakpoint.*, test_int3 ().*" \ 139 "continue to test_int3" 140 141gdb_test "continue" \ 142 "Continuing.*Breakpoint.*, test_int3_end ().*" \ 143 "continue to test_int3_end" 144 145########################################## 146 147# Test rip-relative. 148# GDB picks a spare register to hold the rip-relative address. 149# Exercise all the possibilities (rax-rdi, sans rsp). 150 151# The order must much the order in srcfile. 152set rip_regs { "rax" "rbx" "rcx" "rdx" "rbp" "rsi" "rdi" } 153 154# Assign val to all specified regs. 155 156proc set_regs { regs val } { 157 global gdb_prompt 158 159 foreach reg ${regs} { 160 # Use send_gdb/gdb_expect so that these aren't logged as pass/fail. 161 send_gdb "set \$${reg} = ${val}\n" 162 gdb_expect 10 { 163 -re "$gdb_prompt $" { 164 verbose "Setting ${reg} to ${val}." 2 165 } 166 timeout { 167 warning "Couldn't set ${reg} to ${val}." 168 } 169 } 170 } 171} 172 173# Verify all REGS equal VAL, except REG which equals REG_VAL. 174 175proc verify_regs { test_name regs val except_reg except_reg_val } { 176 global newline 177 178 foreach reg ${regs} { 179 set expected ${val} 180 if { "${reg}" == "${except_reg}" } { 181 set expected ${except_reg_val} 182 } 183 # The cast to (int) is because RBP is printed as a pointer. 184 gdb_test "p (int) \$${reg}" " = ${expected}${newline}" "${test_name} ${reg} expected value" 185 } 186} 187 188proc rip_test { reg } { 189 global srcfile rip_regs 190 191 set test_start_label "test_rip_${reg}" 192 set test_end_label "test_rip_${reg}_end" 193 194 gdb_test "break ${test_start_label}" \ 195 "Breakpoint.*at.* file .*$srcfile, line.*" \ 196 "break ${test_start_label}" 197 gdb_test "break ${test_end_label}" \ 198 "Breakpoint.*at.* file .*$srcfile, line.*" \ 199 "break ${test_end_label}" 200 201 gdb_test "continue" \ 202 "Continuing.*Breakpoint.*, ${test_start_label} ().*" \ 203 "continue to ${test_start_label}" 204 205 set_regs ${rip_regs} 0 206 207 gdb_test "continue" \ 208 "Continuing.*Breakpoint.*, ${test_end_label} ().*" \ 209 "continue to ${test_end_label}" 210 211 verify_regs "test rip w/${reg}" ${rip_regs} 0 ${reg} 42 212} 213 214foreach reg ${rip_regs} { 215 rip_test $reg 216} 217 218########################################## 219 220# Done, run program to exit. 221 222gdb_continue_to_end "amd64-disp-step" 223