]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Emit DAPException when too many variable children are reqeusted
authorTom Tromey <tromey@adacore.com>
Wed, 30 Jul 2025 14:30:49 +0000 (08:30 -0600)
committerTom Tromey <tromey@adacore.com>
Mon, 11 Aug 2025 13:39:10 +0000 (07:39 -0600)
PR dap/33228 points out a failure that occurs when the DAP client
requests more children of a variable than actually exist.  Currently,
gdb throws a somewhat confusing exception.  This patch changes this
code to throw a DAPException instead, resulting in a more ordinary and
readable failure.

The spec seems to be silent on what to do in this case.  I chose an
exception on the theory that it's easier to be strict now and lift the
restriction later (if needed) than vice versa.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33228

gdb/python/lib/gdb/dap/varref.py
gdb/testsuite/gdb.dap/scopes.exp

index 8a13c51a452313fe7fe9c4b4b960146b3c588072..1b54fe745fa20d6da68a0ca36055ac4b812aed34 100644 (file)
@@ -146,6 +146,10 @@ class BaseReference(ABC):
         if self._children is None:
             self._children = [None] * self.child_count()
         for idx in range(start, start + count):
+            if idx >= len(self._children):
+                raise DAPException(
+                    f"requested child {idx} outside range of variable {self._ref}"
+                )
             if self._children[idx] is None:
                 (name, value) = self.fetch_one_child(idx)
                 name = self._compute_name(name)
index b2066e5276c9e5a957e3f5e3237c9c18df1ac559..bce7746c12ffa94adbc9c46cd54c994f9ee39702 100644 (file)
@@ -133,6 +133,13 @@ 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"
+
 set num [dict get $reg_scope variablesReference]
 lassign [dap_check_request_and_response "fetch all registers" \
             "variables" \