[Lldb-commits] [lldb] ecfab0b - [lldb] [DynamicRegisterInfo] Support iterating over registers()
Michał Górny via lldb-commits
lldb-commits at lists.llvm.org
Thu Oct 7 07:07:16 PDT 2021
Author: Michał Górny
Date: 2021-10-07T16:07:04+02:00
New Revision: ecfab0b6f581c69b3e3e8b230f97a84f317bbec2
URL: https://github.com/llvm/llvm-project/commit/ecfab0b6f581c69b3e3e8b230f97a84f317bbec2
DIFF: https://github.com/llvm/llvm-project/commit/ecfab0b6f581c69b3e3e8b230f97a84f317bbec2.diff
LOG: [lldb] [DynamicRegisterInfo] Support iterating over registers()
Add DynamicRegisterInfo::registers() method that returns
llvm::iterator_range<> over RegisterInfos. This is a convenient
replacement for GetNumRegisters() + GetRegisterInfoAtIndex().
Differential Revision: https://reviews.llvm.org/D111136
Added:
Modified:
lldb/include/lldb/Target/DynamicRegisterInfo.h
lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Target/DynamicRegisterInfo.h b/lldb/include/lldb/Target/DynamicRegisterInfo.h
index 5cbafe000e0b0..5fd0389e3e82c 100644
--- a/lldb/include/lldb/Target/DynamicRegisterInfo.h
+++ b/lldb/include/lldb/Target/DynamicRegisterInfo.h
@@ -77,9 +77,13 @@ class DynamicRegisterInfo {
const lldb_private::RegisterInfo *
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);
+ }
+
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;
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
index b80498069f164..f0225d0ad5609 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
@@ -203,16 +203,11 @@ bool GDBRemoteRegisterContext::ReadRegisterBytes(const RegisterInfo *reg_info) {
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;
More information about the lldb-commits
mailing list