From 807f697b176d6c635643118202f36e572872007f Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 15 Aug 2024 12:06:31 -0600 Subject: Fix DAP failure when fetching global variables 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 --- gdb/python/lib/gdb/dap/globalvars.py | 3 +- gdb/testsuite/gdb.dap/global.c | 31 ++++++++++++++++ gdb/testsuite/gdb.dap/global.exp | 72 ++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.dap/global.c create mode 100644 gdb/testsuite/gdb.dap/global.exp diff --git a/gdb/python/lib/gdb/dap/globalvars.py b/gdb/python/lib/gdb/dap/globalvars.py index 149c9a8..38bdc5c 100644 --- a/gdb/python/lib/gdb/dap/globalvars.py +++ b/gdb/python/lib/gdb/dap/globalvars.py @@ -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 index 0000000..d3b7085 --- /dev/null +++ b/gdb/testsuite/gdb.dap/global.c @@ -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 . */ + +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 index 0000000..79f7f2f --- /dev/null +++ b/gdb/testsuite/gdb.dap/global.exp @@ -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 . + +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 -- cgit v1.1