Skip to content

Commit 22044f0

Browse files
committed
[lldb][AArch64] Add testing of save/restore for Linux MTE control register
This has always worked but had no coverage. Adding testing now so that later I can refactor the save/restore code safely. Reviewed By: omjavaid Differential Revision: https://reviews.llvm.org/D157488
1 parent e0c60bf commit 22044f0

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
C_SOURCES := main.c
2+
3+
include Makefile.rules
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""
2+
Test that LLDB correctly reads, writes and restores the MTE control register on
3+
AArch64 Linux.
4+
"""
5+
6+
import lldb
7+
from lldbsuite.test.decorators import *
8+
from lldbsuite.test.lldbtest import *
9+
from lldbsuite.test import lldbutil
10+
11+
12+
class MTECtrlRegisterTestCase(TestBase):
13+
@no_debug_info_test
14+
@skipIf(archs=no_match(["aarch64"]))
15+
@skipIf(oslist=no_match(["linux"]))
16+
def test_mte_ctrl_register(self):
17+
if not self.isAArch64MTE():
18+
self.skipTest("Target must support MTE.")
19+
20+
self.build()
21+
self.line = line_number("main.c", "// Set a break point here.")
22+
23+
exe = self.getBuildArtifact("a.out")
24+
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
25+
26+
lldbutil.run_break_set_by_file_and_line(
27+
self, "main.c", self.line, num_expected_locations=1
28+
)
29+
self.runCmd("run", RUN_SUCCEEDED)
30+
31+
self.expect(
32+
"process status",
33+
STOPPED_DUE_TO_BREAKPOINT,
34+
substrs=["stop reason = breakpoint 1."],
35+
)
36+
37+
# Bit 0 = tagged addressing enabled
38+
# Bit 1 = synchronous faults
39+
# Bit 2 = asynchronous faults
40+
# We start enabled with synchronous faults.
41+
self.expect("register read mte_ctrl", substrs=["0x0000000000000003"])
42+
43+
# Change to asynchronous faults.
44+
self.runCmd("register write mte_ctrl 5")
45+
self.expect("register read mte_ctrl", substrs=["0x0000000000000005"])
46+
47+
# This would return to synchronous faults if we did not restore the
48+
# previous value.
49+
self.expect("expression setup_mte()", substrs=["= 0"])
50+
self.expect("register read mte_ctrl", substrs=["0x0000000000000005"])
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <sys/prctl.h>
2+
3+
// This is its own function so that lldb can call it.
4+
int setup_mte() {
5+
return prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE | PR_MTE_TCF_SYNC,
6+
0, 0, 0);
7+
}
8+
9+
int main(int argc, char const *argv[]) {
10+
if (setup_mte())
11+
return 1;
12+
13+
return 0; // Set a break point here.
14+
}

0 commit comments

Comments
 (0)