[binutils-gdb] Handle supportsVariablePaging in DAP

Tom Tromey tromey@sourceware.org
Thu Jun 22 15:52:02 GMT 2023


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

commit 59e75852dd9edff2199c5cd27a9be9f596a2fba6
Author: Tom Tromey <tromey@adacore.com>
Date:   Fri May 26 13:35:52 2023 -0600

    Handle supportsVariablePaging in DAP
    
    A bug report about the supportsVariablePaging capability in DAP
    resulted in a clarification: when this capability is not present, DAP
    implementations should ignore the paging parameters to the "variables"
    request.  This patch implements this clarification.

Diff:
---
 gdb/python/lib/gdb/dap/evaluate.py |  7 ++++++-
 gdb/testsuite/gdb.dap/scopes.exp   | 24 +++++++++++++++++-------
 gdb/testsuite/lib/dap-support.exp  |  3 ++-
 3 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/gdb/python/lib/gdb/dap/evaluate.py b/gdb/python/lib/gdb/dap/evaluate.py
index af7bf43afd0..a0b199a1ed4 100644
--- a/gdb/python/lib/gdb/dap/evaluate.py
+++ b/gdb/python/lib/gdb/dap/evaluate.py
@@ -20,7 +20,7 @@ import gdb.printing
 from typing import Optional
 
 from .frames import frame_for_id
-from .server import capability, request
+from .server import capability, request, client_bool_capability
 from .startup import send_gdb_with_response, in_gdb_thread
 from .varref import find_variable, VariableReference
 
@@ -98,6 +98,11 @@ def _variables(ref, start, count):
 # Note that we ignore the 'filter' field.  That seems to be
 # specific to javascript.
 def variables(*, variablesReference: int, start: int = 0, count: int = 0, **args):
+    # This behavior was clarified here:
+    # https://github.com/microsoft/debug-adapter-protocol/pull/394
+    if not client_bool_capability("supportsVariablePaging"):
+        start = 0
+        count = 0
     result = send_gdb_with_response(
         lambda: _variables(variablesReference, start, count)
     )
diff --git a/gdb/testsuite/gdb.dap/scopes.exp b/gdb/testsuite/gdb.dap/scopes.exp
index cf9174f06a2..6937badcca0 100644
--- a/gdb/testsuite/gdb.dap/scopes.exp
+++ b/gdb/testsuite/gdb.dap/scopes.exp
@@ -67,13 +67,23 @@ gdb_assert {[dict get $reg_scope presentationHint] == "registers"} \
 gdb_assert {[dict get $reg_scope namedVariables] > 0} "at least one register"
 
 set num [dict get $scope variablesReference]
-set refs [lindex [dap_check_request_and_response "fetch variables" \
-		      "variables" \
-		      [format {o variablesReference [i %d] count [i 3]} \
-			   $num]] \
-	      0]
-
-foreach var [dict get $refs body variables] {
+# Send two requests and combine them, to verify that using a range
+# works.
+set refs1 [lindex [dap_check_request_and_response "fetch variables 0,1" \
+		       "variables" \
+		       [format {o variablesReference [i %d] count [i 2]} \
+			    $num]] \
+	       0]
+set refs2 [lindex [dap_check_request_and_response "fetch variables 2" \
+		       "variables" \
+		       [format {o variablesReference [i %d] \
+				    start [i 2] count [i 1]} \
+			    $num]] \
+	       0]
+
+set vars [concat [dict get $refs1 body variables] \
+	      [dict get $refs2 body variables]]
+foreach var $vars {
     set name [dict get $var name]
 
     if {$name != "dei"} {
diff --git a/gdb/testsuite/lib/dap-support.exp b/gdb/testsuite/lib/dap-support.exp
index 92484bfdb8d..e3750e1d016 100644
--- a/gdb/testsuite/lib/dap-support.exp
+++ b/gdb/testsuite/lib/dap-support.exp
@@ -232,7 +232,8 @@ proc _dap_initialize {name} {
     }
     return [dap_check_request_and_response $name initialize \
 		{o clientID [s "gdb testsuite"] \
-		     supportsVariableType [l true]}]
+		     supportsVariableType [l true] \
+		     supportsVariablePaging [l true]}]
 }
 
 # Start gdb, send a DAP initialize request, and then a launch request


More information about the Gdb-cvs mailing list