]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.dap/rust-slices.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.dap / rust-slices.exp
1 # Copyright 2023-2024 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
16 # Test "scopes" and "variables".
17
18 load_lib rust-support.exp
19 load_lib dap-support.exp
20
21 require allow_dap_tests
22 require allow_rust_tests
23 require {can_compile rust}
24
25 standard_testfile .rs
26
27 if {[build_executable ${testfile}.exp $testfile $srcfile {debug rust}] == -1} {
28 return
29 }
30
31 if {[dap_launch $testfile] == ""} {
32 return
33 }
34
35 set line [gdb_get_line_number "STOP"]
36 set obj [dap_check_request_and_response "set breakpoint by line number" \
37 setBreakpoints \
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]
41
42 dap_check_request_and_response "start inferior" configurationDone
43 dap_wait_for_event_and_check "inferior started" thread "body reason" started
44
45 dap_wait_for_event_and_check "stopped at line breakpoint" stopped \
46 "body reason" breakpoint \
47 "body hitBreakpointIds" $line_bpno
48
49 set bt [lindex [dap_check_request_and_response "backtrace" stackTrace \
50 {o threadId [i 1]}] \
51 0]
52 set frame_id [dict get [lindex [dict get $bt body stackFrames] 0] id]
53
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]
57
58 gdb_assert {[llength $scopes] == 2} "two scopes"
59
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"
65
66 set num [dict get $scope variablesReference]
67 set refs [lindex [dap_check_request_and_response "fetch variables" \
68 "variables" \
69 [format {o variablesReference [i %d]} $num]] \
70 0]
71
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"
79
80 set num [dict get $var variablesReference]
81 set refs [lindex [dap_check_request_and_response \
82 "fetch contents of $name" \
83 "variables" \
84 [format {o variablesReference [i %d]} $num]] \
85 0]
86
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"
91 }
92 }
93
94 foreach var [dict get $refs body variables] {
95 set name [dict get $var name]
96 switch $name {
97 "array" {
98 check_array_contents $var $name 1 2 3 4
99 }
100
101 "slice" {
102 check_array_contents $var $name 2
103 }
104
105 "hello" {
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"
111 }
112
113 default {
114 fail "unknown variable $name"
115 }
116 }
117 }
118
119 dap_shutdown