Skip to content

Commit 3681a05

Browse files
author
dmitrii.kravchenko
committed
attach mode added
1 parent ce3dbe0 commit 3681a05

File tree

5 files changed

+59
-22
lines changed

5 files changed

+59
-22
lines changed

bin/rdebug-ide

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ options = OpenStruct.new(
2222
'evaluation_timeout' => 10,
2323
'rm_protocol_extensions' => false,
2424
'catchpoint_deleted_event' => false,
25-
'value_as_nested_element' => false
25+
'value_as_nested_element' => false,
26+
'attach_mode' => false
2627
)
2728

2829
opts = OptionParser.new do |opts|
@@ -54,7 +55,9 @@ EOB
5455
opts.on("-I", "--include PATH", String, "Add PATH to $LOAD_PATH") do |path|
5556
$LOAD_PATH.unshift(path)
5657
end
57-
58+
opts.on("--attach-mode", "Tells that rdebug-ide is working in attach mode") do
59+
options.attach_mode = true
60+
end
5861
opts.on("--keep-frame-binding", "Keep frame bindings") {options.frame_bind = true}
5962
opts.on("--disable-int-handler", "Disables interrupt signal handler") {options.int_handler = false}
6063
opts.on("--rubymine-protocol-extensions", "Enable all RubyMine-specific incompatible protocol extensions") do
@@ -89,15 +92,17 @@ rescue StandardError => e
8992
exit(1)
9093
end
9194

92-
if ARGV.empty?
95+
if ARGV.empty? && !options.attach_mode
9396
puts opts
9497
puts
9598
puts "Must specify a script to run"
9699
exit(1)
97-
end
100+
end
98101

99-
# save script name
100-
Debugger::PROG_SCRIPT = ARGV.shift
102+
unless options.attach_mode
103+
# save script name
104+
Debugger::PROG_SCRIPT = ARGV.shift
105+
end
101106

102107
if options.dispatcher_port != -1
103108
ENV['IDE_PROCESS_DISPATCHER'] = options.dispatcher_port.to_s
@@ -119,13 +124,20 @@ if options.int_handler
119124
# install interruption handler
120125
trap('INT') { Debugger.interrupt_last }
121126
end
122-
127+
123128
# set options
124129
Debugger.keep_frame_binding = options.frame_bind
125130
Debugger.tracing = options.tracing
126131
Debugger.evaluation_timeout = options.evaluation_timeout
127132
Debugger.catchpoint_deleted_event = options.catchpoint_deleted_event || options.rm_protocol_extensions
128133
Debugger.value_as_nested_element = options.value_as_nested_element || options.rm_protocol_extensions
129134

130-
Debugger.debug_program(options)
135+
if options.attach_mode
136+
Debugger::MultiProcess::pre_child(options)
131137

138+
if Debugger::FRONT_END == "debase"
139+
Debugger.enable_trace_points
140+
end
141+
else
142+
Debugger.debug_program(options)
143+
end

lib/ruby-debug-ide.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
require 'thread'
55
if RUBY_VERSION < '2.0' || defined?(JRUBY_VERSION)
66
require 'ruby-debug-base'
7+
Debugger::FRONT_END = "ruby-debug-base"
78
else
89
require 'debase'
10+
Debugger::FRONT_END = "debase"
911
end
1012

11-
require 'ruby-debug-ide/version'
12-
require 'ruby-debug-ide/xml_printer'
13-
require 'ruby-debug-ide/ide_processor'
14-
require 'ruby-debug-ide/event_processor'
13+
require_relative 'ruby-debug-ide/version'
14+
require_relative 'ruby-debug-ide/xml_printer'
15+
require_relative 'ruby-debug-ide/ide_processor'
16+
require_relative 'ruby-debug-ide/event_processor'
1517

1618
module Debugger
1719

@@ -110,7 +112,6 @@ def start_control(host, port, notify_dispatcher)
110112
server = TCPServer.new(host, port)
111113
print_greeting_msg(host, port)
112114
notify_dispatcher(port) if notify_dispatcher
113-
114115
while (session = server.accept)
115116
$stderr.puts "Connected from #{session.peeraddr[2]}" if Debugger.cli_debug
116117
dispatcher = ENV['IDE_PROCESS_DISPATCHER']
@@ -160,8 +161,8 @@ def notify_dispatcher(port)
160161
return unless ENV['IDE_PROCESS_DISPATCHER']
161162
acceptor_host, acceptor_port = ENV['IDE_PROCESS_DISPATCHER'].split(":")
162163
acceptor_host, acceptor_port = '127.0.0.1', acceptor_host unless acceptor_port
163-
164164
connected = false
165+
165166
3.times do |i|
166167
begin
167168
s = TCPSocket.open(acceptor_host, acceptor_port)

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,31 @@ def help(cmd)
126126
end
127127
end
128128
end
129+
130+
131+
class DetachCommand < Command # :nodoc:
132+
self.control = true
133+
134+
def regexp
135+
/^\s*detach\s*$/
136+
end
137+
138+
def execute
139+
Debugger.stop
140+
Debugger.control_thread = nil
141+
Thread.current.exit #@control_thread is a current thread
142+
end
143+
144+
class << self
145+
def help_command
146+
'detach'
147+
end
148+
149+
def help(cmd)
150+
%{
151+
detach\ndetach debugger\nnote: this option is only for remote debugging (or local attach)
152+
}
153+
end
154+
end
155+
end
129156
end

lib/ruby-debug-ide/ide_processor.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
require 'ruby-debug-ide/interface'
2-
require 'ruby-debug-ide/command'
1+
require_relative 'interface'
2+
require_relative 'command'
33

44
module Debugger
55
class IdeCommandProcessor
@@ -77,7 +77,6 @@ def process_commands
7777
ctrl_cmd_classes = Command.commands.select{|cmd| cmd.control}
7878
state = ControlState.new(@interface)
7979
ctrl_cmds = ctrl_cmd_classes.map{|cmd| cmd.new(state, @printer)}
80-
8180
while input = @interface.read_command
8281
# escape % since print_debug might use printf
8382
# sleep 0.3

lib/ruby-debug-ide/multiprocess/pre_child.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
module Debugger
22
module MultiProcess
33
class << self
4-
def pre_child
5-
4+
def pre_child(options = nil)
65
require 'socket'
76
require 'ostruct'
87

98
host = ENV['DEBUGGER_HOST']
10-
port = find_free_port(host)
119

12-
options = OpenStruct.new(
10+
options ||= OpenStruct.new(
1311
'frame_bind' => false,
1412
'host' => host,
1513
'load_mode' => false,
16-
'port' => port,
14+
'port' => find_free_port(host),
1715
'stop' => false,
1816
'tracing' => false,
1917
'int_handler' => true,

0 commit comments

Comments
 (0)