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 @@ -91,5 +91,16 @@ public static extern bool IsAttached
// report the notification depending on its settings.
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void CustomNotification(ICustomDebuggerNotification data);

/// <summary>
/// If a .NET Debugger is attached with break on user-unhandled exception enabled and a method attributed with
/// DebuggerDisableUserUnhandledExceptionsAttribute calls this method, the debugger will break with the
/// <paramref name="exception"/> details.
/// </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
Expand Up @@ -74,5 +74,16 @@ public static bool IsLogging()
}
return false;
}

/// <summary>
/// If a .NET Debugger is attached with break on user-unhandled exception enabled and a method attributed with
/// DebuggerDisableUserUnhandledExceptionsAttribute calls this method, the debugger will break with the
/// <paramref name="exception"/> details.
/// </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
Expand Up @@ -293,6 +293,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Debug.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\DebuggableAttribute.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 @@ -2800,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,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(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,
}
[AttributeUsage(AttributeTargets.Method)]
public sealed class DebuggerDisableUserUnhandledExceptionsAttribute : 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 @@ -41,5 +41,10 @@ public static void Log(int level, string? category, string? message)
public static void NotifyOfCrossThreadDependency()
{
}

[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void BreakForUserUnhandledException(Exception exception)
{
}
}
}