Add translations for various sub-directories
[binutils-gdb.git] / gdb / testsuite / gdb.arch / i386-pkru.exp
bloba8a36b7fb151b6b633191397780422d355b2e47e
1 # Copyright 2015-2024 Free Software Foundation, Inc.
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.
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.
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/>.
16 standard_testfile
18 require {is_any_target i?86-*-* x86_64-*-*}
20 set default_pkru_re 0x0
21 if { [istarget *-*-linux*] } {
22     # Starting with v4.9, the linux kernel contains commit acd547b29880
23     # ("x86/pkeys: Default to a restrictive init PKRU"), which sets the
24     # pkru register to 0x55555554 by default.
25     set default_pkru_re (0x0|0x55555554)
29 set comp_flags "-I${srcdir}/../nat/"
31 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
32      [list debug additional_flags=${comp_flags}]] } {
33     untested "failed to compile x86 PKEYS test."
34     return -1
37 if ![runto_main] {
38     return -1
41 set supports_pkru 0
42 set test "probe PKRU support"
43 gdb_test_multiple "print have_pkru()" $test {
44     -re ".. = 1\r\n$gdb_prompt $" {
45         pass $test
46         set supports_pkru 1
47     }
48     -re ".. = 0\r\n$gdb_prompt $" {
49         pass $test
50     }
53 if { !$supports_pkru } {
54     unsupported "processor does not support protection key feature."
55     return
58 # Linux kernel versions 5.14.0 to 6.1.x contain a regression related to writing
59 # the PKRU using ptrace, see commit 4a804c4f8356 ("x86/fpu: Allow PKRU to be
60 # (once again) written by ptrace.").
61 set have_xfail 0
62 set v [linux_kernel_version]
63 if { $v != {} } {
64     set have_xfail \
65         [expr \
66              [version_compare [list 5 14 0] <= $v] \
67              && [version_compare $v < [list 6 2 0]]]
70 # Test pkru register at startup
71 gdb_test "print /x \$pkru" "= $default_pkru_re" "pkru register"
73 # Read values from pseudo registers.
74 gdb_breakpoint [ gdb_get_line_number "break here 1" ]
75 gdb_continue_to_breakpoint "break here 1" ".*break here 1.*"
77 set val1 0x12345678
78 gdb_test "info register pkru" ".*pkru.*$val1.*" "read pkru register"
80 set val2 0x44444444
81 gdb_test "print /x \$pkru = $val2" "= $val2" "set pkru value"
83 gdb_test_multiple "info register pkru" "read value after setting value" {
84     -re -wrap ".*pkru.*$val2.*" {
85         pass $gdb_test_name
86     }
87     -re -wrap ".*pkru.*$val1.*" {
88         if { $have_xfail } {
89             xfail $gdb_test_name
90         } else {
91             fail $gdb_test_name
92         }
93     }
96 gdb_breakpoint [ gdb_get_line_number "break here 2" ]
97 gdb_continue_to_breakpoint "break here 2" ".*break here 2.*"
99 gdb_test_multiple "print /x rd_value" "variable after reading pkru" {
100     -re -wrap "= $val2" {
101         pass $gdb_test_name
102     }
103     -re -wrap "= $val1" {
104         if { $have_xfail } {
105             xfail $gdb_test_name
106         } else {
107             fail $gdb_test_name
108         }
109     }