diff options
author | Tom Tromey <tromey@adacore.com> | 2024-08-15 12:06:31 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2024-08-16 08:47:00 -0600 |
commit | 807f697b176d6c635643118202f36e572872007f (patch) | |
tree | c99e5594a410b757943dbebcf58674c3ec6c8bfc /gdb | |
parent | 798bb5cc53edfa13673038b7d76ff09dadfaacb5 (diff) | |
download | binutils-807f697b176d6c635643118202f36e572872007f.zip binutils-807f697b176d6c635643118202f36e572872007f.tar.gz binutils-807f697b176d6c635643118202f36e572872007f.tar.bz2 |
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 <tdevries@suse.de>
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/python/lib/gdb/dap/globalvars.py | 3 | ||||
-rw-r--r-- | gdb/testsuite/gdb.dap/global.c | 31 | ||||
-rw-r--r-- | gdb/testsuite/gdb.dap/global.exp | 72 |
3 files changed, 105 insertions, 1 deletions
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 <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 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 <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 |