16

I type next on binding.pry or byebug to step over to the next line. I use step to step into the procedure. How do I step BACK a line?

I've been looking through documentation with no luck. Help greatly appreciated. Thanks.

Flip
  • 6,233
  • 7
  • 46
  • 75
jamesdlivesinatree
  • 1,016
  • 3
  • 11
  • 36
  • 11
    You don't step back. While there are some debuggers that do "time travel," allowing you to step backwards, Ruby does not have such a debugger. Once an instruction has been executed you can't go back to a state before it was executed. – Jordan Running May 05 '15 at 20:15
  • damn. alright, well, thanks for clearing that up. what languages do support 'time travel' ? – jamesdlivesinatree May 05 '15 at 20:30
  • Here's a discussion on Programmers Stack Exchange about "reverse debugging" that names a few technologies and gives some good background on the challenges involved: http://programmers.stackexchange.com/questions/181527/why-is-reverse-debugging-rarely-used – Jordan Running May 05 '15 at 20:33

4 Answers4

5

There is no way to step back when you using ByeBug.

Madao
  • 3,756
  • 1
  • 22
  • 16
2

You can make use of up & down methods in binding.pry

see here:

Frame number: 0/64

From: /Users/johnmair/ruby/rails_projects/personal_site/app/controllers/posts_controller.rb @ line 7 PostsController#index:

    5: def index
    6:   @posts = Post.all
 => 7:   binding.pry
    8: end

[1] pry(#<PostsController>)> show-stack

Showing all accessible frames in stack (65 in total):
--
=> #0  index <PostsController#index()>
   #1 [method]  send_action <ActionController::ImplicitRender#send_action(method, *args)>
   #2 [method]  process_action <AbstractController::Base#process_action(method_name, *args)>
   #3 [method]  process_action <ActionController::Rendering#process_action(*arg1)>
<... clipped ...>

[2] pry(#<PostsController>)> up

Frame number: 1/64
Frame type: method

From: /Users/johnmair/.rvm/gems/ruby-2.0.0-p0/gems/actionpack-3.2.8/lib/action_controller/metal/implicit_render.rb @ line 4 ActionController::ImplicitRender#send_action:

    3: def send_action(method, *args)
 => 4:   ret = super
    5:   default_render unless response_body
    6:   ret
    7: end

[3] pry(#<PostsController>)> 
Aniket Tiwari
  • 3,561
  • 4
  • 21
  • 61
0

Compromise solution is re-entering into execution of previous pieces of code with pry-moves.

For example if you stopped inside of Controller's action:

def index
    list = Orders.for_user(current_user) 
=>  binding.pry
end

And now you want to understand why is list empty? - You can run:

> debug Orders.for_user(current_user)

and check what's happening there


Why we have to use compromises? The problem is that ruby environment doesn't keep whole state of system on each step. Presumably it is because most probably you still will use external systems (e.g. by API calls) which may change their internal state and you can't automatically "roll it back".

Daniel Garmoshka
  • 5,849
  • 39
  • 40
0

There isn't a step back or undo step command listed on this Pry Cheat Sheet. I would suggest ctrl + c (x2), ctrl + d, the get back into your container and hit the binding pry again.

https://gist.github.com/lfender6445/9919357

Colleen Purcell
  • 473
  • 5
  • 7