| 42333 |
ripley |
1 |
% File src/library/utils/man/debugger.Rd
|
|
|
2 |
% Part of the R package, http://www.R-project.org
|
| 59039 |
ripley |
3 |
% Copyright 1995-2011 R Core Team
|
| 42333 |
ripley |
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
| 27442 |
ripley |
6 |
\name{debugger}
|
| 56186 |
murdoch |
7 |
\alias{debugger}
|
| 27442 |
ripley |
8 |
\alias{dump.frames}
|
|
|
9 |
\title{Post-Mortem Debugging}
|
|
|
10 |
\description{
|
|
|
11 |
Functions to dump the evaluation environments (frames) and to examine
|
|
|
12 |
dumped frames.
|
|
|
13 |
}
|
|
|
14 |
\usage{
|
|
|
15 |
dump.frames(dumpto = "last.dump", to.file = FALSE)
|
|
|
16 |
debugger(dump = last.dump)
|
|
|
17 |
}
|
|
|
18 |
\arguments{
|
|
|
19 |
\item{dumpto}{a character string. The name of the object or file to
|
|
|
20 |
dump to.}
|
|
|
21 |
\item{to.file}{logical. Should the dump be to an \R object or to a
|
|
|
22 |
file?}
|
|
|
23 |
\item{dump}{An \R dump object created by \code{dump.frames}.}
|
|
|
24 |
}
|
|
|
25 |
\details{
|
|
|
26 |
To use post-mortem debugging, set the option \code{error} to be a call
|
|
|
27 |
to \code{dump.frames}. By default this dumps to an \R object
|
| 54482 |
ripley |
28 |
\code{last.dump} in the workspace, but it can be set to dump to a
|
| 40344 |
ripley |
29 |
file (a dump of the object produced by a call to \code{\link{save}}).
|
| 27442 |
ripley |
30 |
The dumped object contain the call stack, the active environments and
|
|
|
31 |
the last error message as returned by \code{\link{geterrmessage}}.
|
|
|
32 |
|
|
|
33 |
When dumping to file, \code{dumpto} gives the name of the dumped
|
| 44902 |
hornik |
34 |
object and the file name has \file{.rda} appended.
|
| 27442 |
ripley |
35 |
|
| 54482 |
ripley |
36 |
A dump object of class \code{"dump.frames"} can be examined by calling
|
|
|
37 |
\code{debugger}. This will give the error message and a list of
|
|
|
38 |
environments from which to select repeatedly. When an environment is
|
|
|
39 |
selected, it is copied and the \code{\link{browser}} called from
|
|
|
40 |
within the copy. Note that not all the information in the original
|
|
|
41 |
frame will be available, e.g. promises which have not yet been
|
|
|
42 |
evaluated and the contents of any \code{\dots} argument.
|
| 27442 |
ripley |
43 |
|
|
|
44 |
If \code{dump.frames} is installed as the error handler, execution
|
| 54482 |
ripley |
45 |
will continue even in non-interactive sessions. See the examples for
|
| 27442 |
ripley |
46 |
how to dump and then quit.
|
|
|
47 |
}
|
|
|
48 |
\value{
|
| 40344 |
ripley |
49 |
Invisible \code{NULL}.
|
| 27442 |
ripley |
50 |
}
|
|
|
51 |
\note{
|
|
|
52 |
Functions such as \code{\link{sys.parent}} and
|
|
|
53 |
\code{\link{environment}} applied to closures will not work correctly
|
|
|
54 |
inside \code{debugger}.
|
|
|
55 |
|
| 54482 |
ripley |
56 |
If the error occurred when computing the default value of a formal
|
|
|
57 |
argument the debugger will report \dQuote{recursive default argument
|
|
|
58 |
reference} when trying to examine that environment.
|
| 61433 |
ripley |
59 |
|
| 27442 |
ripley |
60 |
Of course post-mortem debugging will not work if \R is too damaged to
|
|
|
61 |
produce and save the dump, for example if it has run out of workspace.
|
|
|
62 |
}
|
|
|
63 |
\references{
|
|
|
64 |
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
|
|
|
65 |
\emph{The New S Language}.
|
| 47262 |
ripley |
66 |
Wadsworth & Brooks/Cole.
|
| 27442 |
ripley |
67 |
}
|
|
|
68 |
\seealso{
|
|
|
69 |
\code{\link{options}} for setting \code{error} options;
|
|
|
70 |
\code{\link{recover}} is an interactive debugger working similarly to
|
|
|
71 |
\code{debugger} but directly after the error occurs.
|
|
|
72 |
}
|
|
|
73 |
\examples{
|
|
|
74 |
\dontrun{
|
| 61160 |
ripley |
75 |
options(error = quote(dump.frames("testdump", TRUE)))
|
| 27442 |
ripley |
76 |
|
|
|
77 |
f <- function() {
|
|
|
78 |
g <- function() stop("test dump.frames")
|
|
|
79 |
g()
|
|
|
80 |
}
|
|
|
81 |
f() # will generate a dump on file "testdump.rda"
|
| 61160 |
ripley |
82 |
options(error = NULL)
|
| 27442 |
ripley |
83 |
|
|
|
84 |
## possibly in another R session
|
|
|
85 |
load("testdump.rda")
|
|
|
86 |
debugger(testdump)
|
|
|
87 |
Available environments had calls:
|
|
|
88 |
1: f()
|
|
|
89 |
2: g()
|
|
|
90 |
3: stop("test dump.frames")
|
|
|
91 |
|
|
|
92 |
Enter an environment number, or 0 to exit
|
|
|
93 |
Selection: 1
|
|
|
94 |
Browsing in the environment with call:
|
|
|
95 |
f()
|
|
|
96 |
Called from: debugger.look(ind)
|
|
|
97 |
Browse[1]> ls()
|
|
|
98 |
[1] "g"
|
|
|
99 |
Browse[1]> g
|
|
|
100 |
function() stop("test dump.frames")
|
|
|
101 |
<environment: 759818>
|
| 61433 |
ripley |
102 |
Browse[1]>
|
| 27442 |
ripley |
103 |
Available environments had calls:
|
|
|
104 |
1: f()
|
|
|
105 |
2: g()
|
|
|
106 |
3: stop("test dump.frames")
|
|
|
107 |
|
|
|
108 |
Enter an environment number, or 0 to exit
|
|
|
109 |
Selection: 0
|
|
|
110 |
|
|
|
111 |
## A possible setting for non-interactive sessions
|
| 61160 |
ripley |
112 |
options(error = quote({dump.frames(to.file = TRUE); q()}))
|
| 27442 |
ripley |
113 |
}}
|
|
|
114 |
\keyword{utilities}
|
|
|
115 |
\keyword{error}
|