From 5ef817cc753bd564b2a1d7fbd9d308c641026ee6 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Fri, 20 Jan 2012 01:08:28 -0800 Subject: [PATCH] Fix pry-backtrace with Pry.start, improve docs. [Fixes #379] --- lib/pry/default_commands/context.rb | 7 ++++++- lib/pry/pry_class.rb | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/pry/default_commands/context.rb b/lib/pry/default_commands/context.rb index fbd501d9..a2706b5a 100644 --- a/lib/pry/default_commands/context.rb +++ b/lib/pry/default_commands/context.rb @@ -168,7 +168,12 @@ class Pry banner <<-BANNER Usage: pry-backtrace [OPTIONS] [--help] - Show the backtrace for the Pry session. + Show the backtrace for the position in the code where Pry was started. This can be used to + infer the behavior of the program immediately before it entered Pry, just like the backtrace + property of an exception. + + (NOTE: if you are looking for the backtrace of the most recent exception raised, + just type: `_ex_.backtrace` instead, see https://github.com/pry/pry/wiki/Special-Locals) e.g: pry-backtrace BANNER diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb index 62d36fb8..e4b52f93 100644 --- a/lib/pry/pry_class.rb +++ b/lib/pry/pry_class.rb @@ -113,7 +113,10 @@ class Pry pry_instance = new(options) # save backtrace - pry_instance.backtrace = caller.tap(&:shift) + pry_instance.backtrace = caller + + # if Pry was started via binding.pry, elide that from the backtrace. + pry_instance.backtrace.shift if pry_instance.backtrace.first =~ /pry.*core_extensions.*pry/ # yield the binding_stack to the hook for modification pry_instance.exec_hook(