Git Product home page Git Product logo

defly's Introduction

defly

A ruby debugging tool. Easy way to trace function calls and variables.

Install

Just gem install defly.

Feature

  • Trace method calls: including arguments and return values
  • Trace variable changes
  • Showing source code when NoMethodError is thrown
  • Opening a shell when a particular error occurred
  • Showing the exact path of required library

Tracing method and instance variables

Input

require 'defly'

class Warrior
  attr_accessor :hp, :mp

  def sleep
    self.hp += 10
    self.mp += 2
  end
end

Warrior.debug!
Warrior.new.trace([:hp, :hp=, :mp, :mp=, :sleep], [:@hp, :@mp]) do |warrior|
  warrior.hp = 10
  warrior.mp = 20
  warrior.sleep
end

Output (Run on IRB)

Tracing hp, hp=, mp, mp=, sleep on Warrior instance
Tracing @hp, @mp on Warrior instance
<<<<< Warrior#hp=(10) # (irb):14:in `block in irb_binding'
    @hp = 10 # undefined
    @mp = nil # undefined
>>>>> 10
<<<<< Warrior#mp=(20) # (irb):15:in `block in irb_binding'
    @mp = 20 # undefined
>>>>> 20
<<<<< Warrior#sleep() # (irb):16:in `block in irb_binding'
    <<<<< Warrior#hp() # (irb):7:in `sleep'
    >>>>> 10
    <<<<< Warrior#hp=(20) # (irb):7:in `sleep'
        @hp = 20 # 10 -> 20
    >>>>> 20
    <<<<< Warrior#mp() # (irb):8:in `sleep'
    >>>>> 20
    <<<<< Warrior#mp=(22) # (irb):8:in `sleep'
        @mp = 22 # 20 -> 22
    >>>>> 22
>>>>> 22

Better Error Message

NoMethodError

Showing the exact code and the position of the error.

irb(main):001:0> require 'defly'
=> true
irb(main):002:0> require 'bug'
NoMethodError: undefined method `is_annoying' for "debugging":String
bug.rb:1> "debugging".<<is_annoying>>
	from /Users/eggegg/bug.rb:1:in `<top (required)>'
	...

Inspecting error

Input

class Rocket
  def launch
    @reason = "Bugs invasion"
    raise "Engine Fail"
  end
end

Rocket.debug!
rocket = Rocket.new
rocket.watch_error "Engine Fail"
rocket.launch

Output

>>>>> Error received:
"Engine Fail"
>>>>>
#<Rocket:0(0)>> @reason
=> "Bugs invasion"
#<Rocket:0(0)>>

Showing the require path

irb(main):001:0> require 'defly'
=> true
irb(main):002:0> require 'shoulda', :verbose => true
shoulda cannot be required
LoadError: no such file to load -- shoulda
  from /Users/eggegg/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
  from /Users/eggegg/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
  from /Users/eggegg/.rvm/gems/ruby-1.9.2-p290/gems/defly-0.2.0/lib/defly/require_path.rb:23:in `require'
  from (irb):2
  from /Users/eggegg/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'
irb(main):003:0> require 'rdoc', :verbose => true
Requiring /Users/eggegg/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/rdoc.rb
=> true

Copyright

Copyright (c) 2011 Andrew Liu. See LICENSE.txt for further details.

defly's People

Contributors

andrewytliu avatar

Stargazers

Jim Chang avatar Tai An Su avatar Jack avatar Ash Wu avatar Hooopo avatar  avatar Tim Snowhite avatar 洪盟翔 avatar  avatar Andy Wang avatar Gregoire Lejeune avatar ilake avatar Lin Jen-Shin (godfat) avatar Liang-Bin Hsueh avatar

Watchers

 avatar James Cloos avatar

defly's Issues

Moving files in lib/

I listened your lightning talk in rubyconf.tw. Nice work.

Would you mind to move your files in lib/ directory?
In convention, we will put most files in lib/defly/ .

For example,

lib/defly.rb
lib/defly/inspectable.rb
lib/defly/tracable.rb
lib/defly/whinable.rb

This is to avoid name collision.
If we have another gem named tracable, it's nature to have a file named tracable.rb
One of the file will be shadowed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.