Skip to content
Merged
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
Next Next commit
attach mode added
  • Loading branch information
dmitrii.kravchenko committed Aug 8, 2016
commit 3681a0592cb8894f8c89b99c7a11bc4ca0729374
28 changes: 20 additions & 8 deletions bin/rdebug-ide
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ options = OpenStruct.new(
'evaluation_timeout' => 10,
'rm_protocol_extensions' => false,
'catchpoint_deleted_event' => false,
'value_as_nested_element' => false
'value_as_nested_element' => false,
'attach_mode' => false
)

opts = OptionParser.new do |opts|
Expand Down Expand Up @@ -54,7 +55,9 @@ EOB
opts.on("-I", "--include PATH", String, "Add PATH to $LOAD_PATH") do |path|
$LOAD_PATH.unshift(path)
end

opts.on("--attach-mode", "Tells that rdebug-ide is working in attach mode") do
options.attach_mode = true
end
opts.on("--keep-frame-binding", "Keep frame bindings") {options.frame_bind = true}
opts.on("--disable-int-handler", "Disables interrupt signal handler") {options.int_handler = false}
opts.on("--rubymine-protocol-extensions", "Enable all RubyMine-specific incompatible protocol extensions") do
Expand Down Expand Up @@ -89,15 +92,17 @@ rescue StandardError => e
exit(1)
end

if ARGV.empty?
if ARGV.empty? && !options.attach_mode
puts opts
puts
puts "Must specify a script to run"
exit(1)
end
end

# save script name
Debugger::PROG_SCRIPT = ARGV.shift
unless options.attach_mode
# save script name
Debugger::PROG_SCRIPT = ARGV.shift
end

if options.dispatcher_port != -1
ENV['IDE_PROCESS_DISPATCHER'] = options.dispatcher_port.to_s
Expand All @@ -119,13 +124,20 @@ if options.int_handler
# install interruption handler
trap('INT') { Debugger.interrupt_last }
end

# set options
Debugger.keep_frame_binding = options.frame_bind
Debugger.tracing = options.tracing
Debugger.evaluation_timeout = options.evaluation_timeout
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.debug_program(options)
if options.attach_mode
Debugger::MultiProcess::pre_child(options)

if Debugger::FRONT_END == "debase"
Debugger.enable_trace_points
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't that happen automatically when you add a breakpoint?

Copy link
Contributor Author

@equivalence1 equivalence1 Aug 9, 2016

Choose a reason for hiding this comment

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

@denofevil Yes, It would. But without this line you can't click "Pause" before setting any breakpoints.

Copy link
Member

Choose a reason for hiding this comment

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

@equivalence1 that would mean that pause will not work without breakpoints in normal mode, but it does

end
else
Debugger.debug_program(options)
end
13 changes: 7 additions & 6 deletions lib/ruby-debug-ide.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
require 'thread'
if RUBY_VERSION < '2.0' || defined?(JRUBY_VERSION)
require 'ruby-debug-base'
Debugger::FRONT_END = "ruby-debug-base"
else
require 'debase'
Debugger::FRONT_END = "debase"
end

require 'ruby-debug-ide/version'
require 'ruby-debug-ide/xml_printer'
require 'ruby-debug-ide/ide_processor'
require 'ruby-debug-ide/event_processor'
require_relative 'ruby-debug-ide/version'
Copy link
Member

Choose a reason for hiding this comment

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

ruby-debug-ide is somewhat expected to work on 1.8, I believe that require_relative is not available in 1.8

Copy link
Contributor Author

@equivalence1 equivalence1 Aug 9, 2016

Choose a reason for hiding this comment

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

@denofevil Yeah, sorry. I forgot to change it after my tests.

require_relative 'ruby-debug-ide/xml_printer'
require_relative 'ruby-debug-ide/ide_processor'
require_relative 'ruby-debug-ide/event_processor'

module Debugger

Expand Down Expand Up @@ -110,7 +112,6 @@ def start_control(host, port, notify_dispatcher)
server = TCPServer.new(host, port)
print_greeting_msg(host, port)
notify_dispatcher(port) if notify_dispatcher

while (session = server.accept)
$stderr.puts "Connected from #{session.peeraddr[2]}" if Debugger.cli_debug
dispatcher = ENV['IDE_PROCESS_DISPATCHER']
Expand Down Expand Up @@ -160,8 +161,8 @@ def notify_dispatcher(port)
return unless ENV['IDE_PROCESS_DISPATCHER']
acceptor_host, acceptor_port = ENV['IDE_PROCESS_DISPATCHER'].split(":")
acceptor_host, acceptor_port = '127.0.0.1', acceptor_host unless acceptor_port

connected = false

3.times do |i|
begin
s = TCPSocket.open(acceptor_host, acceptor_port)
Expand Down
27 changes: 27 additions & 0 deletions lib/ruby-debug-ide/commands/control.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,31 @@ def help(cmd)
end
end
end


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

def regexp
/^\s*detach\s*$/
end

def execute
Debugger.stop
Debugger.control_thread = nil
Thread.current.exit #@control_thread is a current thread
end

class << self
def help_command
'detach'
end

def help(cmd)
%{
detach\ndetach debugger\nnote: this option is only for remote debugging (or local attach)
}
end
end
end
end
5 changes: 2 additions & 3 deletions lib/ruby-debug-ide/ide_processor.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'ruby-debug-ide/interface'
require 'ruby-debug-ide/command'
require_relative 'interface'
require_relative 'command'

module Debugger
class IdeCommandProcessor
Expand Down Expand Up @@ -77,7 +77,6 @@ def process_commands
ctrl_cmd_classes = Command.commands.select{|cmd| cmd.control}
state = ControlState.new(@interface)
ctrl_cmds = ctrl_cmd_classes.map{|cmd| cmd.new(state, @printer)}

while input = @interface.read_command
# escape % since print_debug might use printf
# sleep 0.3
Expand Down
8 changes: 3 additions & 5 deletions lib/ruby-debug-ide/multiprocess/pre_child.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
module Debugger
module MultiProcess
class << self
def pre_child

def pre_child(options = nil)
require 'socket'
require 'ostruct'

host = ENV['DEBUGGER_HOST']
port = find_free_port(host)

options = OpenStruct.new(
options ||= OpenStruct.new(
'frame_bind' => false,
'host' => host,
'load_mode' => false,
'port' => port,
'port' => find_free_port(host),
'stop' => false,
'tracing' => false,
'int_handler' => true,
Expand Down