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.



761
762
763
764
765
766
767
768
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 761

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.



759
760
761
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 759

def quit_confirm_request
  @quit_confirm_request
end

Instance Method Details

#is_alive?Boolean

Returns:

  • (Boolean)


779
780
781
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 779

def is_alive?
  @alive
end

#is_windows?Boolean

Returns:

  • (Boolean)


851
852
853
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 851

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

#killObject



836
837
838
839
840
841
842
843
844
845
846
847
848
849
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 836

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



855
856
857
858
859
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 855

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

#set_alive(_value = false) ⇒ Object



783
784
785
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 783

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

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



787
788
789
790
791
792
793
794
795
796
797
798
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
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 787

def start_session(_filename, _host='localhost', _remote_port='8989')
  if is_windows?
    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(RunRubyFileEvent.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
        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



770
771
772
773
774
775
776
777
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 770

def start_session_new(_filename, _host='localhost', _remote_port='8989')
  if is_windows?
     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))
end