Add printing managed assert message to console (#8399)
authorJan Vorlicek <janvorli@microsoft.com>
Thu, 1 Dec 2016 07:51:52 +0000 (08:51 +0100)
committerJan Kotas <jkotas@microsoft.com>
Thu, 1 Dec 2016 07:51:52 +0000 (23:51 -0800)
I have discovered that when GUI assertion dialogs are disabled, the assert
message is not shown anywhere and the app just silently exits.
This change adds printing the message and stack trace to console in such case.

src/vm/debugdebugger.cpp

index 3617740..c8b76bf 100644 (file)
@@ -1367,11 +1367,6 @@ FCIMPL4(INT32, DebuggerAssert::ShowDefaultAssertDialog,
     
     int         result          = IDRETRY;
 
-    if (NoGuiOnAssert())
-    {
-        return FailTerminate;
-    }
-
     struct _gc {
         STRINGREF strCondition;
         STRINGREF strMessage;
@@ -1419,25 +1414,33 @@ FCIMPL4(INT32, DebuggerAssert::ShowDefaultAssertDialog,
         windowTitle.Set(W("Assert Failure"));
     }
 
-    // We're taking a string from managed code, and we can't be sure it doesn't have stuff like %s or \n in it.
-    // So, pass a format string of %s and pass the text as a vararg to our message box method.
-    // Also, varargs and StackSString don't mix.  Convert to string first.
-    const WCHAR* msgTextAsUnicode = msgText.GetUnicode();
-    result = EEMessageBoxNonLocalizedNonFatal(W("%s"), windowTitle, stackTraceText, MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION, msgTextAsUnicode);
-
-    // map the user's choice to the values recognized by 
-    // the System.Diagnostics.Assert package
-    if (result == IDRETRY)
-    {
-        result = FailDebug;
-    }
-    else if (result == IDIGNORE)
+    if (NoGuiOnAssert())
     {
-        result = FailIgnore;
+        fwprintf(stderr, W("%s\n%s\n%s\n"), windowTitle.GetUnicode(), msgText.GetUnicode(), stackTraceText.GetUnicode()); 
+        result = FailTerminate;
     }
     else
     {
-        result = FailTerminate;
+        // We're taking a string from managed code, and we can't be sure it doesn't have stuff like %s or \n in it.
+        // So, pass a format string of %s and pass the text as a vararg to our message box method.
+        // Also, varargs and StackSString don't mix.  Convert to string first.
+        const WCHAR* msgTextAsUnicode = msgText.GetUnicode();
+        result = EEMessageBoxNonLocalizedNonFatal(W("%s"), windowTitle, stackTraceText, MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION, msgTextAsUnicode);
+
+        // map the user's choice to the values recognized by 
+        // the System.Diagnostics.Assert package
+        if (result == IDRETRY)
+        {
+            result = FailDebug;
+        }
+        else if (result == IDIGNORE)
+        {
+            result = FailIgnore;
+        }
+        else
+        {
+            result = FailTerminate;
+        }
     }
 
     HELPER_METHOD_FRAME_END();