Skip to content

Commit

Permalink
Restart threads on DAP evaluation
Browse files Browse the repository at this point in the history
This makes sure DAP evaluation request also doesn't hang.

See ruby#947 for the original console implementation.
  • Loading branch information
st0012 committed Mar 30, 2023
1 parent 24fc36c commit 1ba0008
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/debug/server_dap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ def process_protocol_request req
expr = req.dig('arguments', 'expression')

if find_waiting_tc(tid)
restart_all_threads
request_tc [:dap, :evaluate, req, fid, expr, context]
else
fail_response req
Expand Down Expand Up @@ -701,6 +702,7 @@ def process_protocol_result args
register_vars result[:variables], tid
@ui.respond req, result
when :evaluate
stop_all_threads
message = result.delete :message
if message
@ui.respond req, success: false, message: message
Expand Down
23 changes: 23 additions & 0 deletions test/protocol/eval_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,27 @@ def test_eval_evaluates_arithmetic_expressions
end
end
end

class EvaluateThreadTest < ProtocolTestCase
PROGRAM = <<~RUBY
1| th0 = Thread.new{sleep}
2| m = Mutex.new; q = Queue.new
3| th1 = Thread.new do
4| m.lock; q << true
5| sleep 1
6| m.unlock
7| end
8| q.pop # wait for locking
9| p :ok
RUBY

def test_eval_with_threads
run_protocol_scenario PROGRAM, cdp: false do
req_add_breakpoint 9
req_continue
assert_repl_result({value: 'false', type: 'FalseClass'}, 'm.lock.nil?', frame_idx: 0)
req_continue
end
end
end
end

0 comments on commit 1ba0008

Please sign in to comment.