]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.arch/aarch64-non-address-bits.exp
[gdb/testsuite] Fix failure in gdb.threads/signal-sigtrap.exp
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.arch / aarch64-non-address-bits.exp
1 # Copyright 2022-2024 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 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).
21
22 require is_aarch64_target
23
24 standard_testfile
25 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
26 return -1
27 }
28
29 if ![runto_main] {
30 return -1
31 }
32
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.
36
37 # The tag field has 8 bits.
38 set tag_bits_count 8
39
40 # The pac field has 7 bits.
41 set pac_bits_count 7
42
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"
47
48 set pac_enabled 0
49
50 # Check if PAC is enabled.
51 gdb_test_multiple "ptype \$pauth_cmask" "fetch PAC cmask" {
52 -re -wrap "type = long" {
53 set pac_enabled 1
54 }
55 -re -wrap "type = void" {
56 }
57 -re ".*$gdb_prompt $" {
58 fail $gdb_test_name
59 return 1
60 }
61 }
62
63 # Value of the cmask register.
64 set cmask 0
65
66 # If there are PAC registers, GDB uses those to unmask the PAC bits.
67 if {$pac_enabled} {
68 set cmask [get_valueof "" "\$pauth_cmask >> 48" "0" "fetch PAC cmask"]
69 }
70
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"} {
75
76 # A successful memory read pattern
77 set pattern $memory_read_ok_pattern
78
79 if {!$pac_enabled} {
80 # If PAC is not supported, memory reads will fail if
81 # lower_bits != 0x0
82 if {$lower_bits != "0x0"} {
83 set pattern $memory_read_fail_pattern
84 }
85 } else {
86 # Otherwise, figure out if the memory read will succeed or not by
87 # checking cmask.
88 gdb_test_multiple "p/x (~${cmask}ULL & (${lower_bits}ULL))" "" {
89 -re -wrap "= 0x0" {
90 # Either cmask is 0x7F or lower_bits is 0x0.
91 # Either way, the memory read should succeed.
92 }
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
98 # passed.
99 set pattern $memory_read_fail_pattern
100 }
101 }
102 }
103 }
104
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)))" \
107 $pattern \
108 "user-space memory access"
109
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"
114 }
115 }