The R Project SVN R

Rev

Rev 59039 | Rev 66751 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
56197 maechler 1
 
42333 ripley 2
% File src/library/base/man/debug.Rd
3
% Part of the R package, http://www.R-project.org
59039 ripley 4
% Copyright 1995-2009 R Core Team
42333 ripley 5
% Distributed under GPL 2 or later
6
 
2 r 7
\name{debug}
37213 ripley 8
\title{Debug a Function}
2 r 9
\usage{
61150 ripley 10
debug(fun, text = "", condition = NULL)
11
debugonce(fun, text = "", condition = NULL)
2 r 12
undebug(fun)
47969 rgentlem 13
isdebugged(fun)
2 r 14
}
56186 murdoch 15
\alias{debug}
48288 rgentlem 16
\alias{debugonce}
2 r 17
\alias{undebug}
47969 rgentlem 18
\alias{isdebugged}
2 r 19
\arguments{
230 maechler 20
\item{fun}{any interpreted \R function.}
48551 rgentlem 21
\item{text}{a text string that can be retrieved when the browser is entered.}
22
\item{condition}{a condition that can be retrieved when the browser is entered.}
2 r 23
}
24
\description{
47969 rgentlem 25
  Set, unset or query the debugging flag on a function.
53966 ripley 26
  The \code{text} and \code{condition} arguments are the same as those
27
  that can be supplied via a call to \code{browser}. They can be retrieved
28
  by the user once the browser has been entered, and provide a mechanism to
29
  allow users to identify which breakpoint has been activated.
7081 pd 30
}
31
\details{
32
  When a function flagged for debugging is entered, normal execution
37213 ripley 33
  is suspended and the body of function is executed one statement at a
34
  time.  A new browser context is initiated for each step (and the
35
  previous one destroyed).
35081 maechler 36
 
53966 ripley 37
  At the debug prompt the user can enter commands or \R expressions,
38
  followed by a newline.  The commands are
37213 ripley 39
 
40
  \describe{
53966 ripley 41
    \item{\code{n}}{(or just an empty line, by default).
42
      Advance to the next step.}
37213 ripley 43
    \item{\code{c}}{continue to the end of the current context: e.g. to the
44
      end of the loop if within a loop or to the end of the function.}
45
    \item{\code{cont}}{synonym for \code{c}.}
46
    \item{\code{where}}{print a stack trace of all active function calls.}
47
    \item{\code{Q}}{exit the browser and the current evaluation and
48
      return to the top-level prompt.}
49
  }
53966 ripley 50
  (Leading and trailing whitespace is ignored, except for an empty line).
37213 ripley 51
 
52
  Anything else entered at the debug prompt is interpreted as an
53
  \R expression to be evaluated in the calling environment: in
54
  particular typing an object name will cause the object to be printed,
55
  and \code{ls()} lists the objects in the calling frame.  (If you want
56
  to look at an object with a name such as \code{n}, print it explicitly.)
56197 maechler 57
 
58
  Setting \link[=options]{option} \code{"browserNLdisabled"} to \code{TRUE}
53966 ripley 59
  disables the use of an empty line as a synonym for \code{n}.  If this
60
  is done, the user will be re-prompted for input until a valid command
61
  or an expression is entered.
56197 maechler 62
 
50809 ripley 63
  To debug a function is defined inside a function, single-step though
64
  to the end of its definition, and then call \code{debug} on its name.
48288 rgentlem 65
 
52692 maechler 66
  If you want to debug a function not starting at the very beginning,
56340 ripley 67
  use \code{\link{trace}(..., at = *)} or \code{\link{setBreakpoint}}.
52692 maechler 68
 
48869 murdoch 69
  Using \code{debug} is persistent, and unless debugging is turned off
48288 rgentlem 70
  the debugger will be entered on every invocation (note that if the
71
  function is removed and replaced the debug state is not preserved).
48338 maechler 72
  Use \code{debugonce} to enter the debugger only the next time the
48288 rgentlem 73
  function is invoked.
48338 maechler 74
 
49567 ripley 75
  In order to debug S4 methods (see \code{\link{Methods}}), you
35081 maechler 76
  need to use \code{\link{trace}}, typically calling \code{\link{browser}},
77
  e.g., as \cr
61150 ripley 78
  \code{trace("plot", browser, exit = browser, signature = c("track", "missing"))}
52692 maechler 79
 
50809 ripley 80
  The number of lines printed for the deparsed call when a function is
81
  entered for debugging can be limited by setting
52692 maechler 82
  \code{\link{options}(deparse.max.lines)}.
58795 luke 83
 
84
  When debugging is enabled on a byte compiled function then the
85
  interpreted version of the function will be used until debugging is
86
  disabled.
2 r 87
}
88
\seealso{
35081 maechler 89
  \code{\link{browser}}, \code{\link{trace}};
90
  \code{\link{traceback}} to see the stack after an \code{Error: \dots}
91
  message; \code{\link{recover}} for another debugging approach.
2 r 92
}
286 maechler 93
\keyword{programming}
94
\keyword{environment}