Module: MilkTea::DAP::Server::ServerPauseDiagnostics
- Included in:
- MilkTea::DAP::Server
- Defined in:
- lib/milk_tea/dap/server/pause_diagnostics.rb
Instance Method Summary collapse
- #emit_pause_diagnostic_async(body) ⇒ Object
- #informative_pause_frame?(frame) ⇒ Boolean
- #pause_diagnostic_output(thread_id, stack_response) ⇒ Object
- #pause_frame_summary(frame, include_ip: false) ⇒ Object
Instance Method Details
#emit_pause_diagnostic_async(body) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/milk_tea/dap/server/pause_diagnostics.rb', line 7 def emit_pause_diagnostic_async(body) return unless body.is_a?(Hash) thread_id = normalize_reference_key(dap_value(body, "threadId")) return if thread_id.nil? track_background_thread(Thread.new(thread_id) do |diagnostic_thread_id| stack_response = backend_request("stackTrace", { "threadId" => diagnostic_thread_id, "startFrame" => 0, "levels" => 8 }) write_event("output", { category: "console", output: "#{pause_diagnostic_output(diagnostic_thread_id, stack_response)}\n" }) rescue StandardError => e write_event("output", { category: "console", output: "[milk-tea dap] pause top frame unavailable thread=#{diagnostic_thread_id}: #{e.}\n" }) end) end |
#informative_pause_frame?(frame) ⇒ Boolean
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/milk_tea/dap/server/pause_diagnostics.rb', line 55 def informative_pause_frame?(frame) name = dap_value(frame, "name").to_s return false if name.empty? return false if name.match?(/\A___lldb_unnamed_symbol_/) return false if %w[clock_nanosleep __nanosleep nanosleep].include?(name) source = dap_value(frame, "source") source_path = source.is_a?(Hash) ? dap_value(source, "path").to_s : "" return true if source_path.start_with?("/usr/src/debug/") return true if !source_path.empty? && !source_path.start_with?("/usr/lib/") && !source_path.start_with?("/lib/") true end |
#pause_diagnostic_output(thread_id, stack_response) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/milk_tea/dap/server/pause_diagnostics.rb', line 32 def pause_diagnostic_output(thread_id, stack_response) unless stack_response["success"] return "[milk-tea dap] pause focus unavailable thread=#{thread_id}: #{(stack_response)}" end frames = stack_response.dig("body", "stackFrames") frames = frames.select { |candidate| candidate.is_a?(Hash) } if frames.is_a?(Array) return "[milk-tea dap] pause focus unavailable thread=#{thread_id}: no stack frames" if !frames.is_a?(Array) || frames.empty? raw_frame = frames.first informative_index = frames.index { |frame| informative_pause_frame?(frame) } unless informative_index return "[milk-tea dap] pause top frame thread=#{thread_id}: #{pause_frame_summary(raw_frame, include_ip: true)}" end focus_frames = frames.drop(informative_index).first(3) focus = focus_frames.map { |frame| pause_frame_summary(frame) }.join(" <- ") raw_suffix = informative_index.zero? ? "" : " raw=#{pause_frame_summary(raw_frame, include_ip: true)}" "[milk-tea dap] pause focus thread=#{thread_id}: #{focus}#{raw_suffix}" end |
#pause_frame_summary(frame, include_ip: false) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/milk_tea/dap/server/pause_diagnostics.rb', line 70 def pause_frame_summary(frame, include_ip: false) frame_name = dap_value(frame, "name").to_s frame_name = "(anonymous)" if frame_name.empty? instruction_pointer = dap_value(frame, "instructionPointerReference").to_s source = dap_value(frame, "source") source_path = source.is_a?(Hash) ? dap_value(source, "path").to_s : "" source_name = source.is_a?(Hash) ? dap_value(source, "name").to_s : "" line = dap_value(frame, "line") location_source = if !source_path.empty? && !source_path.include?("`") source_path elsif !source_name.empty? source_name elsif !source_path.empty? source_path else instruction_pointer end location = if location_source.to_s.empty? "(unknown)" elsif line.to_i.positive? && !location_source.include?(":#{line}") "#{location_source}:#{line}" else location_source end if include_ip && !instruction_pointer.empty? && location != instruction_pointer "#{frame_name} @ #{location} ip=#{instruction_pointer}" else "#{frame_name} @ #{location}" end end |