Posted on August 27, 2006
Wouldn't it be great if I can set breakpoints right from within TextMate? I've been thinking about this myself for sometime.
And now I'd like to introduce a new Ruby Debug Bundle.
Note that in order to use it you must have the latest version (0.4.1 or higher) of ruby-debug installed.
How to use it?
Let's say you want to debug your Rails application.
Start your application with the remote debugging enabled:
$ rdebug -sn ./script/server webrick
Connect to the debugger (in new terminal):
$ rdebug -c
Connected.
In TextMate go to the line where you want to set a breakpoint and press ⇧⌘B and select Set Breakpoint at Current Line.
Open your browser and start using your application until you reach the breakpoint.
That's it.
Currently, these commands are available:
- Set Breakpoint at Current Line
- Delete All Breakpoints.
- Show Breakpoints - show all breakpoints as a tooltip.
- Interrupt - interrupt the last debugged thread or, if there is no one, the main thread.
- Quit - quit application.
Filed under: ruby-debug TextMate |
7 comments
Posted on August 25, 2006
Many Rails users enjoyed this little gem developed by Florian Groß. But as Mauricio Fernandez noted in his blog, this extension is broken with the brand new Ruby 1.8.5. In order to make its magic possible, breakpoint library relied on the implementation of Binding.of_caller, which in turn relied on the bug in Ruby's implementation of trace calls. With new release, this bug has been patched.
Mauricio has started working of fixing this problem and proposed a new method binding_n(n), which would return a binding for any frame in the call stack. But you don't have to wait for his work to complete. ruby-debug has this functionality already implemented for you.
Consider this small snippet:
require "rubygems"
require 'ruby-debug'
module Kernel
def binding_n(n = 0)
frame = Debugger.current_context.frames[n+1]
raise "Unknown frame #{n}" unless frame
frame.binding
end
end
def test
puts eval("var", binding_n(1))
end
Debugger.start do
var = 'Hello'
test
end
And most likely, I will add this method to the next version of ruby-debug. It can be handy sometimes.
Filed under: Ruby ruby-debug |
0 comments
Posted on August 25, 2006
New release 0.4 is uploaded to gem server. Thanks to Pascal for providing a valuable feedback and suggestions for this release.
What's new?
sa[ve] FILE command saves current breakpoints and checkpoint to a script file.
sc[ript] FILE command runs a script file. Note that script file can contain only control commands: add/remove breakpoints, interrupt program or thread, etc.
l[ist] on/off command. I don't know about you, but when I step through my application I immediately need to use list command to see where I am in the source code. Now if you use list on, ruby-debug will start doing this for you. To turn it off, use list off.
e[val] on/off command. When it's on*, ruby-debug will evaluate your input if it doesn't recognize it as one of the commands. To turn it off, use *eval off.
tm[ate] n command now accepts a frame number.
Note that in my last announcement I forgot to mention that if you don't want to use rdebug script to start debugger and instead prefer to require 'ruby-debug', now you must activate debugger explicitly by running Debugger.start or Debugger.start_remote method. Also, if you want to debug just a small part of your application, you can wrap it in a block and pass it to Debugger.start method. When start method finishes, it disactivates debugger. For example:
...
Debugger.start do
# code you want to debug goes here
...
end
Enjoy.
Filed under: ruby-debug |
1 comment
Posted on August 15, 2006
OK, here's a new version of ruby-debug. Most changes are related to the remote debugging and improvements targeted for a possible GUI integration:
Wait for a client connection. With this option on, the debugger will wait for a connection, before returning control to the script. You can enable it with -w option of rdebug script or by calling Debugger.wait_connection = true.
Stop on connect. With this option on, the debugger will stop when a remote client establishes a connection. rdebug script has this parameter enabled by default, but you can disable it with -n option. In your own script you can use Debugger.stop_on_connect = true to activate it.
Controlling thread. When activating a remote debugger, a control thread is activated as well. It listens on the socket (port 8990, by default) and accepts a number of commands that you can use to control a debugger, such as add/delete breakpoints, interrupt an application, etc. This is quite helpful for a GUI frontend, where you can set breakpoints at any time while your application is running.
There are also a couple of additions to the debugger commands:
l[ist] = - displays the current exception point.
f[rame] n - switches to nth frame. You can see the list of frames and their numbers with frame or where command.
tm[ate] - if you are running Mac OSX and addicted to TextMate, this command opens the current file using this editor.
That's all for now. Enjoy.
Filed under: Ruby ruby-debug |
8 comments