internal DispatchState CaptureDispatchState() { MonoStackFrame[]? stackFrames; if (_traceIPs != null) { stackFrames = Diagnostics.StackTrace.get_trace(this, 0, true); if (stackFrames.Length > 0) { stackFrames[stackFrames.Length - 1].isLastFrameFromForeignException = true; } if (foreignExceptionsFrames != null) { var combinedStackFrames = new MonoStackFrame[stackFrames.Length + foreignExceptionsFrames.Length]; Array.Copy(foreignExceptionsFrames, 0, combinedStackFrames, 0, foreignExceptionsFrames.Length); Array.Copy(stackFrames, 0, combinedStackFrames, foreignExceptionsFrames.Length, stackFrames.Length); stackFrames = combinedStackFrames; } } else { stackFrames = foreignExceptionsFrames; } return(new DispatchState(stackFrames)); }
internal DispatchState CaptureDispatchState() { MonoStackFrame[]? stackFrames; if (_traceIPs != null) { stackFrames = Diagnostics.StackTrace.get_trace(this, 0, true); if (stackFrames.Length > 0) { stackFrames[stackFrames.Length - 1].isLastFrameFromForeignException = true; } // Make sure foreignExceptionsFrames does not change at this point. // Otherwise, the Array.Copy into combinedStackFrames can fail due to size differences // // See https://github.com/dotnet/runtime/issues/70081 MonoStackFrame[]? feFrames = foreignExceptionsFrames; if (feFrames != null) { var combinedStackFrames = new MonoStackFrame[stackFrames.Length + feFrames.Length]; Array.Copy(feFrames, 0, combinedStackFrames, 0, feFrames.Length); Array.Copy(stackFrames, 0, combinedStackFrames, feFrames.Length, stackFrames.Length); stackFrames = combinedStackFrames; } } else { stackFrames = foreignExceptionsFrames; } return(new DispatchState(stackFrames)); }