00001 /********************************************************************* 00002 Debug utilities for Innobase 00003 00004 (c) 1994, 1995 Innobase Oy 00005 00006 Created 1/30/1994 Heikki Tuuri 00007 **********************************************************************/ 00008 00009 #ifndef ut0dbg_h 00010 #define ut0dbg_h 00011 00012 #include "univ.i" 00013 #include <stdlib.h> 00014 #include "os0thread.h" 00015 00016 #if defined(__GNUC__) && (__GNUC__ > 2) 00017 # define UT_DBG_FAIL(EXPR) UNIV_UNLIKELY(!((ulint)(EXPR))) 00018 #else 00019 extern ulint ut_dbg_zero; /* This is used to eliminate 00020 compiler warnings */ 00021 # define UT_DBG_FAIL(EXPR) !((ulint)(EXPR) + ut_dbg_zero) 00022 #endif 00023 00024 /***************************************************************** 00025 Report a failed assertion. */ 00026 00027 void 00028 ut_dbg_assertion_failed( 00029 /*====================*/ 00030 const char* expr, /* in: the failed assertion */ 00031 const char* file, /* in: source file containing the assertion */ 00032 ulint line); /* in: line number of the assertion */ 00033 00034 #ifdef __NETWARE__ 00035 /* Flag for ignoring further assertion failures. 00036 On NetWare, have a graceful exit rather than a segfault to avoid abends. */ 00037 extern ibool panic_shutdown; 00038 /* Abort the execution. */ 00039 void ut_dbg_panic(void); 00040 # define UT_DBG_PANIC ut_dbg_panic() 00041 /* Stop threads in ut_a(). */ 00042 # define UT_DBG_STOP while (0) /* We do not do this on NetWare */ 00043 #else /* __NETWARE__ */ 00044 # if defined(__WIN__) || defined(__INTEL_COMPILER) 00045 # undef UT_DBG_USE_ABORT 00046 # elif defined(__GNUC__) && (__GNUC__ > 2) 00047 # define UT_DBG_USE_ABORT 00048 # endif 00049 00050 # ifndef UT_DBG_USE_ABORT 00051 /* A null pointer that will be dereferenced to trigger a memory trap */ 00052 extern ulint* ut_dbg_null_ptr; 00053 # endif 00054 00055 # if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT) 00056 /* Flag for indicating that all threads should stop. This will be set 00057 by ut_dbg_assertion_failed(). */ 00058 extern ibool ut_dbg_stop_threads; 00059 00060 /***************************************************************** 00061 Stop a thread after assertion failure. */ 00062 00063 void 00064 ut_dbg_stop_thread( 00065 /*===============*/ 00066 const char* file, 00067 ulint line); 00068 # endif 00069 00070 # ifdef UT_DBG_USE_ABORT 00071 /* Abort the execution. */ 00072 # define UT_DBG_PANIC abort() 00073 /* Stop threads (null operation) */ 00074 # define UT_DBG_STOP while (0) 00075 # else /* UT_DBG_USE_ABORT */ 00076 /* Abort the execution. */ 00077 # define UT_DBG_PANIC \ 00078 if (*(ut_dbg_null_ptr)) ut_dbg_null_ptr = NULL 00079 /* Stop threads in ut_a(). */ 00080 # define UT_DBG_STOP do \ 00081 if (UNIV_UNLIKELY(ut_dbg_stop_threads)) { \ 00082 ut_dbg_stop_thread(__FILE__, (ulint) __LINE__); \ 00083 } while (0) 00084 # endif /* UT_DBG_USE_ABORT */ 00085 #endif /* __NETWARE__ */ 00086 00087 /* Abort execution if EXPR does not evaluate to nonzero. */ 00088 #define ut_a(EXPR) do { \ 00089 if (UT_DBG_FAIL(EXPR)) { \ 00090 ut_dbg_assertion_failed(#EXPR, \ 00091 __FILE__, (ulint) __LINE__); \ 00092 UT_DBG_PANIC; \ 00093 } \ 00094 UT_DBG_STOP; \ 00095 } while (0) 00096 00097 /* Abort execution. */ 00098 #define ut_error do { \ 00099 ut_dbg_assertion_failed(0, __FILE__, (ulint) __LINE__); \ 00100 UT_DBG_PANIC; \ 00101 } while (0) 00102 00103 #ifdef UNIV_DEBUG 00104 #define ut_ad(EXPR) ut_a(EXPR) 00105 #define ut_d(EXPR) do {EXPR;} while (0) 00106 #else 00107 #define ut_ad(EXPR) 00108 #define ut_d(EXPR) 00109 #endif 00110 00111 #define UT_NOT_USED(A) A = A 00112 00113 #endif
1.4.7

