Cheatsheet
Last updated
Last updated
Taken from
If you’re running Byebug on a Rails application in development mode, you no longer need to start the server with --debugger
– the debugger is on by default.
To get going, simply type byebug
(or debugger
) into your source file at the line you’re interested in and run the program. If you’re running it on a Rails application, remember to switch to your terminal window to look at debugger output.
Note: byebug
invocations are just method calls, so you can make them conditional:
Another Note: As is common with debuggers, hitting ‘Enter’ on an empty line in Byebug repeats the last command.
Quit. It stops the thing running. Also exits your program.Note:** To quit without an ‘are you sure?’ prompt, use quit unconditionally
(shortened to q!
)
Really quit. This uses kill -9
, for situations where quit just isn’t fierce enough.
Carry on running until program ends, hits a breakpoint or reaches line line_number (if specified).
Go to next line, stepping over function calls. If number specified, go forward that number of lines.
Go to next line, stepping into function calls. If number is specified, make that many steps.
Get help. With no arguments, returns a list of all the commands Byebug accepts. When passed the name of a command, gives help on using that command.
Puts a breakpoint at line-number in filename (or the current file if filename is blank). Again, can be conditional: b myfile.rb:15 unless my_var.nil?
Puts a breakpoint at the start of the method method in class class. Accepts an optional condition: b MyClass#my_method if my_boolean
List all breakpoints, with status.
Add condition expression to breakpoint <number<>>. If no expression is given, removes any conditions from that breakpoint.
Deletes breakpoint <number>. With no arguments, deletes all breakpoints.
Disable (but don’t delete) breakpoint <number>. With no arguments, disables all breakpoints.
Enable or (with off argument) disable catchpoint on <exception>.
Lists all catchpoints.
Deletes all catchpoints.
Passes a caught exception back to the application, skipping the catchpoint.
Moves to <frame_number> (frame numbers are shown by bt
). With no argument, shows the current frame.
Move up <number> frames (or 1, if no number specified).
Move down <number> frames (or 1, if no number specified).
Arguments of the current frame.
Local variables in the current stack frame.
Instance variables in the current stack frame.
Current global variables.
Local and instance variables of the current frame.
Shows instance methods of the given class or module.
Shows methods of <object>.
Shows instance variables of <object>.
Shows class variables of self.
Shows constants of <object>.
Shows global variables (same as info global_variables
).
Shows instance variables of \ (same as method iv <object>
).
Shows local variables (same as info locals
).
Carry on running until program ends, hits a breakpoint or reaches line <line_number> (if specified).
Go to next line, stepping over function calls. If <number> specified, go forward that number of lines.
Go to next line, stepping into function calls. If <number> is specified, make that many steps.
With no argument, run until the current frame returns. Otherwise, run until <num_frames> have returned.
Start an IRB session. This will have added commands cont
, n
and step
, but these can’t take arguments (unlike the proper byebug commands of the same name).
Restart the program. This also restarts byebug.
Show current thread.
List all threads.
Stop thread number <number>.
Resume thread number <number>.
Switch context to thread <number>.
Evaluate <expression> and display result. By default, you can also just type the expression without any command and get the same thing (disabled by using set noautoeval
).
Evaluate expression and pretty-print the result.
Evaluate an expression with an array result and columnize the output.
Evaluate an expression with an array result, sort and columnize the output.
Automatically display <expression> every time the program halts. With no argument, lists the current display expressions.
List all current display expressions.
Remove display expression number <number> (as listed by info display
). With no argument, cancel all current display expressions.
Stop displaying expression number <number>. The display expression is kept in the list, though, and can be turned back on again using enable display
.
Re-enable previously disabled display expression <number>.
View last <num_commands> byebug commands (or all, if no argument given).
Saves current byebug session options as a script file in <file>.
Loads byebug options from a script file at <file>.
Change value of byebug option <option>.
View current value of byebug option <option>.
Options are:
autoeval
autoirb
autolist
autoreload
autosave
basename
callstyle
forcestep
fullpath
histfile
histsize
linetrace
tracing_plus
listsize
post_mortem
stack_on_error
testing
verbose
width
Reload source code.
Information about the current source file.
All currently loaded files.
Shows the current line number and filename.
Shows source code after the current point. Keep reading for more list options.
Shows source code before the current point.
Shows source code centred around the current point.
Shows all source code from <first> to <last> line numbers.
Edit <file>. With no arguments, edits the current file.
Display .
Sets a at the current line. These can be conditional: break if foo != bar
. Keep reading for more ways to set breakpoints!
Display .