aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2024-11-15 09:29:27 -0700
committerTom Tromey <tromey@adacore.com>2024-12-09 14:26:23 -0700
commit4c2d19e3cd80e23acb555e25b7725592173cbd0d (patch)
tree979f6955c741a120731fd47f5954c60804883318 /gdb/testsuite
parentc286bfe1e5c252689126cb2f45677bd36a2fdd56 (diff)
downloadbinutils-4c2d19e3cd80e23acb555e25b7725592173cbd0d.zip
binutils-4c2d19e3cd80e23acb555e25b7725592173cbd0d.tar.gz
binutils-4c2d19e3cd80e23acb555e25b7725592173cbd0d.tar.bz2
Introduce NoOpStringPrinter
We discovered that attempting to print a very large string-like array would succeed on the CLI, but in DAP would cause the "variables" request to fail with: value requires 67038491 bytes, which is more than max-value-size This turns out to be a limitation in Value.format_string, which de-lazy-ifies the value. This patch fixes this problem by introducing a new NoOpStringPrinter class, and then using it for string-like values. This printer returns a lazy string, which solves the problem. Note there are some special cases where we do not want to return a lazy string. I've documented these in the code. I considered making gdb.Value.lazy_string handle these cases -- for example it could return 'self' rather than a lazy string in some situations -- but this approach was simpler.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/gdb.dap/max-size.c25
-rw-r--r--gdb/testsuite/gdb.dap/max-size.exp83
2 files changed, 108 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.dap/max-size.c b/gdb/testsuite/gdb.dap/max-size.c
new file mode 100644
index 0000000..6bc2e36
--- /dev/null
+++ b/gdb/testsuite/gdb.dap/max-size.c
@@ -0,0 +1,25 @@
+/* Copyright 2024 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+int
+main ()
+{
+ /* Note that this is an array to ensure that is_string_like returns
+ True for the type. */
+ const char the_string[] = "this is a string longer than 16 bytes";
+ return 0; /* STOP */
+}
diff --git a/gdb/testsuite/gdb.dap/max-size.exp b/gdb/testsuite/gdb.dap/max-size.exp
new file mode 100644
index 0000000..05da97c
--- /dev/null
+++ b/gdb/testsuite/gdb.dap/max-size.exp
@@ -0,0 +1,83 @@
+# Copyright 2024 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test printing of string-like objects larger than the maximum value
+# size.
+
+require allow_dap_tests
+
+load_lib dap-support.exp
+
+standard_testfile
+
+if {[build_executable ${testfile}.exp $testfile] == -1} {
+ return
+}
+
+save_vars GDBFLAGS {
+ append GDBFLAGS " -iex \"set max-value-size 16\""
+
+ if {[dap_initialize] == ""} {
+ return
+ }
+}
+
+set launch_id [dap_launch $testfile]
+
+set line [gdb_get_line_number "STOP"]
+set obj [dap_check_request_and_response "set breakpoint by line number" \
+ setBreakpoints \
+ [format {o source [o path [%s]] breakpoints [a [o line [i %d]]]} \
+ [list s $srcfile] $line]]
+set line_bpno [dap_get_breakpoint_number $obj]
+
+dap_check_request_and_response "configurationDone" configurationDone
+
+dap_check_response "launch response" launch $launch_id
+
+dap_wait_for_event_and_check "stopped at line breakpoint" stopped \
+ "body reason" breakpoint \
+ "body hitBreakpointIds" $line_bpno
+
+set bt [lindex [dap_check_request_and_response "backtrace" stackTrace \
+ {o threadId [i 1]}] \
+ 0]
+set frame_id [dict get [lindex [dict get $bt body stackFrames] 0] id]
+
+set scopes [dap_check_request_and_response "get scopes" scopes \
+ [format {o frameId [i %d]} $frame_id]]
+set scopes [dict get [lindex $scopes 0] body scopes]
+
+lassign $scopes scope reg_scope
+gdb_assert {[dict get $scope name] == "Locals"} "scope is locals"
+gdb_assert {[dict get $scope namedVariables] == 1} "one var in scope"
+
+set num [dict get $scope variablesReference]
+set refs [lindex [dap_check_request_and_response "fetch variable" \
+ "variables" \
+ [format {o variablesReference [i %d] count [i 1]} \
+ $num]] \
+ 0]
+
+foreach var [dict get $refs body variables] {
+ gdb_assert {[dict get $var name] == "the_string"} "variable name"
+ # The result looks strange here, but only because TON does not
+ # handle the backslash-quote sequence properly when decoding the
+ # JSON. The actual JSON is: "value": "\"DEI\"".
+ gdb_assert {[dict get $var value] == "\\\"this is a string longer than 16 bytes\\\""} \
+ "variable value"
+}
+
+dap_shutdown