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