Context and further resources
Even though you can get 90% of debugging done with up to 5 basic byebug commands, it comes in handy with it's features for many use cases beyond that to make your life easier.
For this cheatsheat I tried to structure the most useful commands by different use cases, such that a practical oriented overview of all the commands can be gathered by going over this cheatsheet. For some commands I added some tips for their usage and further details on their subcommands
- For most of the commands shortly explained here, there are some examples along with a listing of all commands in the byebug guide Show archive.org snapshot
- The linked cheatsheet at the bottom Show archive.org snapshot also includes some examples and all the aliases to every command with a different useful structuring of most of these commands
- You can also use the helpcommand anytime during a bybebug session to find out more about commands
Cheatsheet
General
- 
quit-- Exits byebug
- 
help <cmd> <subcmd>-- show information about any command with it's aliases and parameters- Can be used as help,help <cmd>andhelp <cmd> <subcmd>, ...
 
- Can be used as 
- 
history-- display history of commands
- 
irb-- starts an irb console which helps to execute any command that conflicts with byebug Show archive.org snapshot
Navigation within the executed program
Breakpoints
- 
continue [n]-- Runs until program ends, hits a breakpoint or reaches linen
- 
continue!- execute to end of program by ignoring all breakpoints
- 
skip-- Runs until the next breakpoint as long as it is different from the current one
Lines
- 
step [n]-- Steps into blocks or methodsntimes. If you accidentallystepped, you can return withfinish 1.
- 
next [n]-- Runsnlines of code within the same frame
Stacktrace
- 
frame [n]-- Moves to a frame in then-th call stack- You can use whereto find out the numbers
 
- You can use 
- 
finish [n]-- Runs the program until then-th frame returns
- 
up-- Moves to a higher frame in the stack trace
- 
down-- Moves to a lower frame in the stack trace
Find out context for the current debugging session (or breakpoint)
- 
where-- Displays the backtrace
- 
list [[-=]] [ nn-mm]-- Lists coming lines of source code from last breakpoint- 
list-lists previous code lines
- 
list=lists code from current line around that line
- 
list d-flists lines fromdtof
 
- 
- 
info [subcommand]-- Shows several informations about the program and the current debugging session,
 [subcommand]can be any of:- breakpoints
- 
display-- displayed variables
- 
file,line,program
- 
argsof the current stack frame
 
# Show archive.org snapshot Find out variables and methods
- 
var [type] [object]-- Shows specified variables and its values,
 [type](and possibly[object]) can be used as:- 
const <object>-- listing variables and their values in<object>.constant
- 
instance <object>-- listing<object>.instance_variables.
- 
instance-- instance_variables of self.
- 
local-- local variables.
- 
global-- global variables
 
- 
- 
method-- shows variables of specified object, class or module- 
method instance <object>-- The same as running<object>.instance_methods(false).
- 
method <class-or-module>-- The same as running<class-or-module>.methods.
 
- 
Commands to change (or add) behavior at breakpoints
- 
display/undisplay [<expression>]- display or undisplays an expression at stopped breakpoint- 
enable/disable [id]can be used activate and deactivate displayed values
- 
info displaycan be used to show all id's of displayed variables
 
- 
- 
condition <i>[ <expression>]-- Sets conditions on breakpointito stop only when<expression>is true- 
info breakpointscan be used to show all id's of breakpoints
 
- 
- 
catch <exception>-- Catches the specified exception- You can use the subcommands to turn off catching all together or only for specific exceptions:
- catch off
- catch <exception> off
 
 
- You can use the subcommands to turn off catching all together or only for specific exceptions:
- 
thread-- Commands to manipulate threads- If you ever have to deal with threads byebugsupports stopping, switching, resuming and listing all current threadsstopped at the breakpoint
 
- If you ever have to deal with threads 
Commands add (or delete) breakpoint(s)
- 
break [n]- Set breakpoint at linenin the current file- Can be used to add breakpoints at any file with break [<file>:]<line>
 
- Can be used to add breakpoints at any file with 
- 
delete-- All breakpoints can be deleted by using thedeletecommand- Use info breakpointsto find out the breakpoint's id
 
- Use 
Shortcuts
While debugging you don't have to type out all commands presented above. For most of them it is enough to type the first letter, e.g.:
- 
cinstead ofcontinue- You can also use c!
 
- You can also use 
- 
sinstead ofstep
- 
l=instead oflist=
Posted by Felix Eschey to makandra dev (2023-07-06 11:51)