VirtualBox

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

Last change on this file since 4394 was 4071, checked in by vboxsync, 17 years ago

Biggest check-in ever. New source code headers for all (C) innotek files.

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