]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.dap/basic-dap.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.dap / basic-dap.exp
1 # Copyright 2022-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 # 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 1
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 0
66 break
67 }
68 }
69 if {$ok} {
70 pass "check lack of new breakpoint event"
71 } else {
72 fail "check lack of new breakpoint event"
73 }
74
75 # Check that there are breakpoint locations on each line between FIRST
76 # and BREAK.
77 set first_line [gdb_get_line_number "FIRST"]
78 set last_line [expr {$line - 1}]
79 set obj [dap_check_request_and_response "breakpoint locations" \
80 breakpointLocations \
81 [format {o source [o path [%s]] line [i %d] endLine [i %d]} \
82 [list s $srcfile] $first_line $last_line]]
83 # We know gdb returns the lines in sorted order.
84 foreach entry [dict get [lindex $obj 0] body breakpoints] {
85 gdb_assert {[dict get $entry line] == $first_line} \
86 "line $first_line in result"
87 incr first_line
88 }
89
90 # Note that in this request, we add a 'source' field to the
91 # SourceBreakpoint object. This isn't in the spec but it once caused
92 # an incorrect exception in the Python code. See PR dap/30820.
93 set obj [dap_check_request_and_response "reset breakpoint by line number" \
94 setBreakpoints \
95 [format {o source [o path [%s]] \
96 breakpoints [a [o source [o path [%s]] \
97 line [i %d]]]} \
98 [list s $srcfile] [list s $srcfile] $line]]
99 set new_line_bpno [dap_get_breakpoint_number $obj]
100 gdb_assert {$new_line_bpno == $line_bpno} "re-setting kept same breakpoint number"
101
102 # This uses "&address_breakpoint_here" as the address -- this is a
103 # hack because we know how this is implemented under the hood.
104 set obj [dap_check_request_and_response "set breakpoint by address" \
105 setInstructionBreakpoints \
106 {o breakpoints [a [o instructionReference [s &address_breakpoint_here]]]}]
107 set insn_bpno [dap_get_breakpoint_number $obj]
108
109 set response [lindex $obj 0]
110 set bplist [dict get $response body breakpoints]
111 set insn_pc [dict get [lindex $bplist 0] instructionReference]
112
113 dap_check_request_and_response "start inferior" configurationDone
114 dap_wait_for_event_and_check "inferior started" thread "body reason" started
115
116 # While waiting for the stopped event, we might receive breakpoint changed
117 # events indicating some breakpoint addresses were relocated. Update INSN_PC
118 # if necessary.
119 lassign [dap_wait_for_event_and_check "stopped at function breakpoint" stopped \
120 "body reason" breakpoint \
121 "body hitBreakpointIds" $fn_bpno] unused objs
122 foreach obj $objs {
123 if { [dict get $obj "type"] != "event" } {
124 continue
125 }
126
127 if { [dict get $obj "event"] != "breakpoint" } {
128 continue
129 }
130
131 set body [dict get $obj "body"]
132
133 if { [dict get $body "reason"] != "changed" } {
134 continue
135 }
136
137 set breakpoint [dict get $body "breakpoint"]
138 set breakpoint_id [dict get $breakpoint "id"]
139
140 if { $breakpoint_id != $insn_bpno } {
141 continue
142 }
143
144 set insn_pc [dict get $breakpoint "instructionReference"]
145 }
146
147 set obj [dap_check_request_and_response "evaluate global in function" \
148 evaluate {o expression [s global_variable]}]
149 dap_match_values "global value in function" [lindex $obj 0] \
150 "body result" 23
151
152 dap_check_request_and_response step stepIn {o threadId [i 1]}
153 dap_wait_for_event_and_check "stopped after step" stopped "body reason" step
154
155 set obj [dap_check_request_and_response "evaluate global second time" \
156 evaluate {o expression [s global_variable]}]
157 dap_match_values "global value after step" [lindex $obj 0] \
158 "body result" 24
159
160 dap_check_request_and_response "continue to address" continue \
161 {o threadId [i 1]}
162 dap_wait_for_event_and_check "stopped at address breakpoint" stopped \
163 "body reason" breakpoint \
164 "body hitBreakpointIds" $insn_bpno
165
166 dap_check_request_and_response "continue to line" continue \
167 {o threadId [i 1]}
168 dap_wait_for_event_and_check "stopped at line breakpoint" stopped \
169 "body reason" breakpoint \
170 "body hitBreakpointIds" $line_bpno \
171 "body allThreadsStopped" true
172
173 dap_check_request_and_response "return from function" stepOut \
174 {o threadId [i 1]}
175 dap_wait_for_event_and_check "stopped after return" stopped \
176 "body reason" step
177
178 set obj [dap_check_request_and_response "evaluate global in main" \
179 evaluate {o expression [s global_variable]}]
180 dap_match_values "global value in main" [lindex $obj 0] \
181 "body result" 25
182
183 set obj [dap_check_request_and_response "set global in main" \
184 setExpression {o expression [s global_variable] value [s 23]}]
185 dap_match_values "global value in main after set" [lindex $obj 0] \
186 "body value" 23 \
187 "body type" int
188
189 set obj [dap_request_and_response \
190 evaluate {o expression [s nosuchvariable]}]
191 set response [lindex $obj 0]
192 gdb_assert { [dict get $response success] == "false" } "result of invalid request"
193
194 set obj [dap_check_request_and_response "disassemble one instruction" \
195 disassemble \
196 [format {o memoryReference [s %s] instructionCount [i 1]} \
197 $insn_pc]]
198 set response [lindex $obj 0]
199 gdb_assert { [dict exists $response body instructions] } "instructions in disassemble output"
200 foreach insn [dict get $response body instructions] {
201 gdb_assert {[dict exists $insn instructionBytes]} \
202 "instruction bytes in disassemble output"
203 set bytes [dict get $insn instructionBytes]
204 gdb_assert {[string length $bytes] % 2 == 0} \
205 "even number of digits"
206 gdb_assert {[regexp "^\[0-9A-Fa-f\]+\$" $bytes]} \
207 "instructionBytes is hex"
208 }
209
210 set obj [dap_check_request_and_response "command repl" \
211 evaluate {o expression [s {output 23}] context [s repl]}]
212 set response [lindex $obj 0]
213 gdb_assert {[dict get $response body result] == 23}
214
215 dap_shutdown