It is often difficult for me to debug endless recursions when ruby coding. Is there a way to get backtracking from a SystemStackError to find out exactly where the infinite loop happens?
Example
For some methods foo , bar and baz that call each other in a loop:
def foo bar end def bar baz end def baz foo end foo
When I run this code, I just get the message test.rb:6: stack level too deep (SystemStackError) . It would be useful to get at least the last 100 lines of the stack, so I could immediately see that this is a loop between foo , bar and baz , for example:
test.rb:6: stack level too deep (SystemStackError) test.rb:2:in `foo' test.rb:10:in `baz' test.rb:6:in `bar' test.rb:2:in `foo' test.rb:10:in `baz' test.rb:6:in `bar' test.rb:2:in `foo' [...]
Is there any way to do this?
EDIT:
As you can see from the answer below, Rubinius can do this. Unfortunately, some rubinius errors will prevent me from using it with software that I would like to debug. Therefore, to be precise, the question is:
How to get back trace with MRI (default ruby) 1.9?
ruby
iblue Jul 18 '12 at 15:05 2012-07-18 15:05
source share