Class: RubyDebug

Inherits:
ArcadiaExt show all
Includes:
Autils
Defined in:
ext/ae-ruby-debug/ae-ruby-debug.rb

Instance Attribute Summary collapse

Attributes inherited from ArcadiaExt

#arcadia, #name

Instance Method Summary collapse

Methods included from Autils

#full_in_path_command, #is_windows?

Methods inherited from ArcadiaExt

#conf, #conf_array, #conf_default, #exec, #float_frame, #frame, #frame_def_visible?, #frame_domain, #frame_domain_default, #frame_visible?, #initialize, #maximize, #maximized?, #resize, #restore_default_conf

Constructor Details

This class inherits a constructor from ArcadiaExt

Instance Attribute Details

#rdcObject (readonly)

Returns the value of attribute rdc.



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

def rdc
  @rdc
end

#rdsObject (readonly)

Returns the value of attribute rds.



1401
1402
1403
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1401

def rds
  @rds
end

Instance Method Details

#break_name(_file, _line) ⇒ Object



1495
1496
1497
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1495

def break_name(_file,_line)
  "#{_file}:#{_line}"
end

#breakpoint_add(_file, _line) ⇒ Object



1518
1519
1520
1521
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1518

def breakpoint_add(_file,_line)
  breakpoint_add_live(_file,_line)
  @static_breakpoints << {:file=>_file,:line=>_line}
end

#breakpoint_add_live(_file, _line) ⇒ Object



1499
1500
1501
1502
1503
1504
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1499

def breakpoint_add_live(_file,_line)
  if @rdc && @rdc.is_alive?
    @breakpoints[breakpoint_suf(_file,_line)] = @rdc.set_breakpoint(_file, _line.to_i)
    #@rdv.break_list_add(_file,_line) if @rdv
  end
end

#breakpoint_del(_file, _line) ⇒ Object

private :breakpoint_add



1524
1525
1526
1527
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1524

def breakpoint_del(_file,_line)
  breakpoint_del_live(_file,_line)
  @static_breakpoints.delete_if{|b| (b[:file]==_file && b[:line]==_line)}
end

#breakpoint_del_live(_file, _line) ⇒ Object



1506
1507
1508
1509
1510
1511
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1506

def breakpoint_del_live(_file,_line)
  if @rdc && @rdc.is_alive?
    @rdc.unset_breakpoint(@breakpoints.delete(breakpoint_suf(_file,_line)))
    #@rdv.break_list_del(_file,_line) if @rdv
  end
end

#breakpoint_free_liveObject



1513
1514
1515
1516
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1513

def breakpoint_free_live
  @breakpoints.clear if @breakpoints
  #@rdv.break_list_free if @rdv
end

#debug(_filename = nil) ⇒ Object



1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1565

def debug(_filename=nil)
  if _filename && !debugging?
    begin
      self.debug_begin
      @arcadia['pers']['run.file.last']=_filename
      @rds = RubyDebugServer.new(self,@arcadia) if @rds.nil?
      @rds.start_session(_filename, conf('server.host'), conf('server.port'))
      #Arcadia.new_msg(self,@rds.to_s)
      
      @rdc = RubyDebugClient.new(self, conf('server.host'), conf('server.port'), conf('server.timeout')) if @rdc.nil?
      @rdv = RubyDebugView.new(self) if @rdv.nil?
      self.frame.show
      @rdv.start_process(_filename)
      if @rdc.start_session
        @static_breakpoints.each{|_b|
          #Arcadia.console(self,'msg'=>" breakpoint_add #{_b[:file]}:#{_b[:line]}")
          breakpoint_add_live(_b[:file], _b[:line])
        }
        if @static_breakpoints.length > 0 && conf("auto_resume_break_on_first_line")!='no'
          @rdv.debug_send(:resume)
        end
      end
    rescue Exception => e
      Arcadia.console(self, 'msg'=>"---> "+e.to_s+ ' ' + e.backtrace[0], 'level'=>'debug')
    end
  end
end

#debug_beginObject



1560
1561
1562
1563
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1560

def debug_begin
  breakpoint_free_live
  #DebugContract.instance.debug_begin(self)
end

#debug_currentObject



1552
1553
1554
1555
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1552

def debug_current
  Arcadia.process_event(StartDebugEvent.new(self, 'file'=>@raised_file)) if @raised_file!=nil
  #debug(@raised_file) if @raised_file!=nil
end

#debug_freeObject



1604
1605
1606
1607
1608
1609
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1604

def debug_free
  self.frame.free
  self.frame(1).free
  @rdc = nil
  @rdv = nil
end

#debug_lastObject



1547
1548
1549
1550
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1547

def debug_last
  Arcadia.process_event(StartDebugEvent.new(self, 'file'=>$arcadia['pers']['run.file.last']))
  #debug($arcadia['pers']['run.file.last'])
end

#debug_quitObject



1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1611

def debug_quit
#p "in debug quit @rdc.is_alive?=#{@rdc.is_alive?}"
  if @rdc 
    if @rdc.is_alive?
      Thread.new{
        Tk.messageBox('icon' => 'info', 
        						'type' => 'ok',
      						 'title' => '(Arcadia) Debug',
      						 'message' => "Debug in course, stop it before exit")
      }
    else
      begin
        debug_free
      rescue Exception => e
        Arcadia.console(self, 'msg'=>"debug_quit:---> "+e.to_s+ ' ' + e.backtrace[0], 'level'=>'debug')
        #Arcadia.new_debug_msg(self, "debug_quit:---> "+e.to_s)
        #@arcadia['shell'].outln("debug_quit:---> "+e.to_s )
      end
    end
  end
end

#debugging?Boolean

debug(@raised_file) if @raised_file!=nil

Returns:

  • (Boolean)


1556
1557
1558
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1556

def debugging?
  !@rdc.nil? && @rdc.is_alive?
end

#eval_expression(_exp) ⇒ Object

def do_editor_event(_event)

  case _event.signature 
    when EditorContract::BREAKPOINT_AFTER_CREATE
      self.breakpoint_add(File.expand_path(_event.context.file), _event.context.line)
    when EditorContract::BREAKPOINT_AFTER_DELETE
      self.breakpoint_del(File.expand_path(_event.context.file), _event.context.line)
    when EditorContract::BUFFER_AFTER_RAISE
      @raised_file=_event.context.file
    when EditorContract::EVAL_EXPRESSION
      eval_expression(_event.context.text)
  end
end


1474
1475
1476
1477
1478
1479
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1474

def eval_expression(_exp)
  res = @rdc.debug_eval(_exp) if @rdc && @rdc.is_debugging_ready?
  hash = Hash.new
  hash[_exp]=res 
  @rdv.show_expression(_exp, hash) if res 
end

#on_before_build(_event) ⇒ Object



1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1403

def on_before_build(_event)
  if RubyWhich.new.which("rdebug") != []
    @breakpoints = Hash.new
    @static_breakpoints = Array.new
    Arcadia.attach_listener(self, BufferEvent)
  else
    Arcadia.console(self, 'msg'=>"Warning: Extension ae-ruby-debug depend upon rdebug command (install it or update system path!)", 'level'=>'error')
    #Arcadia.new_error_msg(self, "Warning: Extension ae-ruby-debug depend upon rdebug command (install it or update system path!)")
  end
  Arcadia.attach_listener(self, DebugEvent)
end

#on_buffer(_event) ⇒ Object



1419
1420
1421
1422
1423
1424
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1419

def on_buffer(_event)
  case _event
    when BufferRaisedEvent
      @raised_file=_event.file
  end
end

#on_build(_event) ⇒ Object



1415
1416
1417
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1415

def on_build(_event)
  #Arcadia.attach_listener(self, DebugEvent)
end

#on_debug(_event) ⇒ Object



1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1426

def on_debug(_event)
  case _event
    when StartDebugEvent
      _filename = _event.file
      _filename = @arcadia['pers']['run.file.last'] if _filename == "*LAST"
      if File.exist?(_filename)
        debug(_filename)
      else
        Arcadia.dialog(self,
          'type'=>'ok',
          'title'=>'File not exist',
          'msg'=>"File #{_filename} not exist!")
      end
    when StepDebugEvent
      if (_event.command == :quit_yes)
        @rds.quit_confirm_request = true
      end
      @rdc.send(_event.command) if @rdc.is_alive?
      
      #p "on_debug -> Thread.current=#{Thread.current}"

      #p "on_debug --> @rdc.is_alive?=#{@rdc.is_alive?}"
      #p "on_debug --> @rds.is_alive?=#{@rds.is_alive?}"
    when SetBreakpointEvent
      self.breakpoint_add(File.expand_path(_event.file), _event.row)
    when UnsetBreakpointEvent
      self.breakpoint_del(File.expand_path(_event.file), _event.row)
    when EvalExpressionEvent
      eval_expression(_event.expression)
    when StopDebugEvent
      self.debug_quit
  end
end

#on_exit_query(_event) ⇒ Object



1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1531

def on_exit_query(_event)
  if @rdc && @rdc.is_alive?
    query = (Tk.messageBox('icon' => 'question', 'type' => 'yesno',
    'title' => '(Arcadia) Debug',
    'message' => "Debug in course, do you want to exit?")=='yes')
    if query
      debug_quit
      _event.can_exit=true
    else
      _event.can_exit=false
    end
  else
    _event.can_exit=true
  end
end

#rdebug_server_update(_state) ⇒ Object



1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
# File 'ext/ae-ruby-debug/ae-ruby-debug.rb', line 1593

def rdebug_server_update(_state)
  case _state
    when RubyDebugServer::RDS_QUIET
      @rdc.kill if @rdc
      #p "@rdc.is_alive?=#{@rdc.is_alive?}"
      #p "rdebug_server_update -> Thread.current=#{Thread.current}"
      #@rdv.command_enabled(false)
      #debug_free
  end
end