mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-12-19 01:19:41 +08:00
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>
This commit is contained in:
@@ -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
|
||||
|
||||
31
gdb/testsuite/gdb.dap/global.c
Normal file
31
gdb/testsuite/gdb.dap/global.c
Normal file
@@ -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 */
|
||||
}
|
||||
72
gdb/testsuite/gdb.dap/global.exp
Normal file
72
gdb/testsuite/gdb.dap/global.exp
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user