Home | History | Annotate | Line # | Download | only in gdb.dap
      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 DAP breakpoint conditions.
     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_initialize] == ""} {
     29     return
     30 }
     31 
     32 set launch_id [dap_launch $testfile]
     33 
     34 set line [gdb_get_line_number "STOP"]
     35 
     36 # Test some breakpoint-setting failure modes.
     37 set obj [dap_check_request_and_response "set invalid breakpoints" \
     38 	     setBreakpoints \
     39 	     [format {o source [o path [%s]] \
     40 			  breakpoints \
     41 			  [a [o line [i %d] condition [s "DEI@@++"]] \
     42 			       [o line [i %d] hitCondition [s "DEI@@++"]]]} \
     43 		  [list s $srcfile] $line $line]]
     44 
     45 set i 1
     46 foreach bp [dict get [lindex $obj 0] body breakpoints] {
     47     gdb_assert {[dict get $bp verified] == "false"} \
     48 	"breakpoint $i invalid"
     49     if {$i == 1} {
     50 	gdb_assert {[dict get $bp reason] == "pending"} \
     51 	    "breakpoint $i pending"
     52     } else {
     53 	gdb_assert {[dict get $bp message] != ""} \
     54 	    "breakpoint $i has message"
     55     }
     56     incr i
     57 }
     58 
     59 set obj [dap_check_request_and_response "set conditional breakpoint" \
     60 	     setBreakpoints \
     61 	     [format {o source [o path [%s]] \
     62 			  breakpoints [a [o line [i %d] \
     63 					      condition [s "i == 3"] \
     64 					      hitCondition [s 3]]]} \
     65 		  [list s $srcfile] $line]]
     66 set fn_bpno [dap_get_breakpoint_number $obj]
     67 
     68 dap_check_request_and_response "configurationDone" configurationDone
     69 
     70 dap_check_response "launch response" launch $launch_id
     71 
     72 dap_wait_for_event_and_check "stopped at function breakpoint" stopped \
     73     "body reason" breakpoint \
     74     "body hitBreakpointIds" $fn_bpno
     75 
     76 set bt [lindex [dap_check_request_and_response "backtrace" stackTrace \
     77 		    {o threadId [i 1]}] \
     78 	    0]
     79 set frame_id [dict get [lindex [dict get $bt body stackFrames] 0] id]
     80 
     81 set obj [dap_check_request_and_response "evaluate i" \
     82 	     evaluate \
     83 	     [format {o expression [s i] frameId [i %s]} $frame_id]]
     84 dap_match_values "value of i" [lindex $obj 0] \
     85     "body result" 3
     86 
     87 set obj [dap_check_request_and_response "evaluate j" \
     88 	     evaluate \
     89 	     [format {o expression [s j] frameId [i %s]} $frame_id]]
     90 dap_match_values "value of j" [lindex $obj 0] \
     91     "body result" 3
     92 
     93 dap_shutdown
     94