Friday, May 18, 2007

Ruby Screenshot of the Week #11: Rails Debugging

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.


First the screenshot - click for full resolution:








The NetBeans Ruby support now lets you debug Rails applications. As the screenshot shows, you can even step right through RHTML files! All the usual debugging features are there - breakpoints, stack view, local variables view - and balloon evaluation, where you hover the mouse over a variable and it displays the current value as a tooltip.



I can't take any credit for this; the debugger has been written by Martin Krauskopf, and uses the debug-commons library. Martin was my co-speaker for the Ruby talk (TS-9972) at JavaOne. If you missed it, Brian Leonard will be doing the same talk at RailsConf this weekend. One thing I want to clarify is that not everything I talked about in the type inference section is actually implemented yet in NetBeans. The talk represents everything I plan to do, not everything I've already done.



Note that the RHTML debugging feature is not present in the recent Milestone 9 bits. We've made a lot of improvements since then. Just this morning I integrated various fixes to make code completion work much better in Rails. You now properly get code completion in your model and migration files etc - as the following screenshot shows:






Another feature we added after Milestone 9 was some preliminary support for Auto Test - see the testing page for some screenshots and more info.



For now, I recommend that you use NetBeans Milestone 9 as your base IDE, and then use the trunk/daily Ruby bits with them. The easiest way to do that is to install Milestone 9, then follow the instructions in the RubyInstallation wiki page to blow away the ruby1 cluster in your M9 installation and replace it with a .zip download from deadlock.nbextras.org. Also be sure to nuke your userdir for any custom installed modules there (usually ~/.netbeans/dev). In the future, staying up to date with the Tools | Plugins manager will be easy, but with Milestone 9, it only displays branched Milestone 9 modules, and we aren't merging and rebuilding the Ruby stuff into the M9 branch at this point.



If all that sounded complicated, just go and download the Ruby-only IDE zip here. Get the zip containing rubyide in the name, unzip somewhere, and run nbrubyide/bin/nbrubyide. This will be daily-everything as opposed to a stable IDE + trunk Ruby, but - it will probably be okay.



Finally, if you're going to be debugging, make sure you first visit the RubyDebugging wiki page which will tell you some really important configuration information - like how to enable fast debugging.


25 comments:

  1. Hey Tor.. playing with the debugging, I can't seem to figure out how to debug a unit test or one off script. Rails debugging works (!) so I have things hooked up correctly, I might just be missing the UI element I need to click to debug. The "Debug File" option is greyed out when I have a unit test open. Any suggestions?
    Great job to all you guys on this, having a real debugger is going to be awesome.

    ReplyDelete
  2. Hi Greg. It is a bug. I forgot to enable debugging of single files in Rails application. In "standard" Ruby application it should work. Thanks for the report. I'll fix it soon.

    ReplyDelete
  3. Now, with ML9, and latest bits from the build, cause a conflict and netbeans complains about Common Scripting Framework 4 required, but found 3. I have been hitting on this issue, for a while. However, for bits older than 1846 work alright with netbeans ML9. Also, importing of textmate templates didn't work at all for me.

    ReplyDelete
  4. Common Scripting Language Support - The module Experimental Editor Hints SPI was requested in implementation version "4" but only "3" was found.
    7 further modules could not be installed due to the above problems.

    ReplyDelete
  5. I'm playing with the Ruby-only IDE downloaded from Hudson.
    First of all, I'm impressed by the Ruby and Rails support you're building into NetBeans -- you're doing a truly exceptional job!
    Now a small issue with the debugging support: when launching a debugging session I don't get any debug toolbar or menu -- either on the main menu or on the right-click context menu. This makes for a less-than-ideal debugging experience as I have to hunt for the keyboard shortcuts. It would be great if you could fix this.

    ReplyDelete
  6. Wow, for adding a simple text file to the project, I had to jump so many hooves(click-click-click-type-click)
    .
    Not trying to sound like a ass, but sometimes IDEs overdo things. I thing, that should be simpler.
    Although this is not related to Ruby part of IDE.

    ReplyDelete
  7. Thanks for your quick response. I'll wait for Martin's fix for the debugger toolbar. In the meantime, I'm relying on this cheat sheet ;-)
    On the bundles topic: is there a way to export snippets "en masse"?

    ReplyDelete
  8. So I broke down and just downloaded Netbeans (I'm an IntelliJ user with the Ruby Plugin)... I'm impressed, but I have a question.
    Is there an equivalent for the CTRL-N or CTRL-SHIFT-N in Intellj (CTRL-R in Eclipse)? The "super open" command where you can put in a partial name and select from the results for a class/file... This is the single biggest, most useful feature in an IDE IMO. I don't see it...
    Thanks,
    phil

    ReplyDelete
  9. Is there a way to set a conditional breakpoint? I've tried Ctrl+Shift+F8 without any result.
    Thanks,
    - Eugene

    ReplyDelete
  10. FYI - the debugger toolbar issue has been fixed for the slim Ruby IDE, so go ahead and try it!

    ReplyDelete
  11. Hi Tor,
    great stuff. Is there any support for cross-platform remote debugging? IE, running my web-server on ubuntu and debugging from netbeans running on windows?

    ReplyDelete
  12. Hi Stephen. This is not supported yet. However it is supported by the backends. At least by Kent's ruby-debug. So it should not be problem to add it. I've filed an RFE for it. You may add yourself to the CC. Thanks for the feedback.

    ReplyDelete
  13. Yes the debugging toolbar now works perfectly in the slim Ruby IDE. Thanks for the quick turnaround!

    ReplyDelete
  14. Since build 1301 I get this error when trying to use Ruby with NetBeans 6.0M9:
    "Warning - could not install some modules:
    Common Scripting Language Support - The module Experimental Editor Hints SPI was requested in implementation version "4" but only "3" was found.
    7 further modules could not be installed due to the above problems."
    I have removed my .netbeans dir but it doesn't help.

    ReplyDelete
  15. Yep. Catch-22: using M9 netbeans w/ trunk ruby plugin doesn't work, but using rubyide build prevents using my jvi plugin for vi keybindings. I guess I am stuck waiting for the new hotness :)

    ReplyDelete
  16. I downloaded the newest nightly build and it seems to work fine.
    http://bits.netbeans.org/download/6.0/nightly/

    ReplyDelete
  17. Wow, first of all I'm impressed with the Ruby support built in Netbeans. Kudos!
    After reading the wiki, I was really excited to learn about fast debugger support and rpsec support! I finally got fast debugger and rspec working, but I can't debug rspec specs. It looks like the IDE does a run rather than a debug on rspec specs. Any idea?
    I went to a bit of trouble to make my setup work though. To let others know, I'm running Ubuntu 7.04. The only way I could make fast debugger and rspec support work was to have my own writable installation of ruby with rubygems installed. I then used that install and downloaded the rspec and ruby-debug-ide gems using the Ruby Gems manager.
    The hard part was installing ruby from source with rubygems support (ran into zlibc install issues).
    I wanted to post the steps on how to do that on the wiki, but I get an error trying to register. Will try later or I can send you an email with the instructions if you'd like.

    ReplyDelete
  18. I've updated the wiki entry http://wiki.netbeans.org/wiki/view/RubyGems with instructions for setting up a private installation of ruby on Ubuntu. I hope that will help some of you.

    ReplyDelete
  19. Hey Tor, re: jvi, to be honest, I don't know much about how it is implemented. When I tried installing the plugin to rubyide it said I had missing dependencies (5-6 of them) and they all said large scary things like "Java Platform Support" etc.
    And yeah, the Java 6 dependency is pretty annoying. I don't know why he implemented it using those collections since it makes things difficult for those of us on Mac OSX. I had to install the Apple preview distribution of Java 6 in order to get vi in netbeans :P

    ReplyDelete
  20. Great Tor,
    RSpec debuuging works perfectly. Have you planned adding a interactive mode to the debugger? I'd like to be able to stop at a break point and start an embedded irb session ... That would be really great

    ReplyDelete
  21. Hi Tor,
    I must be missing something but I can't make tests debugging work in my rails application. Rails debugging works fine though. But test debugging seems to do a run rather than a debug. I set the debugger to verbose mode but I don't see any output. Any idea?
    Also, the Test menu item under Run -> Run File does nothing. The Debug Test for file is grayed out, so I suspect it's an upcoming feature.
    Thanks for your help

    ReplyDelete
  22. I'm using the Ruby ide only build 070604

    ReplyDelete
  23. Hi Vincent,
    I'm not sure - but Martin Krauskopf who wrote the Ruby debugger in NetBeans is coming back from vacation in just a couple of days now and I'm sure he will be able to look into it and fix this.

    ReplyDelete
  24. Greg, regarding jvi for NetBeans requiring Java 6 and the Mac Java 6 VM having problems: jVi 1.0.0.beta2 was just announced and it claims to support Java 5.

    ReplyDelete