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