Skip to content

[release/7.0] Fix edit and continue in VS with hardware exceptions #76427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions src/coreclr/vm/excep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6533,32 +6533,13 @@ AdjustContextForJITHelpers(

#if defined(USE_FEF) && !defined(TARGET_UNIX)

static void FixContextForFaultingExceptionFrame(
EXCEPTION_POINTERS* ep,
EXCEPTION_RECORD* pOriginalExceptionRecord,
CONTEXT* pOriginalExceptionContext)
{
WRAPPER_NO_CONTRACT;

// don't copy param args as have already supplied them on the throw
memcpy((void*) ep->ExceptionRecord,
(void*) pOriginalExceptionRecord,
offsetof(EXCEPTION_RECORD, ExceptionInformation)
);

ReplaceExceptionContextRecord(ep->ContextRecord, pOriginalExceptionContext);

GetThread()->ResetThreadStateNC(Thread::TSNC_DebuggerIsManagedException);
}

struct HandleManagedFaultFilterParam
{
// It's possible for our filter to be called more than once if some other first-pass
// handler lets an exception out. We need to make sure we only fix the context for
// the first exception we see. This flag takes care of that.
BOOL fFilterExecuted;
EXCEPTION_RECORD *pOriginalExceptionRecord;
CONTEXT *pOriginalExceptionContext;
};

static LONG HandleManagedFaultFilter(EXCEPTION_POINTERS* ep, LPVOID pv)
Expand All @@ -6569,7 +6550,8 @@ static LONG HandleManagedFaultFilter(EXCEPTION_POINTERS* ep, LPVOID pv)

if (!pParam->fFilterExecuted)
{
FixContextForFaultingExceptionFrame(ep, pParam->pOriginalExceptionRecord, pParam->pOriginalExceptionContext);
ep->ExceptionRecord->ExceptionAddress = pParam->pOriginalExceptionRecord->ExceptionAddress;
GetThread()->ResetThreadStateNC(Thread::TSNC_DebuggerIsManagedException);
pParam->fFilterExecuted = TRUE;
}

Expand All @@ -6591,15 +6573,14 @@ void HandleManagedFault(EXCEPTION_RECORD* pExceptionRecord, CONTEXT* pContext)
HandleManagedFaultFilterParam param;
param.fFilterExecuted = FALSE;
param.pOriginalExceptionRecord = pExceptionRecord;
param.pOriginalExceptionContext = pContext;

PAL_TRY(HandleManagedFaultFilterParam *, pParam, &param)
{
GetThread()->SetThreadStateNC(Thread::TSNC_DebuggerIsManagedException);

EXCEPTION_RECORD *pRecord = pParam->pOriginalExceptionRecord;

RaiseException(pRecord->ExceptionCode, pRecord->ExceptionFlags,
RaiseException(pRecord->ExceptionCode, 0,
pRecord->NumberParameters, pRecord->ExceptionInformation);
}
PAL_EXCEPT_FILTER(HandleManagedFaultFilter)
Expand Down