Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -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);
Expand Down
78 changes: 78 additions & 0 deletions src/tests/baseservices/exceptions/unhandled/unhandled.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// 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<string> lines = new List<string>();

Process testProcess = new Process();

testProcess.StartInfo.FileName = Environment.ProcessPath;
testProcess.StartInfo.Arguments = Environment.CommandLine + " throw";
testProcess.StartInfo.UseShellExecute = false;
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 ((Environment.OSVersion.Platform == PlatformID.Unix) || (Environment.OSVersion.Platform == PlatformID.MacOSX))
{
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;
}

if (Regex.Match(lines[0], @"Unhandled exception[.:] System\.Exception\: Test", RegexOptions.IgnoreCase) == Match.Empty)
{
Console.WriteLine("Missing Unhandled exception header");
return 102;
}

if (!lines[1].TrimStart().StartsWith("at TestUnhandledException.Program.Main"))
{
Console.WriteLine("Missing exception source frame");
return 103;
}

return 100;
}
}
}
12 changes: 12 additions & 0 deletions src/tests/baseservices/exceptions/unhandled/unhandled.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Optimize>false</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="unhandled.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
</ItemGroup>
</Project>