#include "PrintSignalStackInfo.h"
#include "Common/StackType.h"
namespace MapleRuntime {
void PrintSignalStackInfo::FillInStackTrace()
{
UnwindContext uwContext;
CheckTopUnwindContextAndInit(uwContext);
while (!uwContext.frameInfo.mFrame.IsAnchorFrame(anchorFA)) {
AnalyseAndSetFrameType(uwContext);
if (uwContext.frameInfo.GetFrameType() == FrameType::C2N_STUB && lastFrameType == FrameType::N2C_STUB) {
if (stackIndex >= MAX_SIGNAL_STACK_SIZE) {
stackIndex++;
break;
}
signalStack[stackIndex++] = SigHandlerFrameinfo(MachineFrame(), FrameType::NATIVE);
}
if (stackIndex >= MAX_SIGNAL_STACK_SIZE) {
stackIndex++;
break;
}
signalStack[stackIndex++] = uwContext.frameInfo;
UnwindContext caller;
lastFrameType = uwContext.frameInfo.GetFrameType();
#ifndef _WIN64
if (uwContext.UnwindToCallerContext(caller) == false) {
#else
if (uwContext.UnwindToCallerContext(caller, uwCtxStatus) == false) {
#endif
return;
}
uwContext = caller;
}
}
void PrintSignalStackInfo::PrintStackTrace() const
{
uint16_t stackSize;
bool longStackFlag = false;
if (stackIndex < MAX_SIGNAL_STACK_SIZE) {
stackSize = stackIndex;
} else {
stackSize = MAX_SIGNAL_STACK_SIZE;
longStackFlag = true;
}
for (size_t i = 0; i < stackSize; ++i) {
signalStack[i].PrintFrameInfo(i);
}
if (longStackFlag) {
FLOG(RTLOG_ERROR, " ...");
}
}
}