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