Skip to content

Commit 92d12d9

Browse files
committed
Server Mode
1 parent 91ff6d7 commit 92d12d9

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

bin/rdebug-ide

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ options = OpenStruct.new(
2727
'catchpoint_deleted_event' => false,
2828
'value_as_nested_element' => false,
2929
'attach_mode' => false,
30-
'cli_debug' => false
30+
'server_mode' => false,
31+
'cli_debug' => false,
3132
)
3233

3334
opts = OptionParser.new do |opts|
@@ -80,6 +81,9 @@ EOB
8081
opts.on("--attach-mode", "Tells that rdebug-ide is working in attach mode") do
8182
options.attach_mode = true
8283
end
84+
opts.on("--server-mode", "Tells that rdebug-ide is working in server mode") do
85+
options.server_mode = true
86+
end
8387
opts.on("--ignore-port", "Generate another port") do
8488
options.ignore_port = true
8589
end
@@ -133,13 +137,7 @@ end
133137

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

145143
ENV['DEBUGGER_STORED_RUBYLIB'] = ENV['RUBYLIB']
@@ -166,8 +164,11 @@ Debugger.debugger_memory_limit = options.debugger_memory_limit
166164
Debugger.inspect_time_limit = options.inspect_time_limit
167165
Debugger.catchpoint_deleted_event = options.catchpoint_deleted_event || options.rm_protocol_extensions
168166
Debugger.value_as_nested_element = options.value_as_nested_element || options.rm_protocol_extensions
167+
Debugger.server_mode = options.server_mode
169168

170169
if options.attach_mode
170+
Debugger.require_multiprocess
171+
171172
if Debugger::FRONT_END == "debase"
172173
Debugger.init_variables
173174
end

lib/ruby-debug-ide.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818
module Debugger
1919

2020
class << self
21+
def require_multiprocess
22+
if RUBY_VERSION < "1.9"
23+
lib_path = File.expand_path(File.dirname(__FILE__) + "/../lib/")
24+
$: << lib_path unless $:.include? lib_path
25+
require 'ruby-debug-ide/multiprocess'
26+
else
27+
require_relative '../lib/ruby-debug-ide/multiprocess'
28+
end
29+
end
30+
2131
def find_free_port(host)
2232
server = TCPServer.open(host, 0)
2333
port = server.addr[1]
@@ -57,6 +67,7 @@ def cleanup_backtrace(backtrace)
5767
attr_reader :interface
5868
# protocol extensions
5969
attr_accessor :catchpoint_deleted_event, :value_as_nested_element
70+
attr_accessor :server_mode
6071

6172

6273
#
@@ -88,7 +99,7 @@ def prepare_debugger(options)
8899

89100
# wait for 'start' command
90101
@mutex.synchronize do
91-
@proceed.wait(@mutex)
102+
@proceed.wait(@mutex) unless server_mode
92103
end
93104
end
94105

lib/ruby-debug-ide/commands/control.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,13 @@ def regexp
136136
end
137137

138138
def execute
139+
Debugger.require_multiprocess
140+
interface.command_queue << "finish" if Debugger.server_mode
139141
Debugger.stop
140142
Debugger.interface.close
141143
Debugger::MultiProcess.undo_monkey
142144
Debugger.control_thread = nil
143-
Thread.current.exit #@control_thread is a current thread
145+
Thread.current.exit unless Debugger.server_mode #@control_thread is a current thread
144146
end
145147

146148
class << self

lib/ruby-debug-ide/ide_processor.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ def process_commands
9090
end
9191
end
9292
rescue ::Exception
93+
# Workaround to Disconnect in Paused State
94+
return @interface.command_queue << "finish" if $!.message === 'closed stream'
9395
@printer.print_debug "INTERNAL ERROR!!! #{$!}\n" rescue nil
9496
@printer.print_error "INTERNAL ERROR!!! #{$!}\n" rescue nil
9597
@printer.print_error $!.backtrace.map{|l| "\t#{l}"}.join("\n") rescue nil

0 commit comments

Comments
 (0)