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(_controller, _server = 'localhost', _port = 8989, _timeout = 0) ⇒ RubyDebugClient

Returns a new instance of RubyDebugClient.



944
945
946
947
948
949
950
951
952
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 944

def initialize(_controller, _server='localhost', _port=8989, _timeout=0)
  @controller = _controller
  @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



954
955
956
957
958
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 954

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



1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
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 1209

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.console(self, 'msg'=>"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



1304
1305
1306
1307
1308
1309
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1304

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



1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1332

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



1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1238

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)


976
977
978
979
980
981
982
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 976

def is_alive?
  #p "===>@session=#{@session}" 
  #p "===>@session.closed?=#{@session.closed?}" if @session
  #p "===>@pend=#{@pend}"
  !(@session.nil? || @session.closed? || @pend)
  #([email protected]? && [email protected]? && !@pend)
end

#is_busy?Boolean

Returns:

  • (Boolean)


972
973
974
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 972

def is_busy?
  @busy
end

#is_debugging_ready?Boolean

Returns:

  • (Boolean)


968
969
970
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 968

def is_debugging_ready?
  is_alive? && !is_busy?
end

#killObject



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

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

#local_variablesObject

returns the local variables and there values



1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1312

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



960
961
962
963
964
965
966
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 960

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

#quitObject



1125
1126
1127
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1125

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

#quit_noObject



1135
1136
1137
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1135

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

#quit_yesObject



1129
1130
1131
1132
1133
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1129

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

#resumeObject



1117
1118
1119
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1117

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

#set_breakpoint(_file, _line) ⇒ Object



1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1349

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

#socket_sessionObject



984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 984

def socket_session
    #p "====>socket_session"
    #Arcadia.new_debug_msg(self,"socket_session : passo")    
    if @session.nil? && @controller.rds.is_alive?
      begin
        #sleep(2)
        @session = TCPSocket.new(@server, @port)
        @pend = false
      rescue Errno::ECONNREFUSED,Errno::EBADF => e
        sleep(1)
        @t = @t -1
        if @t > 0
          socket_session
        else
          Arcadia.console(self, 'msg'=>"socket_session : #{e.inspect}", 'level'=>'debug')
          #Arcadia.new_debug_msg(self,"socket_session : #{e.inspect}")    
        end
      rescue Exception => e
        @session = nil
        Arcadia.console(self, 'msg'=>"Error on socket_session : #{e.class}:#{e.message}", 'level'=>'debug')
        #Arcadia.new_debug_msg(self,"Error on socket_session : #{e.class}:#{e.message}")    
      end
    elsif !@controller.rds.is_alive?
      @session = nil
    end
    #Arcadia.new_debug_msg(self,"session : #{@session.inspect}")    
    #p "@session=>#{@session}"
    return @session 
end

#stacktraceObject

return the current stack trace



1140
1141
1142
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1140

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

#start_sessionObject



1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1024

def start_session
  begin
    #p "======>start session"
    @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.console(self, 'msg'=>"Error on start_session : #{e.class}:#{e.message}", 'level'=>'debug')
    #Arcadia.new_debug_msg(self,"Error on start_session : #{e.class}:#{e.message}")    
  end
end

#step_intoObject



1109
1110
1111
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1109

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

#step_outObject



1113
1114
1115
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1113

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

#step_overObject



1105
1106
1107
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1105

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

#stop_sessionObject



1040
1041
1042
1043
1044
1045
1046
1047
1048
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1040

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

#unset_breakpoint(_id) ⇒ Object



1362
1363
1364
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1362

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

#variables(_type) ⇒ Object

returns the local variables and there values



1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1279

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



1121
1122
1123
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1121

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

#yaml_pseudo_load(_obj) ⇒ Object



1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1145

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