Class: RubyDebugServer

Inherits:
Object
  • Object
show all
Includes:
Observable
Defined in:
ext/ae-ruby-debug/ae-ruby-debug.rb

Constant Summary collapse

RDS_QUIET =
'RDS_QUIET'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_caller, _arcadia = nil) ⇒ RubyDebugServer

Returns a new instance of RubyDebugServer.



765
766
767
768
769
770
771
772
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 765

def initialize(_caller, _arcadia=nil)
  if _caller.respond_to? :rdebug_server_update
    ObserverCallback.new(self,_caller,:rdebug_server_update)
  end
  @arcadia = _arcadia
  @quit_confirm_request = false
  @alive = false
end

Instance Attribute Details

#quit_confirm_requestObject

Returns the value of attribute quit_confirm_request.



763
764
765
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 763

def quit_confirm_request
  @quit_confirm_request
end

Instance Method Details

#is_alive?Boolean

Returns:

  • (Boolean)


791
792
793
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 791

def is_alive?
  @alive
end

#is_windows?Boolean

Returns:

  • (Boolean)


883
884
885
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 883

def is_windows?
  !(RUBY_PLATFORM =~ /(win|w)32$/).nil?
end

#killObject



868
869
870
871
872
873
874
875
876
877
878
879
880
881
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 868

def kill
  begin
    if is_windows?
      @tid.join(2)
      @tid.kill!
    else
      Process.kill('QUIT',@pid)
    end
    notify(RDS_QUIET)
  rescue Exception => e
    Arcadia.console(self, 'msg'=>"Error on kill : #{e.class}:#{e.message}", 'level'=>'debug')
    #Arcadia.new_debug_msg(self,"Error on start_server : #{e.class}:#{e.message}")    
  end
end

#notify(_state) ⇒ Object



887
888
889
890
891
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 887

def notify(_state)
   #p "----- notify ----- #{_state}"
   changed
   notify_observers(_state)
end

#set_alive(_value = false) ⇒ Object



795
796
797
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 795

def set_alive(_value=false)
  @alive = _value
end

#start_session(_filename, _host = 'localhost', _remote_port = '8989') ⇒ Object



799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 799

def start_session(_filename, _host='localhost', _remote_port='8989')
  if is_windows?
    if RubyWhich.new.which("rdebug.bat") != []
      rdebug_cmd = "rdebug.bat" 
    elsif RubyWhich.new.which("rdebug.cmd") != []
      rdebug_cmd = "rdebug.cmd"
    else
      rdebug_cmd = "rdebug"
    end
    commandLine = "#{rdebug_cmd} --port #{_remote_port} -sw #{_filename}"
  else
    commandLine = "rdebug --host #{_host} --port #{_remote_port} -sw #{_filename}"
  end
  begin
    @alive = true
    if is_windows?
      @tid = Thread.new do
        if Kernel.system(commandLine)
            Kernel.system('y')
        else
          if @quit_confirm_request
            Arcadia.console(self, 'msg'=>"#{$?.inspect}")
            #Arcadia.new_msg(self,"#{$?.inspect}")    
          else
            _event = Arcadia.process_event(RunCmdEvent.new(self, {'file'=>_filename}))
            Arcadia.console(self, 'msg'=>"#{_event.results[0].output}", 'level'=>'debug')
            #Arcadia.new_debug_msg(self,"#{_event.results[0].output}")    
          end
        end
        set_alive(false)
        notify(RDS_QUIET)
      end
    else
      @pid = Process.fork do
#          pid = Process.pid
#          abort_action = proc{
#            ArcadiaUtils.unix_child_pids(pid).each {|pid|
#              Process.kill(9,pid.to_i)
#            }
#            Process.kill(9,pid.to_i)
#          }
#            
#          alive_check = proc{
#            num = `ps -p #{pid}|wc -l`
#            num.to_i > 1
#          }
#          Arcadia.process_event(SubProcessEvent.new(self,'pid'=>pid, 'name'=>"debugging :#{_filename}",'abort_action'=>abort_action, 'alive_check'=>alive_check))
        if Kernel.system(commandLine)
          set_alive(false)
          #p "alive=#{is_alive?}"
          notify(RDS_QUIET)
          Kernel.system('y')
          Kernel.exit!
        else
          Kernel.exit!
          Arcadia.console(self, 'msg'=>"#{$?.inspect}", 'level'=>'debug')
          #Arcadia.new_debug_msg(self,"#{$?.inspect}")    
        end
        #p "@alive=#{@alive}"
        #notify(RDS_QUIET)
        #Process.wait
      end
    end
  rescue Exception => e
    Arcadia.console(self, 'msg'=>"Error on start_server : #{e.class}:#{e.message}", 'level'=>'debug')
    #Arcadia.new_debug_msg(self,"Error on start_server : #{e.class}:#{e.message}")    
  end
end

#start_session_new(_filename, _host = 'localhost', _remote_port = '8989') ⇒ Object



774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 774

def start_session_new(_filename, _host='localhost', _remote_port='8989')
  if is_windows?
    if RubyWhich.new.which("rdebug.bat") != []
      rdebug_cmd = "rdebug.bat" 
    elsif RubyWhich.new.which("rdebug.cmd") != []
      rdebug_cmd = "rdebug.cmd"
    else
      rdebug_cmd = "rdebug"
    end
    commandLine = "#{rdebug_cmd} --host #{_host} --port #{_remote_port} -sw #{_filename}"
  else
     commandLine = "rdebug --host #{_host} --port #{_remote_port} -sw #{_filename}"
  end
  #Arcadia.process_event(SystemExecEvent.new(self, 'command'=>commandLine))
  Arcadia.process_event(RunCmdEvent.new(self, 'cmd'=>commandLine, 'file'=>_filename))
end