1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
2
* vim: set ts=8 sw=4 et tw=99 ft=cpp:
4
4
* ***** BEGIN LICENSE BLOCK *****
46
46
#include "mozilla/Attributes.h"
47
47
#include "mozilla/Types.h"
55
# include <android/log.h>
50
59
* MOZ_STATIC_ASSERT may be used to assert a condition *at compile time*. This
51
60
* can be useful when you make certain assumptions about what must hold for
134
extern MFBT_API(void)
145
* We used to call DebugBreak() on Windows, but amazingly, it causes
146
* the MSVS 2010 debugger not to be able to recover a call stack.
148
# define MOZ_CRASH() \
150
*((volatile int *) NULL) = 123; \
153
#elif defined(ANDROID)
155
* On Android, raise(SIGABRT) is handled asynchronously. Seg fault now
156
* so we crash immediately and capture the current call stack. We need
157
* to specifically use the global namespace in the C++ case.
160
# define MOZ_CRASH() \
162
*((volatile int *) NULL) = 123; \
166
# define MOZ_CRASH() \
168
*((volatile int *) NULL) = 123; \
172
#elif defined(__APPLE__)
174
* On Mac OS X, Breakpad ignores signals. Only real Mach exceptions are
177
# define MOZ_CRASH() \
179
*((volatile int *) NULL) = 123; \
180
raise(SIGABRT); /* In case above statement gets nixed by the optimizer. */ \
183
# define MOZ_CRASH() \
185
raise(SIGABRT); /* To continue from here in GDB: "signal 0". */ \
137
190
extern MFBT_API(void)
138
191
MOZ_Assert(const char* s, const char* file, int ln);
193
static MOZ_ALWAYS_INLINE void
194
MOZ_OutputAssertMessage(const char* s, const char *file, int ln)
197
__android_log_print(ANDROID_LOG_FATAL, "MOZ_Assert",
198
"Assertion failure: %s, at %s:%d\n", s, file, ln);
200
fprintf(stderr, "Assertion failure: %s, at %s:%d\n", s, file, ln);
140
205
#ifdef __cplusplus
141
206
} /* extern "C" */
177
242
/* First the single-argument form. */
178
243
# define MOZ_ASSERT_HELPER1(expr) \
179
((expr) ? ((void)0) : MOZ_Assert(#expr, __FILE__, __LINE__))
246
MOZ_OutputAssertMessage(#expr, __FILE__, __LINE__); \
180
250
/* Now the two-argument form. */
181
251
# define MOZ_ASSERT_HELPER2(expr, explain) \
182
((expr) ? ((void)0) : MOZ_Assert(#expr " (" explain ")", __FILE__, __LINE__))
254
MOZ_OutputAssertMessage(#expr " (" explain ")", __FILE__, __LINE__); \
183
258
/* And now, helper macrology up the wazoo. */
185
260
* Count the number of arguments passed to MOZ_ASSERT, very carefully
218
293
* designed to catch bugs during debugging, not "in the field".
221
# define MOZ_ASSERT_IF(cond, expr) ((cond) ? MOZ_ASSERT(expr) : ((void)0))
296
# define MOZ_ASSERT_IF(cond, expr) \
223
# define MOZ_ASSERT_IF(cond, expr) ((void)0)
302
# define MOZ_ASSERT_IF(cond, expr) do { } while (0)
226
305
/* MOZ_NOT_REACHED_MARKER() expands (in compilers which support it) to an