Debugger
It
doesn’t matter how easy a language is to use, it usually
contains some bugs if it is more than a few lines long. To help deal
with bugs, the standard distribution of Ruby includes a debugger. In
order to start the Ruby debugger, load the debug library using the
command-line option -r debug. The debugger stops
before the first line of executable code and asks for the input of
user commands.
Here are the debugger commands:
b[reak] [<file|class>:]<line|method>Sets breakpoints
wat[ch]expressionSets watchpoints
b[reak]Displays breakpoints and watchpoints
del[ete] [n]Deletes breakpoints
disp[lay]expressionDisplays value of
expressionundisp[lay] [n]Removes display of
nc[ont]Continues execution
s[tep] [n]Executes next
nlines stepping into methodsn[ext] [n]Executes next
nlines stepping over methodsw[here]Displays stack frame
f[rame]Synonym for where
l[ist][<-|n-m>]Displays source lines from
ntomup [n]Moves up
nlevels in the stack framedown [n]Moves down
nlevels in the stack framefin[ish]Finishes execution of the current method
tr[ace] [on|off]Toggles trace mode on and off
q[uit]Exits debugger
v[ar] g[lobal]Displays global variables
v[ar] l[ocal]Displays local variables
v[ar] i[instance]objectDisplays instance variables of
objectv[ar] c[onst]objectDisplays constants of object
m[ethod] i[instance]objectDisplays instance methods of
objectm[ethod]class|moduleDisplays instance methods of the
classormoduleth[read] l[ist]Displays threads
th[read] c[ur[rent]]Displays current thread ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access