@@ -6,7 +6,7 @@ require 'ostruct'
66$stdout. sync = true
77$stderr. sync = true
88
9- @ options = OpenStruct . new (
9+ $ options = OpenStruct . new (
1010 'pid' => nil ,
1111 'sdk_path' => nil ,
1212 'uid' => nil ,
@@ -20,39 +20,39 @@ Some useful banner.
2020EOB
2121
2222 opts . on ( '--pid PID' , 'pid of process you want to attach to for debugging' ) do |pid |
23- @ options. pid = pid
23+ $ options. pid = pid
2424 end
2525
2626 opts . on ( '--ruby-path RUBY_PATH' , 'path to ruby interpreter' ) do |ruby_path |
27- @ options. ruby_path = ruby_path
27+ $ options. ruby_path = ruby_path
2828 end
2929
3030 opts . on ( '--uid UID' , 'uid which this process should set after executing gdb attach' ) do |uid |
31- @ options. uid = uid
31+ $ options. uid = uid
3232 end
3333
3434 opts . on ( '--include-gem GEM_LIB_PATH' , 'lib of gem to include' ) do |gem_lib_path |
35- @ options. gems_to_include << gem_lib_path
35+ $ options. gems_to_include << gem_lib_path
3636 end
3737end
3838
3939opts . parse! ARGV
4040
41- unless @ options. pid
41+ unless $ options. pid
4242 $stderr. puts 'You should specify PID of process you want to attach to'
4343 exit 1
4444end
4545
46- unless @ options. ruby_path
46+ unless $ options. ruby_path
4747 $stderr. puts 'You should specify path to the ruby interpreter'
4848 exit 1
4949end
5050
5151$argv = '["' + ARGV * '", "' + '"]'
52- $gems_to_include = '["' + @ options. gems_to_include * '", "' + '"]'
52+ $gems_to_include = '["' + $ options. gems_to_include * '", "' + '"]'
5353$path_to_debugger_loader = File . expand_path ( File . dirname ( __FILE__ ) ) + '/../lib/ruby-debug-ide/attach/debugger_loader'
5454
55- @ options. gems_to_include . each do |gem_path |
55+ $ options. gems_to_include . each do |gem_path |
5656 $LOAD_PATH. unshift ( gem_path ) unless $LOAD_PATH. include? ( gem_path )
5757end
5858
@@ -72,6 +72,11 @@ class NativeDebugger
7272 @tbreak = '__func_to_set_breakpoint_at'
7373 @main_thread = nil
7474 @process_threads = nil
75+ debase_path = $options. gems_to_include . select { |gem_path | gem_path =~ /debase/ }
76+ if debase_path . size == 0
77+ raise 'No debase gem found.'
78+ end
79+ @path_to_attach = debase_path [ 0 ] + '/attach.so'
7580
7681 launch_string = "#{ self } #{ executable } #{ options } "
7782 @pipe = IO . popen ( launch_string , 'r+' )
@@ -195,7 +200,7 @@ class LLDB < NativeDebugger
195200
196201 def call_start_attach
197202 super ( )
198- execute "expr (void *) dlopen(\" /home/equi/Job/JetBrains/Internship_2016/ruby-debug-ide/ext/libAttach.so \" , 2)"
203+ execute "expr (void *) dlopen(\" #{ @path_to_attach } \" , 2)"
199204 execute 'call start_attach()'
200205 set_tbreak ( @tbreak )
201206 end
@@ -245,7 +250,7 @@ class GDB < NativeDebugger
245250
246251 def call_start_attach
247252 super ( )
248- execute "call dlopen(\" /home/equi/Job/JetBrains/Internship_2016/ruby-debug-ide/ext/libAttach.so \" , 2)"
253+ execute "call dlopen(\" #{ @path_to_attach } \" , 2)"
249254 execute 'call start_attach()'
250255 set_tbreak ( @tbreak )
251256 end
316321
317322def choose_debugger
318323 if command_exists ( 'gdb' )
319- debugger = GDB . new ( @ options. ruby_path , @ options. pid , '-nh -nx' )
324+ debugger = GDB . new ( $ options. ruby_path , $ options. pid , '-nh -nx' )
320325 elsif command_exists ( 'lldb' )
321- debugger = LLDB . new ( @ options. ruby_path , @ options. pid , '--no-lldbinit' )
326+ debugger = LLDB . new ( $ options. ruby_path , $ options. pid , '--no-lldbinit' )
322327 else
323328 raise 'Neither gdb nor lldb was found. Aborting.'
324329 end
@@ -340,8 +345,8 @@ debugger = choose_debugger
340345debugger . attach_to_process
341346debugger . set_flags
342347
343- if @ options. uid
344- Process ::Sys . setuid ( @ options. uid . to_i )
348+ if $ options. uid
349+ Process ::Sys . setuid ( $ options. uid . to_i )
345350end
346351
347352if debugger . check_already_under_debug
0 commit comments