]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Update use of deque in _frame_iterator
authorTom Tromey <tom@tromey.com>
Mon, 1 Jun 2026 23:45:52 +0000 (17:45 -0600)
committerTom Tromey <tom@tromey.com>
Mon, 22 Jun 2026 22:15:08 +0000 (16:15 -0600)
_frame_iterator has an old comment about some hand-written code that
was needed when supporting Python 2.6.  This patch simplifies the code
by using a couple of features of collections.deque.

gdb/python/lib/gdb/frames.py

index de954e4fb389efc93e3bb7ca98810add6636c8be..6539416b1c20c001997cdf7e5875b6b59e971092 100644 (file)
@@ -186,18 +186,7 @@ def _frame_iterator(frame, frame_low, frame_high, dap_semantics):
 
     # Is this a slice from the end of the backtrace, ie bt -2?
     if frame_low < 0:
-        count = 0
-        slice_length = abs(frame_low)
-        # We cannot use MAXLEN argument for deque as it is 2.6 onwards
-        # and some GDB versions might be < 2.6.
-        sliced = collections.deque()
-
-        for frame_item in frame_iterator:
-            if count >= slice_length:
-                sliced.popleft()
-            count = count + 1
-            sliced.append(frame_item)
-
+        sliced = collections.deque(iterable=frame_iterator, maxlen=abs(frame_low))
         return iter(sliced)
 
     # -1 for frame_high means until the end of the backtrace.  Set to