[R-SIG-Mac] Debug Rcpp with lldb: variables not available

inf0phile |n|0ph||e @end|ng |rom protonm@||@com
Thu Jun 11 18:48:21 CEST 2020


Hello,

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

- The compilation of the cpp files (with clang) is working well

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 compensator_Rcpp.cpp -o compensator_Rcpp.o

This command is automatically generated by pushing the Rstudio package dev button "Install and restart"

- I want now to [debug the code with lldb](https://kevinushey.github.io/blog/2015/04/13/debugging-with-lldb/) (https://kevinushey.github.io/blog/2015/04/13/debugging-with-lldb/) via the Terminal command R -d lldb in order to check the variable values during the execution via the command frame variable. The problem is most of them are not available:

(SEXP) lambda = <variable not available>
(Rcpp::NumericVector) beta = <no location, value may have been optimized out>
(int) index = <variable not available>

- 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](http://dirk.eddelbuettel.com/blog/2017/06/04/) (http://dirk.eddelbuettel.com/blog/2017/06/04/), whose flags are:

CXX_STD = CXX11
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

producing the line-command compilation given above, in which there is indeed -g -O2 making some code optimization.

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

Thanks
	[[alternative HTML version deleted]]



More information about the R-SIG-Mac mailing list