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 commandframe 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