Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
better backtrace cmd for pry-byebug
class Byebug::PryProcessor
CMDS = %i[
backtrace
down
finish
frame
next
step
up
]
def perform(action, options = {})
return unless CMDS.include?(action)
send("perform_#{action}", options)
end
end
class BetterBT < Pry::ClassCommand
include PryByebug::Helpers::Navigation
match "bt"
group "Byebug"
description "Display the current (filtered) stack."
banner <<-BANNER
Usage: bt
Display the current stack, filtered of extra crap.
BANNER
def process
PryByebug.check_file_context(target)
breakout_navigation :bt
end
class Cmd < Byebug::WhereCommand
def print_backtrace
relevant_context = context.stack_size.times.reject { |index|
context.frame_file(index) =~ %r%/(gems|ruby)/%
}
bt = prc('frame.line', relevant_context) do |index, _|
Byebug::Frame.new(context, index).to_hash
end
print(bt)
end
end
module PerformBT
Byebug::PryProcessor::CMDS.unshift :bt
Byebug::PryProcessor.include self
def perform_bt(_options)
BetterBT::Cmd.new(self, "bt").execute
resume_pry
end
end
end
Pry::Commands.add_command(BetterBT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.