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

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Tue May 14 13:05:32 PDT 2024


================
@@ -0,0 +1,13 @@
+%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')
+    %}
----------------
clayborg wrote:

We should add the ability to subscript a `SBAddressRangeList` object, and also use it as an iterable. So something like this should work in python:
```
function = ...; # Get a lldb.SBFunction somehow
ranges = function.GetRanges()
for range in ranges: # Implement iterable for this object
  print(range)
for i in ranges.GetSize():
  range = ranges[i] # Implement the subscripting extension
```
Other classes do this, we should copy that kind of code into this .i file

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


More information about the lldb-commits mailing list