pry-byebug: binding.pry doesn't fire when it's on the last line of a program
Failing case:
gem install pry-byebug
# test.rb
require 'pry'
binding.pry
Test: ruby test.rb. No pry shell opens.
Passing case:
gem uninstall pry-byebug
Or, add a line with assignment. Oddly enough, ending lines of comments or simply an ending line of 1 doesn’t workaround this.
# test.rb
require 'pry'
binding.pry
a = 1
Test: ruby test.rb. The pry shell opens.
The workaround is pretty simple. Ever since moving to ruby 2 and getting rid of pry-nav, I’ve just got in the habit of doing this. Logging an issue in case this is unexpected. 🍰
About this issue
- Original URL
- State: open
- Created 10 years ago
- Reactions: 7
- Comments: 34 (20 by maintainers)
Links to this issue
Commits related to this issue
- Proof of concept for #45 — committed to deivid-rodriguez/pry-byebug by deleted user 9 years ago
- Allow to pass options to Pry.start Adapted from JoshCheek code at https://github.com/deivid-rodriguez/pry-byebug/issues/45 This fixes https://github.com/ConradIrwin/pry-rescue/issues/71 — committed to DamienRobert/pry-byebug by deleted user 6 years ago
- Remove pry-byebug https://github.com/deivid-rodriguez/pry-byebug/issues/45 — committed to annict/annict by shimbaco 6 years ago
(╯°□°)╯︵ ┻━┻
Yeah, that makes sense. An alternative would be to leave it as a plugin, but one which you explicitly enter, eg a
debugcommand to turn it on, and until then, it just delegates down to pry. Another option would be a different method, egpry.debugso that the user could opt into the functionality of their preference.Really, the pain I’m trying to solve is that one of my projects has it as a dependency, so it gets installed with that project, and I didn’t really realize that. So, then when pry autoloads it, and it changes pry’s behaviour, the line numbers are off, so I thought pry was buggy for ~6 months, and finally sat down last night to report it / try to fix it. Anything which addresses this unintentional loading and changing is sufficient, IMO.
Do note that I may be an exception as I often work without bundler, allowing this situation to occur.
FWIW, I got it to behave the way I would expect (didn’t test much, just playing around):
After looking at it for a while and reading a lot of the byebug source, I finally realized that we mostly just needed to pass the supplied binding to pry on the first invocation, and then after that, it can behave the way it currently does.
It turned out to be a lot harder of a problem than I was would expecting, because
byebugseems to mostly just be a wrapper around the tracepoint API. So all it can really do is hook into tracepoint events. Because we startpry-byebugafter the call tobinding.pry, there are no more events on that line.Eg consider this program:
When we run it, we will see the tracepoint events. It prints:
So, we start on line 2, with a return from the C-function
set_trace_func, then move to theendon line 7, where we return froma. If we then moved to line 13, the location we are returning to, this would be easy, but tracepoint skips that and goes to the next event: moving to line 14.Frankly, it doesn’t seem very thought-out. Eg replace the line that says
bwithb;b;b, since both the call and the return pass the method’s binding, there doesn’t seem to be a way to get access to the caller between the invocations. Whenever I’ve played w/ this API in the past, I always had to track everything and re-construct the missing events/data to present a coherent picture. I’m not sure why byebug doesn’t do that.Also, here’s another example that I hit often, where the current implementation doesn’t work (I use big case statements when iterating over things like ASTs):
I’ve been recently considering to actually change the command to enter
pry-byebuginstead of reusingbinding.pry. That way the user would be able to choose whether (s)he wants step-by-step debugging or just a plain REPL (like in this case, since step-by-step debugging doesn’t make a lot of sense from the last line of a program).Would that be a satisfactory resolution for this issue?
@squarism Thanks for the feedback. I have that vim snippet too 😃