Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

debug.h

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1998-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: debug.h,v 12.2 2005/06/16 20:21:47 bostic Exp $
00008  */
00009 
00010 #ifndef _DB_DEBUG_H_
00011 #define _DB_DEBUG_H_
00012 
00013 #if defined(__cplusplus)
00014 extern "C" {
00015 #endif
00016 
00017 /*
00018  * Turn on additional error checking in gcc 3.X.
00019  */
00020 #if !defined(__GNUC__) || __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
00021 #define __attribute__(s)
00022 #endif
00023 
00024 /*
00025  * When running with #DIAGNOSTIC defined, we smash memory and do memory
00026  * guarding with a special byte value.
00027  */
00028 #define CLEAR_BYTE      0xdb
00029 #define GUARD_BYTE      0xdc
00030 
00031 /*
00032  * DB assertions.
00033  *
00034  * Use __STDC__ rather than STDC_HEADERS, the #e construct is ANSI C specific.
00035  */
00036 #if defined(__STDC__) && defined(DIAGNOSTIC)
00037 #define DB_ASSERT(e)    ((e) ? (void)0 : __db_assert(#e, __FILE__, __LINE__))
00038 #else
00039 #define DB_ASSERT(e)
00040 #endif
00041 
00042 /*
00043  * "Shut that bloody compiler up!"
00044  *
00045  * Unused, or not-used-yet variable.  We need to write and then read the
00046  * variable, some compilers are too bloody clever by half.
00047  */
00048 #define COMPQUIET(n, v)                                                 \
00049         (n) = (v);                                                      \
00050         (n) = (n)
00051 
00052 /*
00053  * Purify and other run-time tools complain about uninitialized reads/writes
00054  * of structure fields whose only purpose is padding, as well as when heap
00055  * memory that was never initialized is written to disk.
00056  */
00057 #ifdef  UMRW
00058 #define UMRW_SET(v)     (v) = 0
00059 #else
00060 #define UMRW_SET(v)
00061 #endif
00062 
00063 /*
00064  * Message handling.  Use a macro instead of a function because va_list
00065  * references to variadic arguments cannot be reset to the beginning of the
00066  * variadic argument list (and then rescanned), by functions other than the
00067  * original routine that took the variadic list of arguments.
00068  */
00069 #if defined(STDC_HEADERS) || defined(__cplusplus)
00070 #define DB_REAL_ERR(env, error, error_set, default_stream, fmt) {       \
00071         va_list ap;                                                     \
00072                                                                         \
00073         /* Call the application's callback function, if specified. */   \
00074         va_start(ap, fmt);                                              \
00075         if ((env) != NULL && (env)->db_errcall != NULL)                 \
00076                 __db_errcall(env, error, error_set, fmt, ap);           \
00077         va_end(ap);                                                     \
00078                                                                         \
00079         /* Write to the application's file descriptor, if specified. */\
00080         va_start(ap, fmt);                                              \
00081         if ((env) != NULL && (env)->db_errfile != NULL)                 \
00082                 __db_errfile(env, error, error_set, fmt, ap);           \
00083         va_end(ap);                                                     \
00084                                                                         \
00085         /*                                                              \
00086          * If we have a default and we didn't do either of the above,   \
00087          * write to the default.                                        \
00088          */                                                             \
00089         va_start(ap, fmt);                                              \
00090         if ((default_stream) && ((env) == NULL ||                       \
00091             ((env)->db_errcall == NULL && (env)->db_errfile == NULL)))  \
00092                 __db_errfile(env, error, error_set, fmt, ap);           \
00093         va_end(ap);                                                     \
00094 }
00095 #else
00096 #define DB_REAL_ERR(env, error, error_set, default_stream, fmt) {       \
00097         va_list ap;                                                     \
00098                                                                         \
00099         /* Call the application's callback function, if specified. */   \
00100         va_start(ap);                                                   \
00101         if ((env) != NULL && (env)->db_errcall != NULL)                 \
00102                 __db_errcall(env, error, error_set, fmt, ap);           \
00103         va_end(ap);                                                     \
00104                                                                         \
00105         /* Write to the application's file descriptor, if specified. */\
00106         va_start(ap);                                                   \
00107         if ((env) != NULL && (env)->db_errfile != NULL)                 \
00108                 __db_errfile(env, error, error_set, fmt, ap);           \
00109         va_end(ap);                                                     \
00110                                                                         \
00111         /*                                                              \
00112          * If we have a default and we didn't do either of the above,   \
00113          * write to the default.                                        \
00114          */                                                             \
00115         va_start(ap);                                                   \
00116         if ((default_stream) && ((env) == NULL ||                       \
00117             ((env)->db_errcall == NULL && (env)->db_errfile == NULL)))  \
00118                 __db_errfile(env, error, error_set, fmt, ap);           \
00119         va_end(ap);                                                     \
00120 }
00121 #endif
00122 #if defined(STDC_HEADERS) || defined(__cplusplus)
00123 #define DB_REAL_MSG(env, fmt) {                                         \
00124         va_list ap;                                                     \
00125                                                                         \
00126         /* Call the application's callback function, if specified. */   \
00127         va_start(ap, fmt);                                              \
00128         if ((env) != NULL && (env)->db_msgcall != NULL)                 \
00129                 __db_msgcall(env, fmt, ap);                             \
00130         va_end(ap);                                                     \
00131                                                                         \
00132         /*                                                              \
00133          * If the application specified a file descriptor, or we wrote  \
00134          * to neither the application's callback routine or to its file \
00135          * descriptor, write to stdout.                                 \
00136          */                                                             \
00137         va_start(ap, fmt);                                              \
00138         if ((env) == NULL ||                                            \
00139             (env)->db_msgfile != NULL || (env)->db_msgcall == NULL) {   \
00140                 __db_msgfile(env, fmt, ap);                             \
00141         }                                                               \
00142         va_end(ap);                                                     \
00143 }
00144 #else
00145 #define DB_REAL_MSG(env, fmt) {                                         \
00146         va_list ap;                                                     \
00147                                                                         \
00148         /* Call the application's callback function, if specified. */   \
00149         va_start(ap);                                                   \
00150         if ((env) != NULL && (env)->db_msgcall != NULL)                 \
00151                 __db_msgcall(env, fmt, ap);                             \
00152         va_end(ap);                                                     \
00153                                                                         \
00154         /*                                                              \
00155          * If the application specified a file descriptor, or we wrote  \
00156          * to neither the application's callback routine or to its file \
00157          * descriptor, write to stdout.                                 \
00158          */                                                             \
00159         va_start(ap);                                                   \
00160         if ((env) == NULL ||                                            \
00161             (env)->db_msgfile != NULL || (env)->db_msgcall == NULL) {   \
00162                 __db_msgfile(env, fmt, ap);                             \
00163         }                                                               \
00164         va_end(ap);                                                     \
00165 }
00166 #endif
00167 
00168 /*
00169  * Debugging macro to log operations.
00170  *      If DEBUG_WOP is defined, log operations that modify the database.
00171  *      If DEBUG_ROP is defined, log operations that read the database.
00172  *
00173  * D dbp
00174  * T txn
00175  * O operation (string)
00176  * K key
00177  * A data
00178  * F flags
00179  */
00180 #define LOG_OP(C, T, O, K, A, F) {                                      \
00181         DB_LSN __lsn;                                                   \
00182         DBT __op;                                                       \
00183         if (DBC_LOGGING((C))) {                                         \
00184                 memset(&__op, 0, sizeof(__op));                         \
00185                 __op.data = O;                                          \
00186                 __op.size = strlen(O) + 1;                              \
00187                 (void)__db_debug_log((C)->dbp->dbenv, T, &__lsn, 0,     \
00188                     &__op, (C)->dbp->log_filename->id, K, A, F);        \
00189         }                                                               \
00190 }
00191 #ifdef  DEBUG_ROP
00192 #define DEBUG_LREAD(C, T, O, K, A, F)   LOG_OP(C, T, O, K, A, F)
00193 #else
00194 #define DEBUG_LREAD(C, T, O, K, A, F)
00195 #endif
00196 #ifdef  DEBUG_WOP
00197 #define DEBUG_LWRITE(C, T, O, K, A, F)  LOG_OP(C, T, O, K, A, F)
00198 #else
00199 #define DEBUG_LWRITE(C, T, O, K, A, F)
00200 #endif
00201 
00202 /*
00203  * Hook for testing recovery at various places in the create/delete paths.
00204  * Hook for testing subdb locks.
00205  */
00206 #if CONFIG_TEST
00207 #define DB_TEST_SUBLOCKS(env, flags) do {                               \
00208         if ((env)->test_abort == DB_TEST_SUBDB_LOCKS)                   \
00209                 (flags) |= DB_LOCK_NOWAIT;                              \
00210 } while (0)
00211 
00212 #define DB_ENV_TEST_RECOVERY(env, val, ret, name) do {                  \
00213         int __ret;                                                      \
00214         PANIC_CHECK((env));                                             \
00215         if ((env)->test_copy == (val)) {                                \
00216                 /* COPY the FILE */                                     \
00217                 if ((__ret = __db_testcopy((env), NULL, (name))) != 0)  \
00218                         (ret) = __db_panic((env), __ret);               \
00219         }                                                               \
00220         if ((env)->test_abort == (val)) {                               \
00221                 /* ABORT the TXN */                                     \
00222                 (env)->test_abort = 0;                                  \
00223                 (ret) = EINVAL;                                         \
00224                 goto db_tr_err;                                         \
00225         }                                                               \
00226 } while (0)
00227 
00228 #define DB_TEST_RECOVERY(dbp, val, ret, name) do {                      \
00229         int __ret;                                                      \
00230         PANIC_CHECK((dbp)->dbenv);                                      \
00231         if ((dbp)->dbenv->test_copy == (val)) {                         \
00232                 /* Copy the file. */                                    \
00233                 if (F_ISSET((dbp),                                      \
00234                     DB_AM_OPEN_CALLED) && (dbp)->mpf != NULL)           \
00235                         (void)__db_sync(dbp);                           \
00236                 if ((__ret =                                            \
00237                     __db_testcopy((dbp)->dbenv, (dbp), (name))) != 0)   \
00238                         (ret) = __db_panic((dbp)->dbenv, __ret);        \
00239         }                                                               \
00240         if ((dbp)->dbenv->test_abort == (val)) {                        \
00241                 /* Abort the transaction. */                            \
00242                 (dbp)->dbenv->test_abort = 0;                           \
00243                 (ret) = EINVAL;                                         \
00244                 goto db_tr_err;                                         \
00245         }                                                               \
00246 } while (0)
00247 
00248 #define DB_TEST_RECOVERY_LABEL  db_tr_err:
00249 
00250 #define DB_TEST_WAIT(env, val)                                  \
00251         if ((val) != 0)                                         \
00252                 __os_sleep((env), (u_long)(val), 0)
00253 #else
00254 #define DB_TEST_SUBLOCKS(env, flags)
00255 #define DB_ENV_TEST_RECOVERY(env, val, ret, name)
00256 #define DB_TEST_RECOVERY(dbp, val, ret, name)
00257 #define DB_TEST_RECOVERY_LABEL
00258 #define DB_TEST_WAIT(env, val)
00259 #endif
00260 
00261 #if defined(__cplusplus)
00262 }
00263 #endif
00264 #endif /* !_DB_DEBUG_H_ */

Generated on Sun Dec 25 12:14:22 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2