Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 24a580c

Browse files
sywhangjkotas
authored andcommitted
Fix failfast stacktrace (dotnet/coreclr#15895)
* attempt to fix stacktrace getting printed twice * Fix some default parameter issues, and wrong commit from last commit * Fix build errors, switch call from Debug.Assert to new FailFast FCall * Fix signature to allow more types of exception title * cleanup * Addressing comments from PR * More PR comments * remove useless using * Address comments on GC hole and few naming changes Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
1 parent 120dce4 commit 24a580c

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/Common/src/CoreLib/System/Diagnostics/Debug.Unix.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static partial class Debug
1010
{
1111
private static readonly bool s_shouldWriteToStdErr = Environment.GetEnvironmentVariable("COMPlus_DebugWriteToStdErr") == "1";
1212

13-
private static void ShowAssertDialog(string stackTrace, string message, string detailMessage)
13+
private static void ShowDialog(string stackTrace, string message, string detailMessage, string errorSource)
1414
{
1515
if (Debugger.IsAttached)
1616
{
@@ -22,7 +22,7 @@ private static void ShowAssertDialog(string stackTrace, string message, string d
2222
// Fail in order to avoid anyone catching an exception and masking
2323
// an assert failure.
2424
var ex = new DebugAssertException(message, detailMessage, stackTrace);
25-
Environment.FailFast(ex.Message, ex);
25+
Environment.FailFast(ex.Message, ex, errorSource);
2626
}
2727
}
2828

src/Common/src/CoreLib/System/Diagnostics/Debug.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
// Do not remove this, it is needed to retain calls to these conditional methods in release builds
66
#define DEBUG
7+
using System.Diagnostics.Contracts;
8+
using System.Runtime.CompilerServices;
79

810
namespace System.Diagnostics
911
{
@@ -91,18 +93,34 @@ public static void Assert(bool condition, string message, string detailMessage)
9193
if (!condition)
9294
{
9395
string stackTrace;
94-
9596
try
9697
{
97-
stackTrace = Internal.Runtime.Augments.EnvironmentAugments.StackTrace;
98+
stackTrace = new StackTrace(0, true).ToString(System.Diagnostics.StackTrace.TraceFormat.Normal);
9899
}
99100
catch
100101
{
101102
stackTrace = "";
102103
}
104+
WriteLine(FormatAssert(stackTrace, message, detailMessage));
105+
s_ShowDialog(stackTrace, message, detailMessage, "Assertion Failed");
106+
}
107+
}
103108

109+
internal static void ContractFailure(bool condition, string message, string detailMessage, string failureKindMessage)
110+
{
111+
if (!condition)
112+
{
113+
string stackTrace;
114+
try
115+
{
116+
stackTrace = new StackTrace(0, true).ToString(System.Diagnostics.StackTrace.TraceFormat.Normal);
117+
}
118+
catch
119+
{
120+
stackTrace = "";
121+
}
104122
WriteLine(FormatAssert(stackTrace, message, detailMessage));
105-
s_ShowAssertDialog(stackTrace, message, detailMessage);
123+
s_ShowDialog(stackTrace, message, detailMessage, SR.GetResourceString(failureKindMessage));
106124
}
107125
}
108126

@@ -315,7 +333,8 @@ internal DebugAssertException(string message, string detailMessage, string stack
315333
}
316334

317335
// internal and not readonly so that the tests can swap this out.
318-
internal static Action<string, string, string> s_ShowAssertDialog = ShowAssertDialog;
336+
internal static Action<string, string, string, string> s_ShowDialog = ShowDialog;
337+
319338
internal static Action<string> s_WriteCore = WriteCore;
320339
}
321340
}

0 commit comments

Comments
 (0)