From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 2/7] Add new interface to frame filter iteration
Date: Thu, 22 Jun 2023 10:19:28 -0600 [thread overview]
Message-ID: <20230614-dap-frame-decor-v2-2-10628dfa6b60@adacore.com> (raw)
In-Reply-To: <20230614-dap-frame-decor-v2-0-10628dfa6b60@adacore.com>
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 52f4191a8e8..01e7cff6c70 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)
@@ -233,3 +212,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.40.1
next prev parent reply other threads:[~2023-06-22 16:19 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-22 16:19 [PATCH v2 0/7] Reimplement DAP backtrace using frame filters Tom Tromey
2023-06-22 16:19 ` [PATCH v2 1/7] Fix execute_frame_filters doc string Tom Tromey
2023-06-22 16:19 ` Tom Tromey [this message]
2023-06-22 16:19 ` [PATCH v2 3/7] Fix oversights in frame decorator code Tom Tromey
2023-06-22 16:19 ` [PATCH v2 4/7] Simplify FrameVars Tom Tromey
2023-06-26 15:02 ` Tom Tromey
2023-06-22 16:19 ` [PATCH v2 5/7] Reimplement DAP stack traces using frame filters Tom Tromey
2023-06-22 16:19 ` [PATCH v2 6/7] Handle typedefs in no-op pretty printers Tom Tromey
2023-06-22 16:19 ` [PATCH v2 7/7] Add Ada scope test for DAP Tom Tromey
2023-06-26 15:07 ` [PATCH v2 0/7] Reimplement DAP backtrace using frame filters Tom Tromey
2023-07-10 19:14 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230614-dap-frame-decor-v2-2-10628dfa6b60@adacore.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).