VirtualBox

source: vbox/trunk/include/iprt/assert.h@ 68615

Last change on this file since 68615 was 68615, checked in by vboxsync, 7 years ago

iprt/assert.h: Watcom is picky about RTASSERT_OFFSET_OF too, at least in C++ code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 89.6 KB
Line 
1/** @file
2 * IPRT - Assertions.
3 */
4
5/*
6 * Copyright (C) 2006-2016 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___iprt_assert_h
27#define ___iprt_assert_h
28
29#include <iprt/cdefs.h>
30#include <iprt/types.h>
31#include <iprt/stdarg.h>
32
33/** @defgroup grp_rt_assert Assert - Assertions
34 * @ingroup grp_rt
35 *
36 * Assertions are generally used to check preconditions and other
37 * assumptions. Sometimes it is also used to catch odd errors or errors
38 * that one would like to inspect in the debugger. They should not be
39 * used for errors that happen frequently.
40 *
41 * IPRT provides a host of assertion macros, so many that it can be a bit
42 * overwhelming at first. Don't despair, there is a system (surprise).
43 *
44 * First there are four families of assertions:
45 * - Assert - The normal strict build only assertions.
46 * - AssertLogRel - Calls LogRel() in non-strict builds, otherwise like Assert.
47 * - AssertRelease - Triggers in all builds.
48 * - AssertFatal - Triggers in all builds and cannot be continued.
49 *
50 * Then there are variations wrt to argument list and behavior on failure:
51 * - Msg - Custom RTStrPrintf-like message with the assertion message.
52 * - Return - Return the specific rc on failure.
53 * - ReturnVoid - Return (void) on failure.
54 * - Break - Break (out of switch/loop) on failure.
55 * - Stmt - Execute the specified statement(s) on failure.
56 * - RC - Assert RT_SUCCESS.
57 * - RCSuccess - Assert VINF_SUCCESS.
58 *
59 * In addition there is a very special family AssertCompile that can be
60 * used for some limited compile-time checking, like structure sizes and member
61 * alignment. This family doesn't have the same variations.
62 *
63 *
64 * @remarks As you might have noticed, the macros don't follow the
65 * coding guidelines wrt to macros supposedly being all uppercase
66 * and underscored. For various reasons they don't, and nobody
67 * has complained yet. Wonder why... :-)
68 *
69 * @remarks Each project has its own specific guidelines on how to use
70 * assertions, so the above is just trying to give you the general idea
71 * from the IPRT point of view.
72 *
73 * @{
74 */
75
76RT_C_DECLS_BEGIN
77
78/**
79 * The 1st part of an assert message.
80 *
81 * @param pszExpr Expression. Can be NULL.
82 * @param uLine Location line number.
83 * @param pszFile Location file name.
84 * @param pszFunction Location function name.
85 */
86RTDECL(void) RTAssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction);
87/**
88 * Weak version of RTAssertMsg1 that can be overridden locally in a module to
89 * modify, redirect or otherwise mess with the assertion output.
90 *
91 * @copydoc RTAssertMsg1
92 */
93RTDECL(void) RTAssertMsg1Weak(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction);
94
95/**
96 * The 2nd (optional) part of an assert message.
97 *
98 * @param pszFormat Printf like format string.
99 * @param ... Arguments to that string.
100 */
101RTDECL(void) RTAssertMsg2(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
102/**
103 * Weak version of RTAssertMsg2 that forwards to RTAssertMsg2WeakV.
104 *
105 * There is not need to override this, check out RTAssertMsg2WeakV instead!
106 *
107 * @copydoc RTAssertMsg2
108 */
109RTDECL(void) RTAssertMsg2Weak(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
110
111/**
112 * The 2nd (optional) part of an assert message.
113 *
114 * @param pszFormat Printf like format string.
115 * @param va Arguments to that string.
116 */
117RTDECL(void) RTAssertMsg2V(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
118/**
119 * Weak version of RTAssertMsg2V that can be overridden locally in a module to
120 * modify, redirect or otherwise mess with the assertion output.
121 *
122 * @copydoc RTAssertMsg2V
123 */
124RTDECL(void) RTAssertMsg2WeakV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
125
126/**
127 * Additional information which should be appended to the 2nd part of an
128 * assertion message.
129 *
130 * @param pszFormat Printf like format string.
131 * @param ... Arguments to that string.
132 */
133RTDECL(void) RTAssertMsg2Add(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
134/**
135 * Weak version of RTAssertMsg2Add that forwards to RTAssertMsg2AddWeakV.
136 *
137 * There is not need to override this, check out RTAssertMsg2AddWeakV instead!
138 *
139 * @copydoc RTAssertMsg2Add
140 */
141RTDECL(void) RTAssertMsg2AddWeak(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
142
143/**
144 * Additional information which should be appended to the 2nd part of an
145 * assertion message.
146 *
147 * @param pszFormat Printf like format string.
148 * @param va Arguments to that string.
149 */
150RTDECL(void) RTAssertMsg2AddV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
151/**
152 * Weak version of RTAssertMsg2AddV that can be overridden locally in a module
153 * to modify, redirect or otherwise mess with the assertion output.
154 *
155 * @copydoc RTAssertMsg2AddV
156 */
157RTDECL(void) RTAssertMsg2AddWeakV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
158
159#ifdef IN_RING0
160/**
161 * Panics the system as the result of a fail assertion.
162 */
163RTR0DECL(void) RTR0AssertPanicSystem(void);
164#endif /* IN_RING0 */
165
166/**
167 * Overridable function that decides whether assertions executes the panic
168 * (breakpoint) or not.
169 *
170 * The generic implementation will return true.
171 *
172 * @returns true if the breakpoint should be hit, false if it should be ignored.
173 *
174 * @remark The RTDECL() makes this a bit difficult to override on Windows. So,
175 * you'll have to use RTASSERT_HAVE_SHOULD_PANIC or
176 * RTASSERT_HAVE_SHOULD_PANIC_PRIVATE there to control the kind of
177 * prototype.
178 */
179#if !defined(RTASSERT_HAVE_SHOULD_PANIC) && !defined(RTASSERT_HAVE_SHOULD_PANIC_PRIVATE)
180RTDECL(bool) RTAssertShouldPanic(void);
181#elif defined(RTASSERT_HAVE_SHOULD_PANIC_PRIVATE)
182bool RTAssertShouldPanic(void);
183#else
184DECLEXPORT(bool) RTCALL RTAssertShouldPanic(void);
185#endif
186
187/**
188 * Controls whether the assertions should be quiet or noisy (default).
189 *
190 * @returns The old setting.
191 * @param fQuiet The new setting.
192 */
193RTDECL(bool) RTAssertSetQuiet(bool fQuiet);
194
195/**
196 * Are assertions quiet or noisy?
197 *
198 * @returns True if they are quiet, false if noisy.
199 */
200RTDECL(bool) RTAssertAreQuiet(void);
201
202/**
203 * Makes the assertions panic (default) or not.
204 *
205 * @returns The old setting.
206 * @param fPanic The new setting.
207 */
208RTDECL(bool) RTAssertSetMayPanic(bool fPanic);
209
210/**
211 * Can assertion panic.
212 *
213 * @returns True if they can, false if not.
214 */
215RTDECL(bool) RTAssertMayPanic(void);
216
217
218/** @name Globals for crash analysis
219 * @remarks This is the full potential set, it
220 * @{
221 */
222/** The last assert message, 1st part. */
223extern RTDATADECL(char) g_szRTAssertMsg1[1024];
224/** The last assert message, 2nd part. */
225extern RTDATADECL(char) g_szRTAssertMsg2[4096];
226/** The last assert message, expression. */
227extern RTDATADECL(const char * volatile) g_pszRTAssertExpr;
228/** The last assert message, file name. */
229extern RTDATADECL(const char * volatile) g_pszRTAssertFile;
230/** The last assert message, line number. */
231extern RTDATADECL(uint32_t volatile) g_u32RTAssertLine;
232/** The last assert message, function name. */
233extern RTDATADECL(const char * volatile) g_pszRTAssertFunction;
234/** @} */
235
236RT_C_DECLS_END
237
238/** @def RTAssertDebugBreak()
239 * Debugger breakpoint instruction.
240 *
241 * @remarks This macro does not depend on RT_STRICT.
242 */
243#define RTAssertDebugBreak() do { RT_BREAKPOINT(); } while (0)
244
245
246
247/** @name Compile time assertions.
248 *
249 * These assertions are used to check structure sizes, member/size alignments
250 * and similar compile time expressions.
251 *
252 * @{
253 */
254
255/**
256 * RTASSERTTYPE is the type the AssertCompile() macro redefines.
257 * It has no other function and shouldn't be used.
258 * Visual C++ uses this.
259 */
260typedef int RTASSERTTYPE[1];
261
262/**
263 * RTASSERTVAR is the type the AssertCompile() macro redefines.
264 * It has no other function and shouldn't be used.
265 * GCC uses this.
266 */
267#ifdef __GNUC__
268RT_C_DECLS_BEGIN
269#endif
270extern int RTASSERTVAR[1];
271#ifdef __GNUC__
272RT_C_DECLS_END
273#endif
274
275/** @def RTASSERT_HAVE_STATIC_ASSERT
276 * Indicates that the compiler implements static_assert(expr, msg).
277 */
278#ifdef _MSC_VER
279# if _MSC_VER >= 1600 && defined(__cplusplus)
280# define RTASSERT_HAVE_STATIC_ASSERT
281# endif
282#endif
283#if defined(__GNUC__) && defined(__GXX_EXPERIMENTAL_CXX0X__)
284# define RTASSERT_HAVE_STATIC_ASSERT
285#endif
286#if RT_CLANG_PREREQ(6, 0)
287# if __has_feature(cxx_static_assert) || __has_feature(c_static_assert)
288# define RTASSERT_HAVE_STATIC_ASSERT
289# endif
290#endif
291#ifdef DOXYGEN_RUNNING
292# define RTASSERT_HAVE_STATIC_ASSERT
293#endif
294
295/** @def AssertCompileNS
296 * Asserts that a compile-time expression is true. If it's not break the build.
297 *
298 * This differs from AssertCompile in that it accepts some more expressions
299 * than what C++0x allows - NS = Non-standard.
300 *
301 * @param expr Expression which should be true.
302 */
303#ifdef __GNUC__
304# define AssertCompileNS(expr) extern int RTASSERTVAR[1] __attribute__((__unused__)), RTASSERTVAR[(expr) ? 1 : 0] __attribute__((__unused__))
305#elif defined(__IBMC__) || defined(__IBMCPP__)
306# define AssertCompileNS(expr) extern int RTASSERTVAR[(expr) ? 1 : 0]
307#else
308# define AssertCompileNS(expr) typedef int RTASSERTTYPE[(expr) ? 1 : 0]
309#endif
310
311/** @def AssertCompile
312 * Asserts that a C++0x compile-time expression is true. If it's not break the
313 * build.
314 * @param expr Expression which should be true.
315 */
316#ifdef RTASSERT_HAVE_STATIC_ASSERT
317# define AssertCompile(expr) static_assert(!!(expr), #expr)
318#else
319# define AssertCompile(expr) AssertCompileNS(expr)
320#endif
321
322/** @def RTASSERT_OFFSET_OF()
323 * A offsetof() macro suitable for compile time assertions.
324 * Both GCC v4 and VisualAge for C++ v3.08 has trouble using RT_OFFSETOF.
325 */
326#if defined(__GNUC__)
327# if __GNUC__ >= 4
328# define RTASSERT_OFFSET_OF(a_Type, a_Member) __builtin_offsetof(a_Type, a_Member)
329# else
330# define RTASSERT_OFFSET_OF(a_Type, a_Member) RT_OFFSETOF(a_Type, a_Member)
331# endif
332#elif (defined(__IBMC__) || defined(__IBMCPP__)) && defined(RT_OS_OS2)
333# define RTASSERT_OFFSET_OF(a_Type, a_Member) __offsetof(a_Type, a_Member)
334#elif (defined(__WATCOMC__) && defined(__cplusplus))
335# define RTASSERT_OFFSET_OF(a_Type, a_Member) __offsetof(a_Type, a_Member)
336#else
337# define RTASSERT_OFFSET_OF(a_Type, a_Member) RT_OFFSETOF(a_Type, a_Member)
338#endif
339
340
341/** @def AssertCompileSize
342 * Asserts a size at compile.
343 * @param type The type.
344 * @param size The expected type size.
345 */
346#define AssertCompileSize(type, size) \
347 AssertCompile(sizeof(type) == (size))
348
349/** @def AssertCompileSizeAlignment
350 * Asserts a size alignment at compile.
351 * @param type The type.
352 * @param align The size alignment to assert.
353 */
354#define AssertCompileSizeAlignment(type, align) \
355 AssertCompile(!(sizeof(type) & ((align) - 1)))
356
357/** @def AssertCompileMemberSize
358 * Asserts a member offset alignment at compile.
359 * @param type The type.
360 * @param member The member.
361 * @param size The member size to assert.
362 */
363#define AssertCompileMemberSize(type, member, size) \
364 AssertCompile(RT_SIZEOFMEMB(type, member) == (size))
365
366/** @def AssertCompileMemberSizeAlignment
367 * Asserts a member size alignment at compile.
368 * @param type The type.
369 * @param member The member.
370 * @param align The member size alignment to assert.
371 */
372#define AssertCompileMemberSizeAlignment(type, member, align) \
373 AssertCompile(!(RT_SIZEOFMEMB(type, member) & ((align) - 1)))
374
375/** @def AssertCompileMemberAlignment
376 * Asserts a member offset alignment at compile.
377 * @param type The type.
378 * @param member The member.
379 * @param align The member offset alignment to assert.
380 */
381#define AssertCompileMemberAlignment(type, member, align) \
382 AssertCompile(!(RTASSERT_OFFSET_OF(type, member) & ((align) - 1)))
383
384/** @def AssertCompileMemberOffset
385 * Asserts an offset of a structure member at compile.
386 * @param type The type.
387 * @param member The member.
388 * @param off The expected offset.
389 */
390#define AssertCompileMemberOffset(type, member, off) \
391 AssertCompile(RTASSERT_OFFSET_OF(type, member) == (off))
392
393/** @def AssertCompile2MemberOffsets
394 * Asserts that two (sub-structure) members in union have the same offset.
395 * @param type The type.
396 * @param member1 The first member.
397 * @param member2 The second member.
398 */
399#define AssertCompile2MemberOffsets(type, member1, member2) \
400 AssertCompile(RTASSERT_OFFSET_OF(type, member1) == RTASSERT_OFFSET_OF(type, member2))
401
402/** @def AssertCompileAdjacentMembers
403 * Asserts that two structure members are adjacent.
404 * @param type The type.
405 * @param member1 The first member.
406 * @param member2 The second member.
407 */
408#define AssertCompileAdjacentMembers(type, member1, member2) \
409 AssertCompile(RTASSERT_OFFSET_OF(type, member1) + RT_SIZEOFMEMB(type, member1) == RTASSERT_OFFSET_OF(type, member2))
410
411/** @def AssertCompileMembersAtSameOffset
412 * Asserts that members of two different structures are at the same offset.
413 * @param type1 The first type.
414 * @param member1 The first member.
415 * @param type2 The second type.
416 * @param member2 The second member.
417 */
418#define AssertCompileMembersAtSameOffset(type1, member1, type2, member2) \
419 AssertCompile(RTASSERT_OFFSET_OF(type1, member1) == RTASSERT_OFFSET_OF(type2, member2))
420
421/** @def AssertCompileMembersSameSize
422 * Asserts that members of two different structures have the same size.
423 * @param type1 The first type.
424 * @param member1 The first member.
425 * @param type2 The second type.
426 * @param member2 The second member.
427 */
428#define AssertCompileMembersSameSize(type1, member1, type2, member2) \
429 AssertCompile(RT_SIZEOFMEMB(type1, member1) == RT_SIZEOFMEMB(type2, member2))
430
431/** @def AssertCompileMembersSameSizeAndOffset
432 * Asserts that members of two different structures have the same size and are
433 * at the same offset.
434 * @param type1 The first type.
435 * @param member1 The first member.
436 * @param type2 The second type.
437 * @param member2 The second member.
438 */
439#define AssertCompileMembersSameSizeAndOffset(type1, member1, type2, member2) \
440 AssertCompile( RTASSERT_OFFSET_OF(type1, member1) == RTASSERT_OFFSET_OF(type2, member2) \
441 && RT_SIZEOFMEMB(type1, member1) == RT_SIZEOFMEMB(type2, member2))
442
443/** @} */
444
445
446
447/** @name Assertions
448 *
449 * These assertions will only trigger when RT_STRICT is defined. When it is
450 * undefined they will all be no-ops and generate no code.
451 *
452 * @{
453 */
454
455
456/** @def RTASSERT_QUIET
457 * This can be defined to shut up the messages for a file where this would be
458 * problematic because the message printing code path passes thru it.
459 * @internal */
460#ifdef DOXYGEN_RUNNING
461# define RTASSERT_QUIET
462#endif
463#if defined(RTASSERT_QUIET) && !defined(DOXYGEN_RUNNING)
464# define RTAssertMsg1Weak(pszExpr, uLine, pszfile, pszFunction) \
465 do { } while (0)
466# define RTAssertMsg2Weak if (1) {} else RTAssertMsg2Weak
467#endif
468
469/** @def RTAssertDoPanic
470 * Raises an assertion panic appropriate to the current context.
471 * @remarks This macro does not depend on RT_STRICT.
472 */
473#if defined(IN_RING0) \
474 && (defined(RT_OS_DARWIN) || defined(RT_OS_HAIKU) || defined(RT_OS_SOLARIS))
475# define RTAssertDoPanic() RTR0AssertPanicSystem()
476#else
477# define RTAssertDoPanic() RTAssertDebugBreak()
478#endif
479
480/** @def AssertBreakpoint()
481 * Assertion Breakpoint.
482 * @deprecated Use RTAssertPanic or RTAssertDebugBreak instead.
483 */
484#ifdef RT_STRICT
485# define AssertBreakpoint() RTAssertDebugBreak()
486#else
487# define AssertBreakpoint() do { } while (0)
488#endif
489
490/** @def RTAssertPanic()
491 * If RT_STRICT is defined this macro will invoke RTAssertDoPanic if
492 * RTAssertShouldPanic returns true. If RT_STRICT isn't defined it won't do any
493 * thing.
494 */
495#if defined(RT_STRICT) && !defined(RTASSERT_DONT_PANIC)
496# define RTAssertPanic() do { if (RTAssertShouldPanic()) RTAssertDoPanic(); } while (0)
497#else
498# define RTAssertPanic() do { } while (0)
499#endif
500
501/** @def Assert
502 * Assert that an expression is true. If false, hit breakpoint.
503 * @param expr Expression which should be true.
504 */
505#ifdef RT_STRICT
506# define Assert(expr) \
507 do { \
508 if (RT_LIKELY(!!(expr))) \
509 { /* likely */ } \
510 else \
511 { \
512 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, RT_GCC_EXTENSION __PRETTY_FUNCTION__); \
513 RTAssertPanic(); \
514 } \
515 } while (0)
516#else
517# define Assert(expr) do { } while (0)
518#endif
519
520
521/** @def AssertStmt
522 * Assert that an expression is true. If false, hit breakpoint and execute the
523 * statement.
524 * @param expr Expression which should be true.
525 * @param stmt Statement to execute on failure.
526 */
527#ifdef RT_STRICT
528# define AssertStmt(expr, stmt) \
529 do { \
530 if (RT_LIKELY(!!(expr))) \
531 { /* likely */ } \
532 else \
533 { \
534 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, RT_GCC_EXTENSION __PRETTY_FUNCTION__); \
535 RTAssertPanic(); \
536 stmt; \
537 } \
538 } while (0)
539#else
540# define AssertStmt(expr, stmt) \
541 do { \
542 if (RT_LIKELY(!!(expr))) \
543 { /* likely */ } \
544 else \
545 { \
546 stmt; \
547 } \
548 } while (0)
549#endif
550
551
552/** @def AssertReturn
553 * Assert that an expression is true and returns if it isn't.
554 * In RT_STRICT mode it will hit a breakpoint before returning.
555 *
556 * @param expr Expression which should be true.
557 * @param rc What is to be presented to return.
558 */
559#ifdef RT_STRICT
560# define AssertReturn(expr, rc) \
561 do { \
562 if (RT_LIKELY(!!(expr))) \
563 { /* likely */ } \
564 else \
565 { \
566 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, RT_GCC_EXTENSION __PRETTY_FUNCTION__); \
567 RTAssertPanic(); \
568 return (rc); \
569 } \
570 } while (0)
571#else
572# define AssertReturn(expr, rc) \
573 do { \
574 if (RT_LIKELY(!!(expr))) \
575 { /* likely */ } \
576 else \
577 return (rc); \
578 } while (0)
579#endif
580
581/** @def AssertReturnStmt
582 * Assert that an expression is true, if it isn't execute the given statement
583 * and return rc.
584 *
585 * In RT_STRICT mode it will hit a breakpoint before executing the statement and
586 * returning.
587 *
588 * @param expr Expression which should be true.
589 * @param stmt Statement to execute before returning on failure.
590 * @param rc What is to be presented to return.
591 */
592#ifdef RT_STRICT
593# define AssertReturnStmt(expr, stmt, rc) \
594 do { \
595 if (RT_LIKELY(!!(expr))) \
596 { /* likely */ } \
597 else \
598 { \
599 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
600 RTAssertPanic(); \
601 stmt; \
602 return (rc); \
603 } \
604 } while (0)
605#else
606# define AssertReturnStmt(expr, stmt, rc) \
607 do { \
608 if (RT_LIKELY(!!(expr))) \
609 { /* likely */ } \
610 else \
611 { \
612 stmt; \
613 return (rc); \
614 } \
615 } while (0)
616#endif
617
618/** @def AssertReturnVoid
619 * Assert that an expression is true and returns if it isn't.
620 * In RT_STRICT mode it will hit a breakpoint before returning.
621 *
622 * @param expr Expression which should be true.
623 */
624#ifdef RT_STRICT
625# define AssertReturnVoid(expr) \
626 do { \
627 if (RT_LIKELY(!!(expr))) \
628 { /* likely */ } \
629 else \
630 { \
631 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, RT_GCC_EXTENSION __PRETTY_FUNCTION__); \
632 RTAssertPanic(); \
633 return; \
634 } \
635 } while (0)
636#else
637# define AssertReturnVoid(expr) \
638 do { \
639 if (RT_LIKELY(!!(expr))) \
640 { /* likely */ } \
641 else \
642 return; \
643 } while (0)
644#endif
645
646/** @def AssertReturnVoidStmt
647 * Assert that an expression is true, if it isn't execute the given statement
648 * and return.
649 *
650 * In RT_STRICT mode it will hit a breakpoint before returning.
651 *
652 * @param expr Expression which should be true.
653 * @param stmt Statement to execute before returning on failure.
654 */
655#ifdef RT_STRICT
656# define AssertReturnVoidStmt(expr, stmt) \
657 do { \
658 if (RT_LIKELY(!!(expr))) \
659 { /* likely */ } \
660 else \
661 { \
662 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
663 RTAssertPanic(); \
664 stmt; \
665 return; \
666 } \
667 } while (0)
668#else
669# define AssertReturnVoidStmt(expr, stmt) \
670 do { \
671 if (RT_LIKELY(!!(expr))) \
672 { /* likely */ } \
673 else \
674 { \
675 stmt; \
676 return; \
677 } \
678 } while (0)
679#endif
680
681
682/** @def AssertBreak
683 * Assert that an expression is true and breaks if it isn't.
684 * In RT_STRICT mode it will hit a breakpoint before breaking.
685 *
686 * @param expr Expression which should be true.
687 */
688#ifdef RT_STRICT
689# define AssertBreak(expr) \
690 if (RT_LIKELY(!!(expr))) \
691 { /* likely */ } \
692 else if (1) \
693 { \
694 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
695 RTAssertPanic(); \
696 break; \
697 } else \
698 break
699#else
700# define AssertBreak(expr) \
701 if (RT_LIKELY(!!(expr))) \
702 { /* likely */ } \
703 else \
704 break
705#endif
706
707/** @def AssertContinue
708 * Assert that an expression is true and continue if it isn't.
709 * In RT_STRICT mode it will hit a breakpoint before continuing.
710 *
711 * @param expr Expression which should be true.
712 */
713#ifdef RT_STRICT
714# define AssertContinue(expr) \
715 if (RT_LIKELY(!!(expr))) \
716 { /* likely */ } \
717 else if (1) \
718 { \
719 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
720 RTAssertPanic(); \
721 continue; \
722 } else do {} while (0)
723#else
724# define AssertContinue(expr) \
725 if (RT_LIKELY(!!(expr))) \
726 { /* likely */ } \
727 else \
728 continue
729#endif
730
731/** @def AssertBreakStmt
732 * Assert that an expression is true and breaks if it isn't.
733 * In RT_STRICT mode it will hit a breakpoint before doing break.
734 *
735 * @param expr Expression which should be true.
736 * @param stmt Statement to execute before break in case of a failed assertion.
737 */
738#ifdef RT_STRICT
739# define AssertBreakStmt(expr, stmt) \
740 if (RT_LIKELY(!!(expr))) \
741 { /* likely */ } \
742 else if (1) \
743 { \
744 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
745 RTAssertPanic(); \
746 stmt; \
747 break; \
748 } else do {} while (0)
749#else
750# define AssertBreakStmt(expr, stmt) \
751 if (RT_LIKELY(!!(expr))) \
752 { /* likely */ } \
753 else if (1) \
754 { \
755 stmt; \
756 break; \
757 } else do {} while (0)
758#endif
759
760
761/** @def AssertMsg
762 * Assert that an expression is true. If it's not print message and hit breakpoint.
763 * @param expr Expression which should be true.
764 * @param a printf argument list (in parenthesis).
765 */
766#ifdef RT_STRICT
767# define AssertMsg(expr, a) \
768 do { \
769 if (RT_LIKELY(!!(expr))) \
770 { /* likely */ } \
771 else \
772 { \
773 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, RT_GCC_EXTENSION __PRETTY_FUNCTION__); \
774 RTAssertMsg2Weak a; \
775 RTAssertPanic(); \
776 } \
777 } while (0)
778#else
779# define AssertMsg(expr, a) do { } while (0)
780#endif
781
782/** @def AssertMsgStmt
783 * Assert that an expression is true. If it's not print message and hit
784 * breakpoint and execute the statement.
785 *
786 * @param expr Expression which should be true.
787 * @param a printf argument list (in parenthesis).
788 * @param stmt Statement to execute in case of a failed assertion.
789 *
790 * @remarks The expression and statement will be evaluated in all build types.
791 */
792#ifdef RT_STRICT
793# define AssertMsgStmt(expr, a, stmt) \
794 do { \
795 if (RT_LIKELY(!!(expr))) \
796 { /* likely */ } \
797 else \
798 { \
799 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
800 RTAssertMsg2Weak a; \
801 RTAssertPanic(); \
802 stmt; \
803 } \
804 } while (0)
805#else
806# define AssertMsgStmt(expr, a, stmt) \
807 do { \
808 if (RT_LIKELY(!!(expr))) \
809 { /* likely */ } \
810 else \
811 { \
812 stmt; \
813 } \
814 } while (0)
815#endif
816
817/** @def AssertMsgReturn
818 * Assert that an expression is true and returns if it isn't.
819 * In RT_STRICT mode it will hit a breakpoint before returning.
820 *
821 * @param expr Expression which should be true.
822 * @param a printf argument list (in parenthesis).
823 * @param rc What is to be presented to return.
824 */
825#ifdef RT_STRICT
826# define AssertMsgReturn(expr, a, rc) \
827 do { \
828 if (RT_LIKELY(!!(expr))) \
829 { /* likely */ } \
830 else \
831 { \
832 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, RT_GCC_EXTENSION __PRETTY_FUNCTION__); \
833 RTAssertMsg2Weak a; \
834 RTAssertPanic(); \
835 return (rc); \
836 } \
837 } while (0)
838#else
839# define AssertMsgReturn(expr, a, rc) \
840 do { \
841 if (RT_LIKELY(!!(expr))) \
842 { /* likely */ } \
843 else \
844 return (rc); \
845 } while (0)
846#endif
847
848/** @def AssertMsgReturnStmt
849 * Assert that an expression is true, if it isn't execute the statement and
850 * return.
851 *
852 * In RT_STRICT mode it will hit a breakpoint before returning.
853 *
854 * @param expr Expression which should be true.
855 * @param a printf argument list (in parenthesis).
856 * @param stmt Statement to execute before returning in case of a failed
857 * assertion.
858 * @param rc What is to be presented to return.
859 */
860#ifdef RT_STRICT
861# define AssertMsgReturnStmt(expr, a, stmt, rc) \
862 do { \
863 if (RT_LIKELY(!!(expr))) \
864 { /* likely */ } \
865 else \
866 { \
867 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
868 RTAssertMsg2Weak a; \
869 RTAssertPanic(); \
870 stmt; \
871 return (rc); \
872 } \
873 } while (0)
874#else
875# define AssertMsgReturnStmt(expr, a, stmt, rc) \
876 do { \
877 if (RT_LIKELY(!!(expr))) \
878 { /* likely */ } \
879 else \
880 { \
881 stmt; \
882 return (rc); \
883 } \
884 } while (0)
885#endif
886
887/** @def AssertMsgReturnVoid
888 * Assert that an expression is true and returns if it isn't.
889 * In RT_STRICT mode it will hit a breakpoint before returning.
890 *
891 * @param expr Expression which should be true.
892 * @param a printf argument list (in parenthesis).
893 */
894#ifdef RT_STRICT
895# define AssertMsgReturnVoid(expr, a) \
896 do { \
897 if (RT_LIKELY(!!(expr))) \
898 { /* likely */ } \
899 else \
900 { \
901 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, RT_GCC_EXTENSION __PRETTY_FUNCTION__); \
902 RTAssertMsg2Weak a; \
903 RTAssertPanic(); \
904 return; \
905 } \
906 } while (0)
907#else
908# define AssertMsgReturnVoid(expr, a) \
909 do { \
910 if (RT_LIKELY(!!(expr))) \
911 { /* likely */ } \
912 else \
913 return; \
914 } while (0)
915#endif
916
917/** @def AssertMsgReturnVoidStmt
918 * Assert that an expression is true, if it isn't execute the statement and
919 * return.
920 *
921 * In RT_STRICT mode it will hit a breakpoint before returning.
922 *
923 * @param expr Expression which should be true.
924 * @param a printf argument list (in parenthesis).
925 * @param stmt Statement to execute before return in case of a failed assertion.
926 */
927#ifdef RT_STRICT
928# define AssertMsgReturnVoidStmt(expr, a, stmt) \
929 do { \
930 if (RT_LIKELY(!!(expr))) \
931 { /* likely */ } \
932 else \
933 { \
934 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
935 RTAssertMsg2Weak a; \
936 RTAssertPanic(); \
937 stmt; \
938 return; \
939 } \
940 } while (0)
941#else
942# define AssertMsgReturnVoidStmt(expr, a, stmt) \
943 do { \
944 if (RT_LIKELY(!!(expr))) \
945 { /* likely */ } \
946 else \
947 { \
948 stmt; \
949 return; \
950 } \
951 } while (0)
952#endif
953
954
955/** @def AssertMsgBreak
956 * Assert that an expression is true and breaks if it isn't.
957 * In RT_STRICT mode it will hit a breakpoint before returning.
958 *
959 * @param expr Expression which should be true.
960 * @param a printf argument list (in parenthesis).
961 */
962#ifdef RT_STRICT
963# define AssertMsgBreak(expr, a) \
964 if (RT_LIKELY(!!(expr))) \
965 { /* likely */ } \
966 else if (1) \
967 { \
968 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
969 RTAssertMsg2Weak a; \
970 RTAssertPanic(); \
971 break; \
972 } else \
973 break
974#else
975# define AssertMsgBreak(expr, a) \
976 if (RT_LIKELY(!!(expr))) \
977 { /* likely */ } \
978 else \
979 break
980#endif
981
982/** @def AssertMsgBreakStmt
983 * Assert that an expression is true and breaks if it isn't.
984 * In RT_STRICT mode it will hit a breakpoint before doing break.
985 *
986 * @param expr Expression which should be true.
987 * @param a printf argument list (in parenthesis).
988 * @param stmt Statement to execute before break in case of a failed assertion.
989 */
990#ifdef RT_STRICT
991# define AssertMsgBreakStmt(expr, a, stmt) \
992 if (RT_LIKELY(!!(expr))) \
993 { /* likely */ } \
994 else if (1) \
995 { \
996 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
997 RTAssertMsg2Weak a; \
998 RTAssertPanic(); \
999 stmt; \
1000 break; \
1001 } else \
1002 break
1003#else
1004# define AssertMsgBreakStmt(expr, a, stmt) \
1005 if (RT_LIKELY(!!(expr))) \
1006 { /* likely */ } \
1007 else if (1) \
1008 { \
1009 stmt; \
1010 break; \
1011 } else \
1012 break
1013#endif
1014
1015/** @def AssertFailed
1016 * An assertion failed, hit breakpoint.
1017 */
1018#ifdef RT_STRICT
1019# define AssertFailed() \
1020 do { \
1021 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, RT_GCC_EXTENSION __PRETTY_FUNCTION__); \
1022 RTAssertPanic(); \
1023 } while (0)
1024#else
1025# define AssertFailed() do { } while (0)
1026#endif
1027
1028/** @def AssertFailedStmt
1029 * An assertion failed, hit breakpoint and execute statement.
1030 */
1031#ifdef RT_STRICT
1032# define AssertFailedStmt(stmt) \
1033 do { \
1034 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, RT_GCC_EXTENSION __PRETTY_FUNCTION__); \
1035 RTAssertPanic(); \
1036 stmt; \
1037 } while (0)
1038#else
1039# define AssertFailedStmt(stmt) do { stmt; } while (0)
1040#endif
1041
1042/** @def AssertFailedReturn
1043 * An assertion failed, hit breakpoint (RT_STRICT mode only) and return.
1044 *
1045 * @param rc The rc to return.
1046 */
1047#ifdef RT_STRICT
1048# define AssertFailedReturn(rc) \
1049 do { \
1050 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1051 RTAssertPanic(); \
1052 return (rc); \
1053 } while (0)
1054#else
1055# define AssertFailedReturn(rc) \
1056 do { \
1057 return (rc); \
1058 } while (0)
1059#endif
1060
1061/** @def AssertFailedReturnStmt
1062 * An assertion failed, hit breakpoint (RT_STRICT mode only), execute a
1063 * statement and return a value.
1064 *
1065 * @param stmt The statement to execute before returning.
1066 * @param rc The value to return.
1067 */
1068#ifdef RT_STRICT
1069# define AssertFailedReturnStmt(stmt, rc) \
1070 do { \
1071 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1072 RTAssertPanic(); \
1073 stmt; \
1074 return (rc); \
1075 } while (0)
1076#else
1077# define AssertFailedReturnStmt(stmt, rc) \
1078 do { \
1079 stmt; \
1080 return (rc); \
1081 } while (0)
1082#endif
1083
1084/** @def AssertFailedReturnVoid
1085 * An assertion failed, hit breakpoint (RT_STRICT mode only) and return.
1086 */
1087#ifdef RT_STRICT
1088# define AssertFailedReturnVoid() \
1089 do { \
1090 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1091 RTAssertPanic(); \
1092 return; \
1093 } while (0)
1094#else
1095# define AssertFailedReturnVoid() \
1096 do { \
1097 return; \
1098 } while (0)
1099#endif
1100
1101/** @def AssertFailedReturnVoidStmt
1102 * An assertion failed, hit breakpoint (RT_STRICT mode only), execute a
1103 * statement and return.
1104 *
1105 * @param stmt The statement to execute before returning.
1106 */
1107#ifdef RT_STRICT
1108# define AssertFailedReturnVoidStmt(stmt) \
1109 do { \
1110 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1111 RTAssertPanic(); \
1112 stmt; \
1113 return; \
1114 } while (0)
1115#else
1116# define AssertFailedReturnVoidStmt(stmt) \
1117 do { \
1118 stmt; \
1119 return; \
1120 } while (0)
1121#endif
1122
1123
1124/** @def AssertFailedBreak
1125 * An assertion failed, hit breakpoint (RT_STRICT mode only) and break.
1126 */
1127#ifdef RT_STRICT
1128# define AssertFailedBreak() \
1129 if (1) { \
1130 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1131 RTAssertPanic(); \
1132 break; \
1133 } else \
1134 break
1135#else
1136# define AssertFailedBreak() \
1137 if (1) \
1138 break; \
1139 else \
1140 break
1141#endif
1142
1143/** @def AssertFailedBreakStmt
1144 * An assertion failed, hit breakpoint (RT_STRICT mode only), execute
1145 * the given statement and break.
1146 *
1147 * @param stmt Statement to execute before break.
1148 */
1149#ifdef RT_STRICT
1150# define AssertFailedBreakStmt(stmt) \
1151 if (1) { \
1152 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1153 RTAssertPanic(); \
1154 stmt; \
1155 break; \
1156 } else \
1157 break
1158#else
1159# define AssertFailedBreakStmt(stmt) \
1160 if (1) { \
1161 stmt; \
1162 break; \
1163 } else \
1164 break
1165#endif
1166
1167
1168/** @def AssertMsgFailed
1169 * An assertion failed print a message and a hit breakpoint.
1170 *
1171 * @param a printf argument list (in parenthesis).
1172 */
1173#ifdef RT_STRICT
1174# define AssertMsgFailed(a) \
1175 do { \
1176 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, RT_GCC_EXTENSION __PRETTY_FUNCTION__); \
1177 RTAssertMsg2Weak a; \
1178 RTAssertPanic(); \
1179 } while (0)
1180#else
1181# define AssertMsgFailed(a) do { } while (0)
1182#endif
1183
1184/** @def AssertMsgFailedReturn
1185 * An assertion failed, hit breakpoint with message (RT_STRICT mode only) and return.
1186 *
1187 * @param a printf argument list (in parenthesis).
1188 * @param rc What is to be presented to return.
1189 */
1190#ifdef RT_STRICT
1191# define AssertMsgFailedReturn(a, rc) \
1192 do { \
1193 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1194 RTAssertMsg2Weak a; \
1195 RTAssertPanic(); \
1196 return (rc); \
1197 } while (0)
1198#else
1199# define AssertMsgFailedReturn(a, rc) \
1200 do { \
1201 return (rc); \
1202 } while (0)
1203#endif
1204
1205/** @def AssertMsgFailedReturnVoid
1206 * An assertion failed, hit breakpoint with message (RT_STRICT mode only) and return.
1207 *
1208 * @param a printf argument list (in parenthesis).
1209 */
1210#ifdef RT_STRICT
1211# define AssertMsgFailedReturnVoid(a) \
1212 do { \
1213 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1214 RTAssertMsg2Weak a; \
1215 RTAssertPanic(); \
1216 return; \
1217 } while (0)
1218#else
1219# define AssertMsgFailedReturnVoid(a) \
1220 do { \
1221 return; \
1222 } while (0)
1223#endif
1224
1225
1226/** @def AssertMsgFailedBreak
1227 * An assertion failed, hit breakpoint with message (RT_STRICT mode only) and break.
1228 *
1229 * @param a printf argument list (in parenthesis).
1230 */
1231#ifdef RT_STRICT
1232# define AssertMsgFailedBreak(a) \
1233 if (1) { \
1234 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1235 RTAssertMsg2Weak a; \
1236 RTAssertPanic(); \
1237 break; \
1238 } else \
1239 break
1240#else
1241# define AssertMsgFailedBreak(a) \
1242 if (1) \
1243 break; \
1244 else \
1245 break
1246#endif
1247
1248/** @def AssertMsgFailedBreakStmt
1249 * An assertion failed, hit breakpoint (RT_STRICT mode only), execute
1250 * the given statement and break.
1251 *
1252 * @param a printf argument list (in parenthesis).
1253 * @param stmt Statement to execute before break.
1254 */
1255#ifdef RT_STRICT
1256# define AssertMsgFailedBreakStmt(a, stmt) \
1257 if (1) { \
1258 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1259 RTAssertMsg2Weak a; \
1260 RTAssertPanic(); \
1261 stmt; \
1262 break; \
1263 } else \
1264 break
1265#else
1266# define AssertMsgFailedBreakStmt(a, stmt) \
1267 if (1) { \
1268 stmt; \
1269 break; \
1270 } else \
1271 break
1272#endif
1273
1274/** @} */
1275
1276
1277
1278/** @name Release Log Assertions
1279 *
1280 * These assertions will work like normal strict assertion when RT_STRICT is
1281 * defined and LogRel statements when RT_STRICT is undefined. Typically used for
1282 * things which shouldn't go wrong, but when it does you'd like to know one way
1283 * or the other.
1284 *
1285 * @{
1286 */
1287
1288/** @def RTAssertLogRelMsg1
1289 * RTAssertMsg1Weak (strict builds) / LogRel wrapper (non-strict).
1290 */
1291#ifdef RT_STRICT
1292# define RTAssertLogRelMsg1(pszExpr, iLine, pszFile, pszFunction) \
1293 RTAssertMsg1Weak(pszExpr, iLine, pszFile, pszFunction)
1294#else
1295# define RTAssertLogRelMsg1(pszExpr, iLine, pszFile, pszFunction) \
1296 LogRel(("AssertLogRel %s(%d) %s: %s\n",\
1297 (pszFile), (iLine), (pszFunction), (pszExpr) ))
1298#endif
1299
1300/** @def RTAssertLogRelMsg2
1301 * RTAssertMsg2Weak (strict builds) / LogRel wrapper (non-strict).
1302 */
1303#ifdef RT_STRICT
1304# define RTAssertLogRelMsg2(a) RTAssertMsg2Weak a
1305#else
1306# define RTAssertLogRelMsg2(a) LogRel(a)
1307#endif
1308
1309/** @def AssertLogRel
1310 * Assert that an expression is true.
1311 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1312 *
1313 * @param expr Expression which should be true.
1314 */
1315#define AssertLogRel(expr) \
1316 do { \
1317 if (RT_LIKELY(!!(expr))) \
1318 { /* likely */ } \
1319 else \
1320 { \
1321 RTAssertLogRelMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1322 RTAssertPanic(); \
1323 } \
1324 } while (0)
1325
1326/** @def AssertLogRelReturn
1327 * Assert that an expression is true, return \a rc if it isn't.
1328 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1329 *
1330 * @param expr Expression which should be true.
1331 * @param rc What is to be presented to return.
1332 */
1333#define AssertLogRelReturn(expr, rc) \
1334 do { \
1335 if (RT_LIKELY(!!(expr))) \
1336 { /* likely */ } \
1337 else \
1338 { \
1339 RTAssertLogRelMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1340 RTAssertPanic(); \
1341 return (rc); \
1342 } \
1343 } while (0)
1344
1345/** @def AssertLogRelReturnVoid
1346 * Assert that an expression is true, return void if it isn't.
1347 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1348 *
1349 * @param expr Expression which should be true.
1350 */
1351#define AssertLogRelReturnVoid(expr) \
1352 do { \
1353 if (RT_LIKELY(!!(expr))) \
1354 { /* likely */ } \
1355 else \
1356 { \
1357 RTAssertLogRelMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1358 RTAssertPanic(); \
1359 return; \
1360 } \
1361 } while (0)
1362
1363/** @def AssertLogRelBreak
1364 * Assert that an expression is true, break if it isn't.
1365 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1366 *
1367 * @param expr Expression which should be true.
1368 */
1369#define AssertLogRelBreak(expr) \
1370 if (RT_LIKELY(!!(expr))) \
1371 { /* likely */ } \
1372 else if (1) \
1373 { \
1374 RTAssertLogRelMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1375 RTAssertPanic(); \
1376 break; \
1377 } \
1378 else \
1379 break
1380
1381/** @def AssertLogRelBreakStmt
1382 * Assert that an expression is true, execute \a stmt and break if it isn't.
1383 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1384 *
1385 * @param expr Expression which should be true.
1386 * @param stmt Statement to execute before break in case of a failed assertion.
1387 */
1388#define AssertLogRelBreakStmt(expr, stmt) \
1389 if (RT_LIKELY(!!(expr))) \
1390 { /* likely */ } \
1391 else if (1) \
1392 { \
1393 RTAssertLogRelMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1394 RTAssertPanic(); \
1395 stmt; \
1396 break; \
1397 } else \
1398 break
1399
1400/** @def AssertLogRelMsg
1401 * Assert that an expression is true.
1402 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1403 *
1404 * @param expr Expression which should be true.
1405 * @param a printf argument list (in parenthesis).
1406 */
1407#define AssertLogRelMsg(expr, a) \
1408 do { \
1409 if (RT_LIKELY(!!(expr))) \
1410 { /* likely */ } \
1411 else\
1412 { \
1413 RTAssertLogRelMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1414 RTAssertLogRelMsg2(a); \
1415 RTAssertPanic(); \
1416 } \
1417 } while (0)
1418
1419/** @def AssertLogRelMsgStmt
1420 * Assert that an expression is true, execute \a stmt and break if it isn't
1421 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1422 *
1423 * @param expr Expression which should be true.
1424 * @param a printf argument list (in parenthesis).
1425 * @param stmt Statement to execute in case of a failed assertion.
1426 */
1427#define AssertLogRelMsgStmt(expr, a, stmt) \
1428 do { \
1429 if (RT_LIKELY(!!(expr))) \
1430 { /* likely */ } \
1431 else\
1432 { \
1433 RTAssertLogRelMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1434 RTAssertLogRelMsg2(a); \
1435 RTAssertPanic(); \
1436 stmt; \
1437 } \
1438 } while (0)
1439
1440/** @def AssertLogRelMsgReturn
1441 * Assert that an expression is true, return \a rc if it isn't.
1442 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1443 *
1444 * @param expr Expression which should be true.
1445 * @param a printf argument list (in parenthesis).
1446 * @param rc What is to be presented to return.
1447 */
1448#define AssertLogRelMsgReturn(expr, a, rc) \
1449 do { \
1450 if (RT_LIKELY(!!(expr))) \
1451 { /* likely */ } \
1452 else\
1453 { \
1454 RTAssertLogRelMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1455 RTAssertLogRelMsg2(a); \
1456 RTAssertPanic(); \
1457 return (rc); \
1458 } \
1459 } while (0)
1460
1461/** @def AssertLogRelMsgReturnStmt
1462 * Assert that an expression is true, execute @a stmt and return @a rcRet if it
1463 * isn't.
1464 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1465 *
1466 * @param expr Expression which should be true.
1467 * @param a printf argument list (in parenthesis).
1468 * @param stmt Statement to execute before returning in case of a failed
1469 * assertion.
1470 * @param rcRet What is to be presented to return.
1471 */
1472#define AssertLogRelMsgReturnStmt(expr, a, stmt, rcRet) \
1473 do { \
1474 if (RT_LIKELY(!!(expr))) \
1475 { /* likely */ } \
1476 else\
1477 { \
1478 RTAssertLogRelMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1479 RTAssertLogRelMsg2(a); \
1480 RTAssertPanic(); \
1481 stmt; \
1482 return (rcRet); \
1483 } \
1484 } while (0)
1485
1486/** @def AssertLogRelMsgReturnVoid
1487 * Assert that an expression is true, return (void) if it isn't.
1488 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1489 *
1490 * @param expr Expression which should be true.
1491 * @param a printf argument list (in parenthesis).
1492 */
1493#define AssertLogRelMsgReturnVoid(expr, a) \
1494 do { \
1495 if (RT_LIKELY(!!(expr))) \
1496 { /* likely */ } \
1497 else\
1498 { \
1499 RTAssertLogRelMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1500 RTAssertLogRelMsg2(a); \
1501 RTAssertPanic(); \
1502 return; \
1503 } \
1504 } while (0)
1505
1506/** @def AssertLogRelMsgBreak
1507 * Assert that an expression is true, break if it isn't.
1508 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1509 *
1510 * @param expr Expression which should be true.
1511 * @param a printf argument list (in parenthesis).
1512 */
1513#define AssertLogRelMsgBreak(expr, a) \
1514 if (RT_LIKELY(!!(expr))) \
1515 { /* likely */ } \
1516 else if (1) \
1517 { \
1518 RTAssertLogRelMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1519 RTAssertLogRelMsg2(a); \
1520 RTAssertPanic(); \
1521 break; \
1522 } \
1523 else \
1524 break
1525
1526/** @def AssertLogRelMsgBreakStmt
1527 * Assert that an expression is true, execute \a stmt and break if it isn't.
1528 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1529 *
1530 * @param expr Expression which should be true.
1531 * @param a printf argument list (in parenthesis).
1532 * @param stmt Statement to execute before break in case of a failed assertion.
1533 */
1534#define AssertLogRelMsgBreakStmt(expr, a, stmt) \
1535 if (RT_LIKELY(!!(expr))) \
1536 { /* likely */ } \
1537 else if (1) \
1538 { \
1539 RTAssertLogRelMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1540 RTAssertLogRelMsg2(a); \
1541 RTAssertPanic(); \
1542 stmt; \
1543 break; \
1544 } else \
1545 break
1546
1547/** @def AssertLogRelFailed
1548 * An assertion failed.
1549 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1550 */
1551#define AssertLogRelFailed() \
1552 do { \
1553 RTAssertLogRelMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1554 RTAssertPanic(); \
1555 } while (0)
1556
1557/** @def AssertLogRelFailedReturn
1558 * An assertion failed.
1559 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1560 *
1561 * @param rc What is to be presented to return.
1562 */
1563#define AssertLogRelFailedReturn(rc) \
1564 do { \
1565 RTAssertLogRelMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1566 RTAssertPanic(); \
1567 return (rc); \
1568 } while (0)
1569
1570/** @def AssertLogRelFailedReturnVoid
1571 * An assertion failed, hit a breakpoint and return.
1572 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1573 */
1574#define AssertLogRelFailedReturnVoid() \
1575 do { \
1576 RTAssertLogRelMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1577 RTAssertPanic(); \
1578 return; \
1579 } while (0)
1580
1581/** @def AssertLogRelFailedBreak
1582 * An assertion failed, break.
1583 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1584 */
1585#define AssertLogRelFailedBreak() \
1586 if (1) \
1587 { \
1588 RTAssertLogRelMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1589 RTAssertPanic(); \
1590 break; \
1591 } else \
1592 break
1593
1594/** @def AssertLogRelFailedBreakStmt
1595 * An assertion failed, execute \a stmt and break.
1596 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1597 *
1598 * @param stmt Statement to execute before break.
1599 */
1600#define AssertLogRelFailedBreakStmt(stmt) \
1601 if (1) \
1602 { \
1603 RTAssertLogRelMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1604 RTAssertPanic(); \
1605 stmt; \
1606 break; \
1607 } else \
1608 break
1609
1610/** @def AssertLogRelMsgFailed
1611 * An assertion failed.
1612 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1613 *
1614 * @param a printf argument list (in parenthesis).
1615 */
1616#define AssertLogRelMsgFailed(a) \
1617 do { \
1618 RTAssertLogRelMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1619 RTAssertLogRelMsg2(a); \
1620 RTAssertPanic(); \
1621 } while (0)
1622
1623/** @def AssertLogRelMsgFailedStmt
1624 * An assertion failed, execute @a stmt.
1625 *
1626 * Strict builds will hit a breakpoint, non-strict will only do LogRel. The
1627 * statement will be executed in regardless of build type.
1628 *
1629 * @param a printf argument list (in parenthesis).
1630 * @param stmt Statement to execute after raising/logging the assertion.
1631 */
1632#define AssertLogRelMsgFailedStmt(a, stmt) \
1633 do { \
1634 RTAssertLogRelMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1635 RTAssertLogRelMsg2(a); \
1636 RTAssertPanic(); \
1637 stmt; \
1638 } while (0)
1639
1640/** @def AssertLogRelMsgFailedReturn
1641 * An assertion failed, return \a rc.
1642 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1643 *
1644 * @param a printf argument list (in parenthesis).
1645 * @param rc What is to be presented to return.
1646 */
1647#define AssertLogRelMsgFailedReturn(a, rc) \
1648 do { \
1649 RTAssertLogRelMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1650 RTAssertLogRelMsg2(a); \
1651 RTAssertPanic(); \
1652 return (rc); \
1653 } while (0)
1654
1655/** @def AssertLogRelMsgFailedReturnStmt
1656 * An assertion failed, execute @a stmt and return @a rc.
1657 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1658 *
1659 * @param a printf argument list (in parenthesis).
1660 * @param stmt Statement to execute before returning in case of a failed
1661 * assertion.
1662 * @param rc What is to be presented to return.
1663 */
1664#define AssertLogRelMsgFailedReturnStmt(a, stmt, rc) \
1665 do { \
1666 RTAssertLogRelMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1667 RTAssertLogRelMsg2(a); \
1668 RTAssertPanic(); \
1669 stmt; \
1670 return (rc); \
1671 } while (0)
1672
1673/** @def AssertLogRelMsgFailedReturnVoid
1674 * An assertion failed, return void.
1675 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1676 *
1677 * @param a printf argument list (in parenthesis).
1678 */
1679#define AssertLogRelMsgFailedReturnVoid(a) \
1680 do { \
1681 RTAssertLogRelMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1682 RTAssertLogRelMsg2(a); \
1683 RTAssertPanic(); \
1684 return; \
1685 } while (0)
1686
1687/** @def AssertLogRelMsgFailedReturnVoidStmt
1688 * An assertion failed, execute @a stmt and return void.
1689 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1690 *
1691 * @param a printf argument list (in parenthesis).
1692 * @param stmt Statement to execute before returning in case of a failed
1693 * assertion.
1694 */
1695#define AssertLogRelMsgFailedReturnVoidStmt(a, stmt) \
1696 do { \
1697 RTAssertLogRelMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1698 RTAssertLogRelMsg2(a); \
1699 RTAssertPanic(); \
1700 stmt; \
1701 return; \
1702 } while (0)
1703
1704/** @def AssertLogRelMsgFailedBreak
1705 * An assertion failed, break.
1706 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1707 *
1708 * @param a printf argument list (in parenthesis).
1709 */
1710#define AssertLogRelMsgFailedBreak(a) \
1711 if (1)\
1712 { \
1713 RTAssertLogRelMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1714 RTAssertLogRelMsg2(a); \
1715 RTAssertPanic(); \
1716 break; \
1717 } else \
1718 break
1719
1720/** @def AssertLogRelMsgFailedBreakStmt
1721 * An assertion failed, execute \a stmt and break.
1722 * Strict builds will hit a breakpoint, non-strict will only do LogRel.
1723 *
1724 * @param a printf argument list (in parenthesis).
1725 * @param stmt Statement to execute before break.
1726 */
1727#define AssertLogRelMsgFailedBreakStmt(a, stmt) \
1728 if (1) \
1729 { \
1730 RTAssertLogRelMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1731 RTAssertLogRelMsg2(a); \
1732 RTAssertPanic(); \
1733 stmt; \
1734 break; \
1735 } else \
1736 break
1737
1738/** @} */
1739
1740
1741
1742/** @name Release Assertions
1743 *
1744 * These assertions are always enabled.
1745 * @{
1746 */
1747
1748/** @def RTAssertReleasePanic()
1749 * Invokes RTAssertShouldPanic and RTAssertDoPanic.
1750 *
1751 * It might seem odd that RTAssertShouldPanic is necessary when its result isn't
1752 * checked, but it's done since RTAssertShouldPanic is overrideable and might be
1753 * used to bail out before taking down the system (the VMMR0 case).
1754 */
1755#define RTAssertReleasePanic() do { RTAssertShouldPanic(); RTAssertDoPanic(); } while (0)
1756
1757
1758/** @def AssertRelease
1759 * Assert that an expression is true. If it's not hit a breakpoint.
1760 *
1761 * @param expr Expression which should be true.
1762 */
1763#define AssertRelease(expr) \
1764 do { \
1765 if (RT_LIKELY(!!(expr))) \
1766 { /* likely */ } \
1767 else \
1768 { \
1769 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, RT_GCC_EXTENSION __PRETTY_FUNCTION__); \
1770 RTAssertReleasePanic(); \
1771 } \
1772 } while (0)
1773
1774/** @def AssertReleaseReturn
1775 * Assert that an expression is true, hit a breakpoint and return if it isn't.
1776 *
1777 * @param expr Expression which should be true.
1778 * @param rc What is to be presented to return.
1779 */
1780#define AssertReleaseReturn(expr, rc) \
1781 do { \
1782 if (RT_LIKELY(!!(expr))) \
1783 { /* likely */ } \
1784 else \
1785 { \
1786 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1787 RTAssertReleasePanic(); \
1788 return (rc); \
1789 } \
1790 } while (0)
1791
1792/** @def AssertReleaseReturnVoid
1793 * Assert that an expression is true, hit a breakpoint and return if it isn't.
1794 *
1795 * @param expr Expression which should be true.
1796 */
1797#define AssertReleaseReturnVoid(expr) \
1798 do { \
1799 if (RT_LIKELY(!!(expr))) \
1800 { /* likely */ } \
1801 else \
1802 { \
1803 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1804 RTAssertReleasePanic(); \
1805 return; \
1806 } \
1807 } while (0)
1808
1809
1810/** @def AssertReleaseBreak
1811 * Assert that an expression is true, hit a breakpoint and break if it isn't.
1812 *
1813 * @param expr Expression which should be true.
1814 */
1815#define AssertReleaseBreak(expr) \
1816 if (RT_LIKELY(!!(expr))) \
1817 { /* likely */ } \
1818 else if (1) \
1819 { \
1820 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1821 RTAssertReleasePanic(); \
1822 break; \
1823 } else \
1824 break
1825
1826/** @def AssertReleaseBreakStmt
1827 * Assert that an expression is true, hit a breakpoint and break if it isn't.
1828 *
1829 * @param expr Expression which should be true.
1830 * @param stmt Statement to execute before break in case of a failed assertion.
1831 */
1832#define AssertReleaseBreakStmt(expr, stmt) \
1833 if (RT_LIKELY(!!(expr))) \
1834 { /* likely */ } \
1835 else if (1) \
1836 { \
1837 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1838 RTAssertReleasePanic(); \
1839 stmt; \
1840 break; \
1841 } else \
1842 break
1843
1844
1845/** @def AssertReleaseMsg
1846 * Assert that an expression is true, print the message and hit a breakpoint if it isn't.
1847 *
1848 * @param expr Expression which should be true.
1849 * @param a printf argument list (in parenthesis).
1850 */
1851#define AssertReleaseMsg(expr, a) \
1852 do { \
1853 if (RT_LIKELY(!!(expr))) \
1854 { /* likely */ } \
1855 else \
1856 { \
1857 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1858 RTAssertMsg2Weak a; \
1859 RTAssertReleasePanic(); \
1860 } \
1861 } while (0)
1862
1863/** @def AssertReleaseMsgReturn
1864 * Assert that an expression is true, print the message and hit a breakpoint and return if it isn't.
1865 *
1866 * @param expr Expression which should be true.
1867 * @param a printf argument list (in parenthesis).
1868 * @param rc What is to be presented to return.
1869 */
1870#define AssertReleaseMsgReturn(expr, a, rc) \
1871 do { \
1872 if (RT_LIKELY(!!(expr))) \
1873 { /* likely */ } \
1874 else \
1875 { \
1876 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1877 RTAssertMsg2Weak a; \
1878 RTAssertReleasePanic(); \
1879 return (rc); \
1880 } \
1881 } while (0)
1882
1883/** @def AssertReleaseMsgReturnVoid
1884 * Assert that an expression is true, print the message and hit a breakpoint and return if it isn't.
1885 *
1886 * @param expr Expression which should be true.
1887 * @param a printf argument list (in parenthesis).
1888 */
1889#define AssertReleaseMsgReturnVoid(expr, a) \
1890 do { \
1891 if (RT_LIKELY(!!(expr))) \
1892 { /* likely */ } \
1893 else \
1894 { \
1895 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1896 RTAssertMsg2Weak a; \
1897 RTAssertReleasePanic(); \
1898 return; \
1899 } \
1900 } while (0)
1901
1902
1903/** @def AssertReleaseMsgBreak
1904 * Assert that an expression is true, print the message and hit a breakpoint and break if it isn't.
1905 *
1906 * @param expr Expression which should be true.
1907 * @param a printf argument list (in parenthesis).
1908 */
1909#define AssertReleaseMsgBreak(expr, a) \
1910 if (RT_LIKELY(!!(expr))) \
1911 { /* likely */ } \
1912 else if (1) \
1913 { \
1914 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1915 RTAssertMsg2Weak a; \
1916 RTAssertReleasePanic(); \
1917 break; \
1918 } else \
1919 break
1920
1921/** @def AssertReleaseMsgBreakStmt
1922 * Assert that an expression is true, print the message and hit a breakpoint and break if it isn't.
1923 *
1924 * @param expr Expression which should be true.
1925 * @param a printf argument list (in parenthesis).
1926 * @param stmt Statement to execute before break in case of a failed assertion.
1927 */
1928#define AssertReleaseMsgBreakStmt(expr, a, stmt) \
1929 if (RT_LIKELY(!!(expr))) \
1930 { /* likely */ } \
1931 else if (1) \
1932 { \
1933 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1934 RTAssertMsg2Weak a; \
1935 RTAssertReleasePanic(); \
1936 stmt; \
1937 break; \
1938 } else \
1939 break
1940
1941
1942/** @def AssertReleaseFailed
1943 * An assertion failed, hit a breakpoint.
1944 */
1945#define AssertReleaseFailed() \
1946 do { \
1947 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1948 RTAssertReleasePanic(); \
1949 } while (0)
1950
1951/** @def AssertReleaseFailedReturn
1952 * An assertion failed, hit a breakpoint and return.
1953 *
1954 * @param rc What is to be presented to return.
1955 */
1956#define AssertReleaseFailedReturn(rc) \
1957 do { \
1958 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1959 RTAssertReleasePanic(); \
1960 return (rc); \
1961 } while (0)
1962
1963/** @def AssertReleaseFailedReturnVoid
1964 * An assertion failed, hit a breakpoint and return.
1965 */
1966#define AssertReleaseFailedReturnVoid() \
1967 do { \
1968 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1969 RTAssertReleasePanic(); \
1970 return; \
1971 } while (0)
1972
1973
1974/** @def AssertReleaseFailedBreak
1975 * An assertion failed, hit a breakpoint and break.
1976 */
1977#define AssertReleaseFailedBreak() \
1978 if (1) { \
1979 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1980 RTAssertReleasePanic(); \
1981 break; \
1982 } else \
1983 break
1984
1985/** @def AssertReleaseFailedBreakStmt
1986 * An assertion failed, hit a breakpoint and break.
1987 *
1988 * @param stmt Statement to execute before break.
1989 */
1990#define AssertReleaseFailedBreakStmt(stmt) \
1991 if (1) { \
1992 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
1993 RTAssertReleasePanic(); \
1994 stmt; \
1995 break; \
1996 } else \
1997 break
1998
1999
2000/** @def AssertReleaseMsgFailed
2001 * An assertion failed, print a message and hit a breakpoint.
2002 *
2003 * @param a printf argument list (in parenthesis).
2004 */
2005#define AssertReleaseMsgFailed(a) \
2006 do { \
2007 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, RT_GCC_EXTENSION __PRETTY_FUNCTION__); \
2008 RTAssertMsg2Weak a; \
2009 RTAssertReleasePanic(); \
2010 } while (0)
2011
2012/** @def AssertReleaseMsgFailedReturn
2013 * An assertion failed, print a message, hit a breakpoint and return.
2014 *
2015 * @param a printf argument list (in parenthesis).
2016 * @param rc What is to be presented to return.
2017 */
2018#define AssertReleaseMsgFailedReturn(a, rc) \
2019 do { \
2020 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
2021 RTAssertMsg2Weak a; \
2022 RTAssertReleasePanic(); \
2023 return (rc); \
2024 } while (0)
2025
2026/** @def AssertReleaseMsgFailedReturnVoid
2027 * An assertion failed, print a message, hit a breakpoint and return.
2028 *
2029 * @param a printf argument list (in parenthesis).
2030 */
2031#define AssertReleaseMsgFailedReturnVoid(a) \
2032 do { \
2033 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
2034 RTAssertMsg2Weak a; \
2035 RTAssertReleasePanic(); \
2036 return; \
2037 } while (0)
2038
2039
2040/** @def AssertReleaseMsgFailedBreak
2041 * An assertion failed, print a message, hit a breakpoint and break.
2042 *
2043 * @param a printf argument list (in parenthesis).
2044 */
2045#define AssertReleaseMsgFailedBreak(a) \
2046 if (1) { \
2047 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
2048 RTAssertMsg2Weak a; \
2049 RTAssertReleasePanic(); \
2050 break; \
2051 } else \
2052 break
2053
2054/** @def AssertReleaseMsgFailedBreakStmt
2055 * An assertion failed, print a message, hit a breakpoint and break.
2056 *
2057 * @param a printf argument list (in parenthesis).
2058 * @param stmt Statement to execute before break.
2059 */
2060#define AssertReleaseMsgFailedBreakStmt(a, stmt) \
2061 if (1) { \
2062 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
2063 RTAssertMsg2Weak a; \
2064 RTAssertReleasePanic(); \
2065 stmt; \
2066 break; \
2067 } else \
2068 break
2069
2070/** @} */
2071
2072
2073
2074/** @name Fatal Assertions
2075 * These are similar to release assertions except that you cannot ignore them in
2076 * any way, they will loop for ever if RTAssertDoPanic returns.
2077 *
2078 * @{
2079 */
2080
2081/** @def AssertFatal
2082 * Assert that an expression is true. If it's not hit a breakpoint (for ever).
2083 *
2084 * @param expr Expression which should be true.
2085 */
2086#define AssertFatal(expr) \
2087 do { \
2088 if (RT_LIKELY(!!(expr))) \
2089 { /* likely */ } \
2090 else \
2091 for (;;) \
2092 { \
2093 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
2094 RTAssertReleasePanic(); \
2095 } \
2096 } while (0)
2097
2098/** @def AssertFatalMsg
2099 * Assert that an expression is true, print the message and hit a breakpoint (for ever) if it isn't.
2100 *
2101 * @param expr Expression which should be true.
2102 * @param a printf argument list (in parenthesis).
2103 */
2104#define AssertFatalMsg(expr, a) \
2105 do { \
2106 if (RT_LIKELY(!!(expr))) \
2107 { /* likely */ } \
2108 else \
2109 for (;;) \
2110 { \
2111 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
2112 RTAssertMsg2Weak a; \
2113 RTAssertReleasePanic(); \
2114 } \
2115 } while (0)
2116
2117/** @def AssertFatalFailed
2118 * An assertion failed, hit a breakpoint (for ever).
2119 */
2120#define AssertFatalFailed() \
2121 do { \
2122 for (;;) \
2123 { \
2124 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, RT_GCC_EXTENSION __PRETTY_FUNCTION__); \
2125 RTAssertReleasePanic(); \
2126 } \
2127 } while (0)
2128
2129/** @def AssertFatalMsgFailed
2130 * An assertion failed, print a message and hit a breakpoint (for ever).
2131 *
2132 * @param a printf argument list (in parenthesis).
2133 */
2134#define AssertFatalMsgFailed(a) \
2135 do { \
2136 for (;;) \
2137 { \
2138 RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, RT_GCC_EXTENSION __PRETTY_FUNCTION__); \
2139 RTAssertMsg2Weak a; \
2140 RTAssertReleasePanic(); \
2141 } \
2142 } while (0)
2143
2144/** @} */
2145
2146
2147
2148/** @name Convenience Assertions Macros
2149 * @{
2150 */
2151
2152/** @def AssertRC
2153 * Asserts a iprt status code successful.
2154 *
2155 * On failure it will print info about the rc and hit a breakpoint.
2156 *
2157 * @param rc iprt status code.
2158 * @remark rc is referenced multiple times. In release mode is NOREF()'ed.
2159 */
2160#define AssertRC(rc) AssertMsgRC(rc, ("%Rra\n", (rc)))
2161
2162/** @def AssertRCStmt
2163 * Asserts a iprt status code successful, bitch (RT_STRICT mode only) and execute
2164 * @a stmt if it isn't.
2165 *
2166 * @param rc iprt status code.
2167 * @param stmt Statement to execute before returning in case of a failed
2168 * assertion.
2169 * @remark rc is referenced multiple times. In release mode is NOREF()'ed.
2170 */
2171#define AssertRCStmt(rc, stmt) AssertMsgRCStmt(rc, ("%Rra\n", (rc)), stmt)
2172
2173/** @def AssertRCReturn
2174 * Asserts a iprt status code successful, bitch (RT_STRICT mode only) and return if it isn't.
2175 *
2176 * @param rc iprt status code.
2177 * @param rcRet What is to be presented to return.
2178 * @remark rc is referenced multiple times. In release mode is NOREF()'ed.
2179 */
2180#define AssertRCReturn(rc, rcRet) AssertMsgRCReturn(rc, ("%Rra\n", (rc)), rcRet)
2181
2182/** @def AssertRCReturnStmt
2183 * Asserts a iprt status code successful, bitch (RT_STRICT mode only), execute
2184 * @a stmt and returns @a rcRet if it isn't.
2185 *
2186 * @param rc iprt status code.
2187 * @param stmt Statement to execute before returning in case of a failed
2188 * assertion.
2189 * @param rcRet What is to be presented to return.
2190 * @remark rc is referenced multiple times. In release mode is NOREF()'ed.
2191 */
2192#define AssertRCReturnStmt(rc, stmt, rcRet) AssertMsgRCReturnStmt(rc, ("%Rra\n", (rc)), stmt, rcRet)
2193
2194/** @def AssertRCReturnVoid
2195 * Asserts a iprt status code successful, bitch (RT_STRICT mode only) and return if it isn't.
2196 *
2197 * @param rc iprt status code.
2198 * @remark rc is referenced multiple times. In release mode is NOREF()'ed.
2199 */
2200#define AssertRCReturnVoid(rc) AssertMsgRCReturnVoid(rc, ("%Rra\n", (rc)))
2201
2202/** @def AssertRCReturnVoidStmt
2203 * Asserts a iprt status code successful, bitch (RT_STRICT mode only), and
2204 * execute the given statement/return if it isn't.
2205 *
2206 * @param rc iprt status code.
2207 * @param stmt Statement to execute before returning on failure.
2208 * @remark rc is referenced multiple times. In release mode is NOREF()'ed.
2209 */
2210#define AssertRCReturnVoidStmt(rc, stmt) AssertMsgRCReturnVoidStmt(rc, ("%Rra\n", (rc)), stmt)
2211
2212/** @def AssertRCBreak
2213 * Asserts a iprt status code successful, bitch (RT_STRICT mode only) and break if it isn't.
2214 *
2215 * @param rc iprt status code.
2216 * @remark rc is referenced multiple times. In release mode is NOREF()'ed.
2217 */
2218#define AssertRCBreak(rc) AssertMsgRCBreak(rc, ("%Rra\n", (rc)))
2219
2220/** @def AssertRCBreakStmt
2221 * Asserts a iprt status code successful, bitch (RT_STRICT mode only) and break if it isn't.
2222 *
2223 * @param rc iprt status code.
2224 * @param stmt Statement to execute before break in case of a failed assertion.
2225 * @remark rc is referenced multiple times. In release mode is NOREF()'ed.
2226 */
2227#define AssertRCBreakStmt(rc, stmt) AssertMsgRCBreakStmt(rc, ("%Rra\n", (rc)), stmt)
2228
2229/** @def AssertMsgRC
2230 * Asserts a iprt status code successful.
2231 *
2232 * It prints a custom message and hits a breakpoint on FAILURE.
2233 *
2234 * @param rc iprt status code.
2235 * @param msg printf argument list (in parenthesis).
2236 * @remark rc is referenced multiple times. In release mode is NOREF()'ed.
2237 */
2238#define AssertMsgRC(rc, msg) \
2239 do { AssertMsg(RT_SUCCESS_NP(rc), msg); NOREF(rc); } while (0)
2240
2241/** @def AssertMsgRCStmt
2242 * Asserts a iprt status code successful, bitch (RT_STRICT mode only) and
2243 * execute @a stmt if it isn't.
2244 *
2245 * @param rc iprt status code.
2246 * @param msg printf argument list (in parenthesis).
2247 * @param stmt Statement to execute before returning in case of a failed
2248 * assertion.
2249 * @remark rc is referenced multiple times. In release mode is NOREF()'ed.
2250 */
2251#define AssertMsgRCStmt(rc, msg, stmt) \
2252 do { AssertMsgStmt(RT_SUCCESS_NP(rc), msg, stmt); NOREF(rc); } while (0)
2253
2254/** @def AssertMsgRCReturn
2255 * Asserts a iprt status code successful, bitch (RT_STRICT mode only) and return
2256 * @a rcRet if it isn't.
2257 *
2258 * @param rc iprt status code.
2259 * @param msg printf argument list (in parenthesis).
2260 * @param rcRet What is to be presented to return.
2261 * @remark rc is referenced multiple times. In release mode is NOREF()'ed.
2262 */
2263#define AssertMsgRCReturn(rc, msg, rcRet) \
2264 do { AssertMsgReturn(RT_SUCCESS_NP(rc), msg, rcRet); NOREF(rc); } while (0)
2265
2266/** @def AssertMsgRCReturnStmt
2267 * Asserts a iprt status code successful, bitch (RT_STRICT mode only), execute
2268 * @a stmt and return @a rcRet if it isn't.
2269 *
2270 * @param rc iprt status code.
2271 * @param msg printf argument list (in parenthesis).
2272 * @param stmt Statement to execute before returning in case of a failed
2273 * assertion.
2274 * @param rcRet What is to be presented to return.
2275 * @remark rc is referenced multiple times. In release mode is NOREF()'ed.
2276 */
2277#define AssertMsgRCReturnStmt(rc, msg, stmt, rcRet) \
2278 do { AssertMsgReturnStmt(RT_SUCCESS_NP(rc), msg, stmt, rcRet); NOREF(rc); } while (0)
2279
2280/** @def AssertMsgRCReturnVoid
2281 * Asserts a iprt status code successful, bitch (RT_STRICT mode only) and return
2282 * void if it isn't.
2283 *
2284 * @param rc iprt status code.
2285 * @param msg printf argument list (in parenthesis).
2286 * @remark rc is referenced multiple times. In release mode is NOREF()'ed.
2287 */
2288#define AssertMsgRCReturnVoid(rc, msg) \
2289 do { AssertMsgReturnVoid(RT_SUCCESS_NP(rc), msg); NOREF(rc); } while (0)
2290
2291/** @def AssertMsgRCReturnVoidStmt
2292 * Asserts a iprt status code successful, bitch (RT_STRICT mode only), execute
2293 * @a stmt and return void if it isn't.
2294 *
2295 * @param rc iprt status code.
2296 * @param msg printf argument list (in parenthesis).
2297 * @param stmt Statement to execute before break in case of a failed assertion.
2298 * @remark rc is referenced multiple times. In release mode is NOREF()'ed.
2299 */
2300#define AssertMsgRCReturnVoidStmt(rc, msg, stmt) \
2301 do { AssertMsgReturnVoidStmt(RT_SUCCESS_NP(rc), msg, stmt); NOREF(rc); } while (0)
2302
2303/** @def AssertMsgRCBreak
2304 * Asserts a iprt status code successful, bitch (RT_STRICT mode only) and break
2305 * if it isn't.
2306 *
2307 * @param rc iprt status code.
2308 * @param msg printf argument list (in parenthesis).
2309 * @remark rc is referenced multiple times. In release mode is NOREF()'ed.
2310 */
2311#define AssertMsgRCBreak(rc, msg) \
2312 if (1) { AssertMsgBreak(RT_SUCCESS(rc), msg); NOREF(rc); } else do {} while (0)
2313
2314/** @def AssertMsgRCBreakStmt
2315 * Asserts a iprt status code successful, bitch (RT_STRICT mode only), execute
2316 * @a stmt and break if it isn't.
2317 *
2318 * @param rc iprt status code.
2319 * @param msg printf argument list (in parenthesis).
2320 * @param stmt Statement to execute before break in case of a failed assertion.
2321 * @remark rc is referenced multiple times. In release mode is NOREF()'ed.
2322 */
2323#define AssertMsgRCBreakStmt(rc, msg, stmt) \
2324 if (1) { AssertMsgBreakStmt(RT_SUCCESS_NP(rc), msg, stmt); NOREF(rc); } else do {} while (0)
2325
2326/** @def AssertRCSuccess
2327 * Asserts an iprt status code equals VINF_SUCCESS.
2328 *
2329 * On failure it will print info about the rc and hit a breakpoint.
2330 *
2331 * @param rc iprt status code.
2332 * @remark rc is referenced multiple times. In release mode is NOREF()'ed.
2333 */
2334#define AssertRCSuccess(rc) do { AssertMsg((rc) == VINF_SUCCESS, ("%Rra\n", (rc))); NOREF(rc); } while (0)
2335
2336/** @def AssertRCSuccessReturn
2337 * Asserts that an iprt status code equals VINF_SUCCESS, bitch (RT_STRICT mode only) and return if it isn't.
2338 *
2339 * @param rc iprt status code.
2340 * @param rcRet What is to be presented to return.
2341 * @remark rc is referenced multiple times. In release mode is NOREF()'ed.
2342 */
2343#define AssertRCSuccessReturn(rc, rcRet) AssertMsgReturn((rc) == VINF_SUCCESS, ("%Rra\n", (rc)), rcRet)
2344
2345/** @def AssertRCSuccessReturnVoid
2346 * Asserts that an iprt status code equals VINF_SUCCESS, bitch (RT_STRICT mode only) and return if it isn't.
2347 *
2348 * @param rc iprt status code.
2349 * @remark rc is referenced multiple times. In release mode is NOREF()'ed.
2350 */
2351#define AssertRCSuccessReturnVoid(rc) AssertMsgReturnVoid((rc) == VINF_SUCCESS, ("%Rra\n", (rc)))
2352
2353/** @def AssertRCSuccessBreak
2354 * Asserts that an iprt status code equals VINF_SUCCESS, bitch (RT_STRICT mode only) and break if it isn't.
2355 *
2356 * @param rc iprt status code.
2357 * @remark rc is referenced multiple times. In release mode is NOREF()'ed.
2358 */
2359#define AssertRCSuccessBreak(rc) AssertMsgBreak((rc) == VINF_SUCCESS, ("%Rra\n", (rc)))
2360
2361/** @def AssertRCSuccessBreakStmt
2362 * Asserts that an iprt status code equals VINF_SUCCESS, bitch (RT_STRICT mode only) and break if it isn't.
2363 *
2364 * @param rc iprt status code.
2365 * @param stmt Statement to execute before break in case of a failed assertion.
2366 * @remark rc is referenced multiple times. In release mode is NOREF()'ed.
2367 */
2368#define AssertRCSuccessBreakStmt(rc, stmt) AssertMsgBreakStmt((rc) == VINF_SUCCESS, ("%Rra\n", (rc)), stmt)
2369
2370
2371/** @def AssertLogRelRC
2372 * Asserts a iprt status code successful.
2373 *
2374 * @param rc iprt status code.
2375 * @remark rc is referenced multiple times.
2376 */
2377#define AssertLogRelRC(rc) AssertLogRelMsgRC(rc, ("%Rra\n", (rc)))
2378
2379/** @def AssertLogRelRCReturn
2380 * Asserts a iprt status code successful, returning \a rc if it isn't.
2381 *
2382 * @param rc iprt status code.
2383 * @param rcRet What is to be presented to return.
2384 * @remark rc is referenced multiple times.
2385 */
2386#define AssertLogRelRCReturn(rc, rcRet) AssertLogRelMsgRCReturn(rc, ("%Rra\n", (rc)), rcRet)
2387
2388/** @def AssertLogRelRCReturnStmt
2389 * Asserts a iprt status code successful, executing \a stmt and returning \a rc
2390 * if it isn't.
2391 *
2392 * @param rc iprt status code.
2393 * @param stmt Statement to execute before returning in case of a failed
2394 * assertion.
2395 * @param rcRet What is to be presented to return.
2396 * @remark rc is referenced multiple times.
2397 */
2398#define AssertLogRelRCReturnStmt(rc, stmt, rcRet) AssertLogRelMsgRCReturnStmt(rc, ("%Rra\n", (rc)), stmt, rcRet)
2399
2400/** @def AssertLogRelRCReturnVoid
2401 * Asserts a iprt status code successful, returning (void) if it isn't.
2402 *
2403 * @param rc iprt status code.
2404 * @remark rc is referenced multiple times.
2405 */
2406#define AssertLogRelRCReturnVoid(rc) AssertLogRelMsgRCReturnVoid(rc, ("%Rra\n", (rc)))
2407
2408/** @def AssertLogRelRCBreak
2409 * Asserts a iprt status code successful, breaking if it isn't.
2410 *
2411 * @param rc iprt status code.
2412 * @remark rc is referenced multiple times.
2413 */
2414#define AssertLogRelRCBreak(rc) AssertLogRelMsgRCBreak(rc, ("%Rra\n", (rc)))
2415
2416/** @def AssertLogRelRCBreakStmt
2417 * Asserts a iprt status code successful, execute \a statement and break if it isn't.
2418 *
2419 * @param rc iprt status code.
2420 * @param stmt Statement to execute before break in case of a failed assertion.
2421 * @remark rc is referenced multiple times.
2422 */
2423#define AssertLogRelRCBreakStmt(rc, stmt) AssertLogRelMsgRCBreakStmt(rc, ("%Rra\n", (rc)), stmt)
2424
2425/** @def AssertLogRelMsgRC
2426 * Asserts a iprt status code successful.
2427 *
2428 * @param rc iprt status code.
2429 * @param msg printf argument list (in parenthesis).
2430 * @remark rc is referenced multiple times.
2431 */
2432#define AssertLogRelMsgRC(rc, msg) AssertLogRelMsg(RT_SUCCESS_NP(rc), msg)
2433
2434/** @def AssertLogRelMsgRCReturn
2435 * Asserts a iprt status code successful.
2436 *
2437 * @param rc iprt status code.
2438 * @param msg printf argument list (in parenthesis).
2439 * @param rcRet What is to be presented to return.
2440 * @remark rc is referenced multiple times.
2441 */
2442#define AssertLogRelMsgRCReturn(rc, msg, rcRet) AssertLogRelMsgReturn(RT_SUCCESS_NP(rc), msg, rcRet)
2443
2444/** @def AssertLogRelMsgRCReturnStmt
2445 * Asserts a iprt status code successful, execute \a stmt and return on
2446 * failure.
2447 *
2448 * @param rc iprt status code.
2449 * @param msg printf argument list (in parenthesis).
2450 * @param stmt Statement to execute before returning in case of a failed
2451 * assertion.
2452 * @param rcRet What is to be presented to return.
2453 * @remark rc is referenced multiple times.
2454 */
2455#define AssertLogRelMsgRCReturnStmt(rc, msg, stmt, rcRet) AssertLogRelMsgReturnStmt(RT_SUCCESS_NP(rc), msg, stmt, rcRet)
2456
2457/** @def AssertLogRelMsgRCReturnVoid
2458 * Asserts a iprt status code successful.
2459 *
2460 * @param rc iprt status code.
2461 * @param msg printf argument list (in parenthesis).
2462 * @remark rc is referenced multiple times.
2463 */
2464#define AssertLogRelMsgRCReturnVoid(rc, msg) AssertLogRelMsgReturnVoid(RT_SUCCESS_NP(rc), msg)
2465
2466/** @def AssertLogRelMsgRCBreak
2467 * Asserts a iprt status code successful.
2468 *
2469 * @param rc iprt status code.
2470 * @param msg printf argument list (in parenthesis).
2471 * @remark rc is referenced multiple times.
2472 */
2473#define AssertLogRelMsgRCBreak(rc, msg) AssertLogRelMsgBreak(RT_SUCCESS(rc), msg)
2474
2475/** @def AssertLogRelMsgRCBreakStmt
2476 * Asserts a iprt status code successful, execute \a stmt and break if it isn't.
2477 *
2478 * @param rc iprt status code.
2479 * @param msg printf argument list (in parenthesis).
2480 * @param stmt Statement to execute before break in case of a failed assertion.
2481 * @remark rc is referenced multiple times.
2482 */
2483#define AssertLogRelMsgRCBreakStmt(rc, msg, stmt) AssertLogRelMsgBreakStmt(RT_SUCCESS_NP(rc), msg, stmt)
2484
2485/** @def AssertLogRelRCSuccess
2486 * Asserts that an iprt status code equals VINF_SUCCESS.
2487 *
2488 * @param rc iprt status code.
2489 * @remark rc is referenced multiple times.
2490 */
2491#define AssertLogRelRCSuccess(rc) AssertLogRelMsg((rc) == VINF_SUCCESS, ("%Rra\n", (rc)))
2492
2493/** @def AssertLogRelRCSuccessReturn
2494 * Asserts that an iprt status code equals VINF_SUCCESS.
2495 *
2496 * @param rc iprt status code.
2497 * @param rcRet What is to be presented to return.
2498 * @remark rc is referenced multiple times.
2499 */
2500#define AssertLogRelRCSuccessReturn(rc, rcRet) AssertLogRelMsgReturn((rc) == VINF_SUCCESS, ("%Rra\n", (rc)), rcRet)
2501
2502/** @def AssertLogRelRCSuccessReturnVoid
2503 * Asserts that an iprt status code equals VINF_SUCCESS.
2504 *
2505 * @param rc iprt status code.
2506 * @remark rc is referenced multiple times.
2507 */
2508#define AssertLogRelRCSuccessReturnVoid(rc) AssertLogRelMsgReturnVoid((rc) == VINF_SUCCESS, ("%Rra\n", (rc)))
2509
2510/** @def AssertLogRelRCSuccessBreak
2511 * Asserts that an iprt status code equals VINF_SUCCESS.
2512 *
2513 * @param rc iprt status code.
2514 * @remark rc is referenced multiple times.
2515 */
2516#define AssertLogRelRCSuccessBreak(rc) AssertLogRelMsgBreak((rc) == VINF_SUCCESS, ("%Rra\n", (rc)))
2517
2518/** @def AssertLogRelRCSuccessBreakStmt
2519 * Asserts that an iprt status code equals VINF_SUCCESS.
2520 *
2521 * @param rc iprt status code.
2522 * @param stmt Statement to execute before break in case of a failed assertion.
2523 * @remark rc is referenced multiple times.
2524 */
2525#define AssertLogRelRCSuccessBreakStmt(rc, stmt) AssertLogRelMsgBreakStmt((rc) == VINF_SUCCESS, ("%Rra\n", (rc)), stmt)
2526
2527
2528/** @def AssertReleaseRC
2529 * Asserts a iprt status code successful.
2530 *
2531 * On failure information about the error will be printed and a breakpoint hit.
2532 *
2533 * @param rc iprt status code.
2534 * @remark rc is referenced multiple times.
2535 */
2536#define AssertReleaseRC(rc) AssertReleaseMsgRC(rc, ("%Rra\n", (rc)))
2537
2538/** @def AssertReleaseRCReturn
2539 * Asserts a iprt status code successful, returning if it isn't.
2540 *
2541 * On failure information about the error will be printed, a breakpoint hit
2542 * and finally returning from the function if the breakpoint is somehow ignored.
2543 *
2544 * @param rc iprt status code.
2545 * @param rcRet What is to be presented to return.
2546 * @remark rc is referenced multiple times.
2547 */
2548#define AssertReleaseRCReturn(rc, rcRet) AssertReleaseMsgRCReturn(rc, ("%Rra\n", (rc)), rcRet)
2549
2550/** @def AssertReleaseRCReturnVoid
2551 * Asserts a iprt status code successful, returning if it isn't.
2552 *
2553 * On failure information about the error will be printed, a breakpoint hit
2554 * and finally returning from the function if the breakpoint is somehow ignored.
2555 *
2556 * @param rc iprt status code.
2557 * @remark rc is referenced multiple times.
2558 */
2559#define AssertReleaseRCReturnVoid(rc) AssertReleaseMsgRCReturnVoid(rc, ("%Rra\n", (rc)))
2560
2561/** @def AssertReleaseRCBreak
2562 * Asserts a iprt status code successful, breaking if it isn't.
2563 *
2564 * On failure information about the error will be printed, a breakpoint hit
2565 * and finally breaking the current statement if the breakpoint is somehow ignored.
2566 *
2567 * @param rc iprt status code.
2568 * @remark rc is referenced multiple times.
2569 */
2570#define AssertReleaseRCBreak(rc) AssertReleaseMsgRCBreak(rc, ("%Rra\n", (rc)))
2571
2572/** @def AssertReleaseRCBreakStmt
2573 * Asserts a iprt status code successful, break if it isn't.
2574 *
2575 * On failure information about the error will be printed, a breakpoint hit
2576 * and finally the break statement will be issued if the breakpoint is somehow ignored.
2577 *
2578 * @param rc iprt status code.
2579 * @param stmt Statement to execute before break in case of a failed assertion.
2580 * @remark rc is referenced multiple times.
2581 */
2582#define AssertReleaseRCBreakStmt(rc, stmt) AssertReleaseMsgRCBreakStmt(rc, ("%Rra\n", (rc)), stmt)
2583
2584/** @def AssertReleaseMsgRC
2585 * Asserts a iprt status code successful.
2586 *
2587 * On failure a custom message is printed and a breakpoint is hit.
2588 *
2589 * @param rc iprt status code.
2590 * @param msg printf argument list (in parenthesis).
2591 * @remark rc is referenced multiple times.
2592 */
2593#define AssertReleaseMsgRC(rc, msg) AssertReleaseMsg(RT_SUCCESS_NP(rc), msg)
2594
2595/** @def AssertReleaseMsgRCReturn
2596 * Asserts a iprt status code successful.
2597 *
2598 * On failure a custom message is printed, a breakpoint is hit, and finally
2599 * returning from the function if the breakpoint is somehow ignored.
2600 *
2601 * @param rc iprt status code.
2602 * @param msg printf argument list (in parenthesis).
2603 * @param rcRet What is to be presented to return.
2604 * @remark rc is referenced multiple times.
2605 */
2606#define AssertReleaseMsgRCReturn(rc, msg, rcRet) AssertReleaseMsgReturn(RT_SUCCESS_NP(rc), msg, rcRet)
2607
2608/** @def AssertReleaseMsgRCReturnVoid
2609 * Asserts a iprt status code successful.
2610 *
2611 * On failure a custom message is printed, a breakpoint is hit, and finally
2612 * returning from the function if the breakpoint is somehow ignored.
2613 *
2614 * @param rc iprt status code.
2615 * @param msg printf argument list (in parenthesis).
2616 * @remark rc is referenced multiple times.
2617 */
2618#define AssertReleaseMsgRCReturnVoid(rc, msg) AssertReleaseMsgReturnVoid(RT_SUCCESS_NP(rc), msg)
2619
2620/** @def AssertReleaseMsgRCBreak
2621 * Asserts a iprt status code successful.
2622 *
2623 * On failure a custom message is printed, a breakpoint is hit, and finally
2624 * breaking the current status if the breakpoint is somehow ignored.
2625 *
2626 * @param rc iprt status code.
2627 * @param msg printf argument list (in parenthesis).
2628 * @remark rc is referenced multiple times.
2629 */
2630#define AssertReleaseMsgRCBreak(rc, msg) AssertReleaseMsgBreak(RT_SUCCESS(rc), msg)
2631
2632/** @def AssertReleaseMsgRCBreakStmt
2633 * Asserts a iprt status code successful.
2634 *
2635 * On failure a custom message is printed, a breakpoint is hit, and finally
2636 * the break statement is issued if the breakpoint is somehow ignored.
2637 *
2638 * @param rc iprt status code.
2639 * @param msg printf argument list (in parenthesis).
2640 * @param stmt Statement to execute before break in case of a failed assertion.
2641 * @remark rc is referenced multiple times.
2642 */
2643#define AssertReleaseMsgRCBreakStmt(rc, msg, stmt) AssertReleaseMsgBreakStmt(RT_SUCCESS_NP(rc), msg, stmt)
2644
2645/** @def AssertReleaseRCSuccess
2646 * Asserts that an iprt status code equals VINF_SUCCESS.
2647 *
2648 * On failure information about the error will be printed and a breakpoint hit.
2649 *
2650 * @param rc iprt status code.
2651 * @remark rc is referenced multiple times.
2652 */
2653#define AssertReleaseRCSuccess(rc) AssertReleaseMsg((rc) == VINF_SUCCESS, ("%Rra\n", (rc)))
2654
2655/** @def AssertReleaseRCSuccessReturn
2656 * Asserts that an iprt status code equals VINF_SUCCESS.
2657 *
2658 * On failure information about the error will be printed, a breakpoint hit
2659 * and finally returning from the function if the breakpoint is somehow ignored.
2660 *
2661 * @param rc iprt status code.
2662 * @param rcRet What is to be presented to return.
2663 * @remark rc is referenced multiple times.
2664 */
2665#define AssertReleaseRCSuccessReturn(rc, rcRet) AssertReleaseMsgReturn((rc) == VINF_SUCCESS, ("%Rra\n", (rc)), rcRet)
2666
2667/** @def AssertReleaseRCSuccessReturnVoid
2668 * Asserts that an iprt status code equals VINF_SUCCESS.
2669 *
2670 * On failure information about the error will be printed, a breakpoint hit
2671 * and finally returning from the function if the breakpoint is somehow ignored.
2672 *
2673 * @param rc iprt status code.
2674 * @remark rc is referenced multiple times.
2675 */
2676#define AssertReleaseRCSuccessReturnVoid(rc) AssertReleaseMsgReturnVoid((rc) == VINF_SUCCESS, ("%Rra\n", (rc)))
2677
2678/** @def AssertReleaseRCSuccessBreak
2679 * Asserts that an iprt status code equals VINF_SUCCESS.
2680 *
2681 * On failure information about the error will be printed, a breakpoint hit
2682 * and finally breaking the current statement if the breakpoint is somehow ignored.
2683 *
2684 * @param rc iprt status code.
2685 * @remark rc is referenced multiple times.
2686 */
2687#define AssertReleaseRCSuccessBreak(rc) AssertReleaseMsgBreak((rc) == VINF_SUCCESS, ("%Rra\n", (rc)))
2688
2689/** @def AssertReleaseRCSuccessBreakStmt
2690 * Asserts that an iprt status code equals VINF_SUCCESS.
2691 *
2692 * On failure information about the error will be printed, a breakpoint hit
2693 * and finally the break statement will be issued if the breakpoint is somehow ignored.
2694 *
2695 * @param rc iprt status code.
2696 * @param stmt Statement to execute before break in case of a failed assertion.
2697 * @remark rc is referenced multiple times.
2698 */
2699#define AssertReleaseRCSuccessBreakStmt(rc, stmt) AssertReleaseMsgBreakStmt((rc) == VINF_SUCCESS, ("%Rra\n", (rc)), stmt)
2700
2701
2702/** @def AssertFatalRC
2703 * Asserts a iprt status code successful.
2704 *
2705 * On failure information about the error will be printed and a breakpoint hit.
2706 *
2707 * @param rc iprt status code.
2708 * @remark rc is referenced multiple times.
2709 */
2710#define AssertFatalRC(rc) AssertFatalMsgRC(rc, ("%Rra\n", (rc)))
2711
2712/** @def AssertReleaseMsgRC
2713 * Asserts a iprt status code successful.
2714 *
2715 * On failure a custom message is printed and a breakpoint is hit.
2716 *
2717 * @param rc iprt status code.
2718 * @param msg printf argument list (in parenthesis).
2719 * @remark rc is referenced multiple times.
2720 */
2721#define AssertFatalMsgRC(rc, msg) AssertFatalMsg(RT_SUCCESS_NP(rc), msg)
2722
2723/** @def AssertFatalRCSuccess
2724 * Asserts that an iprt status code equals VINF_SUCCESS.
2725 *
2726 * On failure information about the error will be printed and a breakpoint hit.
2727 *
2728 * @param rc iprt status code.
2729 * @remark rc is referenced multiple times.
2730 */
2731#define AssertFatalRCSuccess(rc) AssertFatalMsg((rc) == VINF_SUCCESS, ("%Rra\n", (rc)))
2732
2733
2734/** @def AssertPtr
2735 * Asserts that a pointer is valid.
2736 *
2737 * @param pv The pointer.
2738 */
2739#define AssertPtr(pv) AssertMsg(VALID_PTR(pv), ("%p\n", (pv)))
2740
2741/** @def AssertPtrReturn
2742 * Asserts that a pointer is valid.
2743 *
2744 * @param pv The pointer.
2745 * @param rcRet What is to be presented to return.
2746 */
2747#define AssertPtrReturn(pv, rcRet) AssertMsgReturn(VALID_PTR(pv), ("%p\n", (pv)), rcRet)
2748
2749/** @def AssertPtrReturnVoid
2750 * Asserts that a pointer is valid.
2751 *
2752 * @param pv The pointer.
2753 */
2754#define AssertPtrReturnVoid(pv) AssertMsgReturnVoid(VALID_PTR(pv), ("%p\n", (pv)))
2755
2756/** @def AssertPtrBreak
2757 * Asserts that a pointer is valid.
2758 *
2759 * @param pv The pointer.
2760 */
2761#define AssertPtrBreak(pv) AssertMsgBreak(VALID_PTR(pv), ("%p\n", (pv)))
2762
2763/** @def AssertPtrBreakStmt
2764 * Asserts that a pointer is valid.
2765 *
2766 * @param pv The pointer.
2767 * @param stmt Statement to execute before break in case of a failed assertion.
2768 */
2769#define AssertPtrBreakStmt(pv, stmt) AssertMsgBreakStmt(VALID_PTR(pv), ("%p\n", (pv)), stmt)
2770
2771/** @def AssertPtrNull
2772 * Asserts that a pointer is valid or NULL.
2773 *
2774 * @param pv The pointer.
2775 */
2776#define AssertPtrNull(pv) AssertMsg(VALID_PTR(pv) || (pv) == NULL, ("%p\n", (pv)))
2777
2778/** @def AssertPtrNullReturn
2779 * Asserts that a pointer is valid or NULL.
2780 *
2781 * @param pv The pointer.
2782 * @param rcRet What is to be presented to return.
2783 */
2784#define AssertPtrNullReturn(pv, rcRet) AssertMsgReturn(VALID_PTR(pv) || (pv) == NULL, ("%p\n", (pv)), rcRet)
2785
2786/** @def AssertPtrNullReturnVoid
2787 * Asserts that a pointer is valid or NULL.
2788 *
2789 * @param pv The pointer.
2790 */
2791#define AssertPtrNullReturnVoid(pv) AssertMsgReturnVoid(VALID_PTR(pv) || (pv) == NULL, ("%p\n", (pv)))
2792
2793/** @def AssertPtrNullBreak
2794 * Asserts that a pointer is valid or NULL.
2795 *
2796 * @param pv The pointer.
2797 */
2798#define AssertPtrNullBreak(pv) AssertMsgBreak(VALID_PTR(pv) || (pv) == NULL, ("%p\n", (pv)))
2799
2800/** @def AssertPtrNullBreakStmt
2801 * Asserts that a pointer is valid or NULL.
2802 *
2803 * @param pv The pointer.
2804 * @param stmt Statement to execute before break in case of a failed assertion.
2805 */
2806#define AssertPtrNullBreakStmt(pv, stmt) AssertMsgBreakStmt(VALID_PTR(pv) || (pv) == NULL, ("%p\n", (pv)), stmt)
2807
2808/** @def AssertGCPhys32
2809 * Asserts that the high dword of a physical address is zero
2810 *
2811 * @param GCPhys The address (RTGCPHYS).
2812 */
2813#define AssertGCPhys32(GCPhys) AssertMsg(VALID_PHYS32(GCPhys), ("%RGp\n", (RTGCPHYS)(GCPhys)))
2814
2815/** @def AssertGCPtr32
2816 * Asserts that the high dword of a physical address is zero
2817 *
2818 * @param GCPtr The address (RTGCPTR).
2819 */
2820#if GC_ARCH_BITS == 32
2821# define AssertGCPtr32(GCPtr) do { } while (0)
2822#else
2823# define AssertGCPtr32(GCPtr) AssertMsg(!((GCPtr) & UINT64_C(0xffffffff00000000)), ("%RGv\n", GCPtr))
2824#endif
2825
2826/** @def AssertForEach
2827 * Equivalent to Assert for each value of the variable from the starting
2828 * value to the finishing one.
2829 *
2830 * @param var Name of the counter variable.
2831 * @param vartype Type of the counter variable.
2832 * @param first Lowest inclusive value of the counter variable.
2833 * This must be free from side effects.
2834 * @param end Highest exclusive value of the counter variable.
2835 * This must be free from side effects.
2836 * @param expr Expression which should be true for each value of @a var.
2837 */
2838#define AssertForEach(var, vartype, first, end, expr) \
2839 do { \
2840 vartype var; \
2841 Assert((first) == (first) && (end) == (end)); /* partial check for side effects */ \
2842 for (var = (first); var < (end); var++) \
2843 AssertMsg(expr, ("%s = %#RX64 (%RI64)", #var, (uint64_t)var, (int64_t)var)); \
2844 } while (0)
2845
2846#ifdef RT_OS_WINDOWS
2847
2848/** @def AssertNtStatus
2849 * Asserts that the NT_SUCCESS() returns true for the given NTSTATUS value.
2850 *
2851 * @param a_rcNt The NTSTATUS to check. Will be evaluated twice and
2852 * subjected to NOREF().
2853 * @sa AssertRC()
2854 */
2855# define AssertNtStatus(a_rcNt) \
2856 do { AssertMsg(NT_SUCCESS(a_rcNt), ("%#x\n", (a_rcNt))); NOREF(a_rcNt); } while (0)
2857
2858/** @def AssertNtStatusSuccess
2859 * Asserts that the given NTSTATUS value equals STATUS_SUCCESS.
2860 *
2861 * @param a_rcNt The NTSTATUS to check. Will be evaluated twice and
2862 * subjected to NOREF().
2863 * @sa AssertRCSuccess()
2864 */
2865# define AssertNtStatusSuccess(a_rcNt) \
2866 do { AssertMsg((a_rcNt) == STATUS_SUCCESS, ("%#x\n", (a_rcNt))); NOREF(a_rcNt); } while (0)
2867
2868#endif /* RT_OS_WINDOWS */
2869
2870/** @} */
2871
2872/** @} */
2873
2874#endif
2875
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette