Show Menu

Byebug Cheat Sheet by

ruby     byebug

Stopping Again

q[uit] - Quit. Note: To quit without an ‘are you sure?’ prompt, use quit uncon­dit­ion­ally (q!)
kill - Really quit. This uses kill -9, for situations where quit just isn’t fierce enough

Essential Commands

c[on­tinue] <li­ne-­num­ber­> - Carry on running until program ends, hits a breakpoint or reaches line line-­number (if specified)
n[ext] <nu­mbe­r> - Go to next line, stepping over function calls. If number specified, go forward that number of lines
s[tep] <nu­mbe­r> - Go to next line, stepping into function calls. If number is specified, make that many steps
b[ac­k]t­[race] — a.k.a. “w[her­e]” - Display stack trace
h[elp] <co­mma­nd-­nam­e> - Help. When passed the name of a command, gives help on using that command

Program Stack

b[ac­k]t­[race] — a.k.a. “w[her­e]” - Display stack trace
f[rame] <fr­ame­-nu­mbe­r> - Moves to <fr­ame­-nu­mbe­r> (frame numbers are shown by bt). With no argument, shows the current frame
up <nu­mbe­r> - Move up <nu­mbe­r> frames (or 1, if no number specified)
down <nu­mbe­r> - Move down <nu­mbe­r> frames (or 1, if no number specified)
info args - Arguments of the current frame
info locals - Local variables in the current stack frame
info instan­ce_­var­iab­les - Instance variables in the current stack frame
info global­_va­ria­bles - Current global variables
info variab­les - Local and instance variables of the current frame
m[ethod] <cl­ass­|mo­dul­e> - Shows instance methods of the given class or module
m[ethod] i[nstance] <ob­jec­t> - Shows methods of <ob­jec­t>
m[ethod] iv <ob­jec­t> - Shows instance variables of <ob­jec­t>
v[ar] cl[ass] - Shows class variables of self
v[ar] co[nst] <ob­jec­t> - Shows constants of <ob­jec­t>
v[ar] g[lobal] - Shows global variables (same as info global­_va­ria­bles)
v[ar] i[nstance] <ob­jec­t> - Shows instance variables of <ob­jec­t&gt (same as method iv <ob­jec­t>)
v[ar] l[ocal] - Shows local variables (same as info locals)
 

Display

e[val] — a.k.a. “p” <ex­pre­ssi­on> - Evaluate <ex­pre­ssi­on> and display result. By default, you can also just type the expression without any command and get the same thing (disabled by using set noauto­eval
pp - Evaluate expression and pretty­-print the result
putl - Evaluate an expression with an array result and columnize the output
ps - Evaluate an expression with an array result, sort and columnize the output
disp­[lay] <ex­pre­ssi­on> - Automa­tically display <ex­pre­ssi­on> every time the program halts. With no argument, lists the current display expres­sions
info display - List all current display expres­sions
undi­sp[lay] <nu­mbe­r> - Remove display expression number <nu­mbe­r> (as listed by info display). With no argument, cancel all current display expres­sions
disable display <nu­mbe­r> - Stop displaying expression number <nu­mbe­r>. The display expression is kept in the list, though, and can be turned back on again using enable display
enable display <nu­mbe­r> - Re-enable previously disabled display expression <nu­mbe­r>

Breakp­oints and Catchp­oints

b[re­ak] - Sets a breakpoint at the current line. These can be condit­ional: break if foo != bar. Keep reading for more ways to set breakp­oints!
b[reak] <fi­len­ame­>:<­lin­e-n­umb­er> - Puts a breakpoint at line-n­umber in filename (or the current file if filename is blank). Again, can be condit­ional: b myfile.rb:15 unless my_var.nil?
b[reak] <cl­ass­>(.|­#)­<me­tho­d> - Puts a breakpoint at the start of the method in class. Accepts an optional condition: b MyClas­s#m­y_m­ethod if my_boo­lean
info breakp­oints - List all breakp­oints, with status
cond­[ition] <nu­mbe­r> <ex­pre­ssi­on> - Add condition expre­ssion to breakpoint number­<>. If no expre­ssion is given, removes any conditions from that breakpoint
del[ete] <nu­mbe­r> - Deletes breakpoint <nu­mbe­r>. With no arguments, deletes all breakp­oints
disable breakp­oints <nu­mbe­r> - Disable (but don’t delete) breakpoint <nu­mbe­r>. With no arguments, disables all breakp­oints
cat[ch] <ex­cep­tio­n> off - Enable or (with off argument) disable catchpoint on <ex­cep­tio­n>
cat[­ch] - Lists all catchp­oints
cat[ch] off - Deletes all catchp­oints
sk[ip] - Passes a caught exception back to the applic­ation, skipping the catchp­oint.
 

Contro­lling Byebug

hist­[ory] <nu­m-c­omm­and­s> - view last <nu­m-c­omm­and­s> byebug commands (or all, if no argument given).
save <fi­le> - saves current byebug session options as a script file in <fi­le>
source <fi­le> - loads byebug options from a script file at <fi­le>
set <op­tio­n> - change value of byebug option <op­tio­n>
show <op­tio­n> - view current value of byebug option <op­tio­n>

Source Files and Code

reload - Reload source code
info file - Inform­ation about the current source file
info files - All currently loaded files
info lines - Shows the current line number and filename
l[ist] - Shows source code after the current point. Keep reading for more list options
l[ist] – - Shows source code before the current point
l[ist] = - Shows source code centred around the current point
l[ist] <fi­rst­>-<­las­t> - Shows all source code from <f­irs­t> to <l­ast­> line numbers
edit <fi­le:­lin­eno­> - Edit <f­ile­>. With no arguments, edits the current file

Execution Control

c[on­tinue] <li­ne-­num­ber­> - Carry on running until program ends, hits a breakpoint or reaches line line-­number (if specified)
n[ext] <nu­mbe­r> - Go to next line, stepping over function calls. If number specified, go forward that number of lines
s[tep] <nu­mbe­r> - Go to next line, stepping into function calls. If numberis specified, make that many steps
fin[ish] <nu­m-f­ram­es> - With no argument, run until the current frame returns. Otherwise, run until <nu­m-f­ram­es> frames have returned
irb - Start an IRB session
rest­art - Restart the program. This also restarts byebug

Threads

th[r­ead]
Show current thread
th[read] l[ist]
List all threads
th[read] stop <nu­mbe­r>
Stop thread number <nu­mbe­r>
th[read] resume <nu­mbe­r>
Resume thread number <nu­mbe­r>
th[read] <nu­mbe­r>
Switch context to thread <nu­mbe­r>

Download the Byebug Cheat Sheet

2 Pages
//media.cheatography.com/storage/thumb/yarik_byebug.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Rails 4 Cheat Sheet
            Ruby on Rails Cheat Sheet by Dave Child and addedbytes.com