Skip to content

Assert in MethodDebugInformation ctor when generating stack in invalid generated code #26440

Open
@danmoseley

Description

During execution of my test, it attempted to execute invalid ref-emitted code. XUnit invoked Exception.GetStackTrace. This hit this assert

        internal MethodDebugInformation(MetadataReader reader, MethodDebugInformationHandle handle)
        {
            Debug.Assert(reader != null);
            Debug.Assert(!handle.IsNil); // <<<<<<

with the callstack below. this is because MetadataTokens.Handle(methodToken); returned a Handle with IsNil set to true. Perhaps this is because the methodToken is generated in memory, so there is no source information to read.

>	System.Private.CoreLib.dll!System.Diagnostics.Debug.Assert(bool condition, string message, string detailMessage) Line 107	C#	Symbols loaded.
 	System.Reflection.Metadata.dll!System.Reflection.Metadata.MethodDebugInformation.MethodDebugInformation(System.Reflection.Metadata.MetadataReader reader, System.Reflection.Metadata.MethodDebugInformationHandle handle) Line 25	C#	Symbols loaded.
 	System.Reflection.Metadata.dll!System.Reflection.Metadata.MetadataReader.GetMethodDebugInformation(System.Reflection.Metadata.MethodDebugInformationHandle handle) Line 1371	C#	Symbols loaded.
 	System.Diagnostics.StackTrace.dll!System.Diagnostics.StackTraceSymbols.GetSourceLineInfo(string assemblyPath, System.IntPtr loadedPeAddress, int loadedPeSize, System.IntPtr inMemoryPdbAddress, int inMemoryPdbSize, int methodToken, int ilOffset, out string sourceFile, out int sourceLine, out int sourceColumn) Line 67	C#	Symbols loaded.
 	System.Private.CoreLib.dll!System.Diagnostics.StackFrameHelper.InitializeSourceInfo(int iSkip, bool fNeedFileInfo, System.Exception exception) Line 135	C#	Symbols loaded.
 	System.Private.CoreLib.dll!System.Diagnostics.StackTrace.CaptureStackTrace(int iSkip, bool fNeedFileInfo, System.Threading.Thread targetThread, System.Exception e) Line 203	C#	Symbols loaded.
 	System.Private.CoreLib.dll!System.Diagnostics.StackTrace.StackTrace(System.Exception e, bool fNeedFileInfo) Line 110	C#	Symbols loaded.
 	System.Private.CoreLib.dll!System.Environment.GetStackTrace(System.Exception e, bool needFileInfo) Line 346	C#	Symbols loaded.
 	System.Private.CoreLib.dll!System.Exception.GetStackTrace(bool needFileInfo) Line 335	C#	Symbols loaded.
 	xunit.execution.dotnet.dll!Xunit.Sdk.ExceptionUtility.ConvertExceptionToFailureInformation(System.Exception ex, int parentIndex, System.Collections.Generic.List<string> exceptionTypes, System.Collections.Generic.List<string> messages, System.Collections.Generic.List<string> stackTraces, System.Collections.Generic.List<int> indices) Line 175	C#	Symbols loaded.

If I comment out the assert, I can get a stack:

   System.InvalidProgramException : JIT Compiler encountered an internal limitation.
        Stack Trace:
              at FindFirstChar282(RegexRunner )
              at System.Text.RegularExpressions.CompiledRegexRunner.FindFirstChar()
              at System.Text.RegularExpressions.RegexRunner.Scan(Regex regex, String text, Int32 textbeg, Int32 textend, Int32 textstart, Int32 prevlen, Boolean quick, TimeSpan timeout)

If the code in System.Diagnostics.StackTrace and System.Reflection.Metadata is all working correctly here, then can we remove the assert? CoreFX tests are typically run with100% debug binaries.

@tmat

Activity

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

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions