显示来自gdb的Rcpp::NumericMatrix的元素 我试图用GDB调试一个使用RCPP特性的简单C++子程序。我使用选项-O0-g构建我的子例程foo.cpp。我使用R-dgdb启动R 我使用dyn.load(“foo.so”)加载子例程,并使用.call(“foo”,X)调用子例程。没有问题。当我进入GDB子程序时,我可以打印标准C++类型,例如“打印I”,我是int。但是,我不能打印RCP:::MigCimultXOUT的元素。我试过了
打印xout(1,1) 以及 打印R_PV(xout(1,1)) 有人知道怎么做吗 <>我的C++代码是:显示来自gdb的Rcpp::NumericMatrix的元素 我试图用GDB调试一个使用RCPP特性的简单C++子程序。我使用选项-O0-g构建我的子例程foo.cpp。我使用R-dgdb启动R 我使用dyn.load(“foo.so”)加载子例程,并使用.call(“foo”,X)调用子例程。没有问题。当我进入GDB子程序时,我可以打印标准C++类型,例如“打印I”,我是int。但是,我不能打印RCP:::MigCimultXOUT的元素。我试过了,c++,r,gdb,rcpp,C++,R,Gdb,Rcpp,打印xout(1,1) 以及 打印R_PV(xout(1,1)) 有人知道怎么做吗 我的C++代码是: #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
#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);
}
然后我开始使用R
R -d gdb
我在foo添加了一个断点
b foo
然后我开始R:
R
在R中,我输入
dyn.load("foo.so")
X =matrix(rnorm(9),3)
.Call("foo",X)
从gdb命令行输入
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}
$1={={{{vptr.RObject=0x7fff8df4b410,
m_sexp=0x2567f20},={={},},={},缓存={
start=0x31e03c39b0},={={},},nrows=-537925942}
我希望能够从gdb访问xin(1,1),例如
print xin(1,1)这有点粗糙。我们没有本机打印成员函数。你可以用犰狳。有关背景信息,请参阅。此处有一个类似问题:
$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}