When, during a pry debug session, I want to inspect step-by-step execution of FooClass.new.foo
I'd do this in pry console
$ FooClass.new.foo #this gives me path and line of the method
break /path/to/foo_class.rb:LINE_WHERE_FOO_IS_DEFINED
FooClass.new.foo
This works but I need to look for the path, line and it leaves a breakpoint I sometimes have to remove.
There's a faster way:
break FooClass#foo
FooClass.new.foo
but it's still two steps, and the breakpoint stays.
Is there a way to do it in one command, like
step-into FooClass.new.foo
which would start a Pry subsession, enter the method execution and after it exits/finishes I'm back in the original session with no extra breakpoints left?
In other words: I'm in the middle of debugging, and see a method called few lines before (I can't step into it immediately). I don't want to put a binding.pry
in the source (it may take a lot of time to start the debugging session again).
step into -> go into the subroutine and wait for next action. step over -> jump over the subroutine without waiting again. step out -> if you are in the subroutine, you will leave it without waiting again.
Force step over From the main menu, select Run | Force Step Over or press Alt+Shift+F8 .
Step into – An action to take in the debugger. If the line does not contain a function it behaves the same as “step over” but if it does the debugger will enter the called function and continue line-by-line debugging there.
When you are on a line of code that is a function or method call, you can press F10 (Debug > Step Over) instead of F11. F10 advances the debugger without stepping into functions or methods in your app code (the code still executes).
The problem has hidden complexity. For instance, one thing you can do is:
pry Foo.new.foo
or
Foo.new.foo.pry
This puts you into a binding on the return value of the function foo
, but that is not what you want. It also shows there is complexity when your line of code Foo.new.foo
runs, for a function to know what exactly to put a binding on.
So that's really the problem I feel; it would take understanding of the expression on the line to understand where to put a breakpoint. If you imagine it was working like the step
function.
If your code Foo.new.foo
was already a break point (e.g. you had a function with that code in and you put a breakpoint on a line like that) then you typed step
, you would go into Foo.new
Foo.initialize
instance of foo
foo.foo
and so on. So, any code trying to do what you would like it to do would have a very hard time understanding where in the expression tree to stop and put your into pry
.
This is why you have to tell pry
where to stop using break
in this context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With