[ESS] Fwd: Running gdb under emacs 23.1 and attaching to an ess-based R process

Douglas Bates bates at stat.wisc.edu
Tue Feb 1 14:28:30 CET 2011


I forgot to cc: the list on this reply.


---------- Forwarded message ----------
From: Douglas Bates <bates at stat.wisc.edu>
Date: Tue, Feb 1, 2011 at 7:27 AM
Subject: Re: [ESS] Running gdb under emacs 23.1 and attaching to an
ess-based R process
To: Sunny Srivastava <research.baba at gmail.com>


On Tue, Feb 1, 2011 at 12:42 AM, Sunny Srivastava
<research.baba at gmail.com> wrote:
> Hello ESS-list:
> I am a happy ESS user but I haven't used it to debug C/C++ code. Recently, I
> am trying to improve the speed of computations by using compiled C++ code in
> my R function(s). But I am stuck at Step 8 mentioned in the previous email
> communications.
> I tried to follow the instructions mentioned by Professor Bates and
> Professor Maechler, but in Step 8) when I type "c", I don't get back to
> running R. Instead, I see "Continuing". (see below)
> (gdb) b UpdateMean
> Breakpoint 5 at 0xb721b0e7: file updateMean.cpp, line 4.
> (gdb) c
> Continuing.

For me, the fact that nothing is shown after the "Continuing line" is
because the prompt has already been printed.  Simply hitting <Enter>
at that point produces a prompt (because you have given R an empty
line to parse and evaluate).

> I understand, my question may be really stupid, but when I try C-c C-c,
> nothing happens (says: Text is read only) and if I try C-c C-q, I get a
> prompt about quiting R. I have tried googling but I am unable to find any
> solution.
> Thank you in advance for any help or pointers.
> S.
> On Mon, Jan 17, 2011 at 8:13 AM, Douglas Bates <bates at stat.wisc.edu> wrote:
>>
>> Thank you, Martin.  This comes at a good time for me as I am still
>> trying to debug some of the increment calculations in lme4a's glmer.
>>
>> On Mon, Jan 17, 2011 at 3:29 AM, Martin Maechler
>> <maechler at stat.math.ethz.ch> wrote:
>> >>>>>> Martin Maechler <maechler at stat.math.ethz.ch>
>> >>>>>>     on Mon, 17 Jan 2011 10:15:17 +0100 writes:
>> >
>> >>>>>> Douglas Bates <bates at stat.wisc.edu>
>> >>>>>>     on Wed, 12 Jan 2011 15:24:52 -0600 writes:
>> >
>> >    >> In the past I had a wonderfully effective way of getting
>> >    >> at compiled code in an R package with gdb.  I would start
>> >    >> R with ESS (M-x R) and load the package.  Then I would
>> >    >> start gdb on the binary (M-x gdb <RET>
>> >    >> /usr/lib/R/bin/exec/R), find the process number of the R
>> >    >> process (M-!  pgrep R) and attach gdb to that
>> >    >> already-running process.  I would interrupt R, set
>> >    >> breakpoints and then send the sig 0 signal.
>> >
>> >    >> Now I am running emacs 23.1 (which, for some reason, is
>> >    >> still called emacs-snapshot in Ubuntu) with enhanced
>> >    >> support for gdb.  M-x gdb ends up opening multiple windows
>> >    >> and I can't get things straightened out to have the input
>> >    >> and output from the attached process associated with the
>> >    >> *R* buffer.
>> >
>> >    >> Has anyone been able to run the gdb/R combination with
>> >    >> emacs support?  My problem is that I am so accustomed to
>> >    >> the emacs/ess key sequences that I feel crippled when
>> >    >> trying to run R in any other environment :-)
>> >
>> >    > As a workaround :
>> >
>> >    > I've been using the much less sophisticated scheme,
>> >    > with the advantage that it has always worked on all versions of
>> >    > Emacs and R ..
>> >
>> >
>> >    > 1)  C-u M-x R  [Enter] -d gdb [Enter]    # starting R with gdb in a
>> > *R* buffer
>> >    > 2)  C-g {to interrupt Emacs waiting for R's prompt .. ouch!}
>> >    > 3)  C-x b *R ... to manually switch the *R..* buffer in which
>> >    > you now have a prompt '(gdb) '
>> >    > 4) r                 # start running R
>> >    > 5) require(...) ...  ## load all R packages and R code I need
>> >    > 6) C-c C-c         (interrupt): break out of R back into gdb
>> >    > 7) br ...             ## setting breakpoints in gdb for C code
>> >
>> >    > 8) r   # back to running R
>> >
>> > oops! this should have been
>> >
>> >      8) c   # [c]ontinue the running R .
>>
>> I think it is [r]un the first time and [c]ontinue on subsequent
>> occasions in the goto 8 loop.
>>
>> >
>> >
>> >    > 9) in R, call the code that will get into calling the break
>> >    > pointed C code
>> >    > 10) work in the *R* buffer entering gdb commands
>> >    > 11) "goto 8)"
>> >
>> >
>> >    > This allows to use ESS (Emacs R interface), almost normally,
>> >    > but of course the disadvantage is that this does not make any
>> >    > use of the Emacs gdb interface.
>> >
>> >    > We (ESS developers) could make steps 1) -- 3) more easy, notably
>> >    > allowing ESS to also detect "(gdb) " as an R prompt which should
>> >    > basically eliminate '2)' and '3)'.
>> >
>> >    > I agree that the real solution should make Doug's original way
>> >    > workable again, but we need someone (not me) tackle that...
>> >
>> >    > Martin
>> >
>>
>> ______________________________________________
>> ESS-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/ess-help
>
>



More information about the ESS-help mailing list