Skip to content

gdb

6 messages · Joe Bloggs, Dirk Eddelbuettel, Martin Maechler

#
I am using gdb to debug a c++ library I made for R using Rcpp.
However, when I step through the code it seems to go all over the place, and some of the variables have been optimized out so I can't see their values.
How can I compile without optimization?
Also, is there any neat way to run R with gdb through emacs?
Thanks.
#
On 3 February 2008 at 01:08, Joe Bloggs wrote:
| I am using gdb to debug a c++ library I made for R using Rcpp.
| However, when I step through the code it seems to go all over the place, and some of the variables have been optimized out so I can't see their values.
| How can I compile without optimization?

Set MAKEFLAGS accordingly, possibly by editing R's Makeconf.  This is
documented in the 'R Extensions' manual.

| Also, is there any neat way to run R with gdb through emacs?

Yes, using 'M-x gdb' to launcg the gdb frontend. I also use ddd on Linux.

Using the debugger is also described in the 'R Extensions' manual.

Hope this helps, Dirk
#
Dirk Eddelbuettel <edd at debian.org> writes:
Thanks, for the benefit of others..

I changed the CXXFLAGS line in /etc/R/Makeconf from:

CXXFLAGS = -g -O2

to:

CXXFLAGS = -ggdb -O2

which seems to work. Changing -O2 to just -O would remove compiler optimizations, but it turns out this wasn't necessary.
Alternatively I could compile my package with

MAKEFLAGS="CXXFLAGS=-ggdb -O2" R CMD INSTALL ...

to temporarily change the flags.
In the manual it says to run R through gdb by: R -d gdb
how can I do this in emacs?
Alternatively how do I run R through gdb after alreay starting gdb?
#
On 4 February 2008 at 01:51, Joe Bloggs wrote:
| Dirk Eddelbuettel <edd at debian.org> writes:
|
| > On 3 February 2008 at 01:08, Joe Bloggs wrote:
| > | I am using gdb to debug a c++ library I made for R using Rcpp.
| > | However, when I step through the code it seems to go all over the place, and some of the variables have been optimized out so I can't see their values.
| > | How can I compile without optimization?
| >
| > Set MAKEFLAGS accordingly, possibly by editing R's Makeconf.  This is
| > documented in the 'R Extensions' manual.
| >
| 
| Thanks, for the benefit of others..
| 
| I changed the CXXFLAGS line in /etc/R/Makeconf from:
| 
| CXXFLAGS = -g -O2
| 
| to:
| 
| CXXFLAGS = -ggdb -O2

Hm, I never seem to have needed -ggdb, for me -g was usually suffcient. Any
idea why you needed -ggdb ?
 
| which seems to work. Changing -O2 to just -O would remove compiler optimizations, but it turns out this wasn't necessary.
| Alternatively I could compile my package with
| 
| MAKEFLAGS="CXXFLAGS=-ggdb -O2" R CMD INSTALL ...
| 
| to temporarily change the flags.
| 
| 
| > | Also, is there any neat way to run R with gdb through emacs?
| >
| > Yes, using 'M-x gdb' to launcg the gdb frontend. I also use ddd on Linux.
| >
| > Using the debugger is also described in the 'R Extensions' manual.
| >
| 
| In the manual it says to run R through gdb by: R -d gdb
| how can I do this in emacs?
| Alternatively how do I run R through gdb after alreay starting gdb?

I thought that was in the manual, but it seems it isn't.  Doug Bates
describes it once or twice a few years back; one quick Google search leads to

	http://tolstoy.newcastle.edu.au/R/help/03a/0566.html

Hope this helps, Dirk

| 
| > Hope this helps, Dirk
| >
| > -- 
| > Three out of two people have difficulties with fractions.
| >
| > ______________________________________________
| > R-devel at r-project.org mailing list
| > https://stat.ethz.ch/mailman/listinfo/r-devel
| 
| ______________________________________________
| R-devel at r-project.org mailing list
| https://stat.ethz.ch/mailman/listinfo/r-devel
#

        
DE> On 4 February 2008 at 01:51, Joe Bloggs wrote:
DE> | Dirk Eddelbuettel <edd at debian.org> writes:
    DE> |
DE> | > On 3 February 2008 at 01:08, Joe Bloggs wrote:
DE> | > | I am using gdb to debug a c++ library I made for R using Rcpp.
    DE> | > | However, when I step through the code it seems to go all over the place, and some of the variables have been optimized out so I can't see their values.
    DE> | > | How can I compile without optimization?
    DE> | >
    DE> | > Set MAKEFLAGS accordingly, possibly by editing R's Makeconf.  This is
    DE> | > documented in the 'R Extensions' manual.
    DE> | >
    DE> | 
    DE> | Thanks, for the benefit of others..
    DE> | 
    DE> | I changed the CXXFLAGS line in /etc/R/Makeconf from:
    DE> | 
    DE> | CXXFLAGS = -g -O2
    DE> | 
    DE> | to:
    DE> | 
    DE> | CXXFLAGS = -ggdb -O2

    DE> Hm, I never seem to have needed -ggdb, for me -g was usually suffcient. Any
    DE> idea why you needed -ggdb ?
 
    DE> | which seems to work. Changing -O2 to just -O would remove compiler optimizations, but it turns out this wasn't necessary.
    DE> | Alternatively I could compile my package with
    DE> | 
    DE> | MAKEFLAGS="CXXFLAGS=-ggdb -O2" R CMD INSTALL ...
    DE> | 
    DE> | to temporarily change the flags.
    DE> | 
    DE> | 
    DE> | > | Also, is there any neat way to run R with gdb through emacs?
    DE> | >
    DE> | > Yes, using 'M-x gdb' to launcg the gdb frontend. I also use ddd on Linux.
    DE> | >
    DE> | > Using the debugger is also described in the 'R Extensions' manual.
    DE> | >
    DE> | 
    DE> | In the manual it says to run R through gdb by: R -d gdb
    DE> | how can I do this in emacs?

C-u M-x R [Enter] -d gdb [Enter]
===

C-u: == Emacs "Prefix" 
        allows you to specify command line arguments to R



    DE> | Alternatively how do I run R through gdb after alreay starting gdb?

    DE> I thought that was in the manual, but it seems it isn't.  Doug Bates
    DE> describes it once or twice a few years back; one quick Google search leads to

    DE> http://tolstoy.newcastle.edu.au/R/help/03a/0566.html



    DE> Hope this helps, Dirk
#
Oops, sorry, I must have made a mistake. Tried it again this morning and realize that I do need to remove compiler optimizations. So probably -g will work just as well as -ggdb, but -O is needed instead of -O2.
Thanks for the link, I also found this: 
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Debugging-R-from-within-Emacs
(should have checked earlier!)
However, I can't seem to get both R & gdb working together in emacs. 
I start R in emacs, load the library to be debugged, then start gdb in emacs, attach it to the R process, set the breakpoint, type "signal 0" in gdb to let R take control, then run the R function I am debugging and... emacs hangs up on me :(

I can get it to work if I run R in a seperate shell, and run gdb from emacs, attaching it to the R process as before. 
If I also load the source for the package I'm debugging then it also shows me whereabouts in that file I am which is very nice.