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