Home | History | Annotate | Line # | Download | only in gdb.dap
pause.exp revision 1.1.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 "pause" in DAP.
     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 $srcfile] == -1} {
     25     return
     26 }
     27 
     28 if {[dap_initialize] == ""} {
     29     return
     30 }
     31 
     32 # Set a conditional breakpoint that will never fire.  This is done to
     33 # test the state-tracking in events -- an inferior call from a
     34 # breakpoint condition should not cause any sort of stop or continue
     35 # events.
     36 set line [gdb_get_line_number "STOP"]
     37 dap_check_request_and_response "set conditional breakpoint" \
     38     setBreakpoints \
     39     [format {o source [o path [%s]] \
     40 		 breakpoints [a [o line [i %d] \
     41 				     condition [s "return_false()"]]]} \
     42 	 [list s $srcfile] $line]
     43 
     44 dap_check_request_and_response "configurationDone" configurationDone
     45 
     46 if {[dap_launch $testfile] == ""} {
     47     return
     48 }
     49 dap_wait_for_event_and_check "process event generated" process \
     50     "body startMethod" process
     51 dap_wait_for_event_and_check "inferior started" thread "body reason" started
     52 
     53 set resp [lindex [dap_request_and_response evaluate {o expression [s 23]}] \
     54 	      0]
     55 gdb_assert {[dict get $resp success] == "false"} \
     56     "evaluate failed while inferior executing"
     57 gdb_assert {[dict get $resp message] == "notStopped"} \
     58     "evaluate issued notStopped"
     59 
     60 dap_check_request_and_response pause pause \
     61     {o threadId [i 1]}
     62 
     63 dap_wait_for_event_and_check "stopped by pause" stopped \
     64     "body reason" pause
     65 
     66 set result [dap_request_and_response evaluate {o expression [s do_nothing()]}]
     67 gdb_assert {[dict get [lindex $result 0] body result] == 91} \
     68     "check result of evaluation"
     69 
     70 set seen fail
     71 foreach event [lindex $result 1] {
     72     if {[dict get $event type] != "event"} {
     73 	continue
     74     }
     75     if {[dict get $event event] == "continued"} {
     76 	set seen pass
     77 	break
     78     }
     79 }
     80 gdb_assert {$seen == "pass"} "continue event from inferior call"
     81 
     82 #
     83 # Test that a repl evaluation that causes a continue can be canceled.
     84 #
     85 
     86 set cont_id [dap_send_request evaluate \
     87 		 {o expression [s continue] context [s repl]}]
     88 dap_wait_for_event_and_check "continued" continued
     89 
     90 set cancel_id [dap_send_request cancel \
     91 		   [format {o requestId [i %d]} $cont_id]]
     92 
     93 # The stop event will come before any responses to the requests.
     94 dap_wait_for_event_and_check "stopped by cancel" stopped
     95 
     96 # Now we can wait for the 'continue' request to complete, and then the
     97 # 'cancel' request.
     98 dap_read_response evaluate $cont_id
     99 dap_read_response cancel $cancel_id
    100 
    101 #
    102 # Test that a repl evaluation of a long-running gdb command (that does
    103 # not continue the inferior) can be canceled.
    104 #
    105 
    106 proc write_file {suffix contents} {
    107     global testfile
    108 
    109     set gdbfile [standard_output_file ${testfile}.$suffix]
    110     set ofd [open $gdbfile w]
    111     puts $ofd $contents
    112     close $ofd
    113     return $gdbfile
    114 }
    115 
    116 set gdbfile [write_file gdb "set \$x = 0\nwhile 1\nset \$x = \$x + 1\nend"]
    117 set cont_id [dap_send_request evaluate \
    118 		 [format {o expression [s "source %s"] context [s repl]} \
    119 		      $gdbfile]]
    120 
    121 # Wait a little to try to ensure the command is running.
    122 sleep 0.2
    123 set cancel_id [dap_send_request cancel \
    124 		   [format {o requestId [i %d]} $cont_id]]
    125 
    126 set info [lindex [dap_read_response evaluate $cont_id] 0]
    127 gdb_assert {[dict get $info success] == "false"} "gdb command failed"
    128 gdb_assert {[dict get $info message] == "cancelled"} "gdb command canceled"
    129 
    130 dap_read_response cancel $cancel_id
    131 
    132 #
    133 # Test that a repl evaluation of a long-running Python command (that
    134 # does not continue the inferior) can be canceled.
    135 #
    136 
    137 set gdbfile [write_file py "while True:\n  pass"]
    138 set cont_id [dap_send_request evaluate \
    139 		 [format {o expression [s "source %s"] context [s repl]} \
    140 		      $gdbfile]]
    141 
    142 # Wait a little to try to ensure the command is running.
    143 sleep 0.2
    144 set cancel_id [dap_send_request cancel \
    145 		   [format {o requestId [i %d]} $cont_id]]
    146 
    147 set info [lindex [dap_read_response evaluate $cont_id] 0]
    148 gdb_assert {[dict get $info success] == "false"} "python command failed"
    149 gdb_assert {[dict get $info message] == "cancelled"} "python command canceled"
    150 
    151 dap_read_response cancel $cancel_id
    152 
    153 dap_shutdown
    154