Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Failfast windows event log #16875

Merged
merged 12 commits into from
Mar 27, 2018
37 changes: 23 additions & 14 deletions src/vm/eventreporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,11 +679,12 @@ void ReportExceptionStackHelper(OBJECTREF exObj, EventReporter& reporter, SmallS
//
// Arguments:
// pExceptionInfo - Exception information
// useManagedException - Flag to indicate whether it's okay to call Exception.ToString()
//
// Return Value:
// None
//
void DoReportForUnhandledException(PEXCEPTION_POINTERS pExceptionInfo)
void DoReportForUnhandledException(PEXCEPTION_POINTERS pExceptionInfo, BOOL useManagedException)
{
WRAPPER_NO_CONTRACT;

Expand All @@ -694,6 +695,7 @@ void DoReportForUnhandledException(PEXCEPTION_POINTERS pExceptionInfo)
EX_TRY
{
StackSString s;
bool doUnmanagedLogging = true;
if (pThread && pThread->HasException() != NULL)
{
GCX_COOP();
Expand All @@ -712,22 +714,29 @@ void DoReportForUnhandledException(PEXCEPTION_POINTERS pExceptionInfo)

if (IsException(gc.throwable->GetMethodTable()))
{
StackSString result;
// Assume we're calling Exception.InternalToString() ...
BinderMethodID sigID = METHOD__EXCEPTION__INTERNAL_TO_STRING;
// If we can use Exception.ToString(), we will use that to maintain consistency with what gets printed on Console
if (useManagedException)
{
StackSString result;
// Assume we're calling Exception.InternalToString() ...
BinderMethodID sigID = METHOD__EXCEPTION__INTERNAL_TO_STRING;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is trying to compute the same string as DefaultCatchHandler. Can we move the logging into the DefaultCatchHandler and eliminate this duplication?


// Get the MethodDesc on which we'll call.
MethodDescCallSite toString(sigID, &(gc.throwable));
// Get the MethodDesc on which we'll call.
MethodDescCallSite toString(sigID, &(gc.throwable));

// Make the call.
ARG_SLOT arg[1] = { ObjToArgSlot(gc.throwable) };
gc.exceptionString = toString.Call_RetSTRINGREF(arg);
if (gc.exceptionString != NULL)
{
gc.exceptionString->GetSString(result);
reporter.AddDescription(result);
// Make the call.
ARG_SLOT arg[1] = { ObjToArgSlot(gc.throwable) };
gc.exceptionString = toString.Call_RetSTRINGREF(arg);
if (gc.exceptionString != NULL)
{
gc.exceptionString->GetSString(result);
reporter.AddDescription(result);
doUnmanagedLogging = false;
}
}
else

// Otherwise we fall back to native log
if (doUnmanagedLogging)
{
SmallStackSString wordAt;
if (!wordAt.LoadResource(CCompRC::Optional, IDS_ER_WORDAT))
Expand Down
2 changes: 1 addition & 1 deletion src/vm/eventreporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ BOOL ShouldLogInEventLog();
// Record managed callstack in EventReporter.
void LogCallstackForEventReporter(EventReporter& reporter);
// Generate a report in EventLog for unhandled exception for both managed and unmanaged.
void DoReportForUnhandledException(PEXCEPTION_POINTERS pExceptionInfo);
void DoReportForUnhandledException(PEXCEPTION_POINTERS pExceptionInfo, BOOL shouldLogManaged);

#endif // _eventreporter_h_
21 changes: 15 additions & 6 deletions src/vm/excep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5234,10 +5234,6 @@ LONG InternalUnhandledExceptionFilter_Worker(
#endif // DEBUGGING_SUPPORTED


#if defined(FEATURE_EVENT_TRACE) && !defined(FEATURE_PAL)
DoReportForUnhandledException(pParam->pExceptionInfo);
#endif // FEATURE_EVENT_TRACE

//
// Except for notifying debugger, ignore exception if unmanaged, or
// if it's a debugger-generated exception or user breakpoint exception.
Expand All @@ -5257,10 +5253,16 @@ LONG InternalUnhandledExceptionFilter_Worker(

LOG((LF_EH, LL_INFO100, "InternalUnhandledExceptionFilter_Worker: Calling DefaultCatchHandler\n"));

BOOL useManagedExceptionLog = false;

// Call our default catch handler to do the managed unhandled exception work.
DefaultCatchHandler(pParam->pExceptionInfo, NULL, useLastThrownObject,
TRUE /*isTerminating*/, FALSE /*isThreadBaseFIlter*/, FALSE /*sendAppDomainEvents*/);
TRUE /*isTerminating*/, FALSE /*isThreadBaseFIlter*/, FALSE /*sendAppDomainEvents*/, &useManagedExceptionLog);

#if defined(FEATURE_EVENT_TRACE) && !defined(FEATURE_PAL)
DoReportForUnhandledException(pParam->pExceptionInfo, useManagedExceptionLog);
#endif // FEATURE_EVENT_TRACE


lDone: ;
}
Expand Down Expand Up @@ -5544,7 +5546,8 @@ DefaultCatchHandler(PEXCEPTION_POINTERS pExceptionPointers,
BOOL useLastThrownObject,
BOOL isTerminating,
BOOL isThreadBaseFilter,
BOOL sendAppDomainEvents)
BOOL sendAppDomainEvents,
BOOL *useManagedExceptionLog)
{
CONTRACTL
{
Expand Down Expand Up @@ -5725,6 +5728,12 @@ DefaultCatchHandler(PEXCEPTION_POINTERS pExceptionPointers,
// this is stack heavy because of the CQuickWSTRBase, so we break it out
// and don't have to carry the weight through our other code paths.
DefaultCatchHandlerExceptionMessageWorker(pThread, throwable, buf, buf_size);

// If this parameter was passed in, set it to true to indicate it's okay to use managed exception
if (useManagedExceptionLog)
{
*useManagedExceptionLog = true;
}
}
}
EX_CATCH
Expand Down
3 changes: 2 additions & 1 deletion src/vm/excep.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ void STDMETHODCALLTYPE DefaultCatchHandler(PEXCEPTION_POINTERS pExceptionInfo,
BOOL useLastThrownObject = FALSE,
BOOL isTerminating = FALSE,
BOOL isThreadBaseFilter = FALSE,
BOOL sendAppDomainEvents = TRUE);
BOOL sendAppDomainEvents = TRUE,
BOOL * shouldLogMessage = NULL);

void ReplaceExceptionContextRecord(T_CONTEXT *pTarget, T_CONTEXT *pSource);

Expand Down