Skip to content

Commit

Permalink
Profiler callback fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
janvorli committed Dec 5, 2023
1 parent 54f4b25 commit a6f73a1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 62 deletions.
84 changes: 22 additions & 62 deletions src/coreclr/vm/exceptionhandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8022,50 +8022,6 @@ extern "C" int32_t QCALLTYPE EHEnumInitFromStackFrameIterator(StackFrameIterator
return result;
}

// static bool ProcessDebuggerInterception(ExInfo *pExInfo, MethodDesc *pMD)
// {
// bool result = true;

// MethodDesc* pInterceptMD = NULL;
// StackFrame sfInterceptStackFrame;

// // check if we have reached the interception point yet
// pExInfo->m_DebuggerExState.GetDebuggerInterceptInfo(&pInterceptMD, NULL,
// reinterpret_cast<PBYTE *>(&(sfInterceptStackFrame.SP)),
// NULL, NULL);

// if (pExInfo->m_passNumber == 1)
// {
// // // Save the target unwind frame just like we do when we find a catch clause.
// // m_sfResumeStackFrame = sfInterceptStackFrame;
// // ReturnStatus = FirstPassComplete;
// // goto lExit;
// result = false; //???
// }
// else
// {
// // If the exception has gone unhandled in the first pass, we wouldn't have a chance
// // to set the target unwind frame. Check for this case now.
// // if (m_sfResumeStackFrame.IsNull())
// // {
// // m_sfResumeStackFrame = sfInterceptStackFrame;
// // }
// // _ASSERTE(m_sfResumeStackFrame == sfInterceptStackFrame);

// if ((pInterceptMD == pMD) && (sfInterceptStackFrame == pExInfo->m_frameIter.m_crawl.GetRegisterSet()->SP))
// {
// // If we have reached the stack frame at which the exception is intercepted,
// // then finish the second pass prematurely.
// // SecondPassIsComplete(pMD, sf);
// // ReturnStatus = SecondPassComplete;
// // goto lExit;
// result = false; //???
// }
// }

// return result;
// }

extern "C" BOOL QCALLTYPE EHEnumNext(EH_CLAUSE_ENUMERATOR* pEHEnum, RhEHClause* pEHClause)
{
QCALL_CONTRACT;
Expand Down Expand Up @@ -8188,7 +8144,6 @@ extern "C" bool QCALLTYPE SfiInit(StackFrameIterator* pThis, CONTEXT* pStackwalk
ExInfo* pExInfo = pThread->GetExceptionState()->GetCurrentExInfo();
REGDISPLAY* pRD = pExInfo->m_pRD;


if (pExInfo->m_passNumber == 1)
{
GCX_COOP();
Expand Down Expand Up @@ -8245,6 +8200,7 @@ extern "C" bool QCALLTYPE SfiInit(StackFrameIterator* pThis, CONTEXT* pStackwalk
else
{
EEToProfilerExceptionInterfaceWrapper::ExceptionSearchCatcherFound(pMD);
EEToProfilerExceptionInterfaceWrapper::ExceptionSearchFunctionLeave(pMD);

// We don't need to do anything special for continuable exceptions after calling
// this callback. We are going to start unwinding anyway.
Expand Down Expand Up @@ -8284,22 +8240,19 @@ extern "C" bool QCALLTYPE SfiInit(StackFrameIterator* pThis, CONTEXT* pStackwalk
result = (retVal != SWA_FAILED);
}

MethodDesc *pMD = pThis->m_crawl.GetFunction();
if (pExInfo->m_passNumber == 1)
{
MethodDesc *pMD = pThis->m_crawl.GetFunction();
EEToProfilerExceptionInterfaceWrapper::ExceptionSearchFunctionEnter(pMD);

// Notify the debugger that we are on the first pass for a managed exception.
// Note that this callback is made for every managed frame.
EEToDebuggerExceptionInterfaceWrapper::FirstChanceManagedException(pThread, GetControlPC(pThis->m_crawl.GetRegisterSet()), GetRegdisplaySP(pThis->m_crawl.GetRegisterSet()));
}

// // check if the exception is intercepted.
// if (result && pExInfo->m_ExceptionFlags.DebuggerInterceptInfo())
// {
// MethodDesc *pMD = pThis->m_crawl.GetFunction();
// result = ProcessDebuggerInterception(pExInfo, pMD);
// }
else
{
EEToProfilerExceptionInterfaceWrapper::ExceptionUnwindFunctionEnter(pMD);
}

pExInfo->m_sfLowBound = GetRegdisplaySP(pThis->m_crawl.GetRegisterSet());

Expand Down Expand Up @@ -8344,6 +8297,16 @@ extern "C" bool QCALLTYPE SfiNext(StackFrameIterator* pThis, uint* uExCollideCla
ExInfo* pExInfo = pThis->GetNextExInfo();
ExInfo* pTopExInfo = pThread->GetExceptionState()->GetCurrentExInfo();

MethodDesc *pMD = pThis->m_crawl.GetFunction();
if (pTopExInfo->m_passNumber == 1)
{
EEToProfilerExceptionInterfaceWrapper::ExceptionSearchFunctionLeave(pMD);
}
else
{
EEToProfilerExceptionInterfaceWrapper::ExceptionUnwindFunctionLeave(pMD);
}

// Check for reverse pinvoke (but eliminate the case when the caller is managed) or CallDescrWorkerInternal.
if (!ExecutionManager::IsManagedCode(GetIP(pThis->m_crawl.GetRegisterSet()->pCallerContext)))
{
Expand Down Expand Up @@ -8489,7 +8452,7 @@ extern "C" bool QCALLTYPE SfiNext(StackFrameIterator* pThis, uint* uExCollideCla
}
else if (pTopExInfo->m_passNumber == 1)
{
MethodDesc *pMD = pFrame->GetFunction();
pMD = pFrame->GetFunction();
if (pMD != NULL)
{
GCX_COOP();
Expand All @@ -8505,22 +8468,19 @@ extern "C" bool QCALLTYPE SfiNext(StackFrameIterator* pThis, uint* uExCollideCla

_ASSERTE(retVal == SWA_FAILED || pThis->GetFrameState() == StackFrameIterator::SFITER_FRAMELESS_METHOD);

pMD = pThis->m_crawl.GetFunction();
if (pTopExInfo->m_passNumber == 1)
{
MethodDesc *pMD = pThis->m_crawl.GetFunction();
EEToProfilerExceptionInterfaceWrapper::ExceptionSearchFunctionEnter(pMD);

// Notify the debugger that we are on the first pass for a managed exception.
// Note that this callback is made for every managed frame.
EEToDebuggerExceptionInterfaceWrapper::FirstChanceManagedException(pThread, GetControlPC(pThis->m_crawl.GetRegisterSet()), GetRegdisplaySP(pThis->m_crawl.GetRegisterSet()));
}

// // check if the exception is intercepted.
// if ((retVal != SWA_FAILED) && pExInfo->m_ExceptionFlags.DebuggerInterceptInfo())
// {
// MethodDesc *pMD = pThis->m_crawl.GetFunction();
// result = ProcessDebuggerInterception(pExInfo, pMD);
// }
else
{
EEToProfilerExceptionInterfaceWrapper::ExceptionUnwindFunctionEnter(pMD);
}

Exit:;
END_QCALL;
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/vm/exinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ void ExInfo::MakeCallbacksRelatedToHandler(

if (fBeforeCallingHandler)
{
m_EHClauseInfo.SetManagedCodeEntered(TRUE);
StackFrame sfToStore = sf;
if ((m_pPrevExInfo != NULL) &&
(m_pPrevExInfo->m_csfEnclosingClause == m_csfEnclosingClause))
Expand Down Expand Up @@ -429,6 +430,8 @@ void ExInfo::MakeCallbacksRelatedToHandler(
}
}

// TODO: when exception happens in filter, this is not called!
m_EHClauseInfo.SetManagedCodeEntered(FALSE);
m_EHClauseInfo.ResetInfo();
}
}
Expand Down

0 comments on commit a6f73a1

Please sign in to comment.