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.
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.
http://apidock.com/ruby/Kernel/caller
caller(0) # Returns the stack trace, omitting 0 initial entry.
puts callerThat'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\>/] }
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