-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathassert.cpp
112 lines (78 loc) · 3.03 KB
/
assert.cpp
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
112
///////////////////////////////////////////////////////////////////////////////
// Copyright (c) Electronic Arts Inc. All rights reserved.
///////////////////////////////////////////////////////////////////////////////
#include <eastl/internal/config.h>
#include <eastl/string.h>
#include <eastl/EABase/eabase.h>
#if defined(EA_PLATFORM_WINDOWS_KERNEL)
#include <Wdm.h>
#elif defined(EA_PLATFORM_MICROSOFT)
EA_DISABLE_ALL_VC_WARNINGS();
#if defined(EA_COMPILER_MSVC)
#include <crtdbg.h>
#endif
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <Windows.h>
EA_RESTORE_ALL_VC_WARNINGS();
#elif defined(EA_PLATFORM_ANDROID)
#include <android/log.h>
#else
#include <stdio.h>
#endif
namespace eastl
{
/// gpAssertionFailureFunction
///
/// Global assertion failure function pointer. Set by SetAssertionFailureFunction.
///
EASTL_API EASTL_AssertionFailureFunction gpAssertionFailureFunction = AssertionFailureFunctionDefault;
EASTL_API void* gpAssertionFailureFunctionContext = NULL;
/// SetAssertionFailureFunction
///
/// Sets the function called when an assertion fails. If this function is not called
/// by the user, a default function will be used. The user may supply a context parameter
/// which will be passed back to the user in the function call. This is typically used
/// to store a C++ 'this' pointer, though other things are possible.
///
/// There is no thread safety here, so the user needs to externally make sure that
/// this function is not called in a thread-unsafe way. The easiest way to do this is
/// to just call this function once from the main thread on application startup.
///
EASTL_API void SetAssertionFailureFunction(EASTL_AssertionFailureFunction pAssertionFailureFunction, void* pContext)
{
gpAssertionFailureFunction = pAssertionFailureFunction;
gpAssertionFailureFunctionContext = pContext;
}
/// AssertionFailureFunctionDefault
///
EASTL_API void AssertionFailureFunctionDefault(const char* pExpression, void* /*pContext*/)
{
#if EASTL_ASSERT_ENABLED
#if defined(EA_PLATFORM_WINDOWS_KERNEL)
DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "%s", pExpression);
#elif defined(EA_PLATFORM_MICROSOFT)
printf("%s\n", pExpression); // Write the message to stdout
if( ::IsDebuggerPresent())
{
OutputDebugStringA(pExpression);
}
#elif defined(EA_PLATFORM_ANDROID)
__android_log_print(ANDROID_LOG_INFO, "PRINTF", "%s\n", pExpression);
#else
printf("%s\n", pExpression); // Write the message to stdout, which happens to be the trace view for many console debug machines.
#endif
#else
EA_UNUSED(pExpression);
#endif
EASTL_DEBUG_BREAK();
}
/// AssertionFailure
///
EASTL_API void AssertionFailure(const char* pExpression)
{
if(gpAssertionFailureFunction)
gpAssertionFailureFunction(pExpression, gpAssertionFailureFunctionContext);
}
} // namespace eastl