Skip to content

Commit

Permalink
Add DebuggerDisableUserUnhandledExceptionsAttribute (#104813)
Browse files Browse the repository at this point in the history
  • Loading branch information
halter73 authored Jul 16, 2024
1 parent 0f2e63f commit 2f09bfa
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace System.Diagnostics
{
public static class Debugger
public static partial class Debugger
{
[MethodImpl(MethodImplOptions.NoInlining)]
[DebuggerHidden] // this helps VS appear to stop on the source line calling Debugger.Break() instead of inside it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Contracts\Contracts.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Debug.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\DebuggableAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Debugger.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\DebuggerBrowsableAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\DebuggerDisableUserUnhandledExceptionsAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\DebuggerDisplayAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\DebuggerHiddenAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\DebuggerNonUserCodeAttribute.cs" />
Expand Down Expand Up @@ -2799,4 +2801,4 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\IUnaryPlusOperators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\IUnsignedNumber.cs" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;

namespace System.Diagnostics
{
public static partial class Debugger
{
/// <summary>
/// Signals a breakpoint to an attached debugger with the <paramref name="exception"/> details
/// if a .NET debugger is attached with break on user-unhandled exception enabled and a method
/// attributed with DebuggerDisableUserUnhandledExceptionsAttribute calls this method.
/// </summary>
/// <param name="exception">The user-unhandled exception.</param>
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void BreakForUserUnhandledException(Exception exception)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Diagnostics
{
/// <summary>
/// If a .NET Debugger is attached which supports the Debugger.BreakForUserUnhandledException(Exception) API,
/// this attribute will prevent the debugger from breaking on user-unhandled exceptions when the
/// exception is caught by a method with this attribute, unless BreakForUserUnhandledException is called.
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public sealed class DebuggerDisableUserUnhandledExceptionsAttribute : Attribute
{
}
}
6 changes: 6 additions & 0 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8666,6 +8666,7 @@ public static partial class Debugger
public static readonly string? DefaultCategory;
public static bool IsAttached { get { throw null; } }
public static void Break() { }
public static void BreakForUserUnhandledException(System.Exception exception) { }
public static bool IsLogging() { throw null; }
public static bool Launch() { throw null; }
public static void Log(int level, string? category, string? message) { }
Expand All @@ -8683,6 +8684,11 @@ public enum DebuggerBrowsableState
Collapsed = 2,
RootHidden = 3,
}
[System.AttributeUsage(System.AttributeTargets.Method)]
public sealed class DebuggerDisableUserUnhandledExceptionsAttribute : System.Attribute
{
public DebuggerDisableUserUnhandledExceptionsAttribute() { }
}
[System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Field | System.AttributeTargets.Property | System.AttributeTargets.Struct, AllowMultiple=true)]
public sealed partial class DebuggerDisplayAttribute : System.Attribute
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace System.Diagnostics
{
public static class Debugger
public static partial class Debugger
{
public static readonly string? DefaultCategory;

Expand Down

0 comments on commit 2f09bfa

Please sign in to comment.