VirtualBox

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

Last change on this file since 6000 was 5999, checked in by vboxsync, 17 years ago

The Giant CDDL Dual-License Header Change.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 37.4 KB
Line 
1/** @file
2 * innotek Portable Runtime - Assertions.
3 */
4
5/*
6 * Copyright (C) 2006-2007 innotek GmbH
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
32/** @defgroup grp_rt_assert Assert - Assertions
33 * @ingroup grp_rt
34 * @{
35 */
36
37
38/** @def AssertBreakpoint()
39 * Assertion Breakpoint.
40 *
41 * @remark In the gnu world we add a nop instruction after the int3 to
42 * force gdb to remain at the int3 source line.
43 * @remark The L4 kernel will try make sense of the breakpoint, thus the jmp.
44 */
45#ifdef RT_STRICT
46# ifdef __GNUC__
47# ifndef __L4ENV__
48# define AssertBreakpoint() do { if (RTAssertDoBreakpoint()) { __asm__ __volatile__ ("int3\n\tnop"); } } while (0)
49# else
50# define AssertBreakpoint() do { if (RTAssertDoBreakpoint()) { __asm__ __volatile__ ("int3; jmp 1f; 1:"); } } while (0)
51# endif
52# elif defined(_MSC_VER)
53# define AssertBreakpoint() do { if (RTAssertDoBreakpoint()) { __debugbreak(); } } while (0)
54# else
55# error "Unknown compiler"
56# endif
57#else
58# define AssertBreakpoint() do { } while (0)
59#endif
60
61/**
62 * RTASSERTTYPE is the type the AssertCompile() macro redefines.
63 * It has no other function and shouldn't be used.
64 * Visual C++ uses this.
65 */
66typedef int RTASSERTTYPE[1];
67
68/**
69 * RTASSERTVAR is the type the AssertCompile() macro redefines.
70 * It has no other function and shouldn't be used.
71 * GCC uses this.
72 */
73#ifdef __GNUC__
74__BEGIN_DECLS
75#endif
76extern int RTASSERTVAR[1];
77#ifdef __GNUC__
78__END_DECLS
79#endif
80
81/** @def AssertCompile
82 * Asserts that a compile-time expression is true. If it's not break the build.
83 * @param expr Expression which should be true.
84 */
85#ifdef __GNUC__
86# define AssertCompile(expr) extern int RTASSERTVAR[1] __attribute__((unused)), RTASSERTVAR[(expr) ? 1 : 0] __attribute__((unused))
87#else
88# define AssertCompile(expr) typedef int RTASSERTTYPE[(expr) ? 1 : 0]
89#endif
90
91/** @def AssertCompileSize
92 * Asserts a size at compile.
93 * @param type The type.
94 * @param size The expected type size.
95 */
96#define AssertCompileSize(type, size) \
97 AssertCompile(sizeof(type) == (size))
98
99/** @def AssertCompileSizeAlignment
100 * Asserts a size alignment at compile.
101 * @param type The type.
102 * @param align The size alignment to assert.
103 */
104#define AssertCompileSizeAlignment(type, align) \
105 AssertCompile(!(sizeof(type) & ((align) - 1)))
106
107/** @def AssertCompileMemberAlignment
108 * Asserts a member offset alignment at compile.
109 * @param type The type.
110 * @param member The member.
111 * @param align The member offset alignment to assert.
112 */
113#if defined(__GNUC__) && defined(__cplusplus)
114# if __GNUC__ >= 4
115# define AssertCompileMemberAlignment(type, member, align) \
116 AssertCompile(!(__builtin_offsetof(type, member) & ((align) - 1)))
117# else
118# define AssertCompileMemberAlignment(type, member, align) \
119 AssertCompile(!(RT_OFFSETOF(type, member) & ((align) - 1)))
120# endif
121#else
122# define AssertCompileMemberAlignment(type, member, align) \
123 AssertCompile(!(RT_OFFSETOF(type, member) & ((align) - 1)))
124#endif
125
126
127/** @def AssertCompileMemberSize
128 * Asserts a member offset alignment at compile.
129 * @param type The type.
130 * @param member The member.
131 * @param size The member size to assert.
132 */
133#define AssertCompileMemberSize(type, member, size) \
134 AssertCompile(RT_SIZEOFMEMB(type, member) == (size))
135
136/** @def AssertCompileMemberSizeAlignment
137 * Asserts a member size alignment at compile.
138 * @param type The type.
139 * @param member The member.
140 * @param align The member size alignment to assert.
141 */
142#define AssertCompileMemberSizeAlignment(type, member, align) \
143 AssertCompile(!(RT_SIZEOFMEMB(type, member) & ((align) - 1)))
144
145
146/** @def Assert
147 * Assert that an expression is true. If it's not hit breakpoint.
148 * @param expr Expression which should be true.
149 */
150#ifdef RT_STRICT
151# define Assert(expr) \
152 do { \
153 if (RT_UNLIKELY(!(expr))) \
154 { \
155 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
156 AssertBreakpoint(); \
157 } \
158 } while (0)
159#else
160# define Assert(expr) do { } while (0)
161#endif
162
163
164/** @def AssertReturn
165 * Assert that an expression is true and returns if it isn't.
166 * In RT_STRICT mode it will hit a breakpoint before returning.
167 *
168 * @param expr Expression which should be true.
169 * @param rc What is to be presented to return.
170 */
171#ifdef RT_STRICT
172# define AssertReturn(expr, rc) \
173 do { \
174 if (RT_UNLIKELY(!(expr))) \
175 { \
176 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
177 AssertBreakpoint(); \
178 return (rc); \
179 } \
180 } while (0)
181#else
182# define AssertReturn(expr, rc) \
183 do { \
184 if (RT_UNLIKELY(!(expr))) \
185 return (rc); \
186 } while (0)
187#endif
188
189/** @def AssertReturnVoid
190 * Assert that an expression is true and returns if it isn't.
191 * In RT_STRICT mode it will hit a breakpoint before returning.
192 *
193 * @param expr Expression which should be true.
194 */
195#ifdef RT_STRICT
196# define AssertReturnVoid(expr) \
197 do { \
198 if (RT_UNLIKELY(!(expr))) \
199 { \
200 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
201 AssertBreakpoint(); \
202 return; \
203 } \
204 } while (0)
205#else
206# define AssertReturnVoid(expr) \
207 do { \
208 if (RT_UNLIKELY(!(expr))) \
209 return; \
210 } while (0)
211#endif
212
213
214/** @def AssertBreak
215 * Assert that an expression is true and breaks if it isn't.
216 * In RT_STRICT mode it will hit a breakpoint before doing break.
217 *
218 * @param expr Expression which should be true.
219 * @param stmt Statement to execute before break in case of a failed assertion.
220 */
221#ifdef RT_STRICT
222# define AssertBreak(expr, stmt) \
223 if (RT_UNLIKELY(!(expr))) { \
224 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
225 AssertBreakpoint(); \
226 stmt; \
227 break; \
228 } else do {} while (0)
229#else
230# define AssertBreak(expr, stmt) \
231 if (RT_UNLIKELY(!(expr))) { \
232 stmt; \
233 break; \
234 } else do {} while (0)
235#endif
236
237
238/** @def AssertMsg
239 * Assert that an expression is true. If it's not print message and hit breakpoint.
240 * @param expr Expression which should be true.
241 * @param a printf argument list (in parenthesis).
242 */
243#ifdef RT_STRICT
244# define AssertMsg(expr, a) \
245 do { \
246 if (RT_UNLIKELY(!(expr))) \
247 { \
248 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
249 AssertMsg2 a; \
250 AssertBreakpoint(); \
251 } \
252 } while (0)
253#else
254# define AssertMsg(expr, a) do { } while (0)
255#endif
256
257/** @def AssertMsgReturn
258 * Assert that an expression is true and returns if it isn't.
259 * In RT_STRICT mode it will hit a breakpoint before returning.
260 *
261 * @param expr Expression which should be true.
262 * @param a printf argument list (in parenthesis).
263 * @param rc What is to be presented to return.
264 */
265#ifdef RT_STRICT
266# define AssertMsgReturn(expr, a, rc) \
267 do { \
268 if (RT_UNLIKELY(!(expr))) \
269 { \
270 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
271 AssertMsg2 a; \
272 AssertBreakpoint(); \
273 return (rc); \
274 } \
275 } while (0)
276#else
277# define AssertMsgReturn(expr, a, rc) \
278 do { \
279 if (RT_UNLIKELY(!(expr))) \
280 return (rc); \
281 } while (0)
282#endif
283
284/** @def AssertMsgReturnVoid
285 * Assert that an expression is true and returns if it isn't.
286 * In RT_STRICT mode it will hit a breakpoint before returning.
287 *
288 * @param expr Expression which should be true.
289 * @param a printf argument list (in parenthesis).
290 */
291#ifdef RT_STRICT
292# define AssertMsgReturnVoid(expr, a) \
293 do { \
294 if (RT_UNLIKELY(!(expr))) \
295 { \
296 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
297 AssertMsg2 a; \
298 AssertBreakpoint(); \
299 return; \
300 } \
301 } while (0)
302#else
303# define AssertMsgReturnVoid(expr, a) \
304 do { \
305 if (RT_UNLIKELY(!(expr))) \
306 return; \
307 } while (0)
308#endif
309
310
311/** @def AssertMsgBreak
312 * Assert that an expression is true and breaks if it isn't.
313 * In RT_STRICT mode it will hit a breakpoint before doing break.
314 *
315 * @param expr Expression which should be true.
316 * @param a printf argument list (in parenthesis).
317 * @param stmt Statement to execute before break in case of a failed assertion.
318 */
319#ifdef RT_STRICT
320# define AssertMsgBreak(expr, a, stmt) \
321 if (RT_UNLIKELY(!(expr))) { \
322 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
323 AssertMsg2 a; \
324 AssertBreakpoint(); \
325 stmt; \
326 break; \
327 } else do {} while (0)
328#else
329# define AssertMsgBreak(expr, a, stmt) \
330 if (RT_UNLIKELY(!(expr))) { \
331 stmt; \
332 break; \
333 } else do {} while (0)
334#endif
335
336
337/** @def AssertFailed
338 * An assertion failed hit breakpoint.
339 */
340#ifdef RT_STRICT
341# define AssertFailed() \
342 do { \
343 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
344 AssertBreakpoint(); \
345 } while (0)
346#else
347# define AssertFailed() do { } while (0)
348#endif
349
350/** @def AssertFailedReturn
351 * An assertion failed, hit breakpoint (RT_STRICT mode only) and return.
352 *
353 * @param rc The rc to return.
354 */
355#ifdef RT_STRICT
356# define AssertFailedReturn(rc) \
357 do { \
358 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
359 AssertBreakpoint(); \
360 return (rc); \
361 } while (0)
362#else
363# define AssertFailedReturn(rc) \
364 do { \
365 return (rc); \
366 } while (0)
367#endif
368
369/** @def AssertFailedReturnVoid
370 * An assertion failed, hit breakpoint (RT_STRICT mode only) and return.
371 */
372#ifdef RT_STRICT
373# define AssertFailedReturnVoid() \
374 do { \
375 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
376 AssertBreakpoint(); \
377 return; \
378 } while (0)
379#else
380# define AssertFailedReturnVoid() \
381 do { \
382 return; \
383 } while (0)
384#endif
385
386
387/** @def AssertFailedBreak
388 * An assertion failed, hit breakpoint (RT_STRICT mode only), execute
389 * the given statement and break.
390 *
391 * @param stmt Statement to execute before break.
392 */
393#ifdef RT_STRICT
394# define AssertFailedBreak(stmt) \
395 if (1) { \
396 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
397 AssertBreakpoint(); \
398 stmt; \
399 break; \
400 } else do {} while (0)
401#else
402# define AssertFailedBreak(stmt) \
403 if (1) { \
404 stmt; \
405 break; \
406 } else do {} while (0)
407#endif
408
409
410/** @def AssertMsgFailed
411 * An assertion failed print a message and a hit breakpoint.
412 *
413 * @param a printf argument list (in parenthesis).
414 */
415#ifdef RT_STRICT
416# define AssertMsgFailed(a) \
417 do { \
418 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
419 AssertMsg2 a; \
420 AssertBreakpoint(); \
421 } while (0)
422#else
423# define AssertMsgFailed(a) do { } while (0)
424#endif
425
426/** @def AssertMsgFailedReturn
427 * An assertion failed, hit breakpoint with message (RT_STRICT mode only) and return.
428 *
429 * @param a printf argument list (in parenthesis).
430 * @param rc What is to be presented to return.
431 */
432#ifdef RT_STRICT
433# define AssertMsgFailedReturn(a, rc) \
434 do { \
435 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
436 AssertMsg2 a; \
437 AssertBreakpoint(); \
438 return (rc); \
439 } while (0)
440#else
441# define AssertMsgFailedReturn(a, rc) \
442 do { \
443 return (rc); \
444 } while (0)
445#endif
446
447/** @def AssertMsgFailedReturnVoid
448 * An assertion failed, hit breakpoint with message (RT_STRICT mode only) and return.
449 *
450 * @param a printf argument list (in parenthesis).
451 */
452#ifdef RT_STRICT
453# define AssertMsgFailedReturnVoid(a) \
454 do { \
455 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
456 AssertMsg2 a; \
457 AssertBreakpoint(); \
458 return; \
459 } while (0)
460#else
461# define AssertMsgFailedReturnVoid(a) \
462 do { \
463 return; \
464 } while (0)
465#endif
466
467
468/** @def AssertMsgFailedBreak
469 * An assertion failed, hit breakpoint (RT_STRICT mode only), execute
470 * the given statement and break.
471 *
472 * @param a printf argument list (in parenthesis).
473 * @param stmt Statement to execute before break.
474 */
475#ifdef RT_STRICT
476# define AssertMsgFailedBreak(a, stmt) \
477 if (1) { \
478 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
479 AssertMsg2 a; \
480 AssertBreakpoint(); \
481 stmt; \
482 break; \
483 } else do {} while (0)
484#else
485# define AssertMsgFailedBreak(a, stmt) \
486 if (1) { \
487 stmt; \
488 break; \
489 } else do {} while (0)
490#endif
491
492
493/** @def AssertReleaseBreakpoint()
494 * Assertion Breakpoint.
495 *
496 * @remark In the gnu world we add a nop instruction after the int3 to
497 * force gdb to remain at the int3 source line.
498 * @remark The L4 kernel will try make sense of the breakpoint, thus the jmp.
499 */
500#ifdef __GNUC__
501# ifndef __L4ENV__
502# define AssertReleaseBreakpoint() do { RTAssertDoBreakpoint(); __asm__ __volatile__ ("int3\n\tnop"); } while (0)
503# else
504# define AssertReleaseBreakpoint() do { RTAssertDoBreakpoint(); __asm__ __volatile__ ("int3; jmp 1f; 1:"); } while (0)
505# endif
506#elif defined(_MSC_VER)
507# define AssertReleaseBreakpoint() do { RTAssertDoBreakpoint(); __debugbreak(); } while (0)
508#else
509# error "Unknown compiler"
510#endif
511
512
513/** @def AssertRelease
514 * Assert that an expression is true. If it's not hit a breakpoint.
515 *
516 * @param expr Expression which should be true.
517 */
518#define AssertRelease(expr) \
519 do { \
520 if (RT_UNLIKELY(!(expr))) \
521 { \
522 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
523 AssertReleaseBreakpoint(); \
524 } \
525 } while (0)
526
527/** @def AssertReleaseReturn
528 * Assert that an expression is true, hit a breakpoing and return if it isn't.
529 *
530 * @param expr Expression which should be true.
531 * @param rc What is to be presented to return.
532 */
533#define AssertReleaseReturn(expr, rc) \
534 do { \
535 if (RT_UNLIKELY(!(expr))) \
536 { \
537 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
538 AssertReleaseBreakpoint(); \
539 return (rc); \
540 } \
541 } while (0)
542
543/** @def AssertReleaseReturnVoid
544 * Assert that an expression is true, hit a breakpoing and return if it isn't.
545 *
546 * @param expr Expression which should be true.
547 */
548#define AssertReleaseReturnVoid(expr) \
549 do { \
550 if (RT_UNLIKELY(!(expr))) \
551 { \
552 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
553 AssertReleaseBreakpoint(); \
554 return; \
555 } \
556 } while (0)
557
558
559/** @def AssertReleaseBreak
560 * Assert that an expression is true, hit a breakpoing and break if it isn't.
561 *
562 * @param expr Expression which should be true.
563 * @param stmt Statement to execute before break in case of a failed assertion.
564 */
565#define AssertReleaseBreak(expr, stmt) \
566 if (RT_UNLIKELY(!(expr))) { \
567 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
568 AssertReleaseBreakpoint(); \
569 stmt; \
570 break; \
571 } else do {} while (0)
572
573
574
575/** @def AssertReleaseMsg
576 * Assert that an expression is true, print the message and hit a breakpoint if it isn't.
577 *
578 * @param expr Expression which should be true.
579 * @param a printf argument list (in parenthesis).
580 */
581#define AssertReleaseMsg(expr, a) \
582 do { \
583 if (RT_UNLIKELY(!(expr))) \
584 { \
585 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
586 AssertMsg2 a; \
587 AssertReleaseBreakpoint(); \
588 } \
589 } while (0)
590
591/** @def AssertReleaseMsgReturn
592 * Assert that an expression is true, print the message and hit a breakpoint and return if it isn't.
593 *
594 * @param expr Expression which should be true.
595 * @param a printf argument list (in parenthesis).
596 * @param rc What is to be presented to return.
597 */
598#define AssertReleaseMsgReturn(expr, a, rc) \
599 do { \
600 if (RT_UNLIKELY(!(expr))) \
601 { \
602 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
603 AssertMsg2 a; \
604 AssertReleaseBreakpoint(); \
605 return (rc); \
606 } \
607 } while (0)
608
609/** @def AssertReleaseMsgReturn
610 * Assert that an expression is true, print the message and hit a breakpoint and return if it isn't.
611 *
612 * @param expr Expression which should be true.
613 * @param a printf argument list (in parenthesis).
614 */
615#define AssertReleaseMsgReturnVoid(expr, a) \
616 do { \
617 if (RT_UNLIKELY(!(expr))) \
618 { \
619 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
620 AssertMsg2 a; \
621 AssertReleaseBreakpoint(); \
622 return; \
623 } \
624 } while (0)
625
626
627/** @def AssertReleaseMsgBreak
628 * Assert that an expression is true, print the message and hit a breakpoing and break if it isn't.
629 *
630 * @param expr Expression which should be true.
631 * @param a printf argument list (in parenthesis).
632 * @param stmt Statement to execute before break in case of a failed assertion.
633 */
634#define AssertReleaseMsgBreak(expr, a, stmt) \
635 if (RT_UNLIKELY(!(expr))) { \
636 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
637 AssertMsg2 a; \
638 AssertReleaseBreakpoint(); \
639 stmt; \
640 break; \
641 } else do {} while (0)
642
643
644/** @def AssertReleaseFailed
645 * An assertion failed, hit a breakpoint.
646 */
647#define AssertReleaseFailed() \
648 do { \
649 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
650 AssertReleaseBreakpoint(); \
651 } while (0)
652
653/** @def AssertReleaseFailedReturn
654 * An assertion failed, hit a breakpoint and return.
655 *
656 * @param rc What is to be presented to return.
657 */
658#define AssertReleaseFailedReturn(rc) \
659 do { \
660 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
661 AssertReleaseBreakpoint(); \
662 return (rc); \
663 } while (0)
664
665/** @def AssertReleaseFailedReturn
666 * An assertion failed, hit a breakpoint and return.
667 */
668#define AssertReleaseFailedReturnVoid() \
669 do { \
670 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
671 AssertReleaseBreakpoint(); \
672 return; \
673 } while (0)
674
675
676/** @def AssertReleaseFailedBreak
677 * An assertion failed, hit a breakpoint and break.
678 *
679 * @param stmt Statement to execute before break.
680 */
681#define AssertReleaseFailedBreak(stmt) \
682 if (1) { \
683 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
684 AssertReleaseBreakpoint(); \
685 stmt; \
686 break; \
687 } else do {} while (0)
688
689
690/** @def AssertReleaseMsgFailed
691 * An assertion failed, print a message and hit a breakpoint.
692 *
693 * @param a printf argument list (in parenthesis).
694 */
695#define AssertReleaseMsgFailed(a) \
696 do { \
697 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
698 AssertMsg2 a; \
699 AssertReleaseBreakpoint(); \
700 } while (0)
701
702/** @def AssertReleaseMsgFailedReturn
703 * An assertion failed, print a message, hit a breakpoint and return.
704 *
705 * @param a printf argument list (in parenthesis).
706 * @param rc What is to be presented to return.
707 */
708#define AssertReleaseMsgFailedReturn(a, rc) \
709 do { \
710 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
711 AssertMsg2 a; \
712 AssertReleaseBreakpoint(); \
713 return (rc); \
714 } while (0)
715
716/** @def AssertReleaseMsgFailedReturnVoid
717 * An assertion failed, print a message, hit a breakpoint and return.
718 *
719 * @param a printf argument list (in parenthesis).
720 */
721#define AssertReleaseMsgFailedReturnVoid(a) \
722 do { \
723 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
724 AssertMsg2 a; \
725 AssertReleaseBreakpoint(); \
726 return; \
727 } while (0)
728
729
730/** @def AssertReleaseMsgFailedBreak
731 * An assertion failed, print a message, hit a breakpoint and break.
732 *
733 * @param a printf argument list (in parenthesis).
734 * @param stmt Statement to execute before break.
735 */
736#define AssertReleaseMsgFailedBreak(a, stmt) \
737 if (1) { \
738 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
739 AssertMsg2 a; \
740 AssertReleaseBreakpoint(); \
741 stmt; \
742 break; \
743 } else do {} while (0)
744
745
746
747/** @def AssertFatal
748 * Assert that an expression is true. If it's not hit a breakpoint (for ever).
749 *
750 * @param expr Expression which should be true.
751 */
752#define AssertFatal(expr) \
753 do { \
754 if (RT_UNLIKELY(!(expr))) \
755 for (;;) \
756 { \
757 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
758 AssertReleaseBreakpoint(); \
759 } \
760 } while (0)
761
762/** @def AssertFatalMsg
763 * Assert that an expression is true, print the message and hit a breakpoint (for ever) if it isn't.
764 *
765 * @param expr Expression which should be true.
766 * @param a printf argument list (in parenthesis).
767 */
768#define AssertFatalMsg(expr, a) \
769 do { \
770 if (RT_UNLIKELY(!(expr))) \
771 for (;;) \
772 { \
773 AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
774 AssertMsg2 a; \
775 AssertReleaseBreakpoint(); \
776 } \
777 } while (0)
778
779/** @def AssertFatalFailed
780 * An assertion failed, hit a breakpoint (for ever).
781 */
782#define AssertFatalFailed() \
783 do { \
784 for (;;) \
785 { \
786 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
787 AssertReleaseBreakpoint(); \
788 } \
789 } while (0)
790
791/** @def AssertFatalMsgFailed
792 * An assertion failed, print a message and hit a breakpoint (for ever).
793 *
794 * @param a printf argument list (in parenthesis).
795 */
796#define AssertFatalMsgFailed(a) \
797 do { \
798 for (;;) \
799 { \
800 AssertMsg1((const char *)0, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
801 AssertMsg2 a; \
802 AssertReleaseBreakpoint(); \
803 } \
804 } while (0)
805
806
807/** @def AssertRC
808 * Asserts a iprt status code successful.
809 *
810 * On failure it will print info about the rc and hit a breakpoint.
811 *
812 * @param rc iprt status code.
813 * @remark rc is references multiple times. In release mode is NOREF()'ed.
814 */
815#define AssertRC(rc) AssertMsgRC(rc, ("%Vra\n", (rc)))
816
817/** @def AssertRCReturn
818 * Asserts a iprt status code successful, bitch (RT_STRICT mode only) and return if it isn't.
819 *
820 * @param rc iprt status code.
821 * @param rcRet What is to be presented to return.
822 * @remark rc is references multiple times. In release mode is NOREF()'ed.
823 */
824#define AssertRCReturn(rc, rcRet) AssertMsgRCReturn(rc, ("%Vra\n", (rc)), rcRet)
825
826/** @def AssertRCReturnVoid
827 * Asserts a iprt status code successful, bitch (RT_STRICT mode only) and return if it isn't.
828 *
829 * @param rc iprt status code.
830 * @remark rc is references multiple times. In release mode is NOREF()'ed.
831 */
832#define AssertRCReturnVoid(rc) AssertMsgRCReturnVoid(rc, ("%Vra\n", (rc)))
833
834/** @def AssertRCBreak
835 * Asserts a iprt status code successful, bitch (RT_STRICT mode only) and break if it isn't.
836 *
837 * @param rc iprt status code.
838 * @param stmt Statement to execute before break in case of a failed assertion.
839 * @remark rc is references multiple times. In release mode is NOREF()'ed.
840 */
841#define AssertRCBreak(rc, stmt) AssertMsgRCBreak(rc, ("%Vra\n", (rc)), stmt)
842
843/** @def AssertMsgRC
844 * Asserts a iprt status code successful.
845 *
846 * It prints a custom message and hits a breakpoint on FAILURE.
847 *
848 * @param rc iprt status code.
849 * @param msg printf argument list (in parenthesis).
850 * @remark rc is references multiple times. In release mode is NOREF()'ed.
851 */
852#define AssertMsgRC(rc, msg) \
853 do { AssertMsg(RT_SUCCESS_NP(rc), msg); NOREF(rc); } while (0)
854
855/** @def AssertMsgRCReturn
856 * Asserts a iprt status code successful and if it's not return the specified status code.
857 *
858 * If RT_STRICT is defined the message will be printed and a breakpoint hit before it returns
859 *
860 * @param rc iprt status code.
861 * @param msg printf argument list (in parenthesis).
862 * @param rcRet What is to be presented to return.
863 * @remark rc is references multiple times. In release mode is NOREF()'ed.
864 */
865#define AssertMsgRCReturn(rc, msg, rcRet) \
866 do { AssertMsgReturn(RT_SUCCESS_NP(rc), msg, rcRet); NOREF(rc); } while (0)
867
868/** @def AssertMsgRCReturnVoid
869 * Asserts a iprt status code successful and if it's not return.
870 *
871 * If RT_STRICT is defined the message will be printed and a breakpoint hit before it returns
872 *
873 * @param rc iprt status code.
874 * @param msg printf argument list (in parenthesis).
875 * @remark rc is references multiple times. In release mode is NOREF()'ed.
876 */
877#define AssertMsgRCReturnVoid(rc, msg) \
878 do { AssertMsgReturnVoid(RT_SUCCESS_NP(rc), msg); NOREF(rc); } while (0)
879
880/** @def AssertMsgRCBreak
881 * Asserts a iprt status code successful and break if it's not.
882 *
883 * If RT_STRICT is defined the message will be printed and a breakpoint hit before it returns
884 *
885 * @param rc iprt status code.
886 * @param msg printf argument list (in parenthesis).
887 * @param stmt Statement to execute before break in case of a failed assertion.
888 * @remark rc is references multiple times. In release mode is NOREF()'ed.
889 */
890#define AssertMsgRCBreak(rc, msg, stmt) \
891 do { AssertMsgBreak(RT_SUCCESS_NP(rc), msg, stmt); NOREF(rc); } while (0)
892
893/** @def AssertRCSuccess
894 * Asserts an iprt status code equals VINF_SUCCESS.
895 *
896 * On failure it will print info about the rc and hit a breakpoint.
897 *
898 * @param rc iprt status code.
899 * @remark rc is references multiple times. In release mode is NOREF()'ed.
900 */
901#define AssertRCSuccess(rc) AssertMsg((rc) == VINF_SUCCESS, ("%Vra\n", (rc)))
902
903/** @def AssertRCSuccessReturn
904 * Asserts that an iprt status code equals VINF_SUCCESS, bitch (RT_STRICT mode only) and return if it isn't.
905 *
906 * @param rc iprt status code.
907 * @param rcRet What is to be presented to return.
908 * @remark rc is references multiple times. In release mode is NOREF()'ed.
909 */
910#define AssertRCSuccessReturn(rc, rcRet) AssertMsgReturn((rc) == VINF_SUCCESS, ("%Vra\n", (rc)), rcRet)
911
912/** @def AssertRCSuccessReturnVoid
913 * Asserts that an iprt status code equals VINF_SUCCESS, bitch (RT_STRICT mode only) and return if it isn't.
914 *
915 * @param rc iprt status code.
916 * @remark rc is references multiple times. In release mode is NOREF()'ed.
917 */
918#define AssertRCSuccessReturnVoid(rc) AssertMsgReturnVoid((rc) == VINF_SUCCESS, ("%Vra\n", (rc)))
919
920/** @def AssertRCSuccessBreak
921 * Asserts that an iprt status code equals VINF_SUCCESS, bitch (RT_STRICT mode only) and break if it isn't.
922 *
923 * @param rc iprt status code.
924 * @param stmt Statement to execute before break in case of a failed assertion.
925 * @remark rc is references multiple times. In release mode is NOREF()'ed.
926 */
927#define AssertRCSuccessBreak(rc, stmt) AssertMsgBreak((rc) == VINF_SUCCESS, ("%Vra\n", (rc)), stmt)
928
929
930/** @def AssertReleaseRC
931 * Asserts a iprt status code successful.
932 *
933 * On failure information about the error will be printed and a breakpoint hit.
934 *
935 * @param rc iprt status code.
936 * @remark rc is references multiple times.
937 */
938#define AssertReleaseRC(rc) AssertReleaseMsgRC(rc, ("%Vra\n", (rc)))
939
940/** @def AssertReleaseRCReturn
941 * Asserts a iprt status code successful, returning if it isn't.
942 *
943 * On failure information about the error will be printed, a breakpoint hit
944 * and finally returning from the function if the breakpoint is somehow ignored.
945 *
946 * @param rc iprt status code.
947 * @param rcRet What is to be presented to return.
948 * @remark rc is references multiple times.
949 */
950#define AssertReleaseRCReturn(rc, rcRet) AssertReleaseMsgRCReturn(rc, ("%Vra\n", (rc)), rcRet)
951
952/** @def AssertReleaseRCReturnVoid
953 * Asserts a iprt status code successful, returning if it isn't.
954 *
955 * On failure information about the error will be printed, a breakpoint hit
956 * and finally returning from the function if the breakpoint is somehow ignored.
957 *
958 * @param rc iprt status code.
959 * @remark rc is references multiple times.
960 */
961#define AssertReleaseRCReturnVoid(rc) AssertReleaseMsgRCReturnVoid(rc, ("%Vra\n", (rc)))
962
963/** @def AssertReleaseRCBreak
964 * Asserts a iprt status code successful, break if it isn't.
965 *
966 * On failure information about the error will be printed, a breakpoint hit
967 * and finally the break statement will be issued if the breakpoint is somehow ignored.
968 *
969 * @param rc iprt status code.
970 * @param stmt Statement to execute before break in case of a failed assertion.
971 * @remark rc is references multiple times.
972 */
973#define AssertReleaseRCBreak(rc, stmt) AssertReleaseMsgRCBreak(rc, ("%Vra\n", (rc)), stmt)
974
975/** @def AssertReleaseMsgRC
976 * Asserts a iprt status code successful.
977 *
978 * On failure a custom message is printed and a breakpoint is hit.
979 *
980 * @param rc iprt status code.
981 * @param msg printf argument list (in parenthesis).
982 * @remark rc is references multiple times.
983 */
984#define AssertReleaseMsgRC(rc, msg) AssertReleaseMsg(RT_SUCCESS_NP(rc), msg)
985
986/** @def AssertReleaseMsgRCReturn
987 * Asserts a iprt status code successful.
988 *
989 * On failure a custom message is printed, a breakpoint is hit, and finally
990 * returning from the function if the breakpoint is showhow ignored.
991 *
992 * @param rc iprt status code.
993 * @param msg printf argument list (in parenthesis).
994 * @param rcRet What is to be presented to return.
995 * @remark rc is references multiple times.
996 */
997#define AssertReleaseMsgRCReturn(rc, msg, rcRet) AssertReleaseMsgReturn(RT_SUCCESS_NP(rc), msg, rcRet)
998
999/** @def AssertReleaseMsgRCReturnVoid
1000 * Asserts a iprt status code successful.
1001 *
1002 * On failure a custom message is printed, a breakpoint is hit, and finally
1003 * returning from the function if the breakpoint is showhow ignored.
1004 *
1005 * @param rc iprt status code.
1006 * @param msg printf argument list (in parenthesis).
1007 * @remark rc is references multiple times.
1008 */
1009#define AssertReleaseMsgRCReturnVoid(rc, msg) AssertReleaseMsgReturnVoid(RT_SUCCESS_NP(rc), msg)
1010
1011/** @def AssertReleaseMsgRCBreak
1012 * Asserts a iprt status code successful.
1013 *
1014 * On failure a custom message is printed, a breakpoint is hit, and finally
1015 * the brean statement is issued if the breakpoint is showhow ignored.
1016 *
1017 * @param rc iprt status code.
1018 * @param msg printf argument list (in parenthesis).
1019 * @param stmt Statement to execute before break in case of a failed assertion.
1020 * @remark rc is references multiple times.
1021 */
1022#define AssertReleaseMsgRCBreak(rc, msg, stmt) AssertReleaseMsgBreak(RT_SUCCESS_NP(rc), msg, stmt)
1023
1024/** @def AssertReleaseRCSuccess
1025 * Asserts that an iprt status code equals VINF_SUCCESS.
1026 *
1027 * On failure information about the error will be printed and a breakpoint hit.
1028 *
1029 * @param rc iprt status code.
1030 * @remark rc is references multiple times.
1031 */
1032#define AssertReleaseRCSuccess(rc) AssertReleaseMsg((rc) == VINF_SUCCESS, ("%Vra\n", (rc)))
1033
1034/** @def AssertReleaseRCSuccessReturn
1035 * Asserts that an iprt status code equals VINF_SUCCESS.
1036 *
1037 * On failure information about the error will be printed, a breakpoint hit
1038 * and finally returning from the function if the breakpoint is somehow ignored.
1039 *
1040 * @param rc iprt status code.
1041 * @param rcRet What is to be presented to return.
1042 * @remark rc is references multiple times.
1043 */
1044#define AssertReleaseRCSuccessReturn(rc, rcRet) AssertReleaseMsgReturn((rc) == VINF_SUCCESS, ("%Vra\n", (rc)), rcRet)
1045
1046/** @def AssertReleaseRCSuccessReturnVoid
1047 * Asserts that an iprt status code equals VINF_SUCCESS.
1048 *
1049 * On failure information about the error will be printed, a breakpoint hit
1050 * and finally returning from the function if the breakpoint is somehow ignored.
1051 *
1052 * @param rc iprt status code.
1053 * @remark rc is references multiple times.
1054 */
1055#define AssertReleaseRCSuccessReturnVoid(rc) AssertReleaseMsgReturnVoid((rc) == VINF_SUCCESS, ("%Vra\n", (rc)))
1056
1057/** @def AssertReleaseRCSuccessBreak
1058 * Asserts that an iprt status code equals VINF_SUCCESS.
1059 *
1060 * On failure information about the error will be printed, a breakpoint hit
1061 * and finally the break statement will be issued if the breakpoint is somehow ignored.
1062 *
1063 * @param rc iprt status code.
1064 * @param stmt Statement to execute before break in case of a failed assertion.
1065 * @remark rc is references multiple times.
1066 */
1067#define AssertReleaseRCSuccessBreak(rc, stmt) AssertReleaseMsgBreak((rc) == VINF_SUCCESS, ("%Vra\n", (rc)), stmt)
1068
1069
1070/** @def AssertFatalRC
1071 * Asserts a iprt status code successful.
1072 *
1073 * On failure information about the error will be printed and a breakpoint hit.
1074 *
1075 * @param rc iprt status code.
1076 * @remark rc is references multiple times.
1077 */
1078#define AssertFatalRC(rc) AssertFatalMsgRC(rc, ("%Vra\n", (rc)))
1079
1080/** @def AssertReleaseMsgRC
1081 * Asserts a iprt status code successful.
1082 *
1083 * On failure a custom message is printed and a breakpoint is hit.
1084 *
1085 * @param rc iprt status code.
1086 * @param msg printf argument list (in parenthesis).
1087 * @remark rc is references multiple times.
1088 */
1089#define AssertFatalMsgRC(rc, msg) AssertFatalMsg(RT_SUCCESS_NP(rc), msg)
1090
1091/** @def AssertFatalRCSuccess
1092 * Asserts that an iprt status code equals VINF_SUCCESS.
1093 *
1094 * On failure information about the error will be printed and a breakpoint hit.
1095 *
1096 * @param rc iprt status code.
1097 * @remark rc is references multiple times.
1098 */
1099#define AssertFatalRCSuccess(rc) AssertFatalMsg((rc) == VINF_SUCCESS, ("%Vra\n", (rc)))
1100
1101
1102/** @def AssertPtr
1103 * Asserts that a pointer is valid.
1104 *
1105 * @param pv The pointer.
1106 */
1107#define AssertPtr(pv) AssertMsg(VALID_PTR(pv), ("%p\n", (pv)))
1108
1109/** @def AssertPtrReturn
1110 * Asserts that a pointer is valid.
1111 *
1112 * @param pv The pointer.
1113 * @param rcRet What is to be presented to return.
1114 */
1115#define AssertPtrReturn(pv, rcRet) AssertMsgReturn(VALID_PTR(pv), ("%p\n", (pv)), rcRet)
1116
1117/** @def AssertPtrReturnVoid
1118 * Asserts that a pointer is valid.
1119 *
1120 * @param pv The pointer.
1121 */
1122#define AssertPtrReturnVoid(pv) AssertMsgReturnVoid(VALID_PTR(pv), ("%p\n", (pv)))
1123
1124/** @def AssertPtrBreak
1125 * Asserts that a pointer is valid.
1126 *
1127 * @param pv The pointer.
1128 * @param stmt Statement to execute before break in case of a failed assertion.
1129 */
1130#define AssertPtrBreak(pv, stmt) AssertMsgBreak(VALID_PTR(pv), ("%p\n", (pv)), stmt)
1131
1132/** @def AssertPtrNull
1133 * Asserts that a pointer is valid or NULL.
1134 *
1135 * @param pv The pointer.
1136 */
1137#define AssertPtrNull(pv) AssertMsg(VALID_PTR(pv) || (pv) == NULL, ("%p\n", (pv)))
1138
1139/** @def AssertPtrNullReturn
1140 * Asserts that a pointer is valid or NULL.
1141 *
1142 * @param pv The pointer.
1143 * @param rcRet What is to be presented to return.
1144 */
1145#define AssertPtrNullReturn(pv, rcRet) AssertMsgReturn(VALID_PTR(pv) || (pv) == NULL, ("%p\n", (pv)), rcRet)
1146
1147/** @def AssertPtrNullReturnVoid
1148 * Asserts that a pointer is valid or NULL.
1149 *
1150 * @param pv The pointer.
1151 */
1152#define AssertPtrNullReturnVoid(pv) AssertMsgReturnVoid(VALID_PTR(pv) || (pv) == NULL, ("%p\n", (pv)))
1153
1154/** @def AssertPtrNullBreak
1155 * Asserts that a pointer is valid or NULL.
1156 *
1157 * @param pv The pointer.
1158 * @param stmt Statement to execute before break in case of a failed assertion.
1159 */
1160#define AssertPtrNullBreak(pv, stmt) AssertMsgBreak(VALID_PTR(pv) || (pv) == NULL, ("%p\n", (pv)), stmt)
1161
1162
1163__BEGIN_DECLS
1164
1165/**
1166 * The 1st part of an assert message.
1167 *
1168 * @param pszExpr Expression. Can be NULL.
1169 * @param uLine Location line number.
1170 * @param pszFile Location file name.
1171 * @param pszFunction Location function name.
1172 * @remark This API exists in HC Ring-3 and GC.
1173 */
1174RTDECL(void) AssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction);
1175
1176/**
1177 * The 2nd (optional) part of an assert message.
1178 * @param pszFormat Printf like format string.
1179 * @param ... Arguments to that string.
1180 * @remark This API exists in HC Ring-3 and GC.
1181 */
1182RTDECL(void) AssertMsg2(const char *pszFormat, ...);
1183
1184/**
1185 * Overridable function that decides whether assertions executes the breakpoint or not.
1186 *
1187 * The generic implementation will return true.
1188 *
1189 * @returns true if the breakpoint should be hit, false if it should be ignored.
1190 * @remark The RTDECL() makes this a bit difficult to override on windows. Sorry.
1191 */
1192RTDECL(bool) RTAssertDoBreakpoint(void);
1193
1194/** The last assert message, 1st part. */
1195extern RTDATADECL(char) g_szRTAssertMsg1[1024];
1196/** The last assert message, 2nd part. */
1197extern RTDATADECL(char) g_szRTAssertMsg2[2048];
1198
1199__END_DECLS
1200
1201/** @} */
1202
1203#endif
1204
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