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

Server Mode #145

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 9 additions & 8 deletions bin/rdebug-ide
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ options = OpenStruct.new(
'value_as_nested_element' => false,
'attach_mode' => false,
'cli_debug' => false,
'key_value_mode' => false
'key_value_mode' => false,
'server_mode' => false
)

opts = OptionParser.new do |opts|
Expand Down Expand Up @@ -84,6 +85,9 @@ EOB
opts.on("--key-value", "Key/Value presentation of hash items") do
options.key_value_mode = true
end
opts.on("--server-mode", "Tells that rdebug-ide is working in server mode") do
options.server_mode = true
end
opts.on("--ignore-port", "Generate another port") do
options.ignore_port = true
end
Expand Down Expand Up @@ -137,13 +141,7 @@ end

if options.dispatcher_port != -1
ENV['IDE_PROCESS_DISPATCHER'] = options.dispatcher_port.to_s
if RUBY_VERSION < "1.9"
lib_path = File.expand_path(File.dirname(__FILE__) + "/../lib/")
$: << lib_path unless $:.include? lib_path
require 'ruby-debug-ide/multiprocess'
else
require_relative '../lib/ruby-debug-ide/multiprocess'
end
Debugger.require_multiprocess
Debugger::MultiProcess.do_monkey

ENV['DEBUGGER_STORED_RUBYLIB'] = ENV['RUBYLIB']
Expand Down Expand Up @@ -171,8 +169,11 @@ Debugger.inspect_time_limit = options.inspect_time_limit
Debugger.catchpoint_deleted_event = options.catchpoint_deleted_event || options.rm_protocol_extensions
Debugger.value_as_nested_element = options.value_as_nested_element || options.rm_protocol_extensions
Debugger.key_value_mode = options.key_value_mode
Debugger.server_mode = options.server_mode

if options.attach_mode
Debugger.require_multiprocess
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we need to require it here?


if Debugger::FRONT_END == "debase"
Debugger.init_variables
end
Expand Down
13 changes: 12 additions & 1 deletion lib/ruby-debug-ide.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
module Debugger

class << self
def require_multiprocess
if RUBY_VERSION < "1.9"
lib_path = File.expand_path(File.dirname(__FILE__) + "/../lib/")
$: << lib_path unless $:.include? lib_path
require 'ruby-debug-ide/multiprocess'
else
require_relative '../lib/ruby-debug-ide/multiprocess'
end
end

def find_free_port(host)
server = TCPServer.open(host, 0)
port = server.addr[1]
Expand Down Expand Up @@ -58,6 +68,7 @@ def cleanup_backtrace(backtrace)
attr_reader :interface
# protocol extensions
attr_accessor :catchpoint_deleted_event, :value_as_nested_element
attr_accessor :server_mode


#
Expand Down Expand Up @@ -89,7 +100,7 @@ def prepare_debugger(options)

# wait for 'start' command
@mutex.synchronize do
@proceed.wait(@mutex)
@proceed.wait(@mutex) unless server_mode
end
end

Expand Down
4 changes: 3 additions & 1 deletion lib/ruby-debug-ide/commands/control.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,13 @@ def regexp
end

def execute
Debugger.require_multiprocess
Copy link
Collaborator

Choose a reason for hiding this comment

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

isn't it already required by this moment?

interface.command_queue << "finish" if Debugger.server_mode
Debugger.stop
Debugger.interface.close
Debugger::MultiProcess.undo_monkey
Debugger.control_thread = nil
Thread.current.exit #@control_thread is a current thread
Thread.current.exit unless Debugger.server_mode #@control_thread is a current thread
end

class << self
Expand Down
2 changes: 2 additions & 0 deletions lib/ruby-debug-ide/ide_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def process_commands
end
end
rescue ::Exception
# Workaround to Disconnect in Paused State
return @interface.command_queue << "finish" if $!.message === 'closed stream'
Copy link
Collaborator

Choose a reason for hiding this comment

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

it's better to return after logging the error and backtrace

@printer.print_debug "INTERNAL ERROR!!! #{$!}\n" rescue nil
@printer.print_error "INTERNAL ERROR!!! #{$!}\n" rescue nil
@printer.print_error $!.backtrace.map{|l| "\t#{l}"}.join("\n") rescue nil
Expand Down