[Lldb-commits] [lldb] [lldb] Introduce ScriptedFrameProvider for real threads (PR #161870)

via lldb-commits lldb-commits at lists.llvm.org
Thu Oct 30 13:57:56 PDT 2025


================
@@ -0,0 +1,46 @@
+%extend lldb::SBFrameList {
+
+#ifdef SWIGPYTHON
+       %nothreadallow;
+#endif
+       std::string lldb::SBFrameList::__str__ (){
+           lldb::SBStream description;
+           const size_t n = $self->GetSize();
+           if (n)
+           {
+               for (size_t i=0; i<n; ++i)
+                   $self->GetFrameAtIndex(i).GetDescription(description);
+           }
+           else
+           {
+               description.Printf("<empty> lldb.SBFrameList()");
+           }
+           const char *desc = description.GetData();
+           size_t desc_len = description.GetSize();
+           if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r'))
+               --desc_len;
+           return std::string(desc, desc_len);
+       }
+#ifdef SWIGPYTHON
+       %clearnothreadallow;
+#endif
+
+#ifdef SWIGPYTHON
+    %pythoncode %{
+        def __iter__(self):
+            '''Iterate over all frames in a lldb.SBFrameList object.'''
+            return lldb_iter(self, 'GetSize', 'GetFrameAtIndex')
+
+        def __len__(self):
+            return int(self.GetSize())
+
+        def __getitem__(self, key):
+            count = len(self)
----------------
jimingham wrote:

Why do you need to count the stack frames in __getitem__?  That has the side-effect of forcing the generation of all the stack frames in the list, which we should only do when directly asked (like when asked for the number of stack frames).  
But also, I don't see how it helps.  If you ran GetFrameAtIndex on an index already fetched, it will return that.  If you run GetFrameAtIndex on a number between what was fetched and the number of frames in the stack, it will realize frames up to that number and stop.  If you ask for more frames than exist, then it will fetch all the frames available, find that your number is too big and return None.
So I don't think you get anything out of forcing the count here.


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


More information about the lldb-commits mailing list