Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DebuggerDisableUserUnhandledExceptionsAttribute #104813

Merged
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably isn't going to make much of a difference, but should we add this new attribute to

<!-- The following attributes are only necessary when debugging is supported -->
<assembly fullname="System.Private.CoreLib" feature="System.Diagnostics.Debugger.IsSupported" featurevalue="false">
<type fullname="System.Diagnostics.DebuggableAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
<type fullname="System.Diagnostics.DebuggerBrowsableAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
<type fullname="System.Diagnostics.DebuggerDisplayAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
<type fullname="System.Diagnostics.DebuggerHiddenAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
<type fullname="System.Diagnostics.DebuggerNonUserCodeAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
<type fullname="System.Diagnostics.DebuggerStepperBoundaryAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
<type fullname="System.Diagnostics.DebuggerStepThroughAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
<type fullname="System.Diagnostics.DebuggerTypeProxyAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
<type fullname="System.Diagnostics.DebuggerVisualizerAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
</assembly>

That way it gets trimmed when DebuggerSupport is off.

{
}
}
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) { }
halter73 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading