[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)
Greg Clayton via lldb-commits
lldb-commits at lists.llvm.org
Thu May 23 13:14:11 PDT 2024
================
@@ -0,0 +1,28 @@
+%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():
+ raise IndexError("list index out of range")
+ return self.GetAddressRangeAtIndex(idx)
+ else:
+ print("error: unsupported idx type: %s" % type(key))
+ return None
----------------
clayborg wrote:
```
>>> a = []
>>> a[12]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range
```
We should throw an `IndexError` just like a normal array
https://github.com/llvm/llvm-project/pull/92014
More information about the lldb-commits
mailing list