From andre_mikulec at hotmail.com  Thu Sep 18 05:52:10 2014
From: andre_mikulec at hotmail.com (Andre Mikulec)
Date: Wed, 17 Sep 2014 23:52:10 -0400
Subject: [Rd] Debug an R windows (Fortran) DLL within R with gdb?
In-Reply-To: <mailman.21.1410861606.22633.r-devel@r-project.org>
References: <mailman.21.1410861606.22633.r-devel@r-project.org>
Message-ID: <BLU174-W190C61E69B2DDD0F3D36019CB70@phx.gbl>

Help,

My?Rgui.exe, main.f, main.o, and main.dll are all in the same directory.
When I try to set a breakpoint, I get this response

(gdb) b main.f:3 ? ? ? ? ? ? ??
No source file named main.f

I tried the -gdwarf-2 requirement in both the compiling and linking statements. ?This did not fix the problem.
The cygwin site recommended the -g option. ?I tried this. ?This did not fix the problem.
I did not use R CMD SHLIB ( I ran the statements manually ).

Andre Mikulec
Andre_Mikulec at Hotmail.com


----------------------------------------
> From: r-devel-request at r-project.org
> Subject: R-devel Digest, Vol 139, Issue 15
> To: r-devel at r-project.org
> Date: Tue, 16 Sep 2014 12:00:06 +0200
>
> Send R-devel mailing list submissions to
> r-devel at r-project.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://stat.ethz.ch/mailman/listinfo/r-devel
> or, via email, send a message with subject or body 'help' to
> r-devel-request at r-project.org
>
> You can reach the person managing the list at
> r-devel-owner at r-project.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of R-devel digest..."
>
>
> Today's Topics:
>
> 1. Debug an R windows (Fortran) DLL within R with gdb?
> (Andre Mikulec)
> 2. Re: Debug an R windows (Fortran) DLL within R with gdb?
> (Duncan Murdoch)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 15 Sep 2014 17:25:49 -0400
> From: Andre Mikulec <andre_mikulec at hotmail.com>
> To: "r-devel at r-project.org" <r-devel at r-project.org>
> Subject: [Rd] Debug an R windows (Fortran) DLL within R with gdb?
> Message-ID: <BLU174-W2834A37215473FEE12D3F39CC80 at phx.gbl>
> Content-Type: text/plain; charset="iso-8859-1"
>
>
> 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
>
> Thank you,
> Andre Mikulec
> Andre_Mikulec at Hotmail.com
>
>
>
>
>
> ------------------------------
>
> Message: 2
> Date: Mon, 15 Sep 2014 18:05:36 -0400
> From: Duncan Murdoch <murdoch.duncan at gmail.com>
> To: Andre Mikulec <andre_mikulec at hotmail.com>, "r-devel at r-project.org"
> <r-devel at r-project.org>
> Subject: Re: [Rd] Debug an R windows (Fortran) DLL within R with gdb?
> Message-ID: <541762B0.1050501 at gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> 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
>
>
>
> ------------------------------
>
> _______________________________________________
> R-devel at r-project.org mailing list DIGESTED
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>
> End of R-devel Digest, Vol 139, Issue 15
> ****************************************
 		 	   		  


[Rd] Debug an R windows (Fortran) DLL within R with gdb?
Andre Mikulec