static void writeStack()

in src/CrashReport.cpp [41:81]


static void writeStack(std::ofstream &out) {
  out << LINE;
  out << "R stack\n";
  out << LINE;
  RContext *ctx = getGlobalContext();

  std::unordered_map<SEXP, std::string> functionReplacement;
  ShieldSEXP baseNamesCall = Rf_lang3(Rf_install("ls"), R_BaseEnv, Rf_ScalarLogical(1));
  SET_TAG(CDDR(baseNamesCall), Rf_install("all.names"));
  ShieldSEXP baseNames = Rf_eval(baseNamesCall, R_BaseEnv);
  if (TYPEOF(baseNames) == STRSXP) {
    for (R_xlen_t i = 0; i < baseNames.length(); ++i) {
      ShieldSEXP symbol = Rf_install(stringEltNative(baseNames, i));
      functionReplacement[Rf_findVarInFrame(R_BaseEnv, symbol)] = quoteIfNeeded(stringEltUTF8(baseNames, i));
    }
  }
  if (RI != nullptr) {
    functionReplacement[RI->myFilePath] = "myFilePath";
    functionReplacement[RI->withReplExceptionHandler] = "withReplExceptionHandler";
    functionReplacement[RI->jetbrainsDebuggerEnable] = "jetbrainsDebuggerEnable";
    functionReplacement[RI->jetbrainsRunFunction] = "jetbrainsRunFunction";
  }

  int i = 0;
  while (ctx != nullptr) {
    if (isToplevelContext(ctx)) {
      out << (i++) << ": TOPLEVEL\n";
    } else if (isCallContext(ctx)) {
      out << (i++) << ": ";
      ShieldSEXP call = getCall(ctx);
      TextBuilder builder;
      builder.functionReplacement = std::move(functionReplacement);
      builder.build(call);
      out << builder.getText();
      out << "\n";
      functionReplacement = std::move(builder.functionReplacement);
    }
    ctx = getNextContext(ctx);
  }
  out << "\n";
}