Class: RubyDebugClient

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

Defined Under Namespace

Classes: Var

Constant Summary collapse

DOMAIN_TYPE_CONSTANT =

require “psych”

YAML::DomainType

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of RubyDebugClient.



972
973
974
975
976
977
978
979
980
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 972

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



982
983
984
985
986
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 982

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
1267
1268
1269
1270
1271
1272
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1241

def debug_dump(_exp)
  return '' if _exp.nil? || _exp.strip.length == 0 || _exp.strip.length == 'nil'
   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.include?('SyntaxError:')
      _to_eval = read("eval require 'pp';eval #{_exp}.pretty_inspect")
      var = eval(_to_eval)
      #var = "?"
    else
      _str = "#{eval(_to_eval)}"
      _str.gsub!('!ruby/object:', '!')
      begin
        _obj = YAML::load(_str)
      rescue Exception => e
        Arcadia.console(self, 'msg'=>"exception on eval in YAML::load #{_str} :#{e.inspect}")
      end
      var = yaml_pseudo_load(_obj)
    end  
  rescue Exception => e
    Arcadia.console(self, 'msg'=>"exception on eval #{_exp} :#{e.inspect}")
    Arcadia.console(self, 'msg'=>"exception on eval #{_exp} : #{_to_eval}")
    #Arcadia.new_msg(self,"exception on eval #{_exp} :#{e.inspect}")
    var = nil
  end
  return var
end

#debug_eval(_exp) ⇒ Object



1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1299

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

#is_alive?Boolean

Returns:

  • (Boolean)


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

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)


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

def is_busy?
  @busy
end

#is_debugging_ready?Boolean

Returns:

  • (Boolean)


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

def is_debugging_ready?
  is_alive? && !is_busy?
end

#killObject



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

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

#notify(_command, _result = nil) ⇒ Object



988
989
990
991
992
993
994
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 988

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

#quitObject



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

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

#quit_noObject



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

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

#quit_yesObject



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

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

#resumeObject



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

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

#set_breakpoint(_file, _line) ⇒ Object



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

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



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

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)
        #@session = IO.popen("|rdebug -c --cport #{@port}",'r+')
        @pend = false
      rescue Errno::ECONNREFUSED,Errno::EBADF => e
        sleep(1)
        @t = @t -1
        if @t > 0
          socket_session
        else
          Arcadia.console(self, 'msg'=>Arcadia.text('ext.ruby_debug.client.e.socket_session.1', [e.inspect]), 'level'=>'debug')
          #Arcadia.new_debug_msg(self,"socket_session : #{e.inspect}")    
        end
      rescue Exception => e
        @session = nil          
        Arcadia.console(self, 'msg'=>Arcadia.text('ext.ruby_debug.client.e.socket_session.2', [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



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

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

#start_sessionObject



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

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'=>Arcadia.text('ext.ruby_debug.client.e.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



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

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

#step_outObject



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

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

#step_overObject



1132
1133
1134
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1132

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

#stop_sessionObject



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

def stop_session
  begin
    quit if is_debugging_ready?
    @session.close if is_alive?
  rescue Exception => e
    Arcadia.console(self, 'msg'=>Arcadia.text('ext.ruby_debug.client.e.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



1328
1329
1330
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1328

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

#variables(_type) ⇒ Object

returns the local variables and there values



1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1275

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)
    if variables.class != Array
      variables = []
    end
    #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=='$;'
    variable_values[var.to_s] = debug_eval(var.to_s)
  end
  return variable_values
end

#whereObject



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

def where
#    notify("where", read("where"))
  notify("where", read("info line"))
end

#yaml_pseudo_load(_obj) ⇒ Object



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
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 1173

def yaml_pseudo_load(_obj)
  just_present =  @valuobjs.include?(_obj)
  @valuobjs << _obj 
  p  _obj.class
  if _obj.class == DOMAIN_TYPE_CONSTANT
    
    p _obj
    
    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