From bates@stat.wisc.edu  Thu Jan 15 14:54:38 1998
From: bates@stat.wisc.edu (Douglas Bates)
Date: 15 Jan 1998 08:54:38 -0600
Subject: debugging dynamically loaded code
In-Reply-To: Friedrich Leisch's message of Thu, 15 Jan 1998 12:13:13 +0100
References: <199801151113.MAA01121@galadriel.ci.tuwien.ac.at>
Message-ID: <6rbtxdwzwx.fsf@franz.stat.wisc.edu>

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                            bates@stat.wisc.edu
Statistics Department                    608/262-2598
University of Wisconsin - Madison        http://www.stat.wisc.edu/~bates/
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


debugging dynamically loaded code
Douglas Bates