Class: RubyDebugClient

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

Defined Under Namespace

Classes: Var

Instance Method Summary collapse

Constructor Details

#initialize(_server = 'localhost', _port = 8989, _timeout = 0) ⇒ RubyDebugClient

Returns a new instance of RubyDebugClient.



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

def initialize(_server='localhost', _port=8989, _timeout=0)
  @session = nil
  @server = _server
  @port = _port
  @timeout = _timeout.to_i
  @busy = false
  @pend = false
end

Instance Method Details

#add_listener(_caller, _method = :rdebug_client_update) ⇒ Object



864
865
866
867
868
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 864

def add_listener(_caller, _method=:rdebug_client_update)
  if _caller.respond_to? :rdebug_client_update
    ObserverCallback.new(self,_caller,:rdebug_client_update)
  end
end

#debug_dump(_exp) ⇒ Object



1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1097

def debug_dump(_exp)
  var = nil
  if @valuobjs.nil?
    @valuobjs = Array.new 
  else
    @valuobjs.clear
  end
  begin
    _to_eval = read("eval YAML::dump(#{_exp})")
    if _to_eval.include?('Exception:')
      _to_eval = read("eval require 'pp';eval #{_exp}.pretty_inspect")
      var = eval(_to_eval)
      #var = "?"
    else
      _str = eval(_to_eval)
      _str.gsub!('!ruby/object:', '!')
      _obj = YAML::load(_str)
      var = yaml_pseudo_load(_obj)
    end  
  rescue Exception => e
    Arcadia.new_msg(self,"exception on eval #{_exp} :#{e.inspect}")
    #Arcadia.new_msg(self,"exception on eval #{_exp} :#{e.inspect}")
    var = nil
  end
  return var
end

#debug_eval(_exp) ⇒ Object



1192
1193
1194
1195
1196
1197
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1192

def debug_eval(_exp)
  command("eval #{res=_exp}.to_s + '|||' + #{res}.class.to_s")
  _str = eval(read)
  _value, _class = _str.split('|||')
  return Var.new(_value, _class)
end

#global_variablesObject

returns the global variables and there values



1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1220

def global_variables
  command("eval global_variables")
  variables = []
  begin
    variables = eval(read)
  rescue Exception
    variables = []
  end
  variable_values = Hash.new
  variables.each do |var|
    command("eval #{var}.to_s")
    variable_values[var] = read
  end
  return variable_values
end

#instance_variables_new(_this = 'self') ⇒ Object

returns the instance variables and there values



1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1126

def instance_variables_new(_this='self')
  command("eval #{_this}.instance_variables")
  variables = []
  begin
    variables = eval(read)
  rescue Exception
    variables = []
  end
  @consider = Array.new
  variable_values = Hash.new
  variables.each do |var|
     #next if var != '@objs'
#      command("eval require 'pp';  #{var}.pretty_inspect() + '|||' + #{var}.class.to_s")
    command("eval YAML::dump(#{var})")
    _str = eval read
    #Arcadia.new_msg(self,"value passato 1 ="+_str)

    _str.gsub!('!ruby/object:', '!')

    #Arcadia.new_msg(self,"value passato 2 ="+_str)

    _obj = YAML::load(_str)
    
    _xvalue = yaml_pseudo_load(_obj)
    if _xvalue.class == Hash
      _xclass = _xvalue['__CLASS__']
    else
      _xclass = _xvalue.class.to_s
    end
    #_vvv = eval(_value)
    
    #Arcadia.new_msg(self,"vvv class="+_vvv.class.to_s)
    
    #Arcadia.new_msg(self,"value="+_xvalue.inspect)
    #Arcadia.new_msg(self,"class="+_xclass)
    variable_values[var] = Var.new(_xvalue, _xclass)
  end
  return variable_values
end

#is_alive?Boolean

Returns:

  • (Boolean)


886
887
888
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 886

def is_alive?
  !@session.nil? && !@session.closed? && !@pend
end

#is_busy?Boolean

Returns:

  • (Boolean)


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

def is_busy?
  @busy
end

#is_debugging_ready?Boolean

Returns:

  • (Boolean)


878
879
880
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 878

def is_debugging_ready?
  is_alive? && !is_busy?
end

#killObject



911
912
913
914
915
916
917
918
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 911

def kill 
  begin
    @session.close if is_alive?
    @session = nil
  rescue Exception => e
    Arcadia.new_debug_msg(self,"Error on close session : #{e.class}:#{e.message}")    
  end
end

#local_variablesObject

returns the local variables and there values



1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1200

def local_variables
  command("eval local_variables")
  variables = []
  begin
    variables = eval(read)
  rescue Exception
    variables = []
  end
  variable_values = Hash.new
  variables.each do |var|
    command("eval #{var}.to_s + '|||' + #{var}.class.to_s")
    _str = eval(read)
    _value, _class = _str.split('|||')
    variable_values[var] = Var.new(_value, eval(_class))
  end
  return variable_values
end

#notify(_command, _result = nil) ⇒ Object



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

def notify(_command, _result=nil)
 #Arcadia.new_debug_msg(self,"notify=>#{_command}")    
  @busy = false
  changed
  notify_observers(_command, _result)
  _result
end

#quitObject



1013
1014
1015
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1013

def quit
  notify("quit", read("q"))
end

#quit_noObject



1023
1024
1025
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1023

def quit_no
  notify("quit_no", read("n"))
end

#quit_yesObject



1017
1018
1019
1020
1021
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1017

def quit_yes
  notify("quit_yes", read("y"))
  #DebugContract.instance.debug_end(self)
  kill
end

#resumeObject



1005
1006
1007
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1005

def resume
  notify("cont", read("cont"))
end

#set_breakpoint(_file, _line) ⇒ Object



1237
1238
1239
1240
1241
1242
1243
1244
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1237

def set_breakpoint(_file, _line)
  #_line = _line + 1
  text = read("break #{_file}:#{_line}")
  breakpoint_no = -1
  matches = text.match(/Set breakpoint ([0-9]*)?/)
  breakpoint_no = matches[1].to_i if (matches.length == 2)
  return breakpoint_no
end

#socket_sessionObject



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

def socket_session
    #Arcadia.new_debug_msg(self,"socket_session : passo")    
    if @session.nil?
      begin
        #sleep(2)
        @session = TCPSocket.new(@server, @port)
        @pend = false
      rescue Errno::ECONNREFUSED => e
        sleep(1)
        @t = @t -1
        if @t > 0
          socket_session
        else
          Arcadia.new_debug_msg(self,"socket_session : #{e.inspect}")    
        end
      end
    end
    #Arcadia.new_debug_msg(self,"session : #{@session.inspect}")    
    return @session 
end

#stacktraceObject

return the current stack trace



1028
1029
1030
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1028

def stacktrace
  notify("backtrace", read("backtrace"))
end

#start_sessionObject



920
921
922
923
924
925
926
927
928
929
930
931
932
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 920

def start_session
  begin
    @t = @timeout 
    if socket_session
      #Arcadia.new_debug_msg(self,"session : #{@session.inspect}")    
      notify('start', read)
      read("eval require 'yaml'")
    end
    return @session
  rescue Exception => e
    Arcadia.new_debug_msg(self,"Error on start_session : #{e.class}:#{e.message}")    
  end
end

#step_intoObject



997
998
999
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 997

def step_into
  notify("step", read("step"))
end

#step_outObject



1001
1002
1003
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1001

def step_out
  notify("fin", read("fin"))
end

#step_overObject



993
994
995
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 993

def step_over
  notify("next", read("next"))
end

#stop_sessionObject



934
935
936
937
938
939
940
941
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 934

def stop_session
  begin
    quit if is_debugging_ready?
    @session.close if is_alive?
  rescue Exception => e
    Arcadia.new_debug_msg(self,"Error on stop_session : #{e.class}:#{e.inspect}")    
  end
end

#unset_breakpoint(_id) ⇒ Object



1246
1247
1248
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1246

def unset_breakpoint(_id)
  read("delete #{_id}")
end

#variables(_type) ⇒ Object

returns the local variables and there values



1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1167

def variables(_type)
  begin
    #variables = read[1..-2].split(', ').collect!{|x| x[1..-2]}
    to_eval = read("eval #{_type}")
    #Arcadia.new_msg(self,"to_eval="+to_eval.to_s)
    variables = eval(to_eval)
    #Arcadia.new_msg(self,"variables="+variables.to_s)
  rescue Exception => e
    variables = []
    #p "on command eval #{_type}:#{e.inspect}"
    #Arcadia.new_debug_msg(self,"on command eval #{_type}:#{e.inspect}")
  end
  variables = [] if variables.nil?
  variable_values = Hash.new
  variables.each do |var|
    next if var=='$;'
#      command("eval #{var}.to_s + '|||' + #{var}.class.to_s")
#      _str = eval(read)
#      _value, _class = _str.split('|||')
#      variable_values[var] = Var.new(_value, _class)
    variable_values[var] = debug_eval(var)
  end
  return variable_values
end

#whereObject



1009
1010
1011
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1009

def where
  notify("where", read("where"))
end

#yaml_pseudo_load(_obj) ⇒ Object



1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1033

def yaml_pseudo_load(_obj)
  just_present =  @valuobjs.include?(_obj)
  @valuobjs << _obj  
  if _obj.class == YAML::DomainType
    return _obj.type_id if just_present
    ret = Hash.new
    ret['__CLASS__']=_obj.type_id
    l = _obj.value.length  
    ret['__LENGTH__']= l.to_s
    if l > 0 
        _obj.value.each{|k,v|
            ret["@#{k}"]=yaml_pseudo_load(v)
        }
    end
    ret
  elsif _obj.class == Hash
  #Arcadia.new_msg(self,"_obj Hash="+_obj.inspect)
    return 'Hash' if just_present
    ret = Hash.new
    ret['__CLASS__']= 'Hash'
    l = _obj.length  
    ret['__LENGTH__']= l.to_s
    if l > 0 
      _obj.each{|k,v|
          ret[k]=yaml_pseudo_load(v)
      }
    end
    ret
  elsif _obj.class == Array
  #Arcadia.new_msg(self,"_obj Array="+_obj.inspect)
    return 'Array' if just_present
    ret = Hash.new
    ret['__CLASS__']= 'Array'
    l = _obj.length  
    ret['__LENGTH__']= l.to_s
    if l > 0 
      _obj.each_with_index{|v,i|
        ret[i.to_s]=yaml_pseudo_load(v)
      }
    end
    ret
  elsif _obj.class == Struct
  #Arcadia.new_msg(self,"_obj Array="+_obj.inspect)
    return 'Struct' if just_present
    ret = Hash.new
    ret['__CLASS__']= 'Struct'
    l = _obj.length  
    ret['__LENGTH__']= l.to_s
    if l > 0
       
      _obj.members.each{|m|
        ret[m]=yaml_pseudo_load(_obj[m])
      }
    end
    ret
  else  
  #Arcadia.new_msg(self,"_obj ="+_obj.inspect)
  
    _obj
  end

end