1 # Copyright 2022-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 # This file is part of the gdb testsuite.
18 # Test that GDB for AArch64/Linux can properly handle pointers with
19 # the upper 16 bits (PAC) or 8 bits (Tag) set, as well as the
20 # VA_RANGE_SELECT bit (55).
22 require is_aarch64_target
25 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
33 # We need to iterate over two distinct ranges, separated by a single bit.
34 # This bit is 55 (VA_RANGE_SELECT) which tells us if we have a kernel-space
35 # address or a user-space address.
37 # The tag field has 8 bits.
40 # The pac field has 7 bits.
43 # A couple patterns that we reuse for the tests later. One is for a successful
44 # memory read and the other is for a memory read failure.
45 set memory_read_ok_pattern "$::hex\( <l>\)?:\[ \t\]+$::hex"
46 set memory_read_fail_pattern "$::hex:\[ \t\]+Cannot access memory at address $::hex"
50 # Check if PAC is enabled.
51 gdb_test_multiple "ptype \$pauth_cmask" "fetch PAC cmask" {
52 -re -wrap "type = long" {
55 -re -wrap "type = void" {
57 -re ".*$gdb_prompt $" {
63 # Value of the cmask register.
66 # If there are PAC registers, GDB uses those to unmask the PAC bits.
68 set cmask [get_valueof "" "\$pauth_cmask >> 48" "0" "fetch PAC cmask"]
71 # Cycle through the tag and pac bit ranges and check how GDB
72 # behaves when trying to access these addresses.
73 foreach_with_prefix upper_bits {"0x0" "0x1" "0x2" "0x4" "0x8" "0x10" "0x20" "0x40" "0x80"} {
74 foreach_with_prefix lower_bits {"0x0" "0x1" "0x2" "0x4" "0x8" "0x10" "0x20" "0x40"} {
76 # A successful memory read pattern
77 set pattern $memory_read_ok_pattern
80 # If PAC is not supported, memory reads will fail if
82 if {$lower_bits != "0x0"} {
83 set pattern $memory_read_fail_pattern
86 # Otherwise, figure out if the memory read will succeed or not by
88 gdb_test_multiple "p/x (~${cmask}ULL & (${lower_bits}ULL))" "" {
90 # Either cmask is 0x7F or lower_bits is 0x0.
91 # Either way, the memory read should succeed.
93 -re -wrap "= $::hex" {
94 if {$lower_bits != "0x0"} {
95 # cmask doesn't mask off all the PAC bits, which
96 # results in a memory read failure, with the actual
97 # address being accessed differing from the one we
99 set pattern $memory_read_fail_pattern
105 # Test without the VA_RANGE_SELECT bit set.
106 gdb_test "x/gx ((unsigned long) l_ptr | ((${upper_bits}ULL << 56) | (${lower_bits}ULL << 48)))" \
108 "user-space memory access"
110 # Now test with the VA_RANGE_SELECT bit set.
111 gdb_test "x/gx ((unsigned long) l_ptr | ((${upper_bits}ULL << 56) | (${lower_bits}ULL << 48) | (1ULL << 55))) " \
112 $memory_read_fail_pattern \
113 "kernel-space memory access"