[Lldb-commits] [lldb] 22044f0 - [lldb][AArch64] Add testing of save/restore for Linux MTE control register

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Thu Aug 31 04:25:13 PDT 2023


Author: David Spickett
Date: 2023-08-31T12:25:08+01:00
New Revision: 22044f0bde015f4bf53fca24831d030ff96efc51

URL: https://github.com/llvm/llvm-project/commit/22044f0bde015f4bf53fca24831d030ff96efc51
DIFF: https://github.com/llvm/llvm-project/commit/22044f0bde015f4bf53fca24831d030ff96efc51.diff

LOG: [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

Added: 
    lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/Makefile
    lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/TestMTECtrlRegister.py
    lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/main.c

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/Makefile b/lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/Makefile
new file mode 100644
index 00000000000000..10495940055b63
--- /dev/null
+++ b/lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules

diff  --git a/lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/TestMTECtrlRegister.py b/lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/TestMTECtrlRegister.py
new file mode 100644
index 00000000000000..48e8bb872e3f02
--- /dev/null
+++ b/lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/TestMTECtrlRegister.py
@@ -0,0 +1,50 @@
+"""
+Test that LLDB correctly reads, writes and restores the MTE control register on
+AArch64 Linux.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class MTECtrlRegisterTestCase(TestBase):
+    @no_debug_info_test
+    @skipIf(archs=no_match(["aarch64"]))
+    @skipIf(oslist=no_match(["linux"]))
+    def test_mte_ctrl_register(self):
+        if not self.isAArch64MTE():
+            self.skipTest("Target must support MTE.")
+
+        self.build()
+        self.line = line_number("main.c", "// Set a break point here.")
+
+        exe = self.getBuildArtifact("a.out")
+        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+        lldbutil.run_break_set_by_file_and_line(
+            self, "main.c", self.line, num_expected_locations=1
+        )
+        self.runCmd("run", RUN_SUCCEEDED)
+
+        self.expect(
+            "process status",
+            STOPPED_DUE_TO_BREAKPOINT,
+            substrs=["stop reason = breakpoint 1."],
+        )
+
+        # Bit 0 = tagged addressing enabled
+        # Bit 1 = synchronous faults
+        # Bit 2 = asynchronous faults
+        # We start enabled with synchronous faults.
+        self.expect("register read mte_ctrl", substrs=["0x0000000000000003"])
+
+        # Change to asynchronous faults.
+        self.runCmd("register write mte_ctrl 5")
+        self.expect("register read mte_ctrl", substrs=["0x0000000000000005"])
+
+        # This would return to synchronous faults if we did not restore the
+        # previous value.
+        self.expect("expression setup_mte()", substrs=["= 0"])
+        self.expect("register read mte_ctrl", substrs=["0x0000000000000005"])
\ No newline at end of file

diff  --git a/lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/main.c b/lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/main.c
new file mode 100644
index 00000000000000..788093fd05038a
--- /dev/null
+++ b/lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/main.c
@@ -0,0 +1,14 @@
+#include <sys/prctl.h>
+
+// This is its own function so that lldb can call it.
+int setup_mte() {
+  return prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE | PR_MTE_TCF_SYNC,
+               0, 0, 0);
+}
+
+int main(int argc, char const *argv[]) {
+  if (setup_mte())
+    return 1;
+
+  return 0; // Set a break point here.
+}


        


More information about the lldb-commits mailing list