]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright (C) 2018-2024 Free Software Foundation, Inc. |
68cffbbd LM |
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 generating and reading a core file with MTE memory tags. | |
19 | ||
20 | proc test_mte_core_file { core_filename mode } { | |
21 | # Load the core file and make sure we see the tag violation fault | |
22 | # information. | |
23 | if {$mode == "sync"} { | |
24 | gdb_test "core $core_filename" \ | |
25 | [multi_line \ | |
26 | "Core was generated by.*\." \ | |
27 | "Program terminated with signal SIGSEGV, Segmentation fault" \ | |
28 | "Memory tag violation while accessing address ${::hex}" \ | |
29 | "Allocation tag ${::hex}" \ | |
30 | "Logical tag ${::hex}\." \ | |
31 | "#0.*${::hex} in main \\(.*\\) at .*" \ | |
32 | ".*mmap_pointers\\\[0\\\] = 0x4;"] \ | |
33 | "core file shows $mode memory tag violation" | |
34 | } else { | |
35 | gdb_test "core $core_filename" \ | |
36 | [multi_line \ | |
37 | "Core was generated by.*\." \ | |
38 | "Program terminated with signal SIGSEGV, Segmentation fault" \ | |
39 | "Memory tag violation" \ | |
40 | "Fault address unavailable\." \ | |
41 | "#0 ${::hex} in .* from .*"] \ | |
42 | "core file shows $mode memory tag violation" | |
43 | } | |
44 | ||
45 | # Make sure we have the tag_ctl register. | |
46 | gdb_test "info register tag_ctl" \ | |
47 | "tag_ctl.*${::hex}.*${::decimal}" \ | |
48 | "tag_ctl is available" | |
49 | ||
50 | # In ASYNC mode, there is nothing left to test, as the program stops at | |
51 | # a place where further source code inspection is not possible. | |
52 | if {$mode == "async"} { | |
53 | return | |
54 | } | |
55 | ||
56 | # First, figure out the page size. | |
57 | set page_size [get_valueof "" "page_sz" "0" \ | |
58 | "fetch value of page size"] | |
59 | ||
60 | # Get the number of maps for the test | |
61 | set nmaps [get_valueof "" "NMAPS" "0" \ | |
62 | "fetch number of maps"] | |
63 | set tag 1 | |
64 | ||
65 | # Iterate over all of the MTE-protected memory mappings and make sure | |
66 | # GDB retrieves the correct allocation tags for each one. If the tag | |
67 | # has the expected value, that means the core file was generated correctly | |
68 | # and that GDB read the contents correctly. | |
69 | for {set i 0} {$i < $nmaps} {incr i} { | |
70 | for {set offset 0} {$offset < $page_size} {set offset [expr $offset + 16]} { | |
71 | set hex_tag [format "%x" $tag] | |
72 | gdb_test "memory-tag print-allocation-tag mmap_pointers\[$i\] + $offset" \ | |
73 | "= 0x$hex_tag" \ | |
74 | "mmap_ponters\[$i\] + $offset contains expected tag" | |
75 | # Update the expected tag. The test writes tags in sequential | |
76 | # order. | |
77 | set tag [expr ($tag + 1) % 16] | |
78 | } | |
79 | } | |
80 | } | |
81 | ||
82 | # Exercise MTE corefile support using mode MODE (Async or Sync) | |
83 | ||
84 | proc test_mode { mode } { | |
85 | ||
86 | set compile_flags {"debug" "macros" "additional_flags=-march=armv8.5-a+memtag"} | |
87 | ||
88 | # If we are testing async mode, we need to force the testcase to use | |
89 | # such mode. | |
90 | if {$mode == "async"} { | |
91 | lappend compile_flags "additional_flags=-DASYNC" | |
92 | } | |
93 | ||
94 | standard_testfile | |
95 | set executable "${::testfile}-${mode}" | |
96 | if {[prepare_for_testing "failed to prepare" ${executable} ${::srcfile} ${compile_flags}]} { | |
97 | return -1 | |
98 | } | |
99 | set binfile [standard_output_file ${executable}] | |
100 | ||
101 | if ![runto_main] { | |
102 | untested "could not run to main" | |
103 | return -1 | |
104 | } | |
105 | ||
106 | # Targets that don't support memory tagging should not execute the | |
107 | # runtime memory tagging tests. | |
108 | if {![supports_memtag]} { | |
109 | unsupported "memory tagging unsupported" | |
110 | return -1 | |
111 | } | |
112 | ||
113 | # Run until a crash and confirm GDB displays memory tag violation | |
114 | # information. | |
115 | if {$mode == "sync"} { | |
116 | gdb_test "continue" \ | |
117 | [multi_line \ | |
118 | "Program received signal SIGSEGV, Segmentation fault" \ | |
119 | "Memory tag violation while accessing address ${::hex}" \ | |
120 | "Allocation tag 0x1" \ | |
121 | "Logical tag 0x0\." \ | |
122 | "${::hex} in main \\(.*\\) at .*" \ | |
123 | ".*mmap_pointers\\\[0\\\] = 0x4;"] \ | |
124 | "run to memory $mode tag violation" | |
125 | } else { | |
126 | gdb_test "continue" \ | |
127 | [multi_line \ | |
128 | "Program received signal SIGSEGV, Segmentation fault" \ | |
129 | "Memory tag violation" \ | |
130 | "Fault address unavailable\." \ | |
131 | "${::hex} in .* from .*"] \ | |
132 | "run to memory $mode tag violation" | |
133 | } | |
134 | ||
135 | # Generate the gcore core file. | |
136 | set gcore_filename [standard_output_file "${executable}.gcore"] | |
137 | set gcore_generated [gdb_gcore_cmd "$gcore_filename" "generate gcore file"] | |
138 | ||
139 | # Generate a native core file. | |
140 | set core_filename [core_find ${binfile}] | |
141 | set core_generated [expr {$core_filename != ""}] | |
142 | ||
143 | # At this point we have a couple core files, the gcore one generated by GDB | |
144 | # and the native one generated by the Linux Kernel. Make sure GDB can read | |
145 | # both correctly. | |
146 | ||
147 | if {$gcore_generated} { | |
148 | clean_restart ${binfile} | |
149 | with_test_prefix "gcore corefile" { | |
150 | test_mte_core_file $gcore_filename $mode | |
151 | } | |
152 | } else { | |
153 | fail "gcore corefile not generated" | |
154 | } | |
155 | ||
156 | if {$core_generated} { | |
157 | clean_restart ${binfile} | |
158 | with_test_prefix "native corefile" { | |
159 | test_mte_core_file $core_filename $mode | |
160 | } | |
161 | } else { | |
162 | untested "native corefile not generated" | |
163 | } | |
164 | ||
165 | } | |
166 | ||
d9050fb8 | 167 | require is_aarch64_target |
68cffbbd | 168 | |
f8ab28d7 TV |
169 | require {have_compile_flag -march=armv8.5-a+memtag} |
170 | ||
68cffbbd LM |
171 | # Run tests |
172 | foreach_with_prefix mode {"sync" "async"} { | |
173 | test_mode $mode | |
174 | } |