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.



778
779
780
781
782
783
784
785
786
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 778

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

Instance Attribute Details

#quit_confirm_requestObject

Returns the value of attribute quit_confirm_request.



776
777
778
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 776

def quit_confirm_request
  @quit_confirm_request
end

Instance Method Details

#is_alive?Boolean

Returns:

  • (Boolean)


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

def is_alive?
  @alive
end

#killObject



859
860
861
862
863
864
865
866
867
868
869
870
871
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 859

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'=>Arcadia.text('ext.ruby_debug.server.e.on_kill', [e.class, e.message]), 'level'=>'debug')
  end
end

#notify(_state) ⇒ Object



873
874
875
876
877
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 873

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

#set_alive(_value = false) ⇒ Object



798
799
800
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 798

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

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



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
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 802

def start_session(_debug_event, _host='localhost', _remote_port='8989')
  _filename = _debug_event.file
  commandLine = "#{Arcadia.ruby} #{@rdebug_file} --host #{_host} --port #{_remote_port} -sw '#{_filename}'"
  #commandLine = "#{Arcadia.ruby} -r debug --host #{_host} --port #{_remote_port} -sw '#{_filename}'"
  #p commandLine
  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 && File.basename(_debug_event.file)[0..1] == '~~'
           File.delete(_debug_event.file) if File.exist?(_debug_event.file)
        end

      end
    else
      @pid = Process.fork do
        if File.basename(Arcadia.ruby) != 'ruby'
          commandLine="export PATH=#{Arcadia.instance.local_dir}/bin:$PATH && #{commandLine}"
        end
        #s_event = Arcadia.process_event(RunCmdEvent.new(self, {'cmd'=>commandLine}))
        #if s_event.flag != Event::FLAG_ERROR
        if Kernel.system(commandLine)
          set_alive(false)
          notify(RDS_QUIET)
          Kernel.system('y')
          if _debug_event.persistent == false && File.basename(_debug_event.file)[0..1] == '~~'
             File.delete(_debug_event.file) if File.exist?(_debug_event.file)
          end
          Kernel.exit!
        else
          set_alive(false)
          notify(RDS_QUIET)
          Kernel.exit!
          Arcadia.console(self, 'msg'=>"#{$!.inspect}", 'level'=>'debug')
        end
      end
    end
  rescue Exception => e
    Arcadia.console(self, 'msg'=>Arcadia.text('ext.ruby_debug.server.e.on_start', [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



788
789
790
791
792
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 788

def start_session_new(_filename, _host='localhost', _remote_port='8989')
  commandLine = "#{@rdebug_file} --host #{_host} --port #{_remote_port} -sw #{_filename}"
  #Arcadia.process_event(SystemExecEvent.new(self, 'command'=>commandLine))
  Arcadia.process_event(RunCmdEvent.new(self, 'cmd'=>commandLine, 'file'=>_filename))
end