From jonathan at rstudio.com  Thu Oct  2 19:56:01 2014
From: jonathan at rstudio.com (Jonathan McPherson)
Date: Thu, 2 Oct 2014 10:56:01 -0700
Subject: [Rd] debuggingState() analogous to tracingState() ?
In-Reply-To: <21549.26470.777198.46400@stat.math.ethz.ch>
References: <CAPRP4-f2d_u90HQqzY5660xqC3ZKMG4ZmEnsFCRY9LB_W98TFg@mail.gmail.com>
	<21549.6213.346772.105674@stat.math.ethz.ch>
	<542D1DAC.4090809@gmail.com>
	<21549.10935.269659.495307@stat.math.ethz.ch>
	<542D34C6.2040301@gmail.com>
	<21549.26470.777198.46400@stat.math.ethz.ch>
Message-ID: <CAAU5OYB+f3RUvEDqWFodTE6cVVp0+urzGhn2qSUo5h67eKunHw@mail.gmail.com>

>
>  > I don't have much of an opinion on these questions.  I've never used the
>  > tracingState() function, though I use trace() all the time (via
>  > setBreakpoint()).  You might want to consult people who write debugger
>  > front-ends.
>
> which I am now doing: I'm including ESS-core,
> Jonathan (RStudio) and Tobias (StatET) which Duncan mentioned as
> being interested and having asked for better debugging support
> functionality in the past, such as
>
>
Some observations from RStudio which may or may not be helpful:

We don't expose any UI that allows the user to modify tracingState(). In
fact, turning off tracingState() will make RStudio's breakpoints stop
working (as they rely on trace()), without any warning or feedback from the
UI. We've never received complaints about this, and so my presumption is
that very few people need to turn off tracing globally, and those who do
know what they're doing and/or aren't using the IDE debugging features.

Some mechanism for globally altering debugging state would be very useful.
Right now we have a problem wherein during debugging the R functions
RStudio calls to e.g. analyze and compose the list of objects in the
workspace are themselves debugged. Today we're solving this by manually
tripping the RDEBUG flag on an environment before we evaluate expressions
in it, which I think we can all agree is less than ideal.

Do you foresee any non-interactive use for debuggingState()? If so, it
might be nice if the state had push/pop rather than on/off semantics, to
make the pattern of disabling locally easier to express.

 > the ability to add a breakpoint to a function that is
 > currently being evaluated.

Yes, this would be useful to us, although unless I'm missing something it
seems pretty orthogonal to the rest of the thread. It's not a common
feature request.

One thing that would be useful is some officially supported way to debug
during source(). Lots of people don't use functions and just have R scripts
full of straight-line statements (sometimes containing references to other
code via source()). RStudio will let you set breakpoints on top-level
statements, and this has proven to be a popular feature, but its
implementation is very messy--we effectively create a function from the
statements in the file and then use the function debugger, which works for
simple scenarios but starts falling apart if you do anything complicated.

Thanks,
Jonathan.

	[[alternative HTML version deleted]]



[Rd] debuggingState() analogous to tracingState() ?
Jonathan McPherson