[binutils-gdb] Do not report totalFrames from DAP stackTrace request

Tom Tromey tromey@sourceware.org
Mon Jun 12 18:14:35 GMT 2023


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=7cb909c4091c156a8242f799e18af57d702da560

commit 7cb909c4091c156a8242f799e18af57d702da560
Author: Tom Tromey <tromey@adacore.com>
Date:   Fri May 19 09:00:52 2023 -0600

    Do not report totalFrames from DAP stackTrace request
    
    Currently, gdb will unwind the entire stack in response to the
    stackTrace request.  I had erroneously thought that the totalFrames
    attribute was required in the response.  However, the spec says:
    
        If omitted or if `totalFrames` is larger than the available
        frames, a client is expected to request frames until a request
        returns less frames than requested (which indicates the end of the
        stack).
    
    This patch removes this from the response in order to improve
    performance when the stack trace is very long.

Diff:
---
 gdb/python/lib/gdb/dap/bt.py | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/gdb/python/lib/gdb/dap/bt.py b/gdb/python/lib/gdb/dap/bt.py
index a38573fbba8..4439b428926 100644
--- a/gdb/python/lib/gdb/dap/bt.py
+++ b/gdb/python/lib/gdb/dap/bt.py
@@ -50,13 +50,9 @@ def _backtrace(thread_id, levels, startFrame):
         current_frame = gdb.newest_frame()
     except gdb.error:
         current_frame = None
-    # Note that we always iterate over all frames, which is lame, but
-    # seemingly necessary to support the totalFrames response.
-    # FIXME maybe the mildly mysterious note about "monotonically
-    # increasing totalFrames values" would let us fix this.
-    while current_frame is not None:
+    while current_frame is not None and (levels == 0 or len(frames) < levels):
         # This condition handles the startFrame==0 case as well.
-        if current_number >= startFrame and (levels == 0 or len(frames) < levels):
+        if current_number >= startFrame:
             newframe = {
                 "id": frame_id(current_frame),
                 "name": _frame_name(current_frame),
@@ -80,9 +76,11 @@ def _backtrace(thread_id, levels, startFrame):
             frames.append(newframe)
         current_number = current_number + 1
         current_frame = current_frame.older()
+    # Note that we do not calculate totalFrames here.  Its absence
+    # tells the client that it may simply ask for frames until a
+    # response yields fewer frames than requested.
     return {
         "stackFrames": frames,
-        "totalFrames": current_number,
     }


More information about the Gdb-cvs mailing list