1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
// 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
}
extern "C" void NYI_Assert(const char *message, ...)
{
#if !defined(DACCESS_COMPILE)
va_list args;
va_start(args, message);
vprintf(message, args);
va_end(args);
ASSERT_UNCONDITIONALLY("NYI");
#else
UNREFERENCED_PARAMETER(message);
#endif
}
#endif // _DEBUG
|