Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I quit from debugger without exiting my IRB session?

This is a long standing source of frustration, but maybe there is something I'm missing. If i'm in the middle of debugging, and I want to exit the debugger and return to IRB or Rails Console, "quit" won't work as it will exit IRB. "finish" also seems to have the same effect as continue. Using "delete" to remove breakpoints and then trying "continue" or "finish" doesn't work.

Any ideas?

like image 923
Jeremy Smith Avatar asked Nov 12 '11 18:11

Jeremy Smith


People also ask

How do I exit debugger?

To exit debug mode, press Alt+B followed by D. at the Command Prompt to exit debug mode.

How do you exit a debugger in rails?

You can exit the debugging session at any time and continue your application execution with the continue (or c ) command. Or, to exit both the debugging session and your application, use the quit (or q ) command.

How do you stop a GDB program?

To stop your program while it is running, type "(ctrl) + c" (hold down the ctrl key and press c). gdb will stop your program at whatever line it has just executed. From here you can examine variables and move through your program.

How do you get out of Byebug?

To exit byebug , use the quit command (abbreviated to q ). Normally, if you are in an interactive session, this command will prompt to ask if you really want to quit. If you want to quit without being prompted, enter quit unconditionally (abbreviated to q! ).


2 Answers

At least in byebug, you can do this:

eval return

Which has the net effect of evaluating a return statement from the current function. That works sometimes, depending on how the call stack looks.

Now while this doesn't remove the current breakpoint .... if you just want control back, this will do that in most cases, depending on how your code is structured.

It also is useful to do this when creating a debug entry in your code:

byebug unless $continue

So if all else fails in a debugging session, you can always run

$continue = true
c

Now this opens up a whole set of possibilities.

like image 95
Bret Weinraub Avatar answered Sep 21 '22 04:09

Bret Weinraub


This SO question has a few good suggestions. It deals with specifically with debugging inside of loops. One great solution is to set the break point outside the loop, then from irb set it inside the loop and clear it manually when you want to.

Basically it comes down to putting a little bit of thought into where you set your breakpoints.

Other than that there doesn't appear to be anything else you can do.

like image 39
Dty Avatar answered Sep 22 '22 04:09

Dty