[Lldb-commits] [PATCH] D111136: [lldb] [DynamicRegisterInfo] Support iterating over Registers()
Michał Górny via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue Oct 5 05:19:06 PDT 2021
mgorny created this revision.
mgorny added reviewers: labath, krytarowski, teemperor, emaste.
mgorny requested review of this revision.
Add DynamicRegisterInfo::Registers() method that returns
llvm::iterator_range<> over RegisterInfos. This is a convenient
replacement for GetNumRegisters() + GetRegisterInfoAtIndex().
https://reviews.llvm.org/D111136
Files:
lldb/include/lldb/Target/DynamicRegisterInfo.h
lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
@@ -210,16 +210,11 @@
SetAllRegisterValid(true);
return true;
} else if (buffer_sp->GetByteSize() > 0) {
- const int regcount = m_reg_info_sp->GetNumRegisters();
- for (int i = 0; i < regcount; i++) {
- struct RegisterInfo *reginfo =
- m_reg_info_sp->GetRegisterInfoAtIndex(i);
- if (reginfo->byte_offset + reginfo->byte_size <=
- buffer_sp->GetByteSize()) {
- m_reg_valid[i] = true;
- } else {
- m_reg_valid[i] = false;
- }
+ for (auto x : llvm::enumerate(m_reg_info_sp->Registers())) {
+ const struct RegisterInfo ®info = x.value();
+ m_reg_valid[x.index()] =
+ (reginfo.byte_offset + reginfo.byte_size <=
+ buffer_sp->GetByteSize());
}
m_gpacket_cached = true;
Index: lldb/include/lldb/Target/DynamicRegisterInfo.h
===================================================================
--- lldb/include/lldb/Target/DynamicRegisterInfo.h
+++ lldb/include/lldb/Target/DynamicRegisterInfo.h
@@ -77,9 +77,13 @@
const lldb_private::RegisterInfo *
GetRegisterInfo(llvm::StringRef reg_name) const;
+ typedef std::vector<lldb_private::RegisterInfo> reg_collection;
+ llvm::iterator_range<reg_collection::iterator> Registers() {
+ return llvm::iterator_range<reg_collection::iterator>(m_regs);
+ }
+
protected:
// Classes that inherit from DynamicRegisterInfo can see and modify these
- typedef std::vector<lldb_private::RegisterInfo> reg_collection;
typedef std::vector<lldb_private::RegisterSet> set_collection;
typedef std::vector<uint32_t> reg_num_collection;
typedef std::vector<reg_num_collection> set_reg_num_collection;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111136.377159.patch
Type: text/x-patch
Size: 2072 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20211005/70da71c3/attachment.bin>
More information about the lldb-commits
mailing list