[Lldb-commits] [lldb] [lldb][AArch64][Linux] Add field information for the mte_ctrl register (PR #71808)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Nov 9 06:08:06 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: David Spickett (DavidSpickett)
<details>
<summary>Changes</summary>
This is a Linux pseudo register provided by the NT_ARM_TAGGED_ADDR_CTRL register set. It reflects the value passed to prctl PR_SET_TAGGED_ADDR_CTRL.
https://docs.kernel.org/arch/arm64/memory-tagging-extension.html
The fields are made from the #defines the kernel provides for setting the value. Its contents are constant so no runtime detection is needed (once we've decided we have this register in the first place).
The permitted generated tags is technically a bitfield but at this time we don't have a way to mark a field as preferring hex formatting.
```
(lldb) register read mte_ctrl
mte_ctrl = 0x000000000007fffb
= (TAGS = 65535, TCF_ASYNC = 0, TCF_SYNC = 1, TAGGED_ADDR_ENABLE = 1)
```
(4 bit tags mean 16 possible tags, 16 bit bitfield)
Testing has been added to TestMTECtrlRegister.py, which needed a more granular way to check for XML support, so I've added hasXMLSupport that can be used within a test case instead of skipping whole tests if XML isn't supported.
Same for the core file tests.
---
Full diff: https://github.com/llvm/llvm-project/pull/71808.diff
5 Files Affected:
- (modified) lldb/packages/Python/lldbsuite/test/lldbtest.py (+11)
- (modified) lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp (+13)
- (modified) lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h (+3-1)
- (modified) lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/TestMTECtrlRegister.py (+19-8)
- (modified) lldb/test/API/linux/aarch64/mte_core_file/TestAArch64LinuxMTEMemoryTagCoreFile.py (+8-1)
``````````diff
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 15e8ba21266c896..19ba0e8c133edcf 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -1224,6 +1224,17 @@ def dumpSessionInfo(self):
# (enables reading of the current test configuration)
# ====================================================
+ def hasXMLSupport(self):
+ """Returns True if lldb was built with XML support. Use this check to
+ enable parts of tests, if you want to skip a whole test use skipIfXmlSupportMissing
+ instead."""
+ return (
+ lldb.SBDebugger.GetBuildConfiguration()
+ .GetValueForKey("xml")
+ .GetValueForKey("value")
+ .GetBooleanValue(False)
+ )
+
def isMIPS(self):
"""Returns true if the architecture is MIPS."""
arch = self.getArchitecture()
diff --git a/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp b/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp
index 87f2464a9eb4868..ca247b628abe78f 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp
+++ b/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp
@@ -24,6 +24,19 @@
using namespace lldb_private;
+LinuxArm64RegisterFlags::Fields
+LinuxArm64RegisterFlags::DetectMTECtrlFields(uint64_t hwcap, uint64_t hwcap2) {
+ (void)hwcap;
+ (void)hwcap2;
+ // Represents the contents of NT_ARM_TAGGED_ADDR_CTRL and the value passed
+ // to prctl(PR_TAGGED_ADDR_CTRL...). Fields are derived from the defines
+ // used to build the value.
+ return {{"TAGS", 3, 18}, // 16 bit bitfield shifted up by PR_MTE_TAG_SHIFT.
+ {"TCF_ASYNC", 2},
+ {"TCF_SYNC", 1},
+ {"TAGGED_ADDR_ENABLE", 0}};
+}
+
LinuxArm64RegisterFlags::Fields
LinuxArm64RegisterFlags::DetectFPCRFields(uint64_t hwcap, uint64_t hwcap2) {
std::vector<RegisterFlags::Field> fpcr_fields{
diff --git a/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h b/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h
index 651a8c86f7c86a9..deff977a03d0a12 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h
+++ b/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h
@@ -58,6 +58,7 @@ class LinuxArm64RegisterFlags {
static Fields DetectCPSRFields(uint64_t hwcap, uint64_t hwcap2);
static Fields DetectFPSRFields(uint64_t hwcap, uint64_t hwcap2);
static Fields DetectFPCRFields(uint64_t hwcap, uint64_t hwcap2);
+ static Fields DetectMTECtrlFields(uint64_t hwcap, uint64_t hwcap2);
struct RegisterEntry {
RegisterEntry(llvm::StringRef name, unsigned size, DetectorFn detector)
@@ -67,10 +68,11 @@ class LinuxArm64RegisterFlags {
llvm::StringRef m_name;
RegisterFlags m_flags;
DetectorFn m_detector;
- } m_registers[3] = {
+ } m_registers[4] = {
RegisterEntry("cpsr", 4, DetectCPSRFields),
RegisterEntry("fpsr", 4, DetectFPSRFields),
RegisterEntry("fpcr", 4, DetectFPCRFields),
+ RegisterEntry("mte_ctrl", 8, DetectMTECtrlFields),
};
// Becomes true once field detection has been run for all registers.
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
index 7fd6b2dada640e6..3eaca00b0dccca9 100644
--- 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
@@ -34,17 +34,28 @@ def test_mte_ctrl_register(self):
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"])
+ def check_mte_ctrl(async_err, sync_err):
+ # Bit 0 = tagged addressing enabled
+ # Bit 1 = synchronous faults
+ # Bit 2 = asynchronous faults
+ value = "0x{:016x}".format((async_err << 2) | (sync_err << 1) | 1)
+ expected = [value]
+
+ if self.hasXMLSupport():
+ expected.append(
+ "(TAGS = 0, TCF_ASYNC = {}, TCF_SYNC = {}, TAGGED_ADDR_ENABLE = 1)".format(
+ async_err, sync_err
+ )
+ )
+
+ self.expect("register read mte_ctrl", substrs=expected)
+ # We start enabled with synchronous faults.
+ check_mte_ctrl(0, 1)
# Change to asynchronous faults.
self.runCmd("register write mte_ctrl 5")
- self.expect("register read mte_ctrl", substrs=["0x0000000000000005"])
-
+ check_mte_ctrl(1, 0)
# 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"])
+ check_mte_ctrl(1, 0)
diff --git a/lldb/test/API/linux/aarch64/mte_core_file/TestAArch64LinuxMTEMemoryTagCoreFile.py b/lldb/test/API/linux/aarch64/mte_core_file/TestAArch64LinuxMTEMemoryTagCoreFile.py
index 4389d3d761d79c2..045f8c0a7010839 100644
--- a/lldb/test/API/linux/aarch64/mte_core_file/TestAArch64LinuxMTEMemoryTagCoreFile.py
+++ b/lldb/test/API/linux/aarch64/mte_core_file/TestAArch64LinuxMTEMemoryTagCoreFile.py
@@ -235,4 +235,11 @@ def test_mte_ctrl_register(self):
# * Allowed tags value of 0xFFFF, shifted up by 3 resulting in 0x7fff8.
# * Bit 1 set to enable synchronous tag faults.
# * Bit 0 set to enable the tagged address ABI.
- self.expect("register read mte_ctrl", substrs=["mte_ctrl = 0x000000000007fffb"])
+ expected = ["mte_ctrl = 0x000000000007fffb"]
+
+ if self.hasXMLSupport():
+ expected.append(
+ "(TAGS = 65535, TCF_ASYNC = 0, TCF_SYNC = 1, TAGGED_ADDR_ENABLE = 1)"
+ )
+
+ self.expect("register read mte_ctrl", substrs=expected)
``````````
</details>
https://github.com/llvm/llvm-project/pull/71808
More information about the lldb-commits
mailing list