Automatic date update in version.in
[binutils-gdb/blckswan.git] / gdb / testsuite / gdb.arch / i386-pkru.exp
blob7724a579631c072b08ed6dfafe8a801eb42f7d7e
1 # Copyright 2015-2022 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 if { ![istarget i?86-*-*] && ![istarget x86_64-*-* ] } {
19     unsupported "skipping x86 PKEYS tests."
20     return
23 set default_pkru_re 0x0
24 if { [istarget *-*-linux*] } {
25     # Starting with v4.9, the linux kernel contains commit acd547b29880
26     # ("x86/pkeys: Default to a restrictive init PKRU"), which sets the
27     # pkru register to 0x55555554 by default.
28     set default_pkru_re (0x0|0x55555554)
32 set comp_flags "-I${srcdir}/../nat/"
34 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
35      [list debug additional_flags=${comp_flags}]] } {
36     untested "failed to compile x86 PKEYS test."
37     return -1
40 if ![runto_main] {
41     return -1
44 set supports_pkru 0
45 set test "probe PKRU support"
46 gdb_test_multiple "print have_pkru()" $test {
47     -re ".. = 1\r\n$gdb_prompt $" {
48         pass $test
49         set supports_pkru 1
50     }
51     -re ".. = 0\r\n$gdb_prompt $" {
52         pass $test
53     }
56 if { !$supports_pkru } {
57     unsupported "processor does not support protection key feature."
58     return
61 # Test pkru register at startup
62 gdb_test "print /x \$pkru" "= $default_pkru_re" "pkru register"
64 # Read values from pseudo registers.
65 gdb_breakpoint [ gdb_get_line_number "break here 1" ]
66 gdb_continue_to_breakpoint "break here 1" ".*break here 1.*"
68 gdb_test "info register pkru" ".*pkru.*0x12345678.*" "read pkru register"
69 gdb_test "print /x \$pkru = 0x44444444" "= 0x44444444" "set pkru value"
70 gdb_test "info register pkru" ".*pkru.*0x44444444.*" "read value after setting value"
72 gdb_breakpoint [ gdb_get_line_number "break here 2" ]
73 gdb_continue_to_breakpoint "break here 2" ".*break here 2.*"
75 gdb_test "print /x rd_value" "= 0x44444444" "variable after reading pkru"