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.



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

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



985
986
987
988
989
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 985

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



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

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



1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1336

def debug_eval(_exp)
  if command("eval #{res=_exp}.to_s + '|||' + #{res}.class.to_s")
    begin
      _str = eval(read)
      _value, _class = _str.split('|||')
    rescue Exception => e
      _value = "?"
      _class = "?"
    end
    return Var.new(_value, _class)
  else
    return Var.new("?", "?")
  end
end

#global_variablesObject

returns the global variables and there values



1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1372

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



1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1270

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)


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

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)


1003
1004
1005
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1003

def is_busy?
  @busy
end

#is_debugging_ready?Boolean

Returns:

  • (Boolean)


999
1000
1001
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 999

def is_debugging_ready?
  is_alive? && !is_busy?
end

#killObject



1045
1046
1047
1048
1049
1050
1051
1052
1053
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1045

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



1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1352

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



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

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

#quitObject



1157
1158
1159
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1157

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

#quit_noObject



1167
1168
1169
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1167

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

#quit_yesObject



1161
1162
1163
1164
1165
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1161

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

#resumeObject



1149
1150
1151
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1149

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

#set_breakpoint(_file, _line) ⇒ Object



1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1389

def set_breakpoint(_file, _line)
  #_line = _line + 1
  text = read("break #{_file}:#{_line}")
  return if text.nil?
  #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 && (matches.length == 2)
  return breakpoint_no
end

#socket_sessionObject



1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1015

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



1172
1173
1174
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1172

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

#start_sessionObject



1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1055

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} #{e.backtrace.join('..')}", 'level'=>'debug')
    #Arcadia.new_debug_msg(self,"Error on start_session : #{e.class}:#{e.message}")    
  end
end

#step_intoObject



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

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

#step_outObject



1145
1146
1147
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1145

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

#step_overObject



1137
1138
1139
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1137

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

#stop_sessionObject



1071
1072
1073
1074
1075
1076
1077
1078
1079
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1071

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



1403
1404
1405
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1403

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

#variables(_type) ⇒ Object

returns the local variables and there values



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

def variables(_type)
  begin
    #variables = read[1..-2].split(', ').collect!{|x| x[1..-2]}
    to_eval = read("eval #{_type}")
    #Arcadia.console(self,'msg'=>"to_eval=#{to_eval.to_s}")
    variables = eval(to_eval)
    #Arcadia.console(self,'msg'=>"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.to_s=='$;'
#      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.to_s] = debug_eval(var.to_s)
  end
  return variable_values
end

#whereObject



1153
1154
1155
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1153

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

#yaml_pseudo_load(_obj) ⇒ Object



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
1207
1208
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
1235
1236
1237
1238
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1177

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