-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Fix unhandled exception line number issues #1890
Conversation
// JIT_OverFlow, etc.) that caused a software exception. | ||
// 3) The instruction after the call to a managed function (non-leaf node). | ||
// | ||
// #2 and #3 are the cases that need to adjust dwOffset because they point after the call instructionand |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// #2 and #3 are the cases that need to adjust dwOffset because they point after the call instructionand | |
// #2 and #3 are the cases that need to adjust dwOffset because they point after the call instruction and |
There are a few paths to get the place (DebugStackTrace::DebugStackTraceElement::InitPass2) where the offset/ip needs an adjustment: 1) The System.Diagnostics.StackTrace constructors that take an exception object. The stack trace in the exception object is used (from the _stackTrace field). 2) Processing an unhandled exception for display (ExceptionTracker::ProcessOSExceptionNotification). 3) The System.Diagnostics.StackTrace constructors that don't take an exception object that get the stack trace of the current thread. The changes for cases dotnet#1 and 2 start with StackTraceInfo/StackTraceElement structs (adding the "fAdjustOffset" field) when the stack trace for an exception is generated and is put in the private _stackTrace Exception object field. When the stack trace for an exception is rendered to a string (via the GetStackFramesInternal FCALL) the internal GetStackFramesData/DebugStackTraceElement structs are initialized and the new fAdjustOffset field there is set from the one in StackTraceElement. That is where the IL offset is calculated and this flag is used to decrement the native offset enough to point to actual instruction that caused the exception. For case dotnet#3 all this happens in the GetStackFramesInternal FCALL called from the managed constructor building the GetStackFramesData/DebugStackTraceElement structs directly. Fixes issues dotnet#27765 and dotnet#25740.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is going to break PrintException in SOS : (
@@ -30,6 +30,9 @@ struct StackTraceElement | |||
// TRUE if this element represents the last frame of the foreign | |||
// exception stack trace. | |||
BOOL fIsLastFrameFromForeignStackTrace; | |||
// TRUE if the ip needs to be adjusted back to the calling or | |||
// throwing instruction. | |||
BOOL fAdjustOffset; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't see this SOS dependency and I was looking at this code for the SOS line number fix. Thanks for catching this.
// This is a workaround to fix the generation of stack traces from exception objects so that | ||
// they point to the line that actually generated the exception instead of the line | ||
// following. | ||
if (!(pCf->HasFaulted() || pCf->IsIPadjusted()) && pStackTraceElem->ip != 0) | ||
if (!pStackTraceElem->fAdjustOffset && pStackTraceElem->ip != 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic appears to have been negated?
!fAdjustOffset ==
!(!pCf->HasFaulted() && !pCf->IsIPadjusted()) ==
( pCf->HasFaulted() || pCf->IsIPadjusted())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what I was thinking. It is simple Boolean logic.
There are a few paths to get the place (DebugStackTrace::DebugStackTraceElement::InitPass2) where
the offset/ip needs an adjustment:
the exception object is used (from the _stackTrace field).
stack trace of the current thread.
The changes for cases #1 and 2 start with StackTraceInfo/StackTraceElement structs (adding the
"fAdjustOffset" field) when the stack trace for an exception is generated and is put in the private
_stackTrace Exception object field.
When the stack trace for an exception is rendered to a string (via the GetStackFramesInternal FCALL)
the internal GetStackFramesData/DebugStackTraceElement structs are initialized and the new fAdjustOffset
field there is set from the one in StackTraceElement. That is where the IL offset is calculated and
this flag is used to decrement the native offset enough to point to actual instruction that caused the
exception.
For case #3 all this happens in the GetStackFramesInternal FCALL called from the managed constructor
building the GetStackFramesData/DebugStackTraceElement structs directly.
Fixes dotnet/coreclr#27765 and fixes dotnet/coreclr#25740.