kmp_debug.h

Go to the documentation of this file.
00001 /*
00002  * kmp_debug.h -- debug / assertion code for Assure library
00003  * $Revision: 42061 $
00004  * $Date: 2013-02-28 16:36:24 -0600 (Thu, 28 Feb 2013) $
00005  */
00006 
00007 /* <copyright>
00008     Copyright (c) 1997-2013 Intel Corporation.  All Rights Reserved.
00009 
00010     Redistribution and use in source and binary forms, with or without
00011     modification, are permitted provided that the following conditions
00012     are met:
00013 
00014       * Redistributions of source code must retain the above copyright
00015         notice, this list of conditions and the following disclaimer.
00016       * Redistributions in binary form must reproduce the above copyright
00017         notice, this list of conditions and the following disclaimer in the
00018         documentation and/or other materials provided with the distribution.
00019       * Neither the name of Intel Corporation nor the names of its
00020         contributors may be used to endorse or promote products derived
00021         from this software without specific prior written permission.
00022 
00023     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00026     A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00027     HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00028     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00029     LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00030     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00031     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 
00035 
00036 ------------------------------------------------------------------------
00037 
00038     Portions of this software are protected under the following patents:
00039         U.S. Patent 5,812,852
00040         U.S. Patent 6,792,599
00041         U.S. Patent 7,069,556
00042         U.S. Patent 7,328,433
00043         U.S. Patent 7,500,242
00044 
00045 </copyright> */
00046 
00047 #ifndef KMP_DEBUG_H
00048 #define KMP_DEBUG_H
00049 
00050 #include <stdarg.h>
00051 
00052 #ifdef __cplusplus
00053     extern "C" {
00054 #endif // __cplusplus
00055 
00056 // -------------------------------------------------------------------------------------------------
00057 // Build-time assertion.
00058 // -------------------------------------------------------------------------------------------------
00059 
00060 /*
00061     Build-time assertion can do compile-time checking of data structure sizes, etc. This works by
00062     declaring a negative-length array if the conditional expression evaluates to false.  In that
00063     case, the compiler issues a syntax error and stops the compilation. If the expression is
00064     true, we get an extraneous static single character array in the scope of the macro.
00065 
00066     Usage:
00067 
00068         KMP_BUILD_ASSERT( sizeof( some_t ) <= 32 );
00069         KMP_BUILD_ASSERT( offsetof( some_t, field ) % 8 == 0 );
00070 
00071     Do not use _KMP_BUILD_ASSERT and __KMP_BUILD_ASSERT directly, it is working guts.
00072 */
00073 
00074 #define __KMP_BUILD_ASSERT( expr, suffix )  static char __kmp_build_check_##suffix[ (expr) ? 1 : -1 ]
00075 #define _KMP_BUILD_ASSERT( expr, suffix )   __KMP_BUILD_ASSERT( (expr), suffix )
00076 #define KMP_BUILD_ASSERT( expr )            _KMP_BUILD_ASSERT( (expr), __LINE__ )
00077 
00078 // -------------------------------------------------------------------------------------------------
00079 // Run-time assertions.
00080 // -------------------------------------------------------------------------------------------------
00081 
00082 extern void __kmp_dump_debug_buffer( void );
00083 
00084 #ifdef KMP_USE_ASSERT
00085     extern int __kmp_debug_assert( char const * expr, char const * file, int line );
00086     #ifdef KMP_DEBUG
00087         #define KMP_ASSERT( cond )             ( (cond) ? 0 : __kmp_debug_assert( #cond, __FILE__, __LINE__ ) )
00088         #define KMP_ASSERT2( cond, msg )       ( (cond) ? 0 : __kmp_debug_assert( (msg), __FILE__, __LINE__ ) )
00089         #define KMP_DEBUG_ASSERT( cond )       KMP_ASSERT( cond )
00090         #define KMP_DEBUG_ASSERT2( cond, msg ) KMP_ASSERT2( cond, msg )
00091     #else
00092         // Do not expose condition in release build. Use "assertion failure".
00093         #define KMP_ASSERT( cond )             ( (cond) ? 0 : __kmp_debug_assert( "assertion failure", __FILE__, __LINE__ ) )
00094         #define KMP_ASSERT2( cond, msg )       KMP_ASSERT( cond )
00095         #define KMP_DEBUG_ASSERT( cond )       0
00096         #define KMP_DEBUG_ASSERT2( cond, msg ) 0
00097     #endif // KMP_DEBUG
00098 #else
00099     #define KMP_ASSERT( cond )             0
00100     #define KMP_ASSERT2( cond, msg )       0
00101     #define KMP_DEBUG_ASSERT( cond )       0
00102     #define KMP_DEBUG_ASSERT2( cond, msg ) 0
00103 #endif // KMP_USE_ASSERT
00104 
00105 #ifdef KMP_DEBUG
00106     extern void __kmp_debug_printf_stdout( char const * format, ... );
00107 #endif
00108 extern void __kmp_debug_printf( char const * format, ... );
00109 
00110 #ifdef KMP_DEBUG
00111 
00112     extern int kmp_a_debug;
00113     extern int kmp_b_debug;
00114     extern int kmp_c_debug;
00115     extern int kmp_d_debug;
00116     extern int kmp_e_debug;
00117     extern int kmp_f_debug;
00118     extern int kmp_diag;
00119 
00120     #define KA_TRACE(d,x)     if (kmp_a_debug >= d) { __kmp_debug_printf x ; }
00121     #define KB_TRACE(d,x)     if (kmp_b_debug >= d) { __kmp_debug_printf x ; }
00122     #define KC_TRACE(d,x)     if (kmp_c_debug >= d) { __kmp_debug_printf x ; }
00123     #define KD_TRACE(d,x)     if (kmp_d_debug >= d) { __kmp_debug_printf x ; }
00124     #define KE_TRACE(d,x)     if (kmp_e_debug >= d) { __kmp_debug_printf x ; }
00125     #define KF_TRACE(d,x)     if (kmp_f_debug >= d) { __kmp_debug_printf x ; }
00126     #define K_DIAG(d,x)       {if (kmp_diag == d) { __kmp_debug_printf_stdout x ; } }
00127 
00128     #define KA_DUMP(d,x)     if (kmp_a_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); }
00129     #define KB_DUMP(d,x)     if (kmp_b_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); }
00130     #define KC_DUMP(d,x)     if (kmp_c_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); }
00131     #define KD_DUMP(d,x)     if (kmp_d_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); }
00132     #define KE_DUMP(d,x)     if (kmp_e_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); }
00133     #define KF_DUMP(d,x)     if (kmp_f_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); }
00134 
00135 #else
00136 
00137     #define KA_TRACE(d,x)     /* nothing to do */
00138     #define KB_TRACE(d,x)     /* nothing to do */
00139     #define KC_TRACE(d,x)     /* nothing to do */
00140     #define KD_TRACE(d,x)     /* nothing to do */
00141     #define KE_TRACE(d,x)     /* nothing to do */
00142     #define KF_TRACE(d,x)     /* nothing to do */
00143     #define K_DIAG(d,x)       {}/* nothing to do */
00144 
00145     #define KA_DUMP(d,x)     /* nothing to do */
00146     #define KB_DUMP(d,x)     /* nothing to do */
00147     #define KC_DUMP(d,x)     /* nothing to do */
00148     #define KD_DUMP(d,x)     /* nothing to do */
00149     #define KE_DUMP(d,x)     /* nothing to do */
00150     #define KF_DUMP(d,x)     /* nothing to do */
00151 
00152 #endif // KMP_DEBUG
00153 
00154 #ifdef __cplusplus
00155     } // extern "C"
00156 #endif // __cplusplus
00157 
00158 #endif /* KMP_DEBUG_H */

Generated on 25 Aug 2013 for libomp_oss by  doxygen 1.6.1