From 70ef91c5aa0626f2aa1ab117b8bd5da4bc6a115f Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 14 Jun 2023 06:54:13 -0600 Subject: [PATCH] Add new interface to frame filter iteration This patch adds a new function, frame_iterator, that wraps the existing code to find and execute the frame filters. However, unlike execute_frame_filters, it will always return an iterator -- whereas execute_frame_filters will return None if no frame filters apply. Nothing uses this new function yet, but it will used by a subsequent DAP patch. --- gdb/python/lib/gdb/frames.py | 85 +++++++++++++++++++++++++----------- 1 file changed, 59 insertions(+), 26 deletions(-) diff --git a/gdb/python/lib/gdb/frames.py b/gdb/python/lib/gdb/frames.py index 4b2141ed722..cff3ba07704 100644 --- a/gdb/python/lib/gdb/frames.py +++ b/gdb/python/lib/gdb/frames.py @@ -156,37 +156,16 @@ def _sort_list(): return sorted_frame_filters -def execute_frame_filters(frame, frame_low, frame_high): - """Internal function called from GDB that will execute the chain - of frame filters. Each filter is executed in priority order. - After the execution completes, slice the iterator to frame_low - - frame_high range. - - Arguments: - frame: The initial frame. - - frame_low: The low range of the slice, counting from 0. If - this is a negative integer then it indicates a backward slice - (ie bt -4) which counts backward from the last frame in the - backtrace. - - frame_high: The high range of the slice, inclusive. If this - is -1 then it indicates all frames until the end of the stack - from frame_low. - - Returns: - frame_iterator: The sliced iterator after all frame - filters have had a chance to execute, or None if no frame - filters are registered. - - """ - +# Internal function that implements frame_iterator and +# execute_frame_filters. If ALWAYS is True, then this will always +# return an iterator. +def _frame_iterator(frame, frame_low, frame_high, always): # Get a sorted list of frame filters. sorted_list = list(_sort_list()) # Check to see if there are any frame-filters. If not, just # return None and let default backtrace printing occur. - if len(sorted_list) == 0: + if not always and len(sorted_list) == 0: return None frame_iterator = FrameIterator(frame) @@ -229,3 +208,57 @@ def execute_frame_filters(frame, frame_low, frame_high): sliced = itertools.islice(frame_iterator, frame_low, frame_high) return sliced + + +def frame_iterator(frame, frame_low, frame_high): + """Helper function that will execute the chain of frame filters. + Each filter is executed in priority order. After the execution + completes, slice the iterator to frame_low - frame_high range. An + iterator is always returned. + + Arguments: + frame: The initial frame. + + frame_low: The low range of the slice, counting from 0. If + this is a negative integer then it indicates a backward slice + (ie bt -4) which counts backward from the last frame in the + backtrace. + + frame_high: The high range of the slice, inclusive. If this + is -1 then it indicates all frames until the end of the stack + from frame_low. + + Returns: + frame_iterator: The sliced iterator after all frame + filters have had a chance to execute. + """ + + return _frame_iterator(frame, frame_low, frame_high, True) + + +def execute_frame_filters(frame, frame_low, frame_high): + """Internal function called from GDB that will execute the chain + of frame filters. Each filter is executed in priority order. + After the execution completes, slice the iterator to frame_low - + frame_high range. + + Arguments: + frame: The initial frame. + + frame_low: The low range of the slice, counting from 0. If + this is a negative integer then it indicates a backward slice + (ie bt -4) which counts backward from the last frame in the + backtrace. + + frame_high: The high range of the slice, inclusive. If this + is -1 then it indicates all frames until the end of the stack + from frame_low. + + Returns: + frame_iterator: The sliced iterator after all frame + filters have had a chance to execute, or None if no frame + filters are registered. + + """ + + return _frame_iterator(frame, frame_low, frame_high, False) -- 2.30.2