From af194799d88557aa1b41549682a7ee97ac533eff Mon Sep 17 00:00:00 2001 From: st0012 Date: Thu, 30 Dec 2021 16:56:13 +0000 Subject: [PATCH] Add debug logging --- lib/debug/config.rb | 1 + lib/debug/session.rb | 4 ++++ lib/debug/thread_client.rb | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/lib/debug/config.rb b/lib/debug/config.rb index 7165ead56..2ad8479ba 100644 --- a/lib/debug/config.rb +++ b/lib/debug/config.rb @@ -7,6 +7,7 @@ module DEBUGGER__ ERROR: 2, WARN: 3, INFO: 4, + DEBUG: 5 }.freeze CONFIG_SET = { diff --git a/lib/debug/session.rb b/lib/debug/session.rb index f03f844ed..0075231e3 100644 --- a/lib/debug/session.rb +++ b/lib/debug/session.rb @@ -2080,6 +2080,10 @@ def self.info msg log :INFO, msg end + def self.debug msg + log :DEBUG, msg + end + def self.log level, msg @logfile = STDERR unless defined? @logfile diff --git a/lib/debug/thread_client.rb b/lib/debug/thread_client.rb index 8abc2996a..c721cd981 100644 --- a/lib/debug/thread_client.rb +++ b/lib/debug/thread_client.rb @@ -118,6 +118,7 @@ def mark_as_management end def set_mode mode + debug_mode(@mode, mode) # STDERR.puts "#{@mode} => #{mode} @ #{caller.inspect}" # pp caller @@ -181,6 +182,7 @@ def puts str = '' end def << req + debug_cmd(req) @q_cmd << req end @@ -191,6 +193,7 @@ def generate_info end def event! ev, *args + debug_event(ev, args) @q_evt << [self, @output, ev, generate_info, *args] @output = [] end @@ -236,6 +239,7 @@ def on_pause def suspend event, tp = nil, bp: nil, sig: nil, postmortem_frames: nil, replay_frames: nil, postmortem_exc: nil return if management? + debug_suspend(event) @current_frame_index = 0 @@ -1052,6 +1056,25 @@ def wait_next_action_ raise end + def debug_event(ev, args) + args = args.map { |arg| DEBUGGER__.safe_inspect(arg) } + DEBUGGER__.debug("#{inspect} sends Event { type: #{ev.inspect}, args: #{args} } to Session") + end + + def debug_mode(old_mode, new_mode) + DEBUGGER__.debug("#{inspect} changes mode (#{old_mode} -> #{new_mode})") + end + + def debug_cmd(cmds) + cmd, *args = *cmds + args = args.map { |arg| DEBUGGER__.safe_inspect(arg) } + DEBUGGER__.debug("#{inspect} receives Cmd { type: #{cmd.inspect}, args: #{args} } from Session") + end + + def debug_suspend(event) + DEBUGGER__.debug("#{inspect} is suspended for #{event.inspect}") + end + class Recorder attr_reader :log, :index attr_accessor :backup_frames