22

I am trying to use the ruby debugger in a Rails app.

What command do I need to type at the (rdb:1) prompt in order to display a stack trace? I've tried backtrace, but it only lists the topmost frame.

1

3 Answers 3

41

http://apidock.com/ruby/Kernel/caller

caller(0)  # Returns the stack trace, omitting 0 initial entry.
Sign up to request clarification or add additional context in comments.

1 Comment

just puts caller
8

That's a bug in debugger. If you are using Ruby >= 2.0, I suggest you use byebug. The issue is solved there since version 1.5.0. This is the bug report in the debugger repo and this is the workaround suggested there:

pp caller.drop_while {|e| e[/ruby-debug|\(eval\)|debugger|\<internal:prelude\>/] }

Comments

1

Pry gem does have a plugin pry-stack_explorer can display stack

Example: Moving around between frames

[8] pry(J)> show-stack

Showing all accessible frames in stack:
--
=> #0 [method]  c <Object#c()>
   #1 [block]   block in b <Object#b()>
   #2 [method]  b <Object#b()>
   #3 [method]  alphabet <Object#alphabet(y)>
   #4 [class]   <class:J>
   #5 [block]   block in <main>
   #6 [eval]    <main>
   #7 [top]     <main>
[9] pry(J)> frame 3

Frame number: 3/7
Frame type: method

From: /Users/john/ruby/projects/pry-stack_explorer/examples/example.rb @ line 10 in Object#alphabet:

     5:
     6: require 'pry-stack_explorer'
     7:
     8: def alphabet(y)
     9:   x = 20
 => 10:   b
    11: end
    12:
    13: def b
    14:   x = 30
    15:   proc {
[10] pry(J)> x
=> 20

Further, it has lot of other features that are missing from ruby debugger. so I would suggest you try pry & its plugins

1 Comment

I've followed the steps at github.com/pry/pry/wiki/Setting-up-Rails-or-Heroku-to-use-Pry but it doesn't help. show-stack just gets me an error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.