[R] R and gdb

Douglas Bates bates at stat.wisc.edu
Mon Jan 20 16:57:02 CET 2003

An alternative method for using gdb with R is to start R and attach
your package or use dyn.load on your shared object.  Then go into
another window and find out the process id number of this process.  (I
usually use 'ps ux' for this.)  After that start start gdb on the R
executable (usually a file with a name like
/usr/local/lib/R/bin/R.bin) and within gdb issue the command

 attach <pid>

where <pid> is the process id of the current R process, set your
breakpoints and use

 signal 0

to get R running again.

For emacs/ESS users this has the wonderful advantage that you can run
both the R and the gdb process under emacs in ESS and gud modes

Pierre-Andre Cornillon <pac at Uhb.Fr> writes:

> Hi,
> I have some problem with setting breakpoints with gdb in order to debug
> some shared library for R.
> Classical use of gdb work well
> gcc -g -o footest.o footest.c
> gdb footest.o
> b 2
> run
> ...
> but as i tried to use it with R :
> $ R -d gdb
> GNU gdb 5.2.1
> Copyright 2002 Free Software Foundation, Inc.
> GDB is free software, covered by the GNU General Public License, and you
> are
> welcome to change it and/or distribute copies of it under certain
> conditions.
> Type "show copying" to see the conditions.
> There is absolutely no warranty for GDB.  Type "show warranty" for
> details.
> This GDB was configured as "sparc64-unknown-linux-gnu"...
> (gdb) R
> Starting program: /usr/local/lib/R/bin/R.bin
> R : Copyright 2003, The R Development Core Team
> Version 1.6.2  (2003-01-10)
> R is free software and comes with ABSOLUTELY NO WARRANTY.
> You are welcome to redistribute it under certain conditions.
> Type `license()' or `licence()' for distribution details.
> R is a collaborative project with many contributors.
> Type `contributors()' for more information.
> Type `demo()' for some demos, `help()' for on-line help, or
> `help.start()' for a HTML browser interface to help.
> Type `q()' to quit R.
> [Previously saved workspace restored]
> > dyn.load("foo.so")
>  "I type Control-C here"
> Program received signal SIGINT, Interrupt.
> 0x703346f8 in select () from /lib/libc.so.6
> (gdb) b foo.c:44
> Breakpoint 1 at 0x705c62a4: file plssvd.c, line 44.
> (gdb) signal 0
> Continuing with no signal.
> foo.r(Xcr,Ycr,2)
> gives directly the final result without stopping at the breakpoints.
> I tried to update R
> from 1.6.1 to 1.62
> and I tried to update gdb too (up to  5.2.1, the 5.3 version doesn't
> compile smoothly on my platform)
> -> nothing change
> my system:
> Ultrasparc 10, sparc Gnu-Linux Suse 7-3, gcc 2-95-3
> kernel 2.4.14 (Suse standard)
> Note that setting the same breakpoint with the same program on a
> Pentium IV, Gnu-Linux Suse 7-3, gcc 2-95-3
> kernel 2.4.14 (Suse standard) works perfectly...
> Does anybody have some hints on this topic?
> Pierre-Andre Cornillon
> PS I do not compile with optimization option as sometimes gdb have some
> trouble to set the breakpoints at the chosen line
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help

Douglas Bates                            bates at stat.wisc.edu
Statistics Department                    608/262-2598
University of Wisconsin - Madison        http://www.stat.wisc.edu/~bates/

More information about the R-help mailing list