Class: MilkTea::DAP::Backends::LLDBDAP
- Inherits:
-
Object
- Object
- MilkTea::DAP::Backends::LLDBDAP
- Defined in:
- lib/milk_tea/dap/backends/lldb_dap.rb
Overview
Thin bridge to an lldb-dap compatible adapter process.
Instance Method Summary collapse
-
#initialize(adapter_command: ["lldb-dap"], on_event: nil, on_request: nil) ⇒ LLDBDAP
constructor
A new instance of LLDBDAP.
- #request(command, arguments = {}, timeout: 5) ⇒ Object
- #running? ⇒ Boolean
- #start! ⇒ Object
- #stop! ⇒ Object
Constructor Details
#initialize(adapter_command: ["lldb-dap"], on_event: nil, on_request: nil) ⇒ LLDBDAP
Returns a new instance of LLDBDAP.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/milk_tea/dap/backends/lldb_dap.rb', line 12 def initialize(adapter_command: ["lldb-dap"], on_event: nil, on_request: nil) @adapter_command = adapter_command @on_event = on_event @on_request = on_request @protocol = nil @stdin = nil @stdout = nil @stderr = nil @wait_thread = nil @reader_thread = nil @stderr_thread = nil @write_mutex = Mutex.new @pending_mutex = Mutex.new @pending = {} @next_seq = 1 end |
Instance Method Details
#request(command, arguments = {}, timeout: 5) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/milk_tea/dap/backends/lldb_dap.rb', line 43 def request(command, arguments = {}, timeout: 5) start! unless running? seq = next_seq queue = Queue.new @pending_mutex.synchronize do @pending[seq] = queue end @write_mutex.synchronize do @protocol.({ seq: seq, type: "request", command: command, arguments: arguments }) end Timeout.timeout(timeout) { queue.pop } rescue Timeout::Error { "type" => "response", "request_seq" => seq, "success" => false, "message" => "backend request timed out: #{command}" } ensure @pending_mutex.synchronize { @pending.delete(seq) } end |
#running? ⇒ Boolean
39 40 41 |
# File 'lib/milk_tea/dap/backends/lldb_dap.rb', line 39 def running? !@wait_thread.nil? && @wait_thread.alive? end |
#start! ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/milk_tea/dap/backends/lldb_dap.rb', line 29 def start! return if running? @stdin, @stdout, @stderr, @wait_thread = Open3.popen3(*@adapter_command) @protocol = Protocol.new(input: @stdout, output: @stdin) @reader_thread = Thread.new { read_loop } @stderr_thread = Thread.new { drain_stderr } end |
#stop! ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/milk_tea/dap/backends/lldb_dap.rb', line 73 def stop! @stdin&.close @stdout&.close @stderr&.close if @wait_thread&.alive? Process.kill("TERM", @wait_thread.pid) end rescue StandardError nil ensure @wait_thread&.join(0.2) @reader_thread&.join(0.2) @stderr_thread&.join(0.2) @stdin = nil @stdout = nil @stderr = nil @wait_thread = nil @reader_thread = nil @stderr_thread = nil end |