0

I'm making a package with RcppArmadillo under the latest version of Rstudio (1.3.959) and R (4.0.0).

Consider the following minimal example, which create the package anRpackage:

library(Rcpp)
library(RcppArmadillo)
RcppArmadillo.package.skeleton()

Setting the working directory in this package, I load it by:

library(devtools)
devtools::load_all()

Then the basic function rcpparma_hello_world() can be executed:

rcpparma_hello_world()
     [,1] [,2] [,3]
[1,]    7    0    0
[2,]    0    7    0
[3,]    0    0    7
  • I want now to debug the code with lldb via the Terminal command R -d lldb in order to check the variable values during the execution via the command frame variable.
R -d lldb
(lldb) breakpoint set --name rcpparma_hello_world()
(lldb) run
> library(devtools)
> devtools::load_all()
> rcpparma_hello_world()
anRpackage.so was compiled with optimization - stepping may behave oddly; variables may not be available.

Indeed, the problem is that most of variables are not available:

> next
> frame variable
(arma::mat) m1 = <no location, value may have been optimized out>
(arma::mat) m2 = <no location, value may have been optimized out>
  • I read in the previous link the following recommandations:

you may consider producing so-called ‘debug’ builds, with optimization toned down, when attempting to debug these kinds of issues as well. For building R packages, this effectively amounts to something like CXXFLAGS=-g -O0 in your ~/.R/Makevars file)

  • I have tried it but it seems to have no effect under the compilation flags used since I have a local file Makevars in my package to specify the way of compiling with RcppArdimillo, whose flags are:
CXX_STD = CXX11
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) 
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

Then, the command devtools::load_all() produces the line-command compilation given below, in which there is indeed -g -O2 making some code optimization:

clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include' -I/usr/local/include    -fPIC  -Wall -g -O2  -c rcpparma_hello_world.cpp -o rcpparma_hello_world.o

Question: how can I have access to the variables in debugging mode?

Thanks

infophile
  • 21
  • 2
  • You probably need help from `r-sig-mac` for this. – Dirk Eddelbuettel Jun 11 '20 at 15:19
  • I just need to send an email to the following list: r-sig-mac@r-project.org, right? No idea about making the optimization toned down in SHLIB_OPENMP_CXXFLAGS ? Thank you @DirkEddelbuettel – infophile Jun 11 '20 at 16:11
  • Yes, and all (well, most, possibly all) emails list at the R Project now require _initial signup first_ to reduce spam a little. – Dirk Eddelbuettel Jun 11 '20 at 16:16
  • Thanks, I sent an email. Also I have edited the previous post by providing a **minimal example** with a debug of `rcpparma_hello_world()`. – infophile Jun 12 '20 at 09:11
  • The [solution](https://gist.github.com/alexg9010/1ab89ecb28c43f8bc217d2facca77f0a) was to specify in `~/.R/Makevars` the flag `ALL_CXXFLAGS= -Wall -g -O0 $(LTO)` (and not only `CXXFLAGS=-g -O0`) – infophile Jun 17 '20 at 08:03

0 Answers0