Skip to content
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 #2269

Merged
merged 5 commits into from
Jan 30, 2020
Merged

Conversation

mikem8361
Copy link
Member

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.

For cases #1 and #2 the StackTraceInfo/StackTraceElement structs are built when the stack trace
for an exception is generated and is put in the private _stackTrace Exception object field. The
IP in each StackTraceElement is decremented for hardware exceptions and not for software exceptions because the CrawlFrame isInterrupted/hasFaulted fields are not initialized (always false). This is backwards for h/w exceptions leaf node frames but really can't be changed to be compatible with other code in the runtime and SOS.

The fIsLastFrameFromForeignStackTrace BOOL in the StackTraceElement/DebugStackTraceElement structs have been replaced with INT "flags" field defined by the StackTraceElementFlags enum. There is a new flag that is set (STEF_IP_ADJUSTED) if the IP has been already adjusted/decremented. This flag is used to adjust the native offset when it is converted to an IL offset for source/line number lookup in DebugStackTraceElement::InitPass2().

When the stack trace for an exception is rendered to a string (via the GetStackFramesInternal FCALL)
the internal GetStackFramesData/DebugStackTraceElement structs are initialized. This new "flags"
field is passed from the StackTraceElement to the DebugStackTraceElement struct.

For case #3 all this happens in the GetStackFramesInternal FCALL called from the managed constructor building the GetStackFramesData/DebugStackTraceElement structs directly.

Fixes issues #27765 and #25740.

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.

For cases dotnet#1 and dotnet#2 the StackTraceInfo/StackTraceElement structs are built when the stack trace
for an exception is generated and is put in the private _stackTrace Exception object field. The
IP in each StackTraceElement is decremented for hardware exceptions and not for software exceptions
because the CrawlFrame isInterrupted/hasFaulted fields are not initialized (always false). This is
backwards for h/w exceptions leaf node frames but really can't be changed to be compatible with
other code in the runtime and SOS.

The fIsLastFrameFromForeignStackTrace BOOL in the StackTraceElement/DebugStackTraceElement structs
have been replaced with INT "flags" field defined by the StackTraceElementFlags enum. There is a new
flag that is set (STEF_IP_ADJUSTED) if the IP has been already adjusted/decremented. This flag is
used to adjust the native offset when it is converted to an IL offset for source/line number lookup
in DebugStackTraceElement::InitPass2().

When the stack trace for an exception is rendered to a string (via the GetStackFramesInternal FCALL)
the internal GetStackFramesData/DebugStackTraceElement structs are initialized. This new "flags"
field is passed from the StackTraceElement to the DebugStackTraceElement struct.

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.
@mikem8361 mikem8361 added this to the 5.0 milestone Jan 28, 2020
@mikem8361 mikem8361 self-assigned this Jan 28, 2020
src/coreclr/src/vm/clrex.h Outdated Show resolved Hide resolved
@mikem8361
Copy link
Member Author

@noahfalk ping?

@noahfalk
Copy link
Member

Sorry for the delay, its on my todo list today.

Copy link
Member

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

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

LGTM

src/coreclr/src/vm/clrex.h Outdated Show resolved Hide resolved
src/coreclr/src/vm/debugdebugger.cpp Outdated Show resolved Hide resolved
src/coreclr/src/vm/clrex.h Show resolved Hide resolved
@mikem8361 mikem8361 merged commit 843d66b into dotnet:master Jan 30, 2020
@mikem8361 mikem8361 deleted the linenums branch January 30, 2020 21:21
@ghost ghost locked as resolved and limited conversation to collaborators Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants