[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Sat May 25 11:46:34 PDT 2024


================
@@ -0,0 +1,27 @@
+%extend lldb::SBAddressRangeList {
+#ifdef SWIGPYTHON
+    %pythoncode%{
+    def __len__(self):
+      '''Return the number of address ranges in a lldb.SBAddressRangeList object.'''
+      return self.GetSize()
+
+    def __iter__(self):
+      '''Iterate over all the address ranges in a lldb.SBAddressRangeList object.'''
+      return lldb_iter(self, 'GetSize', 'GetAddressRangeAtIndex')
+
+    def __getitem__(self, idx):
+      '''Get the address range at a given index in an lldb.SBAddressRangeList object.'''
+      if type(idx) == int:
+        if idx >= self.GetSize():
----------------
clayborg wrote:

`idx` can be negative. If we want to support the typical python indexing negative numbers start at the end, so `-1` is the last entry, `-2` is the second to last entry as well. So either check if `idx >= 0` or add support for negative indexes.

https://github.com/llvm/llvm-project/pull/92014


More information about the lldb-commits mailing list