1 # Copyright 2023-2024 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Test the setVariable request.
18 require allow_dap_tests
20 load_lib dap-support.exp
24 if {[build_executable ${testfile}.exp $testfile] == -1} {
28 set remote_python_file [gdb_remote_download host \
29 ${srcdir}/${subdir}/${testfile}.py]
32 append GDBFLAGS " -iex \"source $remote_python_file\""
34 if {[dap_initialize] == ""} {
39 set launch_id [dap_launch $testfile]
41 set line [gdb_get_line_number "STOP"]
42 set obj [dap_check_request_and_response "set breakpoint by line number" \
44 [format {o source [o path [%s]] breakpoints [a [o line [i %d]]]} \
45 [list s $srcfile] $line]]
46 set line_bpno [dap_get_breakpoint_number $obj]
48 dap_check_request_and_response "configurationDone" configurationDone
50 dap_check_response "launch response" launch $launch_id
52 dap_wait_for_event_and_check "stopped at line breakpoint" stopped \
53 "body reason" breakpoint \
54 "body hitBreakpointIds" $line_bpno
56 set bt [lindex [dap_check_request_and_response "backtrace" stackTrace \
59 set frame_id [dict get [lindex [dict get $bt body stackFrames] 0] id]
61 set scopes [dap_check_request_and_response "get scopes" scopes \
62 [format {o frameId [i %d]} $frame_id]]
63 set scopes [dict get [lindex $scopes 0] body scopes]
65 lassign $scopes scope reg_scope
66 gdb_assert {[dict get $scope name] == "Locals"} "scope is locals"
67 gdb_assert {[dict get $scope namedVariables] == 1} "one var in scope"
69 set num [dict get $scope variablesReference]
70 set refs [lindex [dap_check_request_and_response "fetch variable" \
72 [format {o variablesReference [i %d] count [i 1]} \
76 set desc [dict get $refs body variables]
77 gdb_assert {[llength $desc] == 1} "only one variable fetched"
78 set desc [lindex $desc 0]
80 set saved_ref [dict get $desc variablesReference]
82 proc check_vars {prefix var varref summary} {
83 with_test_prefix $prefix {
84 gdb_assert {[dict get $var name] == "value"} "variable name"
85 gdb_assert {[dict get $var variablesReference] == $varref} \
87 gdb_assert {[dict get $var value] == $summary} \
92 check_vars initial $desc $saved_ref full
94 set refs [lindex [dap_check_request_and_response "assign empty to variable" \
96 [format {o variablesReference [i %d] name [s value] \
100 check_vars "assign empty" [dict get $refs body] 0 empty
102 set refs [lindex [dap_check_request_and_response "assign full to variable" \
104 [format {o variablesReference [i %d] name [s value] \
108 check_vars "assign full" [dict get $refs body] $saved_ref full
110 # Now fetch the children of the variable, to check that the shadowing
112 gdb_assert {[dict get $refs body namedVariables] == 2} \
113 "two children of variable"
115 set num [dict get $refs body variablesReference]
116 set refs [lindex [dap_check_request_and_response \
117 "fetch children of variable" "variables" \
118 [format {o variablesReference [i %d] count [i 2]} \
122 lassign [dict get $refs body variables] one two
123 gdb_assert {[dict get $one name] != [dict get $two name]} \
124 "children have different names"