]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix DAP failure when fetching global variables
authorTom Tromey <tromey@adacore.com>
Thu, 15 Aug 2024 18:06:31 +0000 (12:06 -0600)
committerTom Tromey <tromey@adacore.com>
Fri, 16 Aug 2024 14:47:00 +0000 (08:47 -0600)
The relatively new "globals" scope code in DAP has a fairly obvious
bug -- the fetch_one_child method should return a tuple with two
elements, but instead just returns the variable's value.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32029
Reviewed-By: Tom de Vries <tdevries@suse.de>
gdb/python/lib/gdb/dap/globalvars.py
gdb/testsuite/gdb.dap/global.c [new file with mode: 0644]
gdb/testsuite/gdb.dap/global.exp [new file with mode: 0644]

index 149c9a8f22fdb87ab70f27a7459fdd4b1121bb13..38bdc5ca05ccf5c28487d3f243ca7997ceeebdf7 100644 (file)
@@ -60,7 +60,8 @@ class _Globals(BaseReference):
 
     @in_gdb_thread
     def fetch_one_child(self, idx):
-        return self.var_list[idx].value()
+        sym = self.var_list[idx]
+        return (sym.name, sym.value())
 
 
 @in_gdb_thread
diff --git a/gdb/testsuite/gdb.dap/global.c b/gdb/testsuite/gdb.dap/global.c
new file mode 100644 (file)
index 0000000..d3b7085
--- /dev/null
@@ -0,0 +1,31 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   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/>.  */
+
+static struct {
+  int x;
+  struct {
+    int x2;
+  } y;
+} global;
+
+int
+main ()
+{
+  global.x = 23;
+  global.y.x2 = 47;
+  return 0;                    /* BREAK */
+}
diff --git a/gdb/testsuite/gdb.dap/global.exp b/gdb/testsuite/gdb.dap/global.exp
new file mode 100644 (file)
index 0000000..79f7f2f
--- /dev/null
@@ -0,0 +1,72 @@
+# 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/>.
+
+require allow_dap_tests
+
+load_lib dap-support.exp
+
+standard_testfile
+
+if {[build_executable ${testfile}.exp $testfile $srcfile] == -1} {
+    return
+}
+
+if {[dap_initialize] == ""} {
+    return
+}
+
+set line [gdb_get_line_number "BREAK"]
+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
+
+if {[dap_launch $testfile] == ""} {
+    return
+}
+dap_wait_for_event_and_check "inferior started" thread "body reason" started
+
+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]
+
+gdb_assert {[llength $scopes] == 2} "two scopes"
+
+lassign $scopes reg_scope global_scope
+
+gdb_assert {[dict get $global_scope name] == "Globals"} "scope is globals"
+
+gdb_assert {[dict get $global_scope namedVariables] == 1} "one var in globals"
+
+set num [dict get $global_scope variablesReference]
+set refs [lindex [dap_check_request_and_response "fetch variables" \
+                     "variables" \
+                     [format {o variablesReference [i %d] count [i 1]} \
+                          $num]] \
+             0]
+
+dap_shutdown