]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.dap/ptrref.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.dap / ptrref.exp
CommitLineData
1d506c26 1# Copyright 2023-2024 Free Software Foundation, Inc.
a56e5dce
TT
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
16require allow_dap_tests
17
18load_lib dap-support.exp
19
20standard_testfile .cc
21
22if {[build_executable ${testfile}.exp $testfile $srcfile {debug c++}] == -1} {
23 return
24}
25
26if {[dap_launch $testfile] == ""} {
27 return
28}
29
30set line [gdb_get_line_number "BREAK"]
31set obj [dap_check_request_and_response "set breakpoint by line number" \
32 setBreakpoints \
33 [format {o source [o path [%s]] breakpoints [a [o line [i %d]]]} \
34 [list s $srcfile] $line]]
35set line_bpno [dap_get_breakpoint_number $obj]
36
37dap_check_request_and_response "start inferior" configurationDone
38dap_wait_for_event_and_check "inferior started" thread "body reason" started
39
40dap_wait_for_event_and_check "stopped at line breakpoint" stopped \
41 "body reason" breakpoint \
42 "body hitBreakpointIds" $line_bpno
43
44set bt [lindex [dap_check_request_and_response "backtrace" stackTrace \
45 {o threadId [i 1]}] \
46 0]
47set frame_id [dict get [lindex [dict get $bt body stackFrames] 0] id]
48
49set scopes [dap_check_request_and_response "get scopes" scopes \
50 [format {o frameId [i %d]} $frame_id]]
51set scopes [dict get [lindex $scopes 0] body scopes]
52
53gdb_assert {[llength $scopes] == 2} "two scopes"
54
55lassign $scopes scope reg_scope
56gdb_assert {[dict get $scope name] == "Locals"} "scope is locals"
57
4a1b9a4b 58gdb_assert {[dict get $scope namedVariables] == 4} "three vars in scope"
a56e5dce
TT
59
60set num [dict get $scope variablesReference]
61set refs [lindex [dap_check_request_and_response "fetch variables" \
62 "variables" \
63 [format {o variablesReference [i %d] count [i 3]} \
64 $num]] \
65 0]
66
67proc fetch_pointer {name var} {
68 set num [dict get $var variablesReference]
69 set refs [lindex [dap_check_request_and_response "fetch children of $name" \
70 "variables" \
71 [format {o variablesReference [i %d] count [i 1]} \
72 $num]] \
73 0]
74 set var [lindex [dict get $refs body variables] 0]
75 gdb_assert {[dict get $var value] == 23} \
76 "value of child of $name"
77 gdb_assert {[dict get $var variablesReference] == 0} \
78 "no children for child of $name"
79}
80
81foreach var [dict get $refs body variables] {
82 set name [dict get $var name]
83
84 switch $name {
85 "value" {
86 gdb_assert {[dict get $var value] == "23"} "check value of value"
87 gdb_assert {[dict get $var variablesReference] == 0} \
88 "$name does not have child"
89 }
90 "ptr" -
91 "ref" {
92 gdb_assert {[dict get $var variablesReference] != 0} \
93 "$name has children"
94 # The implementation somewhat arbitrarily chooses "named"
95 # children here.
96 gdb_assert {[dict get $var namedVariables] == 1} \
97 "$name has exactly one child"
98 fetch_pointer $name $var
99 }
4a1b9a4b
TT
100 "aggregate" {
101 gdb_assert {[dict get $var variablesReference] != 0} \
102 "$name has children"
103 # This should omit the static field.
104 gdb_assert {[dict get $var namedVariables] == 2} \
105 "$name has exactly 2 children"
106 }
a56e5dce
TT
107 }
108}
109
110dap_shutdown