diff --git a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs index 251d6c0ae7093d..6110b801d747e7 100644 --- a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs +++ b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs @@ -708,14 +708,14 @@ private static void DispatchEx(scoped ref StackFrameIterator frameIter, ref ExIn uint startIdx = MaxTryRegionIdx; for (; isValid; isValid = frameIter.Next(&startIdx, &unwoundReversePInvoke)) { - prevControlPC = frameIter.ControlPC; - prevOriginalPC = frameIter.OriginalControlPC; - // For GC stackwalking, we'll happily walk across native code blocks, but for EH dispatch, we // disallow dispatching exceptions across native code. if (unwoundReversePInvoke) break; + prevControlPC = frameIter.ControlPC; + prevOriginalPC = frameIter.OriginalControlPC; + DebugScanCallFrame(exInfo._passNumber, frameIter.ControlPC, frameIter.SP); UpdateStackTrace(exceptionObj, exInfo._frameIter.FramePointer, (IntPtr)frameIter.OriginalControlPC, frameIter.SP, ref isFirstRethrowFrame, ref prevFramePtr, ref isFirstFrame, ref exInfo); diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeExceptionHelpers.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeExceptionHelpers.cs index d156c034bdb247..fbe17e69ef95c2 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeExceptionHelpers.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeExceptionHelpers.cs @@ -221,7 +221,7 @@ internal static unsafe void FailFast(string? message, Exception? exception, RhFa string outputMessage; if (exception != null) { - prefix = "Unhandled Exception: "; + prefix = "Unhandled exception. "; outputMessage = exception.ToString(); } else diff --git a/src/tests/baseservices/exceptions/unhandled/unhandled.cs b/src/tests/baseservices/exceptions/unhandled/unhandled.cs new file mode 100644 index 00000000000000..0fa3a4798f2c61 --- /dev/null +++ b/src/tests/baseservices/exceptions/unhandled/unhandled.cs @@ -0,0 +1,101 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; + +namespace TestUnhandledException +{ + class Program + { + static int Main(string[] args) + { + if (args.Length != 0) + { + throw new Exception("Test"); + } + + List lines = new List(); + + Process testProcess = new Process(); + + testProcess.StartInfo.FileName = Environment.ProcessPath; + testProcess.StartInfo.Arguments = Environment.CommandLine + " throw"; + testProcess.StartInfo.RedirectStandardError = true; + testProcess.ErrorDataReceived += (sender, line) => + { + Console.WriteLine($"\"{line.Data}\""); + if (!string.IsNullOrEmpty(line.Data)) + { + lines.Add(line.Data); + } + }; + + testProcess.Start(); + testProcess.BeginErrorReadLine(); + testProcess.WaitForExit(); + testProcess.CancelErrorRead(); + + int expectedExitCode; + if (TestLibrary.Utilities.IsMonoRuntime) + { + expectedExitCode = 1; + } + else if (!OperatingSystem.IsWindows()) + { + expectedExitCode = 128 + 6; + } + else if (TestLibrary.Utilities.IsNativeAot) + { + expectedExitCode = unchecked((int)0xC0000409); + } + else + { + expectedExitCode = unchecked((int)0xE0434352); + } + + if (expectedExitCode != testProcess.ExitCode) + { + Console.WriteLine($"Wrong exit code 0x{testProcess.ExitCode:X8}"); + return 101; + } + + int exceptionStackFrameLine = 1; + if (TestLibrary.Utilities.IsMonoRuntime) + { + if (lines[0] != "Unhandled Exception:") + { + Console.WriteLine("Missing Unhandled exception header"); + return 102; + } + if (lines[1] != "System.Exception: Test") + { + Console.WriteLine("Missing exception type and message"); + return 103; + } + + exceptionStackFrameLine = 2; + } + else + { + if (lines[0] != "Unhandled exception. System.Exception: Test") + { + Console.WriteLine("Missing Unhandled exception header"); + return 102; + } + + } + + if (!lines[exceptionStackFrameLine].TrimStart().StartsWith("at TestUnhandledException.Program.Main")) + { + Console.WriteLine("Missing exception source frame"); + return 103; + } + + return 100; + } + } +} diff --git a/src/tests/baseservices/exceptions/unhandled/unhandled.csproj b/src/tests/baseservices/exceptions/unhandled/unhandled.csproj new file mode 100644 index 00000000000000..047f77d45e41cb --- /dev/null +++ b/src/tests/baseservices/exceptions/unhandled/unhandled.csproj @@ -0,0 +1,12 @@ + + + Exe + false + + + + + + + + diff --git a/src/tests/issues.targets b/src/tests/issues.targets index 88ff8034743849..2d24f9707abc3e 100644 --- a/src/tests/issues.targets +++ b/src/tests/issues.targets @@ -3230,6 +3230,9 @@ + + System.Diagnostics.Process is not supported + System.Threading.Thread.UnsafeStart not supported