]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Change handling of over-long DAP variables requests
authorTom Tromey <tromey@adacore.com>
Fri, 19 Dec 2025 12:51:39 +0000 (05:51 -0700)
committerTom Tromey <tromey@adacore.com>
Mon, 5 Jan 2026 13:37:42 +0000 (06:37 -0700)
In PR dap/33228, we changed gdb to gracefully report an error if a DAP
'variables' request asked for more variables than had been reported.

This behavior was clarified in the spec, see

    https://github.com/microsoft/debug-adapter-protocol/issues/571

This patch changes gdb to conform to the specified approach, namely
truncating the list rather than erroring.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33228
Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb/python/lib/gdb/dap/varref.py
gdb/testsuite/gdb.dap/scopes.exp

index f5ffe34f7f55606805a9df09b803e5f957e2e8a8..e7d114c9d51d70ad7ac443a4651f53f383887339 100644 (file)
@@ -146,10 +146,12 @@ class BaseReference(ABC):
         if self._children is None:
             self._children = [None] * self.child_count()
         for idx in range(start, start + count):
+            # DAP was clarified to say that if too many children are
+            # requested, this is not an error, but instead the result
+            # is just truncated.
+            # https://github.com/microsoft/debug-adapter-protocol/issues/571
             if idx >= len(self._children):
-                raise DAPException(
-                    f"requested child {idx} outside range of variable {self._ref}"
-                )
+                break
             if self._children[idx] is None:
                 (name, value) = self.fetch_one_child(idx)
                 name = self._compute_name(name)
index 52efa683c4ceb29d9b7037c4eccc6be63ab869c9..b3026263a90a0dcac69984ebfe95f043b1889a0f 100644 (file)
@@ -133,12 +133,15 @@ set refs [lindex [dap_check_request_and_response "fetch contents of dei" \
 set deivals [dict get $refs body variables]
 gdb_assert {[llength $deivals] == 2} "dei has two members"
 
-# Request more children than exist.  See PR dap/33228.
-set seq [dap_send_request variables \
-            [format {o variablesReference [i %d] count [i 100]} $dei_ref]]
-lassign [dap_read_response variables $seq] response ignore
-gdb_assert {[dict get $response success] == "false"} \
-    "variables with invalid count"
+# Request more children than exist.  See PR dap/33228 and
+# https://github.com/microsoft/debug-adapter-protocol/issues/571.
+set refs [lindex [dap_check_request_and_response "fetch too many variables" \
+                     "variables" \
+                     [format {o variablesReference [i %d] count [i 100]} \
+                          $dei_ref]] \
+             0]
+set deivals [dict get $refs body variables]
+gdb_assert {[llength $deivals] == 2} "still just two members"
 
 set num [dict get $reg_scope variablesReference]
 lassign [dap_check_request_and_response "fetch all registers" \