Mapping Rcpp :: NumericMatrix elements from gdb

I am trying to use gdb to debug a simple C ++ routine that uses Rcpp functions. I create my foo.cpp routine using the -O0 -g options. I start R using R -d gdb I load the subroutine with dyn.load ("foo.so") and I call the subroutine with .Call ("foo", X). No problem. When I enter a routine in gdb, I can print standard C ++ types, for example, "print i", where I am int. However, I cannot print the elements of Rcpp :: NumericMatrix xout. I tried

print xout (1,1)

and

print R_PV (xout (1,1))

Does anyone know how to do this?

My C ++ code:

#include <iostream>
#include <Rcpp.h>

RcppExport SEXP foo(SEXP x){
    using namespace Rcpp;
    NumericMatrix xin = NumericMatrix(x);
    int nrow = xin.nrow();
    int ncol = xin.ncol();
    NumericMatrix xout(nrow, ncol);
    for(int j = 0; j<ncol; j++) {
      xout(0,j) = xin(0,j);
      for (int i=1; i<nrow; i++) {
          if (ISNA(xin(i,j)))
           xout(i,j) = xout(i-1,j);
          else
           xout(i,j) = xin(i,j);
      }
    }

    return(xout);
}

At the command prompt, I run:

R CMD SHLIB foo.cpp

Then I run R using

R -d gdb

I add a breakpoint in foo

b foo

Then run R:

R

In R, I type

dyn.load("foo.so")
X =matrix(rnorm(9),3)
.Call("foo",X)

At the gdb command prompt, type

print xin

:

$1 = {<Rcpp::Vector<14>> = {<Rcpp::RObject> = {_vptr.RObject = 0x7fff8df4b410, 
      m_sexp = 0x2567f20}, <Rcpp::VectorBase<14, true, Rcpp::Vector<14> >> = {<Rcpp::traits::expands_to_logical__impl<14>> = {<No data fields>}, <No data fields>}, <Rcpp::internal::eval_methods<14>> = {<No data fields>}, cache = {
      start = 0x31e03c39b0}}, <Rcpp::MatrixBase<14, true, Rcpp::Matrix<14> >> = {<Rcpp::traits::expands_to_logical__impl<14>> = {<No data fields>}, <No data fields>}, nrows = -537925942}

xin (1,1) gdb, ,

print xin (1,1)

+4

All Articles