1 1.1 christos # Copyright 2023-2024 Free Software Foundation, Inc. 2 1.1 christos 3 1.1 christos # This program is free software; you can redistribute it and/or modify 4 1.1 christos # it under the terms of the GNU General Public License as published by 5 1.1 christos # the Free Software Foundation; either version 3 of the License, or 6 1.1 christos # (at your option) any later version. 7 1.1 christos # 8 1.1 christos # This program is distributed in the hope that it will be useful, 9 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 1.1 christos # GNU General Public License for more details. 12 1.1 christos # 13 1.1 christos # You should have received a copy of the GNU General Public License 14 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 1.1 christos 16 1.1 christos # Test "pause" in DAP. 17 1.1 christos 18 1.1 christos require allow_dap_tests 19 1.1 christos 20 1.1 christos load_lib dap-support.exp 21 1.1 christos 22 1.1 christos standard_testfile 23 1.1 christos 24 1.1 christos if {[build_executable ${testfile}.exp $testfile $srcfile] == -1} { 25 1.1 christos return 26 1.1 christos } 27 1.1 christos 28 1.1 christos if {[dap_initialize] == ""} { 29 1.1 christos return 30 1.1 christos } 31 1.1 christos 32 1.1.1.2 christos set launch_id [dap_launch $testfile] 33 1.1.1.2 christos 34 1.1 christos # Set a conditional breakpoint that will never fire. This is done to 35 1.1 christos # test the state-tracking in events -- an inferior call from a 36 1.1 christos # breakpoint condition should not cause any sort of stop or continue 37 1.1 christos # events. 38 1.1 christos set line [gdb_get_line_number "STOP"] 39 1.1 christos dap_check_request_and_response "set conditional breakpoint" \ 40 1.1 christos setBreakpoints \ 41 1.1 christos [format {o source [o path [%s]] \ 42 1.1 christos breakpoints [a [o line [i %d] \ 43 1.1 christos condition [s "return_false()"]]]} \ 44 1.1 christos [list s $srcfile] $line] 45 1.1 christos 46 1.1 christos dap_check_request_and_response "configurationDone" configurationDone 47 1.1 christos 48 1.1.1.2 christos dap_check_response "launch response" launch $launch_id 49 1.1.1.2 christos 50 1.1 christos dap_wait_for_event_and_check "process event generated" process \ 51 1.1 christos "body startMethod" process 52 1.1 christos dap_wait_for_event_and_check "inferior started" thread "body reason" started 53 1.1 christos 54 1.1 christos set resp [lindex [dap_request_and_response evaluate {o expression [s 23]}] \ 55 1.1 christos 0] 56 1.1 christos gdb_assert {[dict get $resp success] == "false"} \ 57 1.1 christos "evaluate failed while inferior executing" 58 1.1 christos gdb_assert {[dict get $resp message] == "notStopped"} \ 59 1.1 christos "evaluate issued notStopped" 60 1.1 christos 61 1.1 christos dap_check_request_and_response pause pause \ 62 1.1 christos {o threadId [i 1]} 63 1.1 christos 64 1.1 christos dap_wait_for_event_and_check "stopped by pause" stopped \ 65 1.1 christos "body reason" pause 66 1.1 christos 67 1.1 christos set result [dap_request_and_response evaluate {o expression [s do_nothing()]}] 68 1.1 christos gdb_assert {[dict get [lindex $result 0] body result] == 91} \ 69 1.1 christos "check result of evaluation" 70 1.1 christos 71 1.1 christos set seen fail 72 1.1 christos foreach event [lindex $result 1] { 73 1.1 christos if {[dict get $event type] != "event"} { 74 1.1 christos continue 75 1.1 christos } 76 1.1 christos if {[dict get $event event] == "continued"} { 77 1.1 christos set seen pass 78 1.1 christos break 79 1.1 christos } 80 1.1 christos } 81 1.1 christos gdb_assert {$seen == "pass"} "continue event from inferior call" 82 1.1 christos 83 1.1 christos # 84 1.1 christos # Test that a repl evaluation that causes a continue can be canceled. 85 1.1 christos # 86 1.1 christos 87 1.1 christos set cont_id [dap_send_request evaluate \ 88 1.1 christos {o expression [s continue] context [s repl]}] 89 1.1 christos dap_wait_for_event_and_check "continued" continued 90 1.1 christos 91 1.1 christos set cancel_id [dap_send_request cancel \ 92 1.1 christos [format {o requestId [i %d]} $cont_id]] 93 1.1 christos 94 1.1 christos # The stop event will come before any responses to the requests. 95 1.1 christos dap_wait_for_event_and_check "stopped by cancel" stopped 96 1.1 christos 97 1.1 christos # Now we can wait for the 'continue' request to complete, and then the 98 1.1 christos # 'cancel' request. 99 1.1 christos dap_read_response evaluate $cont_id 100 1.1 christos dap_read_response cancel $cancel_id 101 1.1 christos 102 1.1 christos # 103 1.1 christos # Test that a repl evaluation of a long-running gdb command (that does 104 1.1 christos # not continue the inferior) can be canceled. 105 1.1 christos # 106 1.1 christos 107 1.1 christos proc write_file {suffix contents} { 108 1.1 christos global testfile 109 1.1 christos 110 1.1 christos set gdbfile [standard_output_file ${testfile}.$suffix] 111 1.1 christos set ofd [open $gdbfile w] 112 1.1 christos puts $ofd $contents 113 1.1 christos close $ofd 114 1.1 christos return $gdbfile 115 1.1 christos } 116 1.1 christos 117 1.1 christos set gdbfile [write_file gdb "set \$x = 0\nwhile 1\nset \$x = \$x + 1\nend"] 118 1.1 christos set cont_id [dap_send_request evaluate \ 119 1.1 christos [format {o expression [s "source %s"] context [s repl]} \ 120 1.1 christos $gdbfile]] 121 1.1 christos 122 1.1 christos # Wait a little to try to ensure the command is running. 123 1.1 christos sleep 0.2 124 1.1 christos set cancel_id [dap_send_request cancel \ 125 1.1 christos [format {o requestId [i %d]} $cont_id]] 126 1.1 christos 127 1.1 christos set info [lindex [dap_read_response evaluate $cont_id] 0] 128 1.1 christos gdb_assert {[dict get $info success] == "false"} "gdb command failed" 129 1.1 christos gdb_assert {[dict get $info message] == "cancelled"} "gdb command canceled" 130 1.1 christos 131 1.1 christos dap_read_response cancel $cancel_id 132 1.1 christos 133 1.1 christos # 134 1.1 christos # Test that a repl evaluation of a long-running Python command (that 135 1.1 christos # does not continue the inferior) can be canceled. 136 1.1 christos # 137 1.1 christos 138 1.1 christos set gdbfile [write_file py "while True:\n pass"] 139 1.1 christos set cont_id [dap_send_request evaluate \ 140 1.1 christos [format {o expression [s "source %s"] context [s repl]} \ 141 1.1 christos $gdbfile]] 142 1.1 christos 143 1.1 christos # Wait a little to try to ensure the command is running. 144 1.1 christos sleep 0.2 145 1.1 christos set cancel_id [dap_send_request cancel \ 146 1.1 christos [format {o requestId [i %d]} $cont_id]] 147 1.1 christos 148 1.1 christos set info [lindex [dap_read_response evaluate $cont_id] 0] 149 1.1 christos gdb_assert {[dict get $info success] == "false"} "python command failed" 150 1.1 christos gdb_assert {[dict get $info message] == "cancelled"} "python command canceled" 151 1.1 christos 152 1.1 christos dap_read_response cancel $cancel_id 153 1.1 christos 154 1.1 christos dap_shutdown 155