]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.dap/basic-dap.exp
Implement DAP setExpression request
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.dap / basic-dap.exp
1 # Copyright 2022-2023 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 # Basic DAP test.
17
18 require allow_dap_tests
19
20 load_lib dap-support.exp
21
22 standard_testfile
23
24 if {[build_executable ${testfile}.exp $testfile] == -1} {
25 return
26 }
27
28 if {[dap_launch $testfile] == ""} {
29 return
30 }
31
32 set obj [dap_check_request_and_response "set breakpoint on two functions" \
33 setFunctionBreakpoints \
34 {o breakpoints [a [o name [s function_breakpoint_here]] \
35 [o name [s do_not_stop_here]]]}]
36 set fn_bpno [dap_get_breakpoint_number $obj]
37
38 # This also tests that the previous do_not_stop_here breakpoint is
39 # cleared.
40 set obj [dap_check_request_and_response "set breakpoint on function" \
41 setFunctionBreakpoints \
42 {o breakpoints [a [o name [s function_breakpoint_here]]]}]
43 set fn_bpno [dap_get_breakpoint_number $obj]
44
45 set obj [dap_check_request_and_response "set breakpoint with invalid filename" \
46 setBreakpoints \
47 [format {o source [o path [s nosuchfilename.c]] breakpoints [a [o line [i 29]]]}]]
48
49 set line [gdb_get_line_number "BREAK"]
50 set obj [dap_check_request_and_response "set breakpoint by line number" \
51 setBreakpoints \
52 [format {o source [o path [%s]] breakpoints [a [o line [i %d]]]} \
53 [list s $srcfile] $line]]
54 set line_bpno [dap_get_breakpoint_number $obj]
55
56 # Check the new breakpoint event.
57 set ok 0
58 foreach d [lindex $obj 1] {
59 if {[dict get $d type] != "event"
60 || [dict get $d event] != "breakpoint"} {
61 continue
62 }
63 if {[dict get $d body reason] == "new"
64 && [dict get $d body breakpoint verified] == "true"} {
65 set ok 1
66 pass "check new breakpoint event"
67 break
68 }
69 }
70 if {!$ok} {
71 fail "check new breakpoint event"
72 }
73
74 set obj [dap_check_request_and_response "reset breakpoint by line number" \
75 setBreakpoints \
76 [format {o source [o path [%s]] breakpoints [a [o line [i %d]]]} \
77 [list s $srcfile] $line]]
78 set new_line_bpno [dap_get_breakpoint_number $obj]
79 gdb_assert {$new_line_bpno == $line_bpno} "re-setting kept same breakpoint number"
80
81 # This uses "&address_breakpoint_here" as the address -- this is a
82 # hack because we know how this is implemented under the hood.
83 set obj [dap_check_request_and_response "set breakpoint by address" \
84 setInstructionBreakpoints \
85 {o breakpoints [a [o instructionReference [s &address_breakpoint_here]]]}]
86 set insn_bpno [dap_get_breakpoint_number $obj]
87
88 set response [lindex $obj 0]
89 set bplist [dict get $response body breakpoints]
90 set insn_pc [dict get [lindex $bplist 0] instructionReference]
91
92 dap_check_request_and_response "start inferior" configurationDone
93 dap_wait_for_event_and_check "inferior started" thread "body reason" started
94
95 # While waiting for the stopped event, we might receive breakpoint changed
96 # events indicating some breakpoint addresses were relocated. Update INSN_PC
97 # if necessary.
98 lassign [dap_wait_for_event_and_check "stopped at function breakpoint" stopped \
99 "body reason" breakpoint \
100 "body hitBreakpointIds" $fn_bpno] unused objs
101 foreach obj $objs {
102 if { [dict get $obj "type"] != "event" } {
103 continue
104 }
105
106 if { [dict get $obj "event"] != "breakpoint" } {
107 continue
108 }
109
110 set body [dict get $obj "body"]
111
112 if { [dict get $body "reason"] != "changed" } {
113 continue
114 }
115
116 set breakpoint [dict get $body "breakpoint"]
117 set breakpoint_id [dict get $breakpoint "id"]
118
119 if { $breakpoint_id != $insn_bpno } {
120 continue
121 }
122
123 set insn_pc [dict get $breakpoint "instructionReference"]
124 }
125
126 set obj [dap_check_request_and_response "evaluate global in function" \
127 evaluate {o expression [s global_variable]}]
128 dap_match_values "global value in function" [lindex $obj 0] \
129 "body result" 23
130
131 dap_check_request_and_response step stepIn {o threadId [i 1]}
132 dap_wait_for_event_and_check "stopped after step" stopped "body reason" step
133
134 set obj [dap_check_request_and_response "evaluate global second time" \
135 evaluate {o expression [s global_variable]}]
136 dap_match_values "global value after step" [lindex $obj 0] \
137 "body result" 24
138
139 dap_check_request_and_response "continue to address" continue \
140 {o threadId [i 1]}
141 dap_wait_for_event_and_check "stopped at address breakpoint" stopped \
142 "body reason" breakpoint \
143 "body hitBreakpointIds" $insn_bpno
144
145 dap_check_request_and_response "continue to line" continue \
146 {o threadId [i 1]}
147 dap_wait_for_event_and_check "stopped at line breakpoint" stopped \
148 "body reason" breakpoint \
149 "body hitBreakpointIds" $line_bpno \
150 "body allThreadsStopped" true
151
152 dap_check_request_and_response "return from function" stepOut \
153 {o threadId [i 1]}
154 dap_wait_for_event_and_check "stopped after return" stopped \
155 "body reason" step
156
157 set obj [dap_check_request_and_response "evaluate global in main" \
158 evaluate {o expression [s global_variable]}]
159 dap_match_values "global value in main" [lindex $obj 0] \
160 "body result" 25
161
162 set obj [dap_check_request_and_response "set global in main" \
163 setExpression {o expression [s global_variable] value [s 23]}]
164 dap_match_values "global value in main after set" [lindex $obj 0] \
165 "body result" 23
166
167 set obj [dap_request_and_response \
168 evaluate {o expression [s nosuchvariable]}]
169 set response [lindex $obj 0]
170 gdb_assert { [dict get $response success] == "false" } "result of invalid request"
171
172 set obj [dap_check_request_and_response "disassemble one instruction" \
173 disassemble \
174 [format {o memoryReference [s %s] instructionCount [i 1]} \
175 $insn_pc]]
176 set response [lindex $obj 0]
177 gdb_assert { [dict exists $response body instructions] } "instructions in disassemble output"
178
179 set obj [dap_check_request_and_response "command repl" \
180 evaluate {o expression [s {output 23}] context [s repl]}]
181 set response [lindex $obj 0]
182 gdb_assert {[dict get $response body result] == 23}
183
184 set obj [dap_check_request_and_response sources loadedSources]
185 gdb_assert {[string first basic-dap.c $obj] != -1}
186
187 dap_shutdown