debugging dynamically loaded code

Douglas Bates
15 Jan 1998 08:54:38 -0600

The secret of symbolic debugging of dynamically loaded code is to
 - Call the debugger on the R executable.  Since I do this within
   emacs, I don't use the "R gdb" facility, I symbolically link the
   R.binary file into the directory with my code and call the debugger 
   through M-x gdb.
 - Set the environment variables that the $RHOME/bin/R script would.
 - Start the R program.
 - At the R prompt, use dyn.load() to load your library.
 - Send an interrupt signal.  Inside of gud mode in emacs, I think you 
   send C-C C-C.  This will put you back to the debugger prompt.
 - Set the breakpoints in your code.
 - Continue execution of R by typing "signal 0<ret>".

As I mentioned above, I find it easiest to use the directory with my
code in it as the cwd and then make a symbolic link from that
directory to the R executable.  That way the .gdbinit can stay in the
directory with the code and be used to set up the environment and the
search paths for the source.

A sample .gdbinit would be
 set env RHOME /usr/lib/R
 set env R_PAPERSIZE letter
 set env R_PRINTCMD lpr
 dir /usr/lib/R/src/main
 dir /usr/lib/R/src/math
 dir /usr/lib/R/src/appl
 dir /usr/lib/R/src/unix

It is possible that those last lines could be written as
 dir $(RHOME)/src/main
instead.  I haven't tried it out.
Douglas Bates                  
Statistics Department                    608/262-2598
University of Wisconsin - Madison
r-devel mailing list -- Read
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: