the blog
Back to -Blog

The Call Stack - Debugging Ruby ’Backwards’

The Call Stack gives you a view into your program’s recent past
by Huw Collingbourne
Thursday 15 March 2007.

The Call Stack gives you a great way to ‘trace backwards’ through the execution of your Ruby programs. Whereas a breakpoint shows you where you are at a given moment in the life of your program, the call stack shows you where you have been.

Each time you step into a new method with the debugger, a new entry is added to the call stack [1]. So, if you enter method x, the call stack pane shows x along with (optionally) some other information such as the name of the source file and the line number. If some code in the x method calls the y method, the call stack will show entries for x and for y. But these are not just static indicators of the methods which your program has passed through; they are active ‘moments’ in the flow of execution which can be recalled just by clicking each entry in the call stack.

So if, for example, you have a parameter called aString which has the value “hello world” when it is passed to x; has been changed to “HELLO WORLD” by the time it is passed to y and has become “DLROW OLLEH” when it arrives at z, you can flip up and down the call stack, recalling each point of execution – each ‘moment in the history’ of the program – and view the changing values of aString at each point.

This even works with recursive methods. If a method calc increments a variable sum as it repeatedly calls itself, you can navigate up and down each separate instant at which the calc method was recursively called to check on the changing value of sum.

The call stack is a tremendously useful debugging tool. Be sure to check it out!

- Watch A Screencast of the Call Stack
- Watch More Ruby In Steel Screencasts

[1] Note: Some features of the call stack shown in this article and in the screencast are only available in versions of Ruby In Steel Developer later than 1.00.0212 which will be made available as a free update to registered users before the end of March, 2007

Bookmark and Share   Keywords:  ide
© SapphireSteel Software 2014