On 13/05/2007 12:21 AM, Tong Wang wrote:
> Hi, All:
>     I had some trouble debugging C source dynamically loaded into R , when I 
> issued N  in gdb(or insight) , the debugger, instead of moving downward step 
> by step, jumped to strange positions (upward, downward, one step, a few steps 
> away).
> 
>    To enter the debugger, I issued  gdb(insight) Rgui.exe in Cygwin and add 
> this line :  asm("int $3");   to my C code.  After 
> entering R, I did something like:  dyn.load("mypath/mycode.dll") , then  out 
> <- .C("myfun", arg1=as.numeric(a),......) 
> The C files are compiled with:    R CMD SHLIB -d myfile.c
>    
>    I am using Win XP + Cygwin, and I have a binary version and a cygwin 
> compiled version of R-2.4.1 installed. This same 
> behavior show up in both installations.  

I think you're seeing the code rearrangements that happen when gcc 
optimizes the code.  It puts some functions inline, it shares similar 
sequences of instructions between different blocks of code, etc.

If this is causing problems in debugging, change the -O3 to a lower 
level of optimization, e.g. -O0 (i.e. oh zero) in the relevant Makefile: 
  src/gnuwin32/MakeDll if you're debugging your own package, 
src/gnuwin32/Makefile for most of R, etc.  However, be aware that in 
case of nasty bugs, this may change the behaviour of your program.

By the way, if you used Cygwin compilers to build, expect problems.  The 
supported compiler is MinGW.

> One thing is, even though I set the evn  DEBUG as T when built R from sourse 
> in 
> Cygwin,  the Rgui.exe I got doesn't seem to contain debug info.  (although 
> R.exe does) , I am not sure if this means I did something wrong.  

Perhaps you didn't recompile everything with the flag set.  You need it 
set both when the .o object files are created and later when they are 
linked.  And DEBUG=T has no effect on the initial entry point of 
Rgui.exe, because it is coming from the MinGW libraries, not from R 
source, and R doesn't compile those.

Duncan Murdoch

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to