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 "scopes" and "variables".
18 load_lib rust-support.exp
19 load_lib dap-support.exp
21 require allow_dap_tests
22 require allow_rust_tests
23 require {can_compile rust}
27 if {[build_executable ${testfile}.exp $testfile $srcfile {debug rust}] == -1} {
31 if {[dap_launch $testfile] == ""} {
35 set line [gdb_get_line_number "STOP"]
36 set obj [dap_check_request_and_response "set breakpoint by line number" \
38 [format {o source [o path [%s]] breakpoints [a [o line [i %d]]]} \
39 [list s $srcfile] $line]]
40 set line_bpno [dap_get_breakpoint_number $obj]
42 dap_check_request_and_response "start inferior" configurationDone
43 dap_wait_for_event_and_check "inferior started" thread "body reason" started
45 dap_wait_for_event_and_check "stopped at line breakpoint" stopped \
46 "body reason" breakpoint \
47 "body hitBreakpointIds" $line_bpno
49 set bt [lindex [dap_check_request_and_response "backtrace" stackTrace \
52 set frame_id [dict get [lindex [dict get $bt body stackFrames] 0] id]
54 set scopes [dap_check_request_and_response "get scopes" scopes \
55 [format {o frameId [i %d]} $frame_id]]
56 set scopes [dict get [lindex $scopes 0] body scopes]
58 gdb_assert {[llength $scopes] == 2} "two scopes"
60 lassign $scopes scope ignore
61 gdb_assert {[dict get $scope name] == "Locals"} "scope is locals"
62 gdb_assert {[dict get $scope presentationHint] == "locals"} \
63 "locals presentation hint"
64 gdb_assert {[dict get $scope namedVariables] == 3} "three vars in scope"
66 set num [dict get $scope variablesReference]
67 set refs [lindex [dap_check_request_and_response "fetch variables" \
69 [format {o variablesReference [i %d]} $num]] \
72 # Helper to check the contents of a single array-like object. VAR is
73 # the variable entry. NAME is the name of the variable, pulled out
74 # for convenience. ARGS are the expected child values.
75 proc check_array_contents {var name args} {
76 set len [llength $args]
77 gdb_assert {[dict get $var indexedVariables] == $len} \
78 "check length of $name variable"
80 set num [dict get $var variablesReference]
81 set refs [lindex [dap_check_request_and_response \
82 "fetch contents of $name" \
84 [format {o variablesReference [i %d]} $num]] \
87 foreach subvar [dict get $refs body variables] subvalue $args {
88 set subname [dict get $subvar name]
89 gdb_assert {[dict get $subvar value] == $subvalue} \
90 "check value of $name entry $subname"
94 foreach var [dict get $refs body variables] {
95 set name [dict get $var name]
98 check_array_contents $var $name 1 2 3 4
102 check_array_contents $var $name 2
106 # Note that the expected value looks strange here -- there
107 # are too many backslashes. This is a TON issue, as the
108 # JSON looks ok: "value": "\"hello\"".
109 gdb_assert {[dict get $var value] == "\\\"hello\\\""} \
110 "value of hello variable"
114 fail "unknown variable $name"