summaryrefslogtreecommitdiff
path: root/print/XPSDrvSmpl/src/debug/debug.h
blob: ddfdc038b2cb29056b5503bda9b4a87198ff668d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*++

Copyright (c) 2005 Microsoft Corporation

All rights reserved.

THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

File Name:

   xdsdbg.h

Abstract:

   Debug definitions.

--*/

#pragma once

//
// These macros are used for debugging purposes. They expand
// to white spaces on a free build. Here is a brief description
// of what they do and how they are used:
//
// giDebugLevel
//  Global variable which set the current debug level to control
//  the amount of debug messages emitted.
//
// VERBOSE(msg)
//  Display a message if the current debug level is <= DBG_VERBOSE.
//
// TERSE(msg)
//  Display a message if the current debug level is <= DBG_TERSE.
//
// WARNING(msg)
//  Display a message if the current debug level is <= DBG_WARNING.
//  The message format is: WRN filename (linenumber): message
//
// ERR(msg)
//  Similiar to WARNING macro above - displays a message
//  if the current debug level is <= DBG_ERROR.
//
// ASSERT(cond)
//  Verify a condition is true. If not, force a breakpoint.
//
// ASSERTMSG(cond, msg)
//  Verify a condition is true. If not, display a message and
//  force a breakpoint.
//
// RIP(msg)
//  Display a message and force a breakpoint.
//
// Usage:
//  These macros require extra parantheses for the msg argument
//  example, ASSERTMSG(x > 0, ("x is less than 0\n"));
//           WARNING(("App passed NULL pointer, ignoring...\n"));
//

#pragma once

#define DBG_VERBOSE 1
#define DBG_TERSE   2
#define DBG_WARNING 3
#define DBG_ERROR   4
#define DBG_RIP     5

BOOL
RealDebugMessage(
    _In_ DWORD   dwSize,
    _In_ PCSTR   pszMessage,
         va_list arglist
    );

BOOL
DbgPrint(
    _In_ PCSTR pszFormatString,
    ...
    );

VOID
DbgDOMDoc(
    _In_ PCSTR             pszMessage,
    _In_ IXMLDOMDocument2* pDomDoc
    );

#if DBG

#ifndef MAX_DEBUG_LEVEL
#define MAX_DEBUG_LEVEL DBG_VERBOSE
#endif

#define DBGMSG(level, prefix, msg) { \
            INT dbgLevel = level; \
            if (MAX_DEBUG_LEVEL <= (dbgLevel)) { \
                DbgPrint("%s %s (%d): ", prefix, __FILE__, __LINE__); \
                DbgPrint(msg); \
            } \
        }

#define DBGMSG_ON_HR(level, prefix, hr) { \
            INT dbgLevel = level; \
            HRESULT hres = hr; \
            if (MAX_DEBUG_LEVEL <= (dbgLevel) && FAILED(hres)) { \
                DbgPrint("%s %s (%d): Call failed with HRESULT = 0x%x\n", prefix, __FILE__, __LINE__, hr); \
            } \
        }

#define DBGMSG_ON_HR_EXC(level, prefix, hr, hr_exc) { \
            INT dbgLevel = level; \
            HRESULT hres = hr; \
            if (MAX_DEBUG_LEVEL <= (dbgLevel) && FAILED(hres) && hres != hr_exc) { \
            DbgPrint("%s %s (%d): Call failed with HRESULT = 0x%x\n", prefix, __FILE__, __LINE__, hr); \
            } \
        }

#define DBGPRINT(level, msg) { \
            INT dbgLevel = level; \
            if (MAX_DEBUG_LEVEL <= (dbgLevel)) { \
                DbgPrint(msg); \
            } \
        }

#define DBGXML(msg, pDomDoc) { \
            INT dbgLevel = DBG_VERBOSE; \
            if (MAX_DEBUG_LEVEL <= dbgLevel) { \
                DbgDOMDoc(msg, pDomDoc); \
            } \
        }

#define VERBOSE(msg) DBGPRINT(DBG_VERBOSE, msg)
#define TERSE(msg) DBGPRINT(DBG_TERSE, msg)
#define WARNING(msg) DBGMSG(DBG_WARNING, "WRN", msg)
#define ERR(msg) DBGMSG(DBG_ERROR, "ERR", msg)
#define ERR_ON_HR(hr) DBGMSG_ON_HR(DBG_ERROR, "ERR", hr)
#define ERR_ON_HR_EXC(hr, hr_exc) DBGMSG_ON_HR_EXC(DBG_ERROR, "ERR", hr, hr_exc)

#define ASSERT(cond) { \
            if (! (cond)) { \
                RIP(("\n")); \
            } \
        }

#define ASSERTMSG(cond, msg) { \
            if (!(cond)) { \
                RIP(msg); \
            } \
        }

#define RIP(msg) { \
            DBGMSG(DBG_RIP, "RIP", msg); \
            DebugBreak(); \
        }

#define DBG_ONLY(p) p

#else // !DBG

#define VERBOSE(msg)
#define TERSE(msg)
#define WARNING(msg)
#define ERR(msg)
#define ERR_ON_HR(hr)
#define ERR_ON_HR_EXC(hr, hr_exc)

#define ASSERT(cond)

#define ASSERTMSG(cond, msg)

#define RIP(msg)

#define DBG_ONLY(p)

#define DBGMSG(level, prefix, msg)

#define DBGMSG_ON_HR(level, prefix, hr)

#define DBGPRINT(level, msg)

#define DBGXML(msg, pDomDoc)

#endif