[R] Re: Debugging dynloaded C-code with gdb

Peter Holzer holzer at stat.math.ethz.ch
Tue Oct 3 12:00:22 CEST 2000

Thanks to Robert Gentleman, Thomas Lumley and Kurt Hornik for their
replies. They all pointed out that the problem comes from using
optimisation during compiling, which is usually the default.

The problem can easily be solved by adding the following code to the file

	%.o: %.c
	     $(CC) -g -Wall $(PKG_CFLAGS) $(ALL_CPPFLAGS) -o $@ -c $<

A little bit more fancy is:

	ifneq (,$(findstring o, $(opt)))
	     USE_CFLAGS = -g -Wall $(PKG_CFLAGS)

	%.o: %.c
	     $(CC) $(USE_CFLAGS) $(ALL_CPPFLAGS) -o $@ -c $<

and then using

make opt=o

if I don't want any optimisation and otherwise just normal make (so I don't
need to remember when I have finished debugging that I should reset the


On Mon, 2 Oct 2000, Peter Holzer wrote:

> Dear R users
> I have started to use gdb for debugging dynloaded C code as described in
> `Writing R Extensions'. Unfortunately I have run into several problems that
> I haven't been able to solve:
> - using `n': how comes that the same line of code appears up to three times
>   (and inbetween the next line and maybe even the second next one?)
> - using `print' resp. `display': How comes the variable values are
>   different from those shown by fprintf? How comes the variable values
>   change when actually no value is assigned to them (and I use `n', not
>   `s')?
r-help 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-help-request at stat.math.ethz.ch

More information about the R-help mailing list