Skip to content

Commit b77e734

Browse files
[lldb][AArch64] Add register field enum information (#96887)
This enables XML output for enums and adds enums for 2 fields on AArch64 Linux: * 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 a707d08 commit b77e734

File tree

6 files changed

+35
-9
lines changed

6 files changed

+35
-9
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,22 @@ Arm64RegisterFlagsDetector::DetectMTECtrlFields(uint64_t hwcap,
5353
// Represents the contents of NT_ARM_TAGGED_ADDR_CTRL and the value passed
5454
// to prctl(PR_TAGGED_ADDR_CTRL...). Fields are derived from the defines
5555
// used to build the value.
56+
57+
static const FieldEnum tcf_enum(
58+
"tcf_enum",
59+
{{0, "TCF_NONE"}, {1, "TCF_SYNC"}, {2, "TCF_ASYNC"}, {3, "TCF_ASYMM"}});
5660
return {{"TAGS", 3, 18}, // 16 bit bitfield shifted up by PR_MTE_TAG_SHIFT.
57-
{"TCF_ASYNC", 2},
58-
{"TCF_SYNC", 1},
61+
{"TCF", 1, 2, &tcf_enum},
5962
{"TAGGED_ADDR_ENABLE", 0}};
6063
}
6164

6265
Arm64RegisterFlagsDetector::Fields
6366
Arm64RegisterFlagsDetector::DetectFPCRFields(uint64_t hwcap, uint64_t hwcap2) {
67+
static const FieldEnum rmode_enum(
68+
"rmode_enum", {{0, "RN"}, {1, "RP"}, {2, "RM"}, {3, "RZ"}});
69+
6470
std::vector<RegisterFlags::Field> fpcr_fields{
65-
{"AHP", 26}, {"DN", 25}, {"FZ", 24}, {"RMode", 22, 23},
71+
{"AHP", 26}, {"DN", 25}, {"FZ", 24}, {"RMode", 22, 23, &rmode_enum},
6672
// Bits 21-20 are "Stride" which is unused in AArch64 state.
6773
};
6874

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+
)

lldb/test/Shell/Register/Core/aarch64-freebsd-register-fields.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ register read fpsr
1212
# CHECK-NEXT: = (QC = 0, IDC = 0, IXC = 0, UFC = 0, OFC = 0, DZC = 0, IOC = 0)
1313
register read fpcr
1414
# CHECK: fpcr = 0x02000000
15-
# CHECK-NEXT: = (AHP = 0, DN = 1, FZ = 0, RMode = 0, IDE = 0, IXE = 0, UFE = 0, OFE = 0, DZE = 0, IOE = 0)
15+
# CHECK-NEXT: = (AHP = 0, DN = 1, FZ = 0, RMode = RN, IDE = 0, IXE = 0, UFE = 0, OFE = 0, DZE = 0, IOE = 0)

0 commit comments

Comments
 (0)