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
39 changes: 23 additions & 16 deletions bin/gdb_wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ options = OpenStruct.new(
opts = OptionParser.new do |opts|
# TODO need some banner
opts.banner = <<EOB
Some usefull banner.
Some useful banner.
EOB

opts.on("--pid PID", "pid of process you want to attach to for debugging") do |pid|
options.pid = pid
end

opts.on("--sdk-path SDK_PATH", "path to ruby interpreter") do |sdk_path|
options.sdk_path = sdk_path
opts.on("--ruby-path SDK_PATH", "path to ruby interpreter") do |ruby_path|
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

SDK_PATH left in hint

options.ruby_path = ruby_path
end

opts.on("--uid UID", "uid which this process should set after executing gdb attach") do |uid|
Expand All @@ -40,8 +40,8 @@ unless options.pid
exit 1
end

unless options.sdk_path
$stderr.puts "You must specify SDK_PATH of ruby interpreter"
unless options.ruby_path
$stderr.puts "You must specify RUBY_PATH of ruby interpreter"
Copy link
Copy Markdown
Member

@denofevil denofevil Aug 20, 2016

Choose a reason for hiding this comment

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

How about "You should specify path to the ruby interpreter"?

exit 1
end

Expand All @@ -61,27 +61,34 @@ gems_to_include = '["' + options.gems_to_include * '", "' + '"]'

commands_list = []

def commands_list.add_command(command)
self << "-ex \"#{command}\""
def commands_list.<<(command)
self.push "-ex \"#{command}\""
end

path_to_debugger_loader = File.expand_path(File.dirname(__FILE__)) + "/../lib/ruby-debug-ide/attach/debugger_loader"
path_to_debugger_loader = File.expand_path(File.dirname(__FILE__)) + '/../lib/ruby-debug-ide/attach/debugger_loader'

# rb_finish: wait while execution comes to the next line (this is essential!)
commands_list.add_command("call rb_eval_string_protect(\\\"set_trace_func lambda{|event, file, line, id, binding, classname| if /line/ =~ event; sleep 0; set_trace_func(nil); end}\\\", (int *)0)")
commands_list.add_command("tbreak rb_f_sleep")
commands_list.add_command("cont")
# rb_finish: wait while execution comes to the next line.
# This is essential because we could interrupt process in a middle
# of some evaluations (e.g., system call)
commands_list << "call rb_eval_string_protect(\\\"set_trace_func lambda{|event, file, line, id, binding, classname| if /line/ =~ event; sleep 0; set_trace_func(nil); end}\\\", (int *)0)"
commands_list << "tbreak rb_f_sleep"
commands_list << "cont"

# evalr: loading debugger into the process
evalr = "call rb_eval_string_protect(%s, (int *)0)"
commands_list.add_command("#{evalr}" % ["(\\\"require '#{path_to_debugger_loader}'; load_debugger(#{gems_to_include.gsub("\"", "'")}, #{argv.gsub("\"", "'")})\\\")"])
commands_list << ("#{evalr}" % ["(\\\"require '#{path_to_debugger_loader}'; load_debugger(#{gems_to_include.gsub("\"", "'")}, #{argv.gsub("\"", "'")})\\\")"])

# q: exit gdb and continue process execution with debugger
commands_list.add_command("q")
commands_list << "q"

cmd = "gdb #{options.sdk_path} #{options.pid} -nh -nx -batch #{commands_list.join(" ")}"
cmd = "gdb #{options.ruby_path} #{options.pid} -nh -nx -batch #{commands_list.join(" ")}"

$stderr.puts "Fast Debugger "
options.gems_to_include.each do |gem_path|
$LOAD_PATH.unshift(gem_path) unless $LOAD_PATH.include?(gem_path)
end

require 'ruby-debug-ide/greeter'
Debugger::print_greeting_msg(nil, nil)
$stderr.puts "Running command #{cmd}"

`#{cmd}` or raise "GDB failed. Aborting."
Expand Down
11 changes: 8 additions & 3 deletions bin/rdebug-ide
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ if ARGV.empty? && !options.attach_mode
exit(1)
end

unless options.attach_mode
# save script name
# save script name
if !options.attach_mode
Debugger::PROG_SCRIPT = ARGV.shift
else
Debugger::PROG_SCRIPT = $0
end

if options.dispatcher_port != -1
Expand Down Expand Up @@ -135,8 +137,11 @@ Debugger.value_as_nested_element = options.value_as_nested_element || options.rm
if options.attach_mode
Debugger::MultiProcess::pre_child(options)

# This will trigger `setup_tracepoints` and `prepare_context` (which is private in debase)
# without any actual excessive code execution.
if Debugger::FRONT_END == "debase"
Debugger.enable_trace_points
EMPTY_TEMPLATE = File.expand_path(File.dirname(__FILE__)) + '/../lib/ruby-debug-ide/attach/empty_file.rb'
Debugger.debug_load(EMPTY_TEMPLATE)
end
else
Debugger.debug_program(options)
Expand Down
25 changes: 4 additions & 21 deletions lib/ruby-debug-ide.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
Debugger::FRONT_END = "debase"
end

require_relative 'ruby-debug-ide/version'
require_relative 'ruby-debug-ide/xml_printer'
require_relative 'ruby-debug-ide/ide_processor'
require_relative 'ruby-debug-ide/event_processor'
require 'ruby-debug-ide/greeter'
require 'ruby-debug-ide/xml_printer'
require 'ruby-debug-ide/ide_processor'
require 'ruby-debug-ide/event_processor'

module Debugger

Expand Down Expand Up @@ -137,23 +137,6 @@ def start_control(host, port, notify_dispatcher)
end
end

def print_greeting_msg(host, port)
base_gem_name = if defined?(JRUBY_VERSION) || RUBY_VERSION < '1.9.0'
'ruby-debug-base'
elsif RUBY_VERSION < '2.0.0'
'ruby-debug-base19x'
else
'debase'
end

file_filtering_support = if Command.file_filter_supported?
'supported'
else
'not supported'
end
$stderr.printf "Fast Debugger (ruby-debug-ide #{IDE_VERSION}, #{base_gem_name} #{VERSION}, file filtering is #{file_filtering_support}) listens on #{host}:#{port}\n"
end

private


Expand Down
6 changes: 3 additions & 3 deletions lib/ruby-debug-ide/attach/debugger_loader.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
def load_debugger(gems_to_include, new_argv)
path_to_rdebug = File.expand_path(File.dirname(__FILE__)) + "/../../../bin/rdebug-ide"
path_to_rdebug = File.expand_path(File.dirname(__FILE__)) + '/../../../bin/rdebug-ide'

old_argv = ARGV.clone
ARGV.reject {|x| true}
ARGV.clear
new_argv.each do |x|
ARGV << x
end
Expand All @@ -13,7 +13,7 @@ def load_debugger(gems_to_include, new_argv)

load path_to_rdebug

ARGV.reject {|x| true}
ARGV.clear
old_argv.each do |x|
ARGV << x
end
Expand Down
Empty file.
40 changes: 40 additions & 0 deletions lib/ruby-debug-ide/greeter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
if RUBY_VERSION < '2.0' || defined?(JRUBY_VERSION)
require 'ruby-debug-base'
else
require 'debase'
end

require 'ruby-debug-ide/version'
require 'ruby-debug-ide/ide_processor'

module Debugger

class << self
def print_greeting_msg(host, port)
base_gem_name = if defined?(JRUBY_VERSION) || RUBY_VERSION < '1.9.0'
'ruby-debug-base'
elsif RUBY_VERSION < '2.0.0'
'ruby-debug-base19x'
else
'debase'
end

file_filtering_support = if Command.file_filter_supported?
'supported'
else
'not supported'
end

if host && port
listens_on = " listens on #{host}:#{port}\n"
else
listens_on = "\n"
end

msg = "Fast Debugger (ruby-debug-ide #{IDE_VERSION}, #{base_gem_name} #{VERSION}, file filtering is #{file_filtering_support})" + listens_on

$stderr.printf msg
end
end

end
4 changes: 2 additions & 2 deletions lib/ruby-debug-ide/ide_processor.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative 'interface'
require_relative 'command'
require 'ruby-debug-ide/interface'
require 'ruby-debug-ide/command'

module Debugger
class IdeCommandProcessor
Expand Down
2 changes: 1 addition & 1 deletion ruby-debug-ide.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ EOF
spec.platform = Gem::Platform::RUBY
spec.require_path = "lib"
spec.bindir = "bin"
spec.executables = ["rdebug-ide"]
spec.executables = ["rdebug-ide", "gdb_wrapper"]
spec.files = FILES

spec.extensions << "ext/mkrf_conf.rb" unless ENV['NO_EXT']
Expand Down