diff options
author | Jan Kotas <jkotas@microsoft.com> | 2016-03-23 20:02:38 +0300 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2016-03-23 20:02:38 +0300 |
commit | 9b2906c1bb89bbdc270200f7d8f32361410ca789 (patch) | |
tree | 395d87c09fb37b8df8752a0c889a8908cf0a6617 /src/Native/Runtime/rhassert.cpp | |
parent | 02617d5e3d73a3811354f87f93e5d5997236d13e (diff) |
Rename runtime\assert.h to runtime\rhassert.h
Fixing TODOs about collisions with the system assert.h header
[tfs-changeset: 1589045]
Diffstat (limited to 'src/Native/Runtime/rhassert.cpp')
-rw-r--r-- | src/Native/Runtime/rhassert.cpp | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/Native/Runtime/rhassert.cpp b/src/Native/Runtime/rhassert.cpp new file mode 100644 index 000000000..1639f66d3 --- /dev/null +++ b/src/Native/Runtime/rhassert.cpp @@ -0,0 +1,98 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. +#include "common.h" +#include "CommonTypes.h" +#include "CommonMacros.h" +#include "PalRedhawkCommon.h" +#include "PalRedhawk.h" +#include "rhassert.h" + + +#include "RhConfig.h" + +#ifdef _DEBUG + +#define MB_ABORTRETRYIGNORE 0x00000002L +#define IDABORT 3 +#define IDRETRY 4 +#define IDIGNORE 5 + +void Assert(const char * expr, const char * file, UInt32 line_num, const char * message) +{ +#ifndef DACCESS_COMPILE +#ifdef NO_UI_ASSERT + PalDebugBreak(); +#else + if (g_pRhConfig->GetBreakOnAssert()) + { + printf( + "--------------------------------------------------\n" + "Debug Assertion Violation\n\n" + "%s%s%s" + "Expression: '%s'\n\n" + "File: %s, Line: %u\n" + "--------------------------------------------------\n", + message ? ("Message: ") : (""), + message ? (message) : (""), + message ? ("\n\n") : (""), + expr, file, line_num); + + // Flush standard output before failing fast to make sure the assertion failure message + // is retained when tests are being run with redirected stdout. + fflush(stdout); + + // If there's no debugger attached, we just FailFast + if (!PalIsDebuggerPresent()) + PalRaiseFailFastException(NULL, NULL, FAIL_FAST_GENERATE_EXCEPTION_ADDRESS); + + // If there is a debugger attached, we break and then allow continuation. + PalDebugBreak(); + return; + } + + char buffer[4096]; + + sprintf_s(buffer, COUNTOF(buffer), + "--------------------------------------------------\n" + "Debug Assertion Violation\n\n" + "%s%s%s" + "Expression: '%s'\n\n" + "File: %s, Line: %u\n" + "--------------------------------------------------\n" + "Abort: Exit Immediately\n" + "Retry: DebugBreak()\n" + "Ignore: Keep Going\n" + "--------------------------------------------------\n", + message ? ("Message: ") : (""), + message ? (message) : (""), + message ? ("\n\n") : (""), + expr, file, line_num); + + HANDLE hMod = PalLoadLibraryExW(L"user32.dll", NULL, 0); + Int32 (* pfn)(HANDLE, char *, const char *, UInt32) = + (Int32 (*)(HANDLE, char *, const char *, UInt32))PalGetProcAddress(hMod, "MessageBoxA"); + + Int32 result = pfn(NULL, buffer, "Redhawk Assert", MB_ABORTRETRYIGNORE); + + switch (result) + { + case IDABORT: + PalTerminateProcess(PalGetCurrentProcess(), 666); + break; + case IDRETRY: + PalDebugBreak(); + break; + case IDIGNORE: + break; + } +#endif +#else + UNREFERENCED_PARAMETER(expr); + UNREFERENCED_PARAMETER(file); + UNREFERENCED_PARAMETER(line_num); + UNREFERENCED_PARAMETER(message); +#endif //!DACCESS_COMPILE +} + +#endif // _DEBUG |