[Lldb-commits] [lldb] [lldb][AArch64] Move register info reconfigure into architecture plugin (PR #70950)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Wed Nov 1 09:28:19 PDT 2023
================
@@ -762,82 +756,22 @@ uint32_t GDBRemoteRegisterContext::ConvertRegisterKindToRegisterNumber(
return m_reg_info_sp->ConvertRegisterKindToRegisterNumber(kind, num);
}
-void GDBRemoteRegisterContext::AArch64Reconfigure() {
- assert(m_reg_info_sp);
-
- // Once we start to reconfigure registers, we cannot read any of them.
- // So we must read VG and SVG up front.
-
- const uint64_t fail_value = LLDB_INVALID_ADDRESS;
- std::optional<uint64_t> vg_reg_value;
- const RegisterInfo *vg_reg_info = m_reg_info_sp->GetRegisterInfo("vg");
- if (vg_reg_info) {
- // Make sure we get the latest value of vg from the remote.
- SetRegisterIsValid(vg_reg_info, false);
- uint32_t vg_reg_num = vg_reg_info->kinds[eRegisterKindLLDB];
- uint64_t reg_value = ReadRegisterAsUnsigned(vg_reg_num, fail_value);
- if (reg_value != fail_value && reg_value <= 32)
- vg_reg_value = reg_value;
- }
-
- std::optional<uint64_t> svg_reg_value;
- const RegisterInfo *svg_reg_info = m_reg_info_sp->GetRegisterInfo("svg");
- if (svg_reg_info) {
- // When vg is written it is automatically made invalid. Writing vg will also
- // change svg if we're in streaming mode but it will not be made invalid
- // so do this manually so the following read gets the latest svg value.
- SetRegisterIsValid(svg_reg_info, false);
-
- uint32_t svg_reg_num = svg_reg_info->kinds[eRegisterKindLLDB];
- uint64_t reg_value = ReadRegisterAsUnsigned(svg_reg_num, fail_value);
- if (reg_value != fail_value && reg_value <= 32)
- svg_reg_value = reg_value;
- }
-
- if (vg_reg_value)
- m_reg_info_sp->UpdateARM64SVERegistersInfos(*vg_reg_value);
- if (svg_reg_value)
- m_reg_info_sp->UpdateARM64SMERegistersInfos(*svg_reg_value);
-
- // At this point if we have updated any registers, their offsets will all be
- // invalid. If we did, we need to update them all.
- if (vg_reg_value || svg_reg_value) {
- m_reg_info_sp->ConfigureOffsets();
- // From here we are able to read registers again.
-
- // Make a heap based buffer that is big enough to store all registers
- m_reg_data.SetData(std::make_shared<DataBufferHeap>(
- m_reg_info_sp->GetRegisterDataByteSize(), 0));
- m_reg_data.SetByteOrder(GetByteOrder());
- }
-}
-
-void GDBRemoteDynamicRegisterInfo::UpdateARM64SVERegistersInfos(uint64_t vg) {
- // SVE Z register size is vg x 8 bytes.
- uint32_t z_reg_byte_size = vg * 8;
-
- // SVE vector length has changed, accordingly set size of Z, P and FFR
- // registers. Also invalidate register offsets it will be recalculated
- // after SVE register size update.
- for (auto ® : m_regs) {
- if (reg.value_regs == nullptr) {
- if (reg.name[0] == 'z' && isdigit(reg.name[1]))
- reg.byte_size = z_reg_byte_size;
- else if (reg.name[0] == 'p' && isdigit(reg.name[1]))
- reg.byte_size = vg;
- else if (strcmp(reg.name, "ffr") == 0)
- reg.byte_size = vg;
- }
- reg.byte_offset = LLDB_INVALID_INDEX32;
- }
+bool GDBRemoteRegisterContext::RegisterWriteCausesReconfigure(
+ const char *name) {
+ ExecutionContext exe_ctx(CalculateThread());
+ Process *process = exe_ctx.GetProcessPtr();
+ const Architecture *architecture =
+ process->GetTarget().GetArchitecturePlugin();
+ return architecture && architecture->RegisterWriteCausesReconfigure(name);
}
-void GDBRemoteDynamicRegisterInfo::UpdateARM64SMERegistersInfos(uint64_t svg) {
- for (auto ® : m_regs) {
- if (strcmp(reg.name, "za") == 0) {
- // ZA is a register with size (svg*8) * (svg*8). A square essentially.
- reg.byte_size = (svg * 8) * (svg * 8);
- }
- reg.byte_offset = LLDB_INVALID_INDEX32;
- }
+bool GDBRemoteRegisterContext::ReconfigureRegisterInfo() {
+ ExecutionContext exe_ctx(CalculateThread());
+ Process *process = exe_ctx.GetProcessPtr();
----------------
JDevlieghere wrote:
Are you sure this pointer is always valid? If so you should use `GetProcessRef` instead to convey that. Otherwise I'd do something like the snippet below which is a common pattern especially in LLVM.
```
if (Process *process = exe_ctx.GetProcessPtr()) {
if (const Architecture *architecture = process->GetTarget().GetArchitecturePlugin()) {
[...]
}
}
```
https://github.com/llvm/llvm-project/pull/70950
More information about the lldb-commits
mailing list