[Lldb-commits] [PATCH] D111136: [lldb] [DynamicRegisterInfo] Support iterating over Registers()

Michał Górny via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 6 06:02:04 PDT 2021


mgorny updated this revision to Diff 377516.
mgorny added a comment.

Switch to a `const_iterator`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111136/new/

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
@@ -203,16 +203,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 &reginfo = 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::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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111136.377516.patch
Type: text/x-patch
Size: 2090 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20211006/0754443a/attachment.bin>


More information about the lldb-commits mailing list