Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lldb] Add template method for getting const or mutable regs from DynamicRegisterInfo #71402

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lldb/include/lldb/Target/DynamicRegisterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,18 @@ class DynamicRegisterInfo {
GetRegisterInfo(llvm::StringRef reg_name) const;

typedef std::vector<lldb_private::RegisterInfo> reg_collection;
llvm::iterator_range<reg_collection::const_iterator> registers() const {
return llvm::iterator_range<reg_collection::const_iterator>(m_regs);

template <typename T> T registers();
DavidSpickett marked this conversation as resolved.
Show resolved Hide resolved

typedef llvm::iterator_range<reg_collection::const_iterator>
reg_collection_const_range;
template <> reg_collection_const_range registers() {
return reg_collection_const_range(m_regs);
}

llvm::iterator_range<reg_collection::iterator> registers_mutable() {
return llvm::iterator_range<reg_collection::iterator>(m_regs);
typedef llvm::iterator_range<reg_collection::iterator> reg_collection_range;
template <> reg_collection_range registers() {
return reg_collection_range(m_regs);
}

void ConfigureOffsets();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ ArchitectureAArch64::Create(const ArchSpec &arch) {
return std::unique_ptr<Architecture>(new ArchitectureAArch64());
}

static void UpdateARM64SVERegistersInfos(
llvm::iterator_range<
lldb_private::DynamicRegisterInfo::reg_collection::iterator>
regs,
uint64_t vg) {
static void
UpdateARM64SVERegistersInfos(DynamicRegisterInfo::reg_collection_range regs,
uint64_t vg) {
// SVE Z register size is vg x 8 bytes.
uint32_t z_reg_byte_size = vg * 8;

Expand All @@ -62,11 +60,9 @@ static void UpdateARM64SVERegistersInfos(
}
}

static void UpdateARM64SMERegistersInfos(
llvm::iterator_range<
lldb_private::DynamicRegisterInfo::reg_collection::iterator>
regs,
uint64_t svg) {
static void
UpdateARM64SMERegistersInfos(DynamicRegisterInfo::reg_collection_range regs,
uint64_t svg) {
for (auto &reg : regs) {
if (strcmp(reg.name, "za") == 0) {
// ZA is a register with size (svg*8) * (svg*8). A square essentially.
Expand Down Expand Up @@ -108,10 +104,11 @@ bool ArchitectureAArch64::ReconfigureRegisterInfo(DynamicRegisterInfo &reg_info,
if (!vg_reg_value && !svg_reg_value)
return false;

auto regs = reg_info.registers<DynamicRegisterInfo::reg_collection_range>();
DavidSpickett marked this conversation as resolved.
Show resolved Hide resolved
if (vg_reg_value)
UpdateARM64SVERegistersInfos(reg_info.registers_mutable(), *vg_reg_value);
UpdateARM64SVERegistersInfos(regs, *vg_reg_value);
if (svg_reg_value)
UpdateARM64SMERegistersInfos(reg_info.registers_mutable(), *svg_reg_value);
UpdateARM64SMERegistersInfos(regs, *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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ bool GDBRemoteRegisterContext::ReadRegisterBytes(const RegisterInfo *reg_info) {
SetAllRegisterValid(true);
return true;
} else if (buffer_sp->GetByteSize() > 0) {
for (auto x : llvm::enumerate(m_reg_info_sp->registers())) {
for (auto x : llvm::enumerate(
DavidSpickett marked this conversation as resolved.
Show resolved Hide resolved
m_reg_info_sp->registers<
DynamicRegisterInfo::reg_collection_const_range>())) {
const struct RegisterInfo &reginfo = x.value();
m_reg_valid[x.index()] =
(reginfo.byte_offset + reginfo.byte_size <=
Expand Down
Loading