• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

修訂dc57be664942967ec34330c07eda591cd7b3662c (tree)
時間2020-06-16 21:58:33
作者Luis Machado <luis.machado@lina...>
CommiterLuis Machado

Log Message

Add memory tagging testcases

Add an AArch64-specific test and a more generic memory tagging test that
other architectures can run.

Even though architectures not supporting memory tagging can run the memory
tagging tests, the runtime check will make the tests bail out early, as it
would make no sense to proceed without proper support.

gdb/testsuite/ChangeLog:

YYYY-MM-DD Luis Machado <luis.machado@linaro.org>

* gdb.arch/aarch64-mte.c: New file.
* gdb.arch/aarch64-mte.exp: New test.
* gdb.base/memtag.c: New file.
* gdb.base/memtag.exp: New test.
* lib/gdb.exp (supports_memtag): New function.

Change Summary

差異

--- /dev/null
+++ b/gdb/testsuite/gdb.arch/aarch64-mte.c
@@ -0,0 +1,22 @@
1+/* This test program is part of GDB, the GNU debugger.
2+
3+ Copyright 2020 Free Software Foundation, Inc.
4+
5+ This program is free software; you can redistribute it and/or modify
6+ it under the terms of the GNU General Public License as published by
7+ the Free Software Foundation; either version 3 of the License, or
8+ (at your option) any later version.
9+
10+ This program is distributed in the hope that it will be useful,
11+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ GNU General Public License for more details.
14+
15+ You should have received a copy of the GNU General Public License
16+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
17+
18+int
19+main (int argc, char **argv)
20+{
21+ return 0;
22+}
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/aarch64-mte.exp
@@ -0,0 +1,196 @@
1+# Copyright (C) 2020 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+# Test a binary with address signing works regardless of whether the target
17+# supports pauth instructions. On non pauth systems, all pauth instructions
18+# are treated as nops.
19+
20+global hex
21+global decimal
22+
23+# Return TAG in hex format with no leading zeroes.
24+proc get_hex_tag { tag } {
25+ return [format "%x" $tag]
26+}
27+
28+# Return TAG in the NN format where N is 4 bits of the byte.
29+proc get_tag_nn { tag } {
30+ return [format "%02x" $tag]
31+}
32+
33+# Return the address of PTR with a tag of TAG.
34+proc get_tagged_ptr { tag ptr } {
35+ return [get_valueof "/x" \
36+ "${ptr} & (0x00ffffffffffffff) | ((unsigned long) ${tag} << 56)" \
37+ "0" "fetch pointer ${ptr} with tag ${tag}"]
38+}
39+
40+# Return the logical TAG from PTR.
41+proc get_ltag_from_ptr { ptr } {
42+ return [get_valueof "/x" "$ptr >> 56 & 0xf" -1 "fetch tag from pointer ${ptr}"]
43+}
44+
45+if {![is_aarch64_target]} {
46+ verbose "Skipping ${gdb_test_file_name}."
47+ return
48+}
49+
50+standard_testfile
51+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
52+ return -1
53+}
54+
55+if ![runto_main] {
56+ untested "could not run to main"
57+ return -1
58+}
59+
60+# Targets that don't support memory tagging should not execute the
61+# runtime memory tagging tests.
62+if {![supports_memtag]} {
63+ untested "memory tagging unsupported"
64+ return -1
65+}
66+
67+with_test_prefix "literals" {
68+ set setatag_msg "Allocation tag\\(s\\) updated successfully\."
69+ set check_msg "Memory tags match\."
70+
71+ # Test setting and showing the logical tags.
72+ for {set i 0} {$i < 32} {incr i} {
73+ set addr [get_tagged_ptr $i 0xdeadbeef]
74+ set tag [get_hex_tag [expr $i % 16]]
75+ gdb_test "mtag showltag $addr" " = 0x${tag}" "showltag with tag ${i}"
76+
77+ set tag_nn [get_tag_nn $i]
78+ gdb_test "mtag setltag ${addr} ${tag_nn}" " = \\(void \\*\\) ${addr}" \
79+ "setltag with tag ${i}"
80+ }
81+
82+ # Fetch the pointer to a known PROT_MTE-mapped area.
83+ set tagged_ptr [get_hexadecimal_valueof "argv" -1]
84+
85+ if {$tagged_ptr == -1} {
86+ untested "unexpected pointer or tag value"
87+ return -1
88+ }
89+
90+ # Test setting and showing the allocation tags
91+ for {set i 0} {$i < 32} {incr i} {
92+
93+ set tag_nn [get_tag_nn $i]
94+ gdb_test "mtag setatag $tagged_ptr 0 ${tag_nn}" \
95+ $setatag_msg \
96+ "setatag with tag ${i}"
97+
98+ set tag [get_hex_tag [expr $i % 16]]
99+ gdb_test "mtag showatag $tagged_ptr" " = 0x${i}" \
100+ "showatag with tag ${i}"
101+ }
102+
103+ # Test tag mismatches.
104+ with_test_prefix "tag mismatches" {
105+ for {set i 0} {$i < 32} {incr i} {
106+
107+ # Set the allocation tag to a known value.
108+ set tag_nn [get_tag_nn $i]
109+ gdb_test "mtag setatag $tagged_ptr 0 ${tag_nn}" \
110+ $setatag_msg \
111+ "setatag with tag ${i}"
112+
113+ # Validate that the logical tag matches against the allocation
114+ # tag.
115+ set addr [get_tagged_ptr $i $tagged_ptr]
116+ gdb_test "mtag check $addr" $check_msg \
117+ "check match with tag ${i}"
118+
119+ # Get a pointer with the logical tag that does not match the
120+ # allocation tag.
121+ set ltag [expr $i + 1]
122+ with_test_prefix "fetch mismatch tag" {
123+ set addr [get_tagged_ptr $ltag $tagged_ptr]
124+ }
125+
126+ # Validate that the logical tag does not match the allocation
127+ # tag.
128+ set ltag [get_hex_tag [expr [expr $i + 1]% 16]]
129+ set atag [get_hex_tag [expr $i % 16]]
130+ gdb_test "mtag check $addr" \
131+ "Logical tag \\(0x${ltag}\\) does not match the allocation tag \\(0x${atag}\\)\." \
132+ "check mismatch with tag ${i}"
133+ }
134+ }
135+
136+}
137+
138+# Test the memory tagging extensions for the "print" command.
139+with_test_prefix "print command" {
140+ set ptr_name "argv"
141+ set tagged_ptr [get_hexadecimal_valueof $ptr_name -1]
142+
143+ if {$tagged_ptr == -1} {
144+ untested "unexpected pointer or tag value"
145+ return -1
146+ }
147+
148+ set ltag [get_ltag_from_ptr ${tagged_ptr}]
149+
150+ if {$ltag == -1} {
151+ untested "unexpected tag value"
152+ return -1
153+ }
154+
155+ set atag [expr [expr $ltag + 1] % 16]
156+ set atag_nn [get_tag_nn $atag]
157+
158+ gdb_test "mtag setatag $tagged_ptr 0 ${atag_nn}" \
159+ $setatag_msg \
160+ "make atag and ltag different"
161+
162+ gdb_test "p $ptr_name" \
163+ [multi_line \
164+ "Logical tag \\(${ltag}\\) does not match Allocation tag \\(0x${atag}\\)\." \
165+ "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <.*>)?\[\r\n\]+"] \
166+ "show tag mismatch"
167+}
168+
169+# Test the memory tagging extensions for the "x" command.
170+with_test_prefix "x command" {
171+ set ptr_name "argv"
172+
173+ # Check if the allocation tags match what we expect.
174+ gdb_test "x/gxm argv" \
175+ [multi_line \
176+ "<Allocation Tag $hex for range \\\[$hex,$hex\\)>" \
177+ "$hex:\[ \t\]+$hex"] \
178+ "outputs tag information"
179+}
180+
181+# Validate the presence of the MTE registers.
182+foreach reg {"sctlr" "gcr"} {
183+ gdb_test "info registers $reg" \
184+ "$reg\[ \t\]+$hex\[ \t\]+$decimal" \
185+ "register $reg available"
186+}
187+
188+# Run until a crash and confirm GDB displays memory tag violation
189+# information.
190+gdb_test "continue" \
191+ [multi_line \
192+ "Memory tag violation while accessing address $hex" \
193+ "Logical tag $hex" \
194+ "Allocation tag $hex" \
195+ "$hex in main \\(argc=1, argv=0xfffffffff3b8\\) at .*"] \
196+ "display tag violation information"
--- /dev/null
+++ b/gdb/testsuite/gdb.base/memtag.c
@@ -0,0 +1,22 @@
1+/* This test program is part of GDB, the GNU debugger.
2+
3+ Copyright 2020 Free Software Foundation, Inc.
4+
5+ This program is free software; you can redistribute it and/or modify
6+ it under the terms of the GNU General Public License as published by
7+ the Free Software Foundation; either version 3 of the License, or
8+ (at your option) any later version.
9+
10+ This program is distributed in the hope that it will be useful,
11+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ GNU General Public License for more details.
14+
15+ You should have received a copy of the GNU General Public License
16+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
17+
18+int
19+main (int argc, char **argv)
20+{
21+ return 0;
22+}
--- /dev/null
+++ b/gdb/testsuite/gdb.base/memtag.exp
@@ -0,0 +1,59 @@
1+# Copyright 2020 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+# Exercise the various bits of memory tagging support in GDB.
17+
18+# Return 0 if memory tagging is supported.
19+# Return 1 otherwise.
20+
21+set u_msg "Memory tagging not supported or disabled by the current architecture\."
22+
23+standard_testfile
24+if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile}]} {
25+ return -1
26+}
27+
28+# Test commands without running the program.
29+with_test_prefix "before program execution" {
30+ # These commands should all fails without a running program.
31+ foreach subcmd {"setltag" "showltag" "setatag" "showatag" "check"} {
32+ gdb_test "mtag $subcmd" "$u_msg"
33+ }
34+}
35+
36+if ![runto_main] {
37+ untested "could not run to main"
38+ return -1
39+}
40+
41+# Targets that don't support memory tagging should not execute the
42+# runtime memory tagging tests.
43+if {![supports_memtag]} {
44+ untested "memory tagging unsupported"
45+ return -1
46+}
47+
48+# With the program running, try to use the memory tagging commands.
49+with_test_prefix "during program execution" {
50+ set msg "Argument required \\(address or pointer\\)\."
51+
52+ # Test the various mtag commands again.
53+ gdb_test "mtag showltag" $msg
54+ gdb_test "mtag showatag" $msg
55+ gdb_test "mtag setltag" "Arguments required \\(<address> <tag>\\)\."
56+ gdb_test "mtag setatag"
57+ "Arguments required \\(<starting address> <length> <tag bytes>\\)\."
58+ gdb_test "mtag check" $msg
59+}
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -2613,6 +2613,22 @@ proc supports_get_siginfo_type {} {
26132613 }
26142614 }
26152615
2616+# Return 1 if memory tagging is supported at runtime, otherwise return 0.
2617+
2618+proc supports_memtag {} {
2619+ global gdb_prompt
2620+
2621+ gdb_test_multiple "mtag check" "" {
2622+ -re "Memory tagging not supported or disabled by the current architecture\..*$gdb_prompt $" {
2623+ return 0
2624+ }
2625+ -re "Argument required \\(address or pointer\\).*$gdb_prompt $" {
2626+ return 1
2627+ }
2628+ }
2629+ return 0
2630+}
2631+
26162632 # Return 1 if the target supports hardware single stepping.
26172633
26182634 proc can_hardware_single_step {} {