Note: This code is still at the incredibly rough, proof-of-concept stage with no test coverage, and shouldn't be considered usable for any kind of actual real debugging yet. But if you're interested in building a new kind of debugger, I'd love some help.
Panorama is a web-based visual debugger that's different from most. It's primarily inspired by the ideas of Bret Victor, especially those he presented in his essay Learnable Programming. It uses Ruby 2.0's new TracePoint API. I introduced it during my talk "Programming is Debugging, So Debug Better" at Open Source Bridge 2013.
Rather than stepping through your code in progress, it gathers all the data it can and presents it after execution has finished. It shows you:
- every invocation of a Ruby method, whether in your code or someone else's
- the arguments and return value of each method invocation
- which lines were executed during that invocation
- the values of each local variable at that line
To be the debugging tool you use instead of adding puts
statements all over your code.
This sounds like an easy goal. However, all the top Ruby coders I've interviewed about this (at least four of them - see this slide) use puts
as their first resort when debugging. So, can we make a better replacement?
Laughably poor. There's so much to be done:
- Gem packaging
- Actual tests
- Actual documentation
- Proper Sinatra app setup (using Vegas?)
- Colour the run lines properly
- Are we handing exceptions correctly? How about passed blocks? Anything else?
- Macros to invoke from within editors
- Link to a test runner, so the code can be re-run continually
- Bret-tastic loop value display
- Can it work using Ruby 1.9's
set_trace_func()
? - Some kind of thread/concurrency safety would be good - at present, it does Stupid Things With Globals
- A billion other things
Some of this work has started in the not_laughable branch.
At present, Ruby 2.0 is required. If you need to run earlier versions of Ruby as well, I highly recommend the excellent rbenv
- Clone the repo to a nearby ditch
- Run
bundle install
. (If you don't havebundler
installed yet:gem install bundler
) - To start the webapp:
bundle exec rerun gazer.rb
- Once you see
Listening on localhost:4567, CTRL+C to stop
, visit (http://localhost:4567) in your browser.
At present, the work is split between
panorama.rb
- a set of TracePoint hooks which build an in-memory profile of running codegazer.rb
- a minimal Sinatra app which can invoke Panorama, then present the results as a browsable dataset
Once you have it running locally, click this for a browsable example: http://localhost:4567/?codefile=.%2Fweb-test.rb
If you want to try using Panorama's TracePoint hooks without the web app, cli-test.rb
is a simple example.
I'm Yoz Grahame, and I work for 18F.
Problems or patches? Check the issues, and if it you don't see your question addressed, add one.
If this code is remotely interesting to you, I'd love to know. Send me email (I bet you can work it out) or tweet at me.