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
help
command 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 methodsn
times -
next [n]
-- Runsn
lines of code within the same frame
Stacktrace
-
frame [n]
-- Moves to a frame in then
-th call stack- You can use
where
to 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-f
lists lines fromd
tof
-
-
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
-
args
of 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 display
can be used to show all id's of displayed variables
-
-
condition <i>[ <expression>]
-- Sets conditions on breakpointi
to stop only when<expression>
is true-
info breakpoints
can 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
byebug
supports 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 linen
in 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 thedelete
command- Use
info breakpoints
to 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.:
-
c
instead ofcontinue
- You can also use
c!
- You can also use
-
s
instead ofstep
-
l=
instead oflist=
Posted by Felix Eschey to makandra dev (2023-07-06 11:51)