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