Skip to content

Make it easier for debugger to perform source file mapping #1041

@renkun-ken

Description

@renkun-ken

Recently, I create a demo package vscode-rcpp-demo to demonstrate writing and debugging Rcpp code in VSCode. For debugging, however, it only works well for source files in package when devtools::load_all() is called which loads the built shared library in src rather than a tmp directory, and the source file mapping is good for debugging.

For standalone source files, one has to call Rcpp::sourceCpp(file) to compile and load the shared library which lies in a temp directory and source file is copied and reorganized to include the Rcpp wrapper, which is easy to use but seems more difficult for debugger to do source mapping.

For example, the following source code:

#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
double calc_sum(NumericVector x) {
  double sum = 0;
  for (int i = 0; i < x.size(); i++) {
    sum += x[i];
  }
  return sum;
}

goes to a temp directory and becomes

#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
double calc_sum(NumericVector x) {
  double sum = 0;
  for (int i = 0; i < x.size(); i++) {
    sum += x[i];
  }
  return sum;
}


#include <Rcpp.h>
// calc_sum
double calc_sum(NumericVector x);
RcppExport SEXP sourceCpp_1_calc_sum(SEXP xSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< NumericVector >::type x(xSEXP);
    rcpp_result_gen = Rcpp::wrap(calc_sum(x));
    return rcpp_result_gen;
END_RCPP
}

I'm wondering if it can be also made easier for debugger too?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions