Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve debug log -add remote debuggee backlog #132

Merged
merged 2 commits into from
Jul 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions test/support/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,24 @@ def type(command)
end

def create_message fail_msg
"#{fail_msg} on #{@mode} mode\n[DEBUG SESSION LOG]\n> " + @backlog.join('> ')
"#{fail_msg} on #{@mode} mode\n[DEBUGGER SESSION LOG]\n> #{@backlog.join('> ')}#{debuggee_backlog}"
end

def debuggee_backlog
return if @mode == 'LOCAL'

backlog = []
begin
Timeout.timeout(TIMEOUT_SEC) do
while (line = @remote_r.gets)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it can raise EIO error, so you need to rescue it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
I'll change it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backlog << line
end
end
rescue Timeout::Error, Errno::EIO
# result of `gets` return Errno::EIO in some platform
# https://github.com/ruby/ruby/blob/master/ext/pty/pty.c#L729-L736
end
"\n[DEBUGGEE SESSION LOG]\n> #{backlog.join('> ')}"
end

# This method will execute both local and remote mode by default.
Expand Down Expand Up @@ -74,21 +91,21 @@ def debug_on_tcpip repl_prompt = '(rdbg:remote)'
end

def setup_remote_debuggee(cmd)
@remote_r, @remote_w, @remote_debuggee_pid = PTY.spawn(cmd, :in=>'/dev/null', :out=>'/dev/null')
@remote_r, @remote_w, @remote_debuggee_pid = PTY.spawn(cmd)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to change this part to output complete backlog(In the above example, this would be "hello") in remote deguggee.

@remote_r.read(1) # wait for the remote server to boot up
end

TIMEOUT_SEC = (ENV['RUBY_DEBUG_TIMEOUT_SEC'] || 10).to_i

def run_test_scenario(cmd, repl_prompt)
@queue = Queue.new
@scenario.call

timeout_sec = (ENV['RUBY_DEBUG_TIMEOUT_SEC'] || 10).to_i

PTY.spawn(cmd) do |read, write, pid|
@backlog = []
@last_backlog = []
begin
Timeout.timeout(timeout_sec) do
Timeout.timeout(TIMEOUT_SEC) do
while (line = read.gets)
debug_print line
case line.chomp
Expand Down Expand Up @@ -124,7 +141,7 @@ def run_test_scenario(cmd, repl_prompt)
# https://github.com/ruby/ruby/blob/master/ext/pty/pty.c#L729-L736
assert_empty_queue(exception: e)
rescue Timeout::Error => e
assert false, create_message("TIMEOUT ERROR (#{timeout_sec} sec)")
assert false, create_message("TIMEOUT ERROR (#{TIMEOUT_SEC} sec)")
ensure
# kill remote debuggee
if defined?(@remote_debuggee_pid) && @remote_debuggee_pid
Expand Down