@@ -13,15 +13,15 @@ options = OpenStruct.new(
1313opts = OptionParser . new do |opts |
1414 # TODO need some banner
1515 opts . banner = <<EOB
16- Some usefull banner.
16+ Some useful banner.
1717EOB
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
4141end
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
4646end
4747
@@ -61,27 +61,34 @@ gems_to_include = '["' + options.gems_to_include * '", "' + '"]'
6161
6262commands_list = [ ]
6363
64- def commands_list . add_command ( command )
65- self << "-ex \" #{ command } \" "
64+ def commands_list . << ( command )
65+ self . push "-ex \" #{ command } \" "
6666end
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
7678evalr = "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."
0 commit comments