Skip to content

Commit

Permalink
Server Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dlanileonardo committed Apr 24, 2018
1 parent 91ff6d7 commit 5975142
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
17 changes: 9 additions & 8 deletions bin/rdebug-ide
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ options = OpenStruct.new(
'catchpoint_deleted_event' => false,
'value_as_nested_element' => false,
'attach_mode' => false,
'cli_debug' => false
'server_mode' => false,
'cli_debug' => false,
)

opts = OptionParser.new do |opts|
Expand Down Expand Up @@ -80,6 +81,9 @@ EOB
opts.on("--attach-mode", "Tells that rdebug-ide is working in attach mode") do
options.attach_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 @@ -133,13 +137,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 All @@ -166,8 +164,11 @@ Debugger.debugger_memory_limit = options.debugger_memory_limit
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.server_mode = options.server_mode

if options.attach_mode
Debugger.require_multiprocess

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 @@ -57,6 +67,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 @@ -88,7 +99,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
22 changes: 12 additions & 10 deletions lib/ruby-debug-ide/commands/control.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ def help_command

def help(cmd)
%{
q[uit]\texit from debugger,
q[uit]\texit from debugger,
exit\talias to quit
}
end
end
end

class RestartCommand < Command # :nodoc:
self.control = true

Expand All @@ -39,7 +39,7 @@ def regexp
$
/x
end

def execute
if not defined? Debugger::RDEBUG_SCRIPT or not defined? Debugger::ARGV
print "We are not in a context we can restart from.\n"
Expand All @@ -64,7 +64,7 @@ def help_command

def help(cmd)
%{
restart|R [args]
restart|R [args]
Restart the program. This is is a re-exec - all debugger state
is lost. If command arguments are passed those are used.
}
Expand All @@ -78,7 +78,7 @@ class StartCommand < Command # :nodoc:
def regexp
/^\s*(start)(\s+ \S+ .*)?$/x
end

def execute
@printer.print_debug("Starting: running program script")
Debugger.run_prog_script #Debugger.prog_script_running?
Expand All @@ -102,23 +102,23 @@ class InterruptCommand < Command # :nodoc:
self.event = false
self.control = true
self.need_context = true

def regexp
/^\s*i(?:nterrupt)?\s*$/
end

def execute
unless Debugger.interrupt_last
context = Debugger.thread_context(Thread.main)
context.interrupt
end
end

class << self
def help_command
'interrupt'
end

def help(cmd)
%{
i[nterrupt]\tinterrupt the program
Expand All @@ -136,11 +136,13 @@ def regexp
end

def execute
Debugger.require_multiprocess
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'
@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

0 comments on commit 5975142

Please sign in to comment.