test: debug.h Source File

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# debug.h

Go to the documentation of this file.

    00001 /****************************Module*Header******************************\
    00002 * Module Name: DEBUG.H
    00003 *
    00004 * Module Descripton: Debugging macros for ICM project
    00005 *
    00006 * Warnings:
    00007 *
    00008 * Issues:
    00009 *
    00010 * Created:  8 January 1996
    00011 * Author:   Srinivasan Chandraekar    [srinivac]
    00012 *
    00013 * Copyright (c) 1996, 1997  Microsoft Corporation
    00014 \***********************************************************************/
    00015
    00016 #ifndef _DEBUG_H_
    00017 #define _DEBUG_H_
    00018
    00019 #ifdef DBG
    00020
    00021 //
    00022 // These are used for debugging purposes, and do not generate code in the
    00023 // retail version of the driver.
    00024 //
    00025 // A global variable (again present only in the debug build) maintains the
    00026 // current debug level in the low order WORD. The high order WORD is treated
    00027 // as a bitfield and is used to give more flexibility to debugging.
    00028 //
    00029
    00030 PSTR StripDirPrefixA(PSTR);
    00031 VOID MyDebugPrintW(PWSTR, ...);
    00032 VOID MyDebugPrintA(PSTR, ...);
    00033
    00034 #ifdef UNICODE
    00035 #define MyDebugPrint    MyDebugPrintW
    00036 #else
    00037 #define MyDebugPrint    MyDebugPrintA
    00038 #endif
    00039
    00040 #define DBGPRINT            MyDebugPrint
    00041 #define DBGPRINTA           MyDebugPrintA
    00042 #define DBGBREAK()          DebugBreak()
    00043
    00044 //
    00045 // List of debug levels for low WORD of gdwDebugControl
    00046 //
    00047
    00048 #define DBG_LEVEL_VERBOSE   0x00000001
    00049 #define DBG_LEVEL_TERSE     0x00000002
    00050 #define DBG_LEVEL_WARNING   0x00000003
    00051 #define DBG_LEVEL_ERROR     0x00000004
    00052 #define DBG_LEVEL_FATAL     0x00000005
    00053
    00054 //
    00055 // Bits used in the high WORD of gdwDebugControl
    00056 //
    00057
    00058 #define FLAG_TRACEAPI       0x00010000      // Trace API entries
    00059
    00060 #define CHECK_DBG_LEVEL(level)  ((level) >= gdwDebugControl)
    00061
    00062 #define TRACEAPI(funcname)                                              \
    00063     {                                                                   \
    00064         if (gdwDebugControl & FLAG_TRACEAPI)                            \
    00065         {                                                               \
    00066             DBGPRINTA("ICM: Entering function ");                       \
    00067             DBGPRINT funcname;                                          \
    00068         }                                                               \
    00069     }
    00070
    00071 #define DBGMSG(level, mesg)                                             \
    00072     {                                                                   \
    00073         if (CHECK_DBG_LEVEL(level))                                     \
    00074         {                                                               \
    00075             DBGPRINTA("ICM: %s (%d): ",                                 \
    00076                     StripDirPrefixA(__FILE__), __LINE__);               \
    00077             DBGPRINT mesg;                                              \
    00078         }                                                               \
    00079     }
    00080
    00081 //
    00082 // These are the main macros that you'll be using in your code.
    00083 // For giving additional parameters enclose the parameters in
    00084 // paranthesis as shown in the example below.
    00085 //
    00086 // WARNING((__TEXT("Out of memory")));
    00087 // ERR((__TEXT("Incorrect return value: %d"), rc));  // Note extra brackets
    00088 //
    00089
    00090 #define VERBOSE(mesg)       DBGMSG(DBG_LEVEL_VERBOSE, mesg)
    00091 #define TERSE(mesg)         DBGMSG(DBG_LEVEL_TERSE,   mesg)
    00092 #define WARNING(mesg)       DBGMSG(DBG_LEVEL_WARNING, mesg)
    00093 #define ERR(mesg)           DBGMSG(DBG_LEVEL_ERROR,   mesg)
    00094 #define FATAL(mesg)         DBGMSG(DBG_LEVEL_FATAL,   mesg)
    00095
    00096 //
    00097 // These macros are for Asserting and work independently of the
    00098 // debugging variable.
    00099 //
    00100
    00101 #define ASSERT(expr)                                                    \
    00102     {                                                                   \
    00103         if (! (expr)) {                                                 \
    00104             DBGPRINTA("ICM: Assertion failed: %s (%d)\n",               \
    00105                     StripDirPrefixA(__FILE__), __LINE__);               \
    00106             DBGBREAK();                                                 \
    00107         }                                                               \
    00108     }
    00109
    00110 //
    00111 // For giving additional parameters, enclose the message and the other
    00112 // parameters in extra paranthesis as shown below.
    00113 //
    00114 // ASSERTMSG(x>0, "x less than 0");
    00115 // ASSERTMSG(x>0, ("x less than 0: x=%d", x));
    00116 //
    00117
    00118 #define ASSERTMSG(expr, mesg)                                           \
    00119     {                                                                   \
    00120         if (! (expr)) {                                                 \
    00121             DBGPRINTA("ICM: Assertion failed: %s (%d)\n",               \
    00122                     StripDirPrefixA(__FILE__), __LINE__);               \
    00123             DBGPRINT mesg;                                              \
    00124             DBGPRINTA("\n");                                            \
    00125             DBGBREAK();                                                 \
    00126         }                                                               \
    00127     }
    00128
    00129 #define RIP(mesg)                                                       \
    00130     {                                                                   \
    00131         DBGPRINTA("ICM: ");                                             \
    00132         DBGPRINT mesg;                                                  \
    00133         DBGBREAK();                                                     \
    00134     }
    00135
    00136 #else   // !DBG
    00137
    00138 #define TRACEAPI(mesg)
    00139 #define DBGMSG(level, mesg)
    00140 #define VERBOSE(mesg)
    00141 #define TERSE(mesg)
    00142 #define WARNING(mesg)
    00143 #define ERR(mesg)
    00144 #define FATAL(mesg)
    00145
    00146 #define ASSERT(expr)
    00147 #define ASSERTMSG(expr, mesg)
    00148
    00149 #define RIP(mesg)
    00150
    00151 #endif  // !DBG
    00152
    00153 #endif  // ifndef _DEBUG_H_
    00154