[Lldb-commits] [PATCH] D157488: [lldb][AArch64] Add testing of save/restore for Linux MTE control register

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


This revision was automatically updated to reflect the committed changes.
Closed by commit rG22044f0bde01: [lldb][AArch64] Add testing of save/restore for Linux MTE control register (authored by DavidSpickett).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157488/new/

https://reviews.llvm.org/D157488

Files:
  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


Index: lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/main.c
===================================================================
--- /dev/null
+++ 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.
+}
Index: lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/TestMTECtrlRegister.py
===================================================================
--- /dev/null
+++ 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
Index: lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/Makefile
===================================================================
--- /dev/null
+++ lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157488.554979.patch
Type: text/x-patch
Size: 2957 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230831/ff479457/attachment.bin>


More information about the lldb-commits mailing list