RubyMotion, SublimeText, and Breakpoints


RubyMotion released a new build today which supports GDB debugging. I did my early Flash games with just a text editor, the command-line compiler, and FDB, so the concept of a command-line debugger isn’t totally foreign. Still, I’ve gotten pretty used to nice GUI debugging tools. Those are hopefully on the way for RubyMotion, but in the meantime I wanted to see if there was anything I could do. The debugger in RubyMotion supports a simple debugger_cmds file with breakpoint commands, so the first thing I looked for was a way to set breakpoints in TextMate (even keeping them in a file somewhere). At worst, I figured I could put some comments (“#BP:blahblahblah”) and do something similar to the TODO viewer. Cumbersome, annoying to disable… not the best idea.

While looking around, I stumbled across the SublimeGDB package for Sublime Text 2, along with a couple of RubyMotion bundles for making builds easier (a syntax bundle and a build helper called SublimeRubyMotionBuilder). That was enough to give it a shot. I’m pretty new to Sublime, Python, and GDB–so I had no luck trying to get RubyMotion to connect with it out of the box. I imagine RubyMotion is doing some alchemy under the hood, but I was willing to settle for visual breakpoints.

The SublimeGDB has a “view breakpoints” action, but this doesn’t map exactly to a file. There’s probably a cleaner way to access the data directly, but here’s what I settled on:

Within RubyMotionBuilder.py (in SublimeRubyMotionBuilder), I duplicated the “RubyMotionRun” action into “RubyMotionDebug” (along with creating a corresponding rubymotion_debug.sh and adding entries to the command/menu/keymap). That function already finds the Rakefile for the RubyMotion project, then calls out to a shell script. Here’s my RubyMotionDebug function:

[gist id=3759265]

The sleep is a little dirty, but I kept ending up with an empty paste buffer because of the time needed to render the BreakpointView. There’s probably some way in Python to check if gdb_open_breakpoint_view has been defined (i.e. the SublimeGDB package is installed), but I’m pretty content with it for personal use. I’ll probably map the Toggle Breakpoint command to something a little easier (currently you have to right click and select the menu item), but it’s a pretty compelling reason to use SublimeText for doing RubyMotion development (also the autocomplete seems a lot better).

RubyMotion + Break Points

 

Update: I put all my tweaks in a fork over at github (https://github.com/SimianLogic/SublimeRubyMotionBuilder). Just add a package repository in sublime, delete the old SublimeRubyMotionBuilder, and install the one from my fork. I don’t want to submit it as an actual Sublime Package because (1) I don’t know how (and am lazy), (2) there’s still a dependency on SublimeGDB which means it can’t stand on its own as a package, and (3) I’m sure the guys at RubyMotion are working on better tools anyway. This is a temp hack at best!

, ,

  1. #1 by Christian on 09/22/2012 - 7:03 am

    Hi this sounds like a very nice way to debug!

    I was unable to get it to work in my sublime text. Would you be willing to add this as a sublime text package so others can install it via the package manager?

    cheers,

    Christian

(will not be published)