Small note: if you are using a recent version of OSX, then gdb is
essentially useless, but you can use llvm, which is nicer in many respects,
anyway.

Gabor


On Fri, Jan 17, 2014 at 3:43 AM, Gabriel Becker <gmbec...@ucdavis.edu>wrote:

> Saisai,
>
> I haven't watched the specific video Sandip posted, but from the title it
> looks to be correct. Running R with/in gdb is the correct way to debug C
> code in R packages.
>
> One thing to watch out for: The default compiler flags for C/C++ code in R
> packages call for substantial optimization (I believe it's '-O2'). This
> mess with the execution order of some instructions, making step by step
> debugging annoying. Also, it will optimize out values that may be important
> to your debugging. To fix this you'll need to look into how Makevars files
> work, and specifically how to set/override compiler flags in them.
>
> There were some deeper issues with what you asked, though. Sourcing an R
> file will have no effect on a package in the namespace at all unless you
> are using something like ESS's developer mode which sources the file into
> the package namespace. Furthermore, C code included in R packages is only
> compiled at installation from source or binary build time.
>
> Even if you are using a developer mode, sourcing an R file will have no
> effect on a) the shared object library (DLL/so/dylib) available in the R
> session, nor which shared objects are associated with the package. There
> are ways to unload shared libraries within an R session, but personally I
> tend to avoid them. The best way of being absolutely sure that the right
> shared library is getting used is to reinstall the package, then close the
> R session and restart.
>
> I would encourage you to look into how R compiles and interacts with native
> code in and out of packages before trying to tackle something like this
> directly. It's all in the Writing R extensions manual here:
> http://cran.r-project.org/doc/manuals/R-exts.html
>
> Hope that helps,
> ~G
>
>
> On Thu, Jan 16, 2014 at 8:04 PM, Sandip Nandi <sanna...@umail.iu.edu>
> wrote:
>
> > Hi ,
> >
> > The video may help you
> >
> > http://vimeo.com/11937905
> >
> > Thanks,
> > Sandip
> >
> >
> > On Thu, Jan 16, 2014 at 4:17 PM, Ma, Saisai - maysy020 <
> > saisai...@mymail.unisa.edu.au> wrote:
> >
> > > Hi all,
> > >
> > > Sorry to bother you.
> > >
> > > I am a beginner in R programming. I have encountered some problems
> when I
> > > modified a R package with C code.
> > > I would like to modified the C code within the R package, and want to
> > > debug the C program. But I have no idea how to debug this kind of R
> > package.
> > >
> > > In the package, a R file named aaa.R use the interface .call(bbb.c,
> ...)
> > > to call the C code named bbb.c.
> > > And what I did is that I resourced aaa.R and ran it in R Stdio again,
> > > after modifying bbb.c. But there is nothing happened.
> > > I am very sure that the all the path of R file and C file is correct.
> And
> > > I am using Windows operating system.
> > >
> > > Could anyone give me a few pointers on how to debug R packages (or
> > > extensions with C++/C code)? If possible, Could you please give me an
> > > simple example or some command lines?
> > >
> > >
> > > Regards,
> > > Saisai
> > >
> > >
> > >         [[alternative HTML version deleted]]
> > >
> > > ______________________________________________
> > > R-devel@r-project.org mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-devel
> > >
> >
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-devel@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>
>
>
> --
> Gabriel Becker
> Graduate Student
> Statistics Department
> University of California, Davis
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

        [[alternative HTML version deleted]]

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

Reply via email to