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.



773
774
775
776
777
778
779
780
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 773

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.



771
772
773
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 771

def quit_confirm_request
  @quit_confirm_request
end

Instance Method Details

#is_alive?Boolean

Returns:

  • (Boolean)


801
802
803
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 801

def is_alive?
  @alive
end

#killObject



891
892
893
894
895
896
897
898
899
900
901
902
903
904
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 891

def kill
  begin
    if Arcadia.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



906
907
908
909
910
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 906

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

#set_alive(_value = false) ⇒ Object



805
806
807
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 805

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

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



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
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 809

def start_session(_debug_event, _host='localhost', _remote_port='8989')
  _filename = _debug_event.file
  if Arcadia.is_windows?
    #if RubyWhich.new.which("rdebug.bat") != []
    if Arcadia.which("rdebug.bat")
      rdebug_cmd = "rdebug.bat" 
    #elsif RubyWhich.new.which("rdebug.cmd") != []
    elsif Arcadia.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
  begin
    @alive = true
    if Arcadia.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)
        if _debug_event.persistent == false && _debug_event.file[-2..-1] == '~~'
           File.delete(_debug_event.file) if File.exist?(_debug_event.file)
        end

      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')

          if _debug_event.persistent == false && _debug_event.file[-2..-1] == '~~'
             File.delete(_debug_event.file) if File.exist?(_debug_event.file)
          end

          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



782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 782

def start_session_new(_filename, _host='localhost', _remote_port='8989')
  if Arcadia.is_windows?
    #if RubyWhich.new.which("rdebug.bat") != []
    if Arcadia.which("rdebug.bat")
      rdebug_cmd = "rdebug.bat" 
    #elsif RubyWhich.new.which("rdebug.cmd") != []
    elsif Arcadia.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