1 # Copyright 2022-2023 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/>.
18 require allow_dap_tests
20 load_lib dap-support.exp
24 if {[build_executable ${testfile}.exp $testfile] == -1} {
28 if {[dap_launch $testfile] == ""} {
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]
38 # This also tests that the previous do_not_stop_here breakpoint is
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]
45 set obj [dap_check_request_and_response "set breakpoint with invalid filename" \
47 [format {o source [o path [s nosuchfilename.c]] breakpoints [a [o line [i 29]]]}]]
49 set line [gdb_get_line_number "BREAK"]
50 set obj [dap_check_request_and_response "set breakpoint by line number" \
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]
56 # Check the new breakpoint event.
58 foreach d [lindex $obj 1] {
59 if {[dict get $d type] != "event"
60 || [dict get $d event] != "breakpoint"} {
63 if {[dict get $d body reason] == "new"
64 && [dict get $d body breakpoint verified] == "true"} {
66 pass "check new breakpoint event"
71 fail "check new breakpoint event"
74 set obj [dap_check_request_and_response "reset breakpoint by line number" \
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"
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]
88 set response [lindex $obj 0]
89 set bplist [dict get $response body breakpoints]
90 set insn_pc [dict get [lindex $bplist 0] instructionReference]
92 dap_check_request_and_response "start inferior" configurationDone
93 dap_wait_for_event_and_check "inferior started" thread "body reason" started
95 # While waiting for the stopped event, we might receive breakpoint changed
96 # events indicating some breakpoint addresses were relocated. Update INSN_PC
98 lassign [dap_wait_for_event_and_check "stopped at function breakpoint" stopped \
99 "body reason" breakpoint \
100 "body hitBreakpointIds" $fn_bpno] unused objs
102 if { [dict get $obj "type"] != "event" } {
106 if { [dict get $obj "event"] != "breakpoint" } {
110 set body [dict get $obj "body"]
112 if { [dict get $body "reason"] != "changed" } {
116 set breakpoint [dict get $body "breakpoint"]
117 set breakpoint_id [dict get $breakpoint "id"]
119 if { $breakpoint_id != $insn_bpno } {
123 set insn_pc [dict get $breakpoint "instructionReference"]
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] \
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
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] \
139 dap_check_request_and_response "continue to address" continue \
141 dap_wait_for_event_and_check "stopped at address breakpoint" stopped \
142 "body reason" breakpoint \
143 "body hitBreakpointIds" $insn_bpno
145 dap_check_request_and_response "continue to line" continue \
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
152 dap_check_request_and_response "return from function" stepOut \
154 dap_wait_for_event_and_check "stopped after return" stopped \
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] \
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] \
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"
172 set obj [dap_check_request_and_response "disassemble one instruction" \
174 [format {o memoryReference [s %s] instructionCount [i 1]} \
176 set response [lindex $obj 0]
177 gdb_assert { [dict exists $response body instructions] } "instructions in disassemble output"
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}
184 set obj [dap_check_request_and_response sources loadedSources]
185 gdb_assert {[string first basic-dap.c $obj] != -1}