Skip to content

Commit 9d0eae6

Browse files
committed
[lldb][AArch64] Add register field enum information
This enables XML output for enums and adds enums for 2 fields on AArch64: * mte_ctrl.tcf, which controls how tag faults are delivered. * fpcr.rmode, which sets the rounding mode for floating point operations. The other one we could do is cpsr.btype, but it is not clear what would be useful here so I'm not including it in this change.
1 parent 2033b1c commit 9d0eae6

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,23 @@ LinuxArm64RegisterFlags::DetectMTECtrlFields(uint64_t hwcap, uint64_t hwcap2) {
5151
// Represents the contents of NT_ARM_TAGGED_ADDR_CTRL and the value passed
5252
// to prctl(PR_TAGGED_ADDR_CTRL...). Fields are derived from the defines
5353
// used to build the value.
54+
55+
static const FieldEnum tcf_enum(
56+
"tcf_enum",
57+
{{0, "TCF_NONE"}, {1, "TCF_SYNC"}, {2, "TCF_ASYNC"}, {3, "TCF_ASYMM"}});
5458
return {{"TAGS", 3, 18}, // 16 bit bitfield shifted up by PR_MTE_TAG_SHIFT.
55-
{"TCF_ASYNC", 2},
56-
{"TCF_SYNC", 1},
59+
{"TCF", 1, 2, &tcf_enum},
5760
{"TAGGED_ADDR_ENABLE", 0}};
5861
}
5962

6063
LinuxArm64RegisterFlags::Fields
6164
LinuxArm64RegisterFlags::DetectFPCRFields(uint64_t hwcap, uint64_t hwcap2) {
65+
66+
static const FieldEnum rmode_enum(
67+
"rmode_enum", {{0, "RN"}, {1, "RP"}, {2, "RM"}, {3, "RZ"}});
68+
6269
std::vector<RegisterFlags::Field> fpcr_fields{
63-
{"AHP", 26}, {"DN", 25}, {"FZ", 24}, {"RMode", 22, 23},
70+
{"AHP", 26}, {"DN", 25}, {"FZ", 24}, {"RMode", 22, 23, &rmode_enum},
6471
// Bits 21-20 are "Stride" which is unused in AArch64 state.
6572
};
6673

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3083,6 +3083,7 @@ GDBRemoteCommunicationServerLLGS::BuildTargetXml() {
30833083
if (registers_count)
30843084
response.IndentMore();
30853085

3086+
llvm::StringSet<> field_enums_seen;
30863087
for (int reg_index = 0; reg_index < registers_count; reg_index++) {
30873088
const RegisterInfo *reg_info =
30883089
reg_context.GetRegisterInfoAtIndex(reg_index);
@@ -3096,6 +3097,7 @@ GDBRemoteCommunicationServerLLGS::BuildTargetXml() {
30963097

30973098
if (reg_info->flags_type) {
30983099
response.IndentMore();
3100+
reg_info->flags_type->EnumsToXML(response, field_enums_seen);
30993101
reg_info->flags_type->ToXML(response);
31003102
response.IndentLess();
31013103
}

lldb/test/API/commands/register/register/register_command/TestRegisters.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,13 @@ def test_register_read_fields(self):
632632
self.expect("register read fpsr", substrs=["= (QC = 0, IDC = 0, IXC = 0"])
633633
# AHP/DN/FZ/RMode always present, others may vary.
634634
self.expect(
635-
"register read fpcr", substrs=["= (AHP = 0, DN = 0, FZ = 0, RMode = 0"]
635+
"register read fpcr", substrs=["= (AHP = 0, DN = 0, FZ = 0, RMode = RN"]
636+
)
637+
638+
# Should get enumerator descriptions for RMode.
639+
self.expect(
640+
"register info fpcr",
641+
substrs=["RMode: 0 = RN, 1 = RP, 2 = RM, 3 = RZ"],
636642
)
637643

638644
@skipUnlessPlatform(["linux"])

lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,12 @@ def test_aarch64_sve_regs_full(self):
583583
self.expect("register read fpsr", substrs=["= (QC = 0, IDC = 0, IXC = 0"])
584584
# AHP/DN/FZ/RMode always present, others may vary.
585585
self.expect(
586-
"register read fpcr", substrs=["= (AHP = 0, DN = 0, FZ = 0, RMode = 0"]
586+
"register read fpcr", substrs=["= (AHP = 0, DN = 0, FZ = 0, RMode = RN"]
587+
)
588+
# RMode should have enumerator descriptions.
589+
self.expect(
590+
"register info fpcr",
591+
substrs=["RMode: 0 = RN, 1 = RP, 2 = RM, 3 = RZ"],
587592
)
588593

589594
@skipIfLLVMTargetMissing("AArch64")

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,15 @@ def test_mte_ctrl_register(self):
238238
expected = ["mte_ctrl = 0x000000000007fffb"]
239239

240240
if self.hasXMLSupport():
241-
expected.append(
242-
"(TAGS = 65535, TCF_ASYNC = 0, TCF_SYNC = 1, TAGGED_ADDR_ENABLE = 1)"
243-
)
241+
expected.append("(TAGS = 65535, TCF = TCF_SYNC, TAGGED_ADDR_ENABLE = 1)")
244242

245243
self.expect("register read mte_ctrl", substrs=expected)
244+
245+
if self.hasXMLSupport():
246+
# Should get enumerator descriptions for TCF
247+
self.expect(
248+
"register info mte_ctrl",
249+
substrs=[
250+
"TCF: 0 = TCF_NONE, 1 = TCF_SYNC, 2 = TCF_ASYNC, 3 = TCF_ASYMM"
251+
],
252+
)

0 commit comments

Comments
 (0)