in src/debugger/RDebugger.cpp [476:506]
std::vector<RDebuggerStackFrame> RDebugger::buildStack(std::vector<ContextDump> const& contexts) {
std::vector<RDebuggerStackFrame> stack;
if (contexts.empty()) return stack;
WithDebuggerEnabled with(false);
std::string functionName;
SEXP frame = R_NilValue;
SEXP functionSrcref = R_NilValue;
for (auto const& ctx : contexts) {
SEXP call = ctx.call;
SEXP srcref = ctx.srcref;
srcref = (srcref == nullptr) ? R_NilValue : srcref;
if (srcref == R_NilValue) {
srcref = call ? Rf_getAttrib(call, RI->srcrefAttr) : R_NilValue;
if (srcref == R_NilValue) {
srcref = functionSrcref;
}
}
if (call != nullptr) {
auto position = srcrefToPosition(srcref);
if (stack.empty()) functionName = "";
stack.push_back({position.first, position.second, frame, functionName, srcref});
functionName = getCallFunctionName(call);
}
if (ctx.function != R_NilValue) {
functionSrcref = sourceFileManager.getFunctionSrcref((SEXP)ctx.function, functionName);
}
frame = ctx.environment;
}
return stack;
}