Skip to content

Commit 2f8e3d5

Browse files
[lldb][AArch64][Linux] Add field information for the mte_ctrl register (#71808)
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.
1 parent 4178a66 commit 2f8e3d5

File tree

5 files changed

+54
-10
lines changed

5 files changed

+54
-10
lines changed

lldb/packages/Python/lldbsuite/test/lldbtest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,17 @@ def dumpSessionInfo(self):
12241224
# (enables reading of the current test configuration)
12251225
# ====================================================
12261226

1227+
def hasXMLSupport(self):
1228+
"""Returns True if lldb was built with XML support. Use this check to
1229+
enable parts of tests, if you want to skip a whole test use skipIfXmlSupportMissing
1230+
instead."""
1231+
return (
1232+
lldb.SBDebugger.GetBuildConfiguration()
1233+
.GetValueForKey("xml")
1234+
.GetValueForKey("value")
1235+
.GetBooleanValue(False)
1236+
)
1237+
12271238
def isMIPS(self):
12281239
"""Returns true if the architecture is MIPS."""
12291240
arch = self.getArchitecture()

lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@
2424

2525
using namespace lldb_private;
2626

27+
LinuxArm64RegisterFlags::Fields
28+
LinuxArm64RegisterFlags::DetectMTECtrlFields(uint64_t hwcap, uint64_t hwcap2) {
29+
(void)hwcap;
30+
(void)hwcap2;
31+
// Represents the contents of NT_ARM_TAGGED_ADDR_CTRL and the value passed
32+
// to prctl(PR_TAGGED_ADDR_CTRL...). Fields are derived from the defines
33+
// used to build the value.
34+
return {{"TAGS", 3, 18}, // 16 bit bitfield shifted up by PR_MTE_TAG_SHIFT.
35+
{"TCF_ASYNC", 2},
36+
{"TCF_SYNC", 1},
37+
{"TAGGED_ADDR_ENABLE", 0}};
38+
}
39+
2740
LinuxArm64RegisterFlags::Fields
2841
LinuxArm64RegisterFlags::DetectFPCRFields(uint64_t hwcap, uint64_t hwcap2) {
2942
std::vector<RegisterFlags::Field> fpcr_fields{

lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class LinuxArm64RegisterFlags {
5858
static Fields DetectCPSRFields(uint64_t hwcap, uint64_t hwcap2);
5959
static Fields DetectFPSRFields(uint64_t hwcap, uint64_t hwcap2);
6060
static Fields DetectFPCRFields(uint64_t hwcap, uint64_t hwcap2);
61+
static Fields DetectMTECtrlFields(uint64_t hwcap, uint64_t hwcap2);
6162

6263
struct RegisterEntry {
6364
RegisterEntry(llvm::StringRef name, unsigned size, DetectorFn detector)
@@ -67,10 +68,11 @@ class LinuxArm64RegisterFlags {
6768
llvm::StringRef m_name;
6869
RegisterFlags m_flags;
6970
DetectorFn m_detector;
70-
} m_registers[3] = {
71+
} m_registers[4] = {
7172
RegisterEntry("cpsr", 4, DetectCPSRFields),
7273
RegisterEntry("fpsr", 4, DetectFPSRFields),
7374
RegisterEntry("fpcr", 4, DetectFPCRFields),
75+
RegisterEntry("mte_ctrl", 8, DetectMTECtrlFields),
7476
};
7577

7678
// Becomes true once field detection has been run for all registers.

lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/TestMTECtrlRegister.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,28 @@ def test_mte_ctrl_register(self):
3434
substrs=["stop reason = breakpoint 1."],
3535
)
3636

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"])
37+
def check_mte_ctrl(async_err, sync_err):
38+
# Bit 0 = tagged addressing enabled
39+
# Bit 1 = synchronous faults
40+
# Bit 2 = asynchronous faults
41+
value = "0x{:016x}".format((async_err << 2) | (sync_err << 1) | 1)
42+
expected = [value]
43+
44+
if self.hasXMLSupport():
45+
expected.append(
46+
"(TAGS = 0, TCF_ASYNC = {}, TCF_SYNC = {}, TAGGED_ADDR_ENABLE = 1)".format(
47+
async_err, sync_err
48+
)
49+
)
50+
51+
self.expect("register read mte_ctrl", substrs=expected)
4252

53+
# We start enabled with synchronous faults.
54+
check_mte_ctrl(0, 1)
4355
# Change to asynchronous faults.
4456
self.runCmd("register write mte_ctrl 5")
45-
self.expect("register read mte_ctrl", substrs=["0x0000000000000005"])
46-
57+
check_mte_ctrl(1, 0)
4758
# This would return to synchronous faults if we did not restore the
4859
# previous value.
4960
self.expect("expression setup_mte()", substrs=["= 0"])
50-
self.expect("register read mte_ctrl", substrs=["0x0000000000000005"])
61+
check_mte_ctrl(1, 0)

lldb/test/API/linux/aarch64/mte_core_file/TestAArch64LinuxMTEMemoryTagCoreFile.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,11 @@ def test_mte_ctrl_register(self):
235235
# * Allowed tags value of 0xFFFF, shifted up by 3 resulting in 0x7fff8.
236236
# * Bit 1 set to enable synchronous tag faults.
237237
# * Bit 0 set to enable the tagged address ABI.
238-
self.expect("register read mte_ctrl", substrs=["mte_ctrl = 0x000000000007fffb"])
238+
expected = ["mte_ctrl = 0x000000000007fffb"]
239+
240+
if self.hasXMLSupport():
241+
expected.append(
242+
"(TAGS = 65535, TCF_ASYNC = 0, TCF_SYNC = 1, TAGGED_ADDR_ENABLE = 1)"
243+
)
244+
245+
self.expect("register read mte_ctrl", substrs=expected)

0 commit comments

Comments
 (0)