Skip to content
banister edited this page Feb 15, 2012 · 12 revisions

Pry Stack explorer

Quick Menu:

Overview

...FIXME...

Back to the top

The show-stack command

The show-stack command is used to display the current backtrace. Unlike the normal Ruby caller method, it only displays those frames that are accessible to Pry -- so frames for C functions are skipped. show-stack also displays more information about each frame, including the frame type, and the class-name.

The following options are supported:

  • Use the -v option to include extra information such as the file and line associated with the frame.
  • Use the -H option to display the first N stack frames (defaults to 10).
  • Use the -T option to display the last N stack frames (defaults to 10).
  • Use the -c option to display N frames either side of current frame (default to 5).

Example: Using -c switch to display 1 frame either side of current

[9] (pry) main: 0> show-stack -c 1

Showing all accessible frames in stack (6 in total):
--
   #2 [method]  parse_options <Pry::CLI.parse_options(args=?)>
=> #3 [top]     <top (required)> 
   #4 [eval]    <main> 

Back to the top

The up command

This command moves up to the parent frame. It also accepts optional numeric parameter for how many frames to move up.

Example: Moving up 2 frames

[11] (pry) main: 0> up 2

Frame number: 2/5
Frame type: method

From: /Users/john/.rvm/gems/ruby-1.9.3-p0/gems/pry-0.9.8.2/lib/pry/cli.rb @ line 59 in Pry::CLI.parse_options:

    54: 
    55:       def parse_options(args=ARGV.dup)
    56:         raise NoOptionsError, "No command line options defined! Use Pry::CLI.add_options to add command line options." if !options
    57: 
    58:         opts = Slop.parse(args, :help => true, :multiple_switches => false, &options)
 => 59:         option_processors.each { |processor| processor.call(opts) } if option_processors # option processors are optional
    60: 
    61:         self
    62:       end
    63: 
    64:     end

[12] (pry) Pry::CLI: 0> 

Back to the top

The down command

This command moves down to the callee frame. It also accepts optional numeric parameter for how many frames to move down.

Example: Moving down 1 frame

[3] (pry) main: 0> down

Frame number: 0/14
Frame type: method

From: (pry) @ line 5 in Object#beta:

    1: def alpha
    2:   beta
    3: end
    4: def beta
 => 5:   binding.pry
    6: end

[4] (pry) main: 0> 

1. Block-form

The general form takes a block, the block is passed both the frame where the exception was raised, and the exception itself. The user then creates an assertion (a stack-assertion) based on these attributes. If the assertion is later satisfied by a raised exception, that exception will be intercepted.

The first parameter yielded to the block is a PryExceptionExplorer::LazyFrame instance ( representing the context where the exception was raised), the second is the exception object.

The PryExceptionExplorer::LazyFrame instance supports a number of methods that expose details of the stack frame:

Clone this wiki locally