Skip to content

Commit fa128e1

Browse files
author
dmitrii.kravchenko
committed
relative imports replaced with normal ones. print_greeting_msg now in separate file. enable_trace_points call (wrong) replaced with empty_file loading (ugly but should always work). Including gems into $LOAD_PATH.
1 parent 768323f commit fa128e1

File tree

8 files changed

+81
-46
lines changed

8 files changed

+81
-46
lines changed

bin/gdb_wrapper

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ options = OpenStruct.new(
1313
opts = OptionParser.new do |opts|
1414
# TODO need some banner
1515
opts.banner = <<EOB
16-
Some usefull banner.
16+
Some useful banner.
1717
EOB
1818

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

23-
opts.on("--sdk-path SDK_PATH", "path to ruby interpreter") do |sdk_path|
24-
options.sdk_path = sdk_path
23+
opts.on("--ruby-path SDK_PATH", "path to ruby interpreter") do |ruby_path|
24+
options.ruby_path = ruby_path
2525
end
2626

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

43-
unless options.sdk_path
44-
$stderr.puts "You must specify SDK_PATH of ruby interpreter"
43+
unless options.ruby_path
44+
$stderr.puts "You must specify RUBY_PATH of ruby interpreter"
4545
exit 1
4646
end
4747

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

6262
commands_list = []
6363

64-
def commands_list.add_command(command)
65-
self << "-ex \"#{command}\""
64+
def commands_list.<<(command)
65+
self.push "-ex \"#{command}\""
6666
end
6767

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

70-
# rb_finish: wait while execution comes to the next line (this is essential!)
71-
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)")
72-
commands_list.add_command("tbreak rb_f_sleep")
73-
commands_list.add_command("cont")
70+
# rb_finish: wait while execution comes to the next line.
71+
# This is essential because we could interrupt process in a middle
72+
# of some evaluations (e.g., system call)
73+
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)"
74+
commands_list << "tbreak rb_f_sleep"
75+
commands_list << "cont"
7476

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

7981
# q: exit gdb and continue process execution with debugger
80-
commands_list.add_command("q")
82+
commands_list << "q"
8183

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

84-
$stderr.puts "Fast Debugger "
86+
options.gems_to_include.each do |gem_path|
87+
$LOAD_PATH.unshift(gem_path) unless $LOAD_PATH.include?(gem_path)
88+
end
89+
90+
require 'ruby-debug-ide/greeter'
91+
Debugger::print_greeting_msg(nil, nil)
8592
$stderr.puts "Running command #{cmd}"
8693

8794
`#{cmd}` or raise "GDB failed. Aborting."

bin/rdebug-ide

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,11 @@ if ARGV.empty? && !options.attach_mode
9999
exit(1)
100100
end
101101

102-
unless options.attach_mode
103-
# save script name
102+
# save script name
103+
if !options.attach_mode
104104
Debugger::PROG_SCRIPT = ARGV.shift
105+
else
106+
Debugger::PROG_SCRIPT = $0
105107
end
106108

107109
if options.dispatcher_port != -1
@@ -135,8 +137,11 @@ Debugger.value_as_nested_element = options.value_as_nested_element || options.rm
135137
if options.attach_mode
136138
Debugger::MultiProcess::pre_child(options)
137139

140+
# This will trigger `setup_tracepoints` and `prepare_context` (which is private in debase)
141+
# without any actual excessive code execution.
138142
if Debugger::FRONT_END == "debase"
139-
Debugger.enable_trace_points
143+
EMPTY_TEMPLATE = File.expand_path(File.dirname(__FILE__)) + '/../lib/ruby-debug-ide/attach/empty_file.rb'
144+
Debugger.debug_load(EMPTY_TEMPLATE)
140145
end
141146
else
142147
Debugger.debug_program(options)

lib/ruby-debug-ide.rb

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
Debugger::FRONT_END = "debase"
1111
end
1212

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'
13+
require 'ruby-debug-ide/greeter'
14+
require 'ruby-debug-ide/xml_printer'
15+
require 'ruby-debug-ide/ide_processor'
16+
require 'ruby-debug-ide/event_processor'
1717

1818
module Debugger
1919

@@ -137,23 +137,6 @@ def start_control(host, port, notify_dispatcher)
137137
end
138138
end
139139

140-
def print_greeting_msg(host, port)
141-
base_gem_name = if defined?(JRUBY_VERSION) || RUBY_VERSION < '1.9.0'
142-
'ruby-debug-base'
143-
elsif RUBY_VERSION < '2.0.0'
144-
'ruby-debug-base19x'
145-
else
146-
'debase'
147-
end
148-
149-
file_filtering_support = if Command.file_filter_supported?
150-
'supported'
151-
else
152-
'not supported'
153-
end
154-
$stderr.printf "Fast Debugger (ruby-debug-ide #{IDE_VERSION}, #{base_gem_name} #{VERSION}, file filtering is #{file_filtering_support}) listens on #{host}:#{port}\n"
155-
end
156-
157140
private
158141

159142

lib/ruby-debug-ide/attach/debugger_loader.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
def load_debugger(gems_to_include, new_argv)
2-
path_to_rdebug = File.expand_path(File.dirname(__FILE__)) + "/../../../bin/rdebug-ide"
2+
path_to_rdebug = File.expand_path(File.dirname(__FILE__)) + '/../../../bin/rdebug-ide'
33

44
old_argv = ARGV.clone
5-
ARGV.reject {|x| true}
5+
ARGV.clear
66
new_argv.each do |x|
77
ARGV << x
88
end
@@ -13,7 +13,7 @@ def load_debugger(gems_to_include, new_argv)
1313

1414
load path_to_rdebug
1515

16-
ARGV.reject {|x| true}
16+
ARGV.clear
1717
old_argv.each do |x|
1818
ARGV << x
1919
end

lib/ruby-debug-ide/attach/empty_file.rb

Whitespace-only changes.

lib/ruby-debug-ide/greeter.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
if RUBY_VERSION < '2.0' || defined?(JRUBY_VERSION)
2+
require 'ruby-debug-base'
3+
else
4+
require 'debase'
5+
end
6+
7+
require 'ruby-debug-ide/version'
8+
require 'ruby-debug-ide/ide_processor'
9+
10+
module Debugger
11+
12+
class << self
13+
def print_greeting_msg(host, port)
14+
base_gem_name = if defined?(JRUBY_VERSION) || RUBY_VERSION < '1.9.0'
15+
'ruby-debug-base'
16+
elsif RUBY_VERSION < '2.0.0'
17+
'ruby-debug-base19x'
18+
else
19+
'debase'
20+
end
21+
22+
file_filtering_support = if Command.file_filter_supported?
23+
'supported'
24+
else
25+
'not supported'
26+
end
27+
28+
if host && port
29+
listens_on = " listens on #{host}:#{port}\n"
30+
else
31+
listens_on = "\n"
32+
end
33+
34+
msg = "Fast Debugger (ruby-debug-ide #{IDE_VERSION}, #{base_gem_name} #{VERSION}, file filtering is #{file_filtering_support})" + listens_on
35+
36+
$stderr.printf msg
37+
end
38+
end
39+
40+
end

lib/ruby-debug-ide/ide_processor.rb

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

44
module Debugger
55
class IdeCommandProcessor

ruby-debug-ide.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ EOF
3636
spec.platform = Gem::Platform::RUBY
3737
spec.require_path = "lib"
3838
spec.bindir = "bin"
39-
spec.executables = ["rdebug-ide"]
39+
spec.executables = ["rdebug-ide", "gdb_wrapper"]
4040
spec.files = FILES
4141

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

0 commit comments

Comments
 (0)