From murdoch.duncan at gmail.com  Tue Sep 16 00:05:36 2014
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Mon, 15 Sep 2014 18:05:36 -0400
Subject: [Rd] Debug an R  windows (Fortran) DLL within R with gdb?
In-Reply-To: <BLU174-W2834A37215473FEE12D3F39CC80@phx.gbl>
References: <BLU174-W2834A37215473FEE12D3F39CC80@phx.gbl>
Message-ID: <541762B0.1050501@gmail.com>

On 15/09/2014, 5:25 PM, Andre Mikulec wrote:
> 
> Hi, 
> I have a Fortran 77 subroutine (dll).
> 
> On windows XP, how  would I 'debug it(Fortran) within R' using gdb?
> 
> This is how I made it.
> ----------------------
> 
> R CMD SHLIB main.f
> 
> gfortran -m32     -O3  -mtune=core2 -c main.f -o main.o
> 
> gcc -m32 -shared -s -static-libgcc -o main.dll tmp.def main.o -Ld:/RCompile/CRANpkg/extralibs64/local/lib/i386 -Ld:/RCompile/CRANpkg/extralibs64/local/lib -lgfortran -LF:/ProgramFiles/R/R-3.1.1/bin/i386 -lR
> 
> 
> Here is the contents of the file  main.f
> -----------------------------------------
> 
>       SUBROUTINE NGCD(NA, NB, NGCDO) 
>         IA = NA
>         IB = NB
>     1   IF (IB.NE.0) THEN
>           ITEMP = IA
>           IA = IB
>           IB = MOD(ITEMP, IB)
>           GOTO 1
>         END IF
>         NGCDO = IA  
>         RETURN
>       END

I don't think you put in any compile options to include symbolic
information.  You need to do that.  I think the option you want is
-gdwarf-2, but I rarely use Fortran, and never use SHLIB, so I could be
wrong.  I'll assume you can figure out how to do that.

Run R under gdb using

gdb Rgui

Load your DLL.

Break to gdb using the menu entry "Misc | Break to debugger".

Set a breakpoint, e.g.

b main.f:3

to set it on line 3.  Then use c to let R continue, and make a call to
your code.  Then the usual gdb commands will work after it breaks.

Duncan Murdoch



[Rd] Debug an R windows (Fortran) DLL within R with gdb?
Duncan Murdoch