Skip to content

Prevent assert if stack trace has function pointer #63787

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 9 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,12 @@ private void EmitTypeName(Handle typeHandle, bool namespaceQualified)
EmitString(typeHandle.ToGenericParameterHandle(_metadataReader).GetGenericParameter(_metadataReader).Name);
break;

case HandleType.FunctionPointerSignature:
EmitFunctionPointerTypeName();
break;

default:
Debug.Assert(false);
Debug.Assert(false, $"Type handle {typeHandle.HandleType} was not handled");
_outputBuilder.Append("???");
break;
}
Expand Down Expand Up @@ -407,6 +411,14 @@ private void EmitPointerTypeName(PointerSignatureHandle pointerSigHandle)
_outputBuilder.Append('*');
}

/// <summary>
/// Emit function pointer type.
/// </summary>
private void EmitFunctionPointerTypeName()
{
_outputBuilder.Append("IntPtr");
}

/// <summary>
/// Emit by-reference type.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,15 @@ public void ToString_NullFrame_ThrowsNullReferenceException()
Assert.Equal(Environment.NewLine, stackTrace.ToString());
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/11354", TestRuntimes.Mono)]
public unsafe void ToString_FunctionPointerSignature()
{
// This is sepate from ToString_Invoke_ReturnsExpected since unsafe cannot be used for iterators
var stackTrace = FunctionPointerParameter(null);
Copy link
Contributor

Choose a reason for hiding this comment

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

Usage of explicit type (for reference: Coding Guidelines))

Suggested change
var stackTrace = FunctionPointerParameter(null);
StackTrace stackTrace = FunctionPointerParameter(null);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see var style used a lot in this file. I would say most of the time.

Assert.Contains("System.Diagnostics.Tests.StackTraceTests.FunctionPointerParameter(IntPtr x)", stackTrace.ToString());
}

[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
public void ToString_ShowILOffset()
{
Expand Down Expand Up @@ -384,6 +393,9 @@ public void ToString_ShowILOffset()
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
private static StackTrace TwoParameters(int x, string y) => new StackTrace();

[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
private unsafe static StackTrace FunctionPointerParameter(delegate*<void> x) => new StackTrace();

[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
private static StackTrace Generic<T>() => new StackTrace();
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
<TestRuntime>true</TestRuntime>
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

<!-- these tests depend on the pdb files -->
<DebuggerSupport Condition="'$(DebuggerSupport)' == '' and '$(TargetOS)' == 'Browser'">true</DebuggerSupport>
Expand Down