How to add Reveal to your RubyMotion app without modifying the Rakefile

By markvillacampa on April 8, 2014 — 2 mins read


Add this lines to a file named debugger_cmds in the root of your RubyMotion app. Then run your app with rake debug=1 to have Reveal automatically loaded.

breakpoint set -n UIApplicationMain
breakpoint command add -s python -o 'lldb.debugger.HandleCommand("call (void*)dlopen(\"/Applications/\", 0x2)");lldb.debugger.HandleCommand("continue")'

Remember to add debugger_cmds to your gitignore file.

Long version

Reveal is an awesome tool to debug and modify iOS views during development. However you usually have to modify your Rakefile to load it, and it might not please your coworkers if you accidentally commit the changes.

Reveal connects to your app by loading a library, starting a Bonjour server and streaming data both ways. To include Reveal’s framework in your project you would usually do it in your Rakefile.

In order to avoid having to modify your project to load Reveal, we’re going to use LLDB and dinamically load the library at runtime.

Rubymotion will make LLDB execute all the commands in a file named debugger_cmds in the root of your project, as explained in the official Debugging RubyMotion applications guide.

First, we’ll set a breakpoing in UIApplicationMain.

breakpoint set -n UIApplicationMain

Then we will add a command to be executed when the previous breakpoint is hit. This command will automatically load the Reveal library using dlopen and continue the execution.

breakpoint command add -s python -o 'lldb.debugger.HandleCommand("call (void*)dlopen(\"/Applications/\", 0x2)");lldb.debugger.HandleCommand("continue")'

Some things to take into account:

  • The breakpoint command add documentation says we have to pass a breakpoint id as the last argument. However adding a command without an id assumes the last added breakpoint by default. I have not found documentation for this behaviour, but seems to work.

  • You normally have to add CoreGraphics, CFNetwork and QuartzCore frameworks to your app for Reveal to work. RubyMotion handily links against this frameworks automatically. This is undocumented behaviour but I can safely assume this is not going to change. However if your app uses one of those frameworks I recommend explicitly adding them in your Rakefile.

  • breakpoint command add accepts passing normal LLDB commands as argumennt, however I could not find how to add multiple commands in one line, so I opted to do it with a Python script which does allow for multiple commands in one line. If anyone knows a better solution please tell me 🙂