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

Conversation

@ateoi
Copy link

@ateoi ateoi commented Feb 21, 2018

Fix #15780

}

if (bSkipLastElement && gc.stackTrace.Size() != 0)
gc.stackTrace.AppendSkipLast(m_pStackTrace, m_pStackTrace + m_dFrameCount);
Copy link
Member

Choose a reason for hiding this comment

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

AppendSkipLast seems to be unused now. Delete it?

Copy link
Member

Choose a reason for hiding this comment

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

Also: StackTraceElement.PartiallyEqual/PartialAtomicUpdate

Copy link
Author

Choose a reason for hiding this comment

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

Pushed d938b0c to remove them.

@jkotas
Copy link
Member

jkotas commented Feb 21, 2018

@ateoi Thanks for fixing this!

Copy link
Member

@janvorli janvorli left a comment

Choose a reason for hiding this comment

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

LGTM modulo @jkotas's comments.

@danmoseley
Copy link
Member

Great to see a fix for this.

You might want to open a bug in the dotnet/docs repo to update this text for 2.1:

If the exception is thrown, and later rethrown, in the same method, the stack trace only contains the location where the exception was rethrown and does not include the location where the exception was originally thrown.

@danmoseley
Copy link
Member

danmoseley commented Feb 21, 2018

Also, would you be willing to open a PR in the corefx repo to add a test? I am not certain the best place, I don't see tests specifically for what is in Exception.StackTrace. Some possible places are

src\System.Runtime\tests\System\Runtime\ExceptionServices\ExceptionDispatchInfoTests.netcoreapp.cs
src\System.Runtime.Extensions\tests\System\Environment.StackTrace.cs
src\System.Diagnostics.StackTrace\tests\StackTraceTests.cs
src\System.Runtime\tests\System\ExceptionTests.cs
A naive test could do something like

        static int expectedThrowLine;

       [Fact]
        static void ThrowStatementDoesNotResetExceptionStackLine()
        {
            try
            {
                DoStuff();
            }
            catch (Exception ex)
            {
                int reportedThrowLine = Convert.ToInt32(Regex.Match(ex.StackTrace, @".*DoStuff[^\n]*line (\d+)", RegexOptions.Multiline).Groups[1].Value);
                Assert.Equals(expectedThrowLine, reportedThrowLine);
            }

        }

        private static void DoStuff()
        {
            try
            {
                expectedThrowLine = 1 + Convert.ToInt32(Regex.Match(Environment.StackTrace, @".*DoStuff[^\n]*line (\d+)", RegexOptions.Multiline).Groups[1].Value);
                throw new Exception("Boom!");
            }
            catch (Exception)
            {
                throw;
            }
        }

if (bSkipLastElement && gc.stackTrace.Size() != 0)
gc.stackTrace.AppendSkipLast(m_pStackTrace, m_pStackTrace + m_dFrameCount);
else
if (!bSkipLastElement)
Copy link
Member

Choose a reason for hiding this comment

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

Despite reading the code, I cannot form a picture of what is going on here. What is the purpose of bSkipLastElement ?

Copy link
Author

Choose a reason for hiding this comment

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

From my analysis, this flag is set during a rethrown exception handling.

if (STS_FirstRethrowFrame == STState)
{
bSkipLastElement = TRUE;
}

@danmoseley
Copy link
Member

Our tests for ExceptionDispatchInfo (all in ExceptionDispatchInfoTests.netcoreapp.cs) probably ought to do some similar line number verification (example). Not your job, of course.

- StackTraceArray::AppendSkipLast
- StackTraceElement::PartiallyEqual
- StackTraceElement::PartialAtomicUpdate
@ateoi
Copy link
Author

ateoi commented Feb 21, 2018

Ok, I can open a bug for the doc and submit a PR to add a test.

@danmoseley
Copy link
Member

@jkotas any other feedback?

@danmoseley
Copy link
Member

Oop, we generally wait for the test PR to be up before merging the implementation PR.

@jkotas
Copy link
Member

jkotas commented Feb 21, 2018

@jkotas any other feedback?

Looks fine to me.

we generally wait for the test PR to be up before merging the implementation PR.

As far as I know, we have no automated tests for the stacktraces, and we have merged number of tweaks of the stacktraces without them (e.g. #14655). It would be a bit unfair to block this one on tests. I agree that we should add tests for this though.

@danmoseley
Copy link
Member

OK

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants