22 #if !defined(DBG_KERNELMODE) && !defined(DBG_USERMODE)
23 #error DBG_KERNELMODE or DBG_USERMODE must be specified!
27 #if defined(DBG_KERNELMODE) && defined(DBG_USERMODE)
28 #error Only one of DBG_KERNELMODE and DBG_USERMODE must be specified!
34 #define __FUNCTION__ ""
44 #if defined(_PREFAST_)
45 #define DBG_I_BREAKPOINT() __debugbreak
46 #elif defined(DBG_KERNELMODE)
47 #define DBG_I_BREAKPOINT() DbgBreakPoint()
50 #define DBG_I_BREAKPOINT() DebugBreak()
52 #define DBG_I_BREAKPOINT()
62 #define OutputDebugString(_xxx) printf( "%s\n", _xxx);
66 #define STATUS_SUCCESS 0
70 typedef unsigned char UCHAR;
72 typedef unsigned long ULONG;
74 typedef unsigned long* PULONG;
82 const unsigned char *InputBuffer,
83 const unsigned int Count);
105 #define DBG_MEMDUMP(_Where, _Buffer, _Count) dbg_memdump(_Where, _Buffer, _Count)
108 #define DBG_MAX_BUFFERLEN 4096
110 #ifdef DBG_KERNELMODE
113 #define DBG_MAX_BUFFER 32
118 #define DBG_MAX_BUFFER 1
120 #endif // #ifdef DBG_KERNELMODE
125 #define DBGF_BREAK 0x80000000
128 #define DBGF_ENTER 0x40000000
131 #define DBGF_LEAVE 0x20000000
135 #define DBGF_LEAVE_FAILURE 0x10000000
138 #define DBGF_PARAM 0x08000000
140 #ifdef DBG_KERNELMODE
143 #define DBGF_IEC 0x04000000
146 #define DBGF_IRQ 0x02000000
149 #define DBGF_ASSERTIRQL 0x01000000
152 #define DBGF_PORT 0x00800000
155 #define DBGF_THREAD 0x00400000
158 #define DBGF_IRPPATH 0x00200000
161 #define DBGF_IRP 0x00100000
164 #define DBGF_DPC 0x00080000
167 #define DBGF_CABLE 0x00040000
171 #define DBGF_DBGMEMBUF 0x00020000
174 #define DBGF_DBGPRINT 0x00010000
176 #endif // #ifdef DBG_KERNELMODE
179 #define DBGF_PPORT 0x0010
182 #define DBGF_SUCCESS 0x0008
185 #define DBGF_WARNING 0x0004
188 #define DBGF_ERROR 0x0002
191 #define DBGF_ASSERT 0x0001
195 int __cdecl
main(
int argc,
char *argv[])
203 #define DBG_I_ASSUME(_x) __assume(_x)
205 #define DBG_I_ASSUME(_x)
208 #ifdef DBG_KERNELMODE
213 #endif // #ifdef DBG_KERNELMODE
220 extern void DbgOutputIntoBuffer(
unsigned long BufferNumber,
const char *
const Format, ...);
225 #define ISDBG_BREAK() (DbgFlags & DBGF_BREAK)
226 #define ISDBG_ENTER() (DbgFlags & DBGF_ENTER)
227 #define ISDBG_LEAVE() (DbgFlags & DBGF_LEAVE)
228 #define ISDBG_LEAVE_FAILURE() (DbgFlags & (DBGF_LEAVE|DBGF_LEAVE_FAILURE))
229 #define ISDBG_PARAM() (DbgFlags & DBGF_PARAM)
230 #ifdef DBG_KERNELMODE
231 #define ISDBG_IEC() (DbgFlags & DBGF_IEC)
232 #define ISDBG_IRQ() (DbgFlags & DBGF_IRQ)
233 #define ISDBG_ASSERTIRQL() (DbgFlags & DBGF_ASSERTIRQL)
234 #define ISDBG_PORT() (DbgFlags & DBGF_PORT)
235 #define ISDBG_THREAD() (DbgFlags & DBGF_THREAD)
236 #define ISDBG_IRPPATH() (DbgFlags & DBGF_IRPPATH)
237 #define ISDBG_IRP() (DbgFlags & DBGF_IRP)
238 #define ISDBG_DPC() (DbgFlags & DBGF_DPC)
239 #define ISDBG_CABLE() (DbgFlags & DBGF_CABLE)
240 #define ISDBG_DBGMEMBUF() (DbgFlags & DBGF_DBGMEMBUF)
241 #define ISDBG_DBGPRINT() (DbgFlags & DBGF_DBGPRINT)
242 #endif // #ifdef DBG_KERNELMODE
243 #define ISDBG_PPORT() (DbgFlags & DBGF_PPORT)
244 #define ISDBG_SUCCESS() (DbgFlags & DBGF_SUCCESS)
245 #define ISDBG_WARN() (DbgFlags & DBGF_WARNING)
246 #define ISDBG_ERROR() (DbgFlags & DBGF_ERROR)
247 #define ISDBG_ASSERT() (DbgFlags & DBGF_ASSERT)
248 #define ISDBG_PANIC() (1)
252 #ifdef DBG_KERNELMODE
260 #define _DBG_PERFORM(_xxx) \
261 if (ISDBG_DBGMEMBUF()) \
263 DbgOutputMemoryBuffer(_xxx); \
265 if (ISDBG_DBGPRINT()) \
267 DbgPrint("%s", _xxx); \
271 #define FUNC_DEF ULONG DebugBufferNo = 0;
275 #define _DBG_START_ADD { ULONG BufferUsed; \
277 DebugBufferNo = InterlockedIncrement(&DebugBufferCounter) & (DBG_MAX_BUFFER-1); \
278 BufferUsed = InterlockedExchange(&DebugBufferUsed[DebugBufferNo], 1); \
279 } while (BufferUsed); }
283 #define _DBG_END_ADD InterlockedExchange(&DebugBufferUsed[DebugBufferNo], 0);
285 extern LONG DebugBufferCounter;
286 extern LONG DebugBufferUsed[];
290 #define DEBUG_BUFFER_NO DebugBufferNo
292 #else // #ifdef DBG_KERNELMODE
299 #define _DBG_PERFORM(_xxx) OutputDebugString(_xxx);
306 #define _DBG_START_ADD
314 #define DEBUG_BUFFER_NO 0
316 #endif // #ifdef DBG_KERNELMODE
320 #define DBG_PREFIX DEBUG_BUFFER_NO,
323 #define _DBGO(_xxx) DbgOutputIntoBuffer _xxx
325 #ifdef DBG_KERNELMODE
328 #define _DBG_START() _DBG_START_ADD DbgBufferPos[DEBUG_BUFFER_NO] = 0; DbgOutputIntoBuffer(DBG_PREFIX "%s(%u,%02x)," __FUNCTION__ "(%u): ", DBG_PROGNAME, CbmGetCurrentProcessorNumber(), DebugBufferNo, __LINE__)
330 #else // #if DBG_KERNELMODE
333 #define _DBG_START() _DBG_START_ADD DbgBufferPos[DEBUG_BUFFER_NO] = 0; DbgOutputIntoBuffer(DBG_PREFIX "%s," __FUNCTION__ "(%u): ", DBG_PROGNAME, __LINE__)
335 #endif // #if DBG_KERNELMODE
338 #define _DBG_END() DbgOutputIntoBuffer(DBG_PREFIX "\n"); _DBG_PERFORM(&DbgBuffer[DEBUG_BUFFER_NO][0]) _DBG_END_ADD
341 #define DBGO(_xxx) { _DBG_START(); _DBGO(_xxx); _DBG_END() }
344 #define DBG_BREAKPOINT() { if (ISDBG_BREAK()) { DBG_I_BREAKPOINT(); }; }
347 #define FUNC_ENTER() FUNC_DEF { if (ISDBG_ENTER()) { DBGO(( DBG_PREFIX "Entering %s", __FUNCTION__ )); } }
349 #define FUNC_LEAVE() { if (ISDBG_LEAVE()) { DBGO(( DBG_PREFIX "Leaving %s", __FUNCTION__ )); } return; }
351 #define FUNC_PARAM( _xxx ) { if (ISDBG_PARAM()) { _DBG_START(); _DBGO(( DBG_PREFIX "Parameter for %s: ", __FUNCTION__ )); _DBGO( _xxx ); _DBG_END() } }
354 #define FUNC_LEAVE_BOOL( _xxx ) { const BOOL _OUT_ = _xxx; if (ISDBG_LEAVE()) { DBGO(( DBG_PREFIX "Leaving %s with BOOL=%s", __FUNCTION__, (_OUT_)?"TRUE":"FALSE" )); } return _OUT_; }
356 #define FUNC_LEAVE_BOOLEAN(_xxx ) { const BOOLEAN _OUT_ = _xxx; if (ISDBG_LEAVE()) { DBGO(( DBG_PREFIX "Leaving %s with BOOL=%s", __FUNCTION__, (_OUT_)?"TRUE":"FALSE" )); } return _OUT_; }
358 #define FUNC_LEAVE_INT( _xxx ) { const int _OUT_ = _xxx; if (ISDBG_LEAVE()) { DBGO(( DBG_PREFIX "Leaving %s with INT=%u (%d)", __FUNCTION__, (unsigned int)(_OUT_), (signed int)(_OUT_) )); } return _OUT_; }
360 #define FUNC_LEAVE_UINT( _xxx ) { const unsigned int _OUT_ = _xxx; if (ISDBG_LEAVE()) { DBGO(( DBG_PREFIX "Leaving %s with INT=%u (%d)", __FUNCTION__, _OUT_, _OUT_ )); } return _OUT_; }
362 #define FUNC_LEAVE_USHORT( _xxx ) { const USHORT _OUT_ = _xxx; if (ISDBG_LEAVE()) { DBGO(( DBG_PREFIX "Leaving %s with INT=%u (%d)", __FUNCTION__, (unsigned int)(_OUT_), (signed int)(_OUT_) )); } return _OUT_; }
364 #define FUNC_LEAVE_UCHAR( _xxx ) { const UCHAR _OUT_ = _xxx; if (ISDBG_LEAVE()) { DBGO(( DBG_PREFIX "Leaving %s with UCHAR=%u", __FUNCTION__, (unsigned int)(_OUT_) )); } return _OUT_; }
366 #define FUNC_LEAVE_HANDLE( _xxx ) { const HANDLE _OUT_ = _xxx; if (ISDBG_LEAVE()) { DBGO(( DBG_PREFIX "Leaving %s with HANDLE=%u", __FUNCTION__, (unsigned int)(_OUT_) )); } return _OUT_; }
368 #define FUNC_LEAVE_STRING( _xxx ) { const char * _OUT_ = _xxx; if (ISDBG_LEAVE()) { DBGO(( DBG_PREFIX "Leaving %s with '%s'", __FUNCTION__, (_OUT_) )); } return _xxx; }
370 #define FUNC_LEAVE_ULONG( _xxx ) { const ULONG _OUT_ = _xxx; if (ISDBG_LEAVE()) { DBGO(( DBG_PREFIX "Leaving %s with ULONG=%ul", __FUNCTION__, (ULONG) (_OUT_) )); } return _OUT_; }
372 #define FUNC_LEAVE_LONG( _xxx ) { const LONG _OUT_ = _xxx; if (ISDBG_LEAVE()) { DBGO(( DBG_PREFIX "Leaving %s with LONG=%l", __FUNCTION__, (LONG) (_OUT_) )); } return _OUT_; }
374 #define FUNC_LEAVE_TYPE( _xxx, _TYPE, _FORMAT) { _TYPE _OUT_ = _xxx; if (ISDBG_LEAVE()) { DBGO(( DBG_PREFIX "Leaving %s with " #_TYPE "=" _FORMAT, __FUNCTION__, (_OUT_) )); } return _OUT_; }
376 #define FUNC_LEAVE_PTR( _xxx, _TYPE ) FUNC_LEAVE_TYPE( _xxx, _TYPE, "0x%p")
378 #ifdef DBG_KERNELMODE
380 #define FUNC_LEAVE_NTSTATUS_CONST( _xxx ) { if (ISDBG_LEAVE() || (ISDBG_LEAVE_FAILURE() && (_xxx != STATUS_SUCCESS))) { DBGO(( DBG_PREFIX "Leaving %s with NTSTATUS=%s", __FUNCTION__, #_xxx )); } return _xxx; }
382 #define FUNC_LEAVE_NTSTATUS( _xxx ) { NTSTATUS _OUT_ = _xxx; if (ISDBG_LEAVE() || (ISDBG_LEAVE_FAILURE() && (_xxx != STATUS_SUCCESS))) { DBGO(( DBG_PREFIX "Leaving %s with NTSTATUS=%s", __FUNCTION__, DebugNtStatus(_OUT_) )); } return _OUT_; }
384 #define DBG_IRQL( _xxx ) { if (!(KeGetCurrentIrql() _xxx)) if (ISDBG_ASSERTIRQL()) { DBGO(( DBG_PREFIX "***IRQL ASSERTION FAILED!***: '%s' in %s:%s(%u)", #_xxx, __FILE__, __FUNCTION__, __LINE__ )); DBG_BREAKPOINT(); } }
387 #define FUNC_LEAVE_HMODULE( _xxx ) FUNC_LEAVE_TYPE( _xxx, HMODULE, "0x%08x")
391 #define DBG_PPORT( _xxx ) { if (ISDBG_PPORT()){ DBGO( _xxx ); } }
393 #define DBG_SUCCESS( _xxx ) { if (ISDBG_SUCCESS()) { _DBG_START(); _DBGO( _xxx ); _DBGO((DBG_PREFIX " SUCCESS")); _DBG_END(); } }
395 #define DBG_WARN( _xxx ) { if (ISDBG_WARN()) { _DBG_START(); _DBGO(( DBG_PREFIX "Warning: ")); _DBGO( _xxx ); _DBG_END(); } }
397 #define DBG_ERROR( _xxx ) { if (ISDBG_ERROR()) { _DBG_START(); _DBGO(( DBG_PREFIX "***ERROR***: ")); _DBGO( _xxx ); _DBG_END(); } }
399 #define DBG_PANIC( _xxx ) { if (ISDBG_PANIC()) { _DBG_START(); _DBGO(( DBG_PREFIX "***PANIC***: ")); _DBGO( _xxx ); _DBG_END(); } }
401 #define DBG_ASSERT( _xxx ) { if (!(_xxx)) if (ISDBG_ASSERT()) { DBGO(( DBG_PREFIX "***ASSERTION FAILED!***: %s in %s:%s(%u)", #_xxx, __FILE__, __FUNCTION__, __LINE__ )); DBG_BREAKPOINT(); } DBG_I_ASSUME(_xxx); }
403 #define DBG_PRINT( _xxx ) { DBGO( _xxx ); }
406 #define DBG_VERIFY( _xxx ) DBG_ASSERT( _xxx )
409 #define DBGDO( _xxx ) _xxx
411 #ifdef DBG_KERNELMODE
414 #define DBG_INIT() DbgInit()
418 #define DBG_IEC( _xxx ) { if (ISDBG_IEC()) { DBGO( _xxx ); } }
420 #define DBG_IRQ( _xxx ) { if (ISDBG_IRQ()) { DBGO(( DBG_PREFIX _xxx )); } }
422 #define DBG_PORT( _xxx ) { if (ISDBG_PORT()) { _DBG_START(); _DBGO((DBG_PREFIX "Port Command: ")); _DBGO(_xxx); _DBG_END(); } }
424 #define DBG_THREAD( _xxx )
426 #define DBG_IRPPATH( _xxx ) { if (ISDBG_IRPPATH()) { DBGO(_xxx); } }
428 #define DBG_IRP( _xxx ) { if (ISDBG_IRP()) { DBGO(( DBG_PREFIX "Got IRP: " #_xxx )); } }
430 #define DBG_DPC( _xxx ) { if (ISDBG_DPC()) { DBGO( _xxx ); } }
432 #define DBG_CABLE( _xxx ) { if (ISDBG_CABLE()) { DBGO( _xxx ); } }
441 #define DBG_MEMDUMP(_Where, _Buffer, _Count)
444 #define DBG_BREAKPOINT
450 #define FUNC_LEAVE( ) return
453 #define FUNC_PARAM( _xxx )
456 #define FUNC_LEAVE_BOOL( _xxx ) return _xxx
459 #define FUNC_LEAVE_BOOLEAN( _xxx ) return _xxx
462 #define FUNC_LEAVE_INT( _xxx ) return _xxx
465 #define FUNC_LEAVE_UINT( _xxx ) return _xxx
468 #define FUNC_LEAVE_USHORT( _xxx ) return _xxx
471 #define FUNC_LEAVE_UCHAR( _xxx ) return _xxx
474 #define FUNC_LEAVE_HANDLE( _xxx ) return _xxx
477 #define FUNC_LEAVE_STRING( _xxx ) return _xxx
480 #define FUNC_LEAVE_ULONG( _xxx ) return _xxx
483 #define FUNC_LEAVE_LONG( _xxx ) return _xxx
486 #define FUNC_LEAVE_TYPE( _xxx, _TYPE, _FORMAT) return _xxx
489 #define FUNC_LEAVE_PTR( _xxx, _yyy ) return _xxx
491 #ifdef DBG_KERNELMODE
492 #define FUNC_LEAVE_NTSTATUS_CONST( _xxx ) return _xxx
496 #define FUNC_LEAVE_NTSTATUS( _xxx ) return _xxx
503 #define DBG_PPORT( _xxx )
506 #define DBG_SUCCESS( _xxx )
509 #define DBG_WARN( _xxx )
512 #define DBG_ERROR( _xxx )
515 #define DBG_PANIC( _xxx )
518 #define DBG_ASSERT( _xxx )
521 #define DBG_PRINT( _xxx )
524 #define DBGDO( _xxx )
527 #define DBG_VERIFY( _xxx ) _xxx
529 #ifdef DBG_KERNELMODE
535 #define DBG_IEC( _xxx )
538 #define DBG_IRQ( _xxx )
541 #define DBG_IRQL( _xxx )
544 #define DBG_PORT( _xxx )
547 #define DBG_THREAD( _xxx )
550 #define DBG_IRPPATH( _xxx )
553 #define DBG_IRP( _xxx )
556 #define DBG_DPC( _xxx )
559 #define DBG_CABLE( _xxx )
564 #define FUNC_LEAVE_HMODULE( _xxx ) return _xxx;
571 #define DBG_IRPPATH_PROCESS( _Where_ ) DBG_IRPPATH((DBG_PREFIX "IrpPath: + Processing IRP %08x in " _Where_, (char*)Irp))
574 #define DBG_IRPPATH_COMPLETE( _Where_ ) DBG_IRPPATH((DBG_PREFIX "IrpPath: - Completing IRP %08x in " _Where_ " with ntStatus = %s", (char*)Irp, (char*)DebugNtStatus(ntStatus)))
577 #define DBG_IRPPATH_CANCEL( _Where_ ) DBG_IRPPATH((DBG_PREFIX "IrpPath: - CANCELLING IRP %08x in " _Where_, (char*)Irp))
580 #define DBG_IRPPATH_EXECUTE( _Where_ ) DBG_IRPPATH((DBG_PREFIX "IrpPath: = Executing IRP %08x in " _Where_, (char*)Irp))
582 #endif // #ifndef DBG_H
#define DBG_MAX_BUFFERLEN
Maximum size of a debugging buffer.
VOID DbgAllocateMemoryBuffer(VOID)
Get storage area for debugging output.
int ARCH_MAINDECL main(int argc, char **argv)
Initialize the xum1541 device This function tries to find and identify the xum1541 device...
VOID DbgOutputMemoryBuffer(const char *String)
Output into the debugging buffer.
void DbgOutputIntoBuffer(unsigned long BufferNumber, const char *const Format,...)
Append something to the DebugBuffer.
void dbg_memdump(const char *Where, const unsigned char *InputBuffer, const unsigned int Count)
output a memory dump to the debugging system
const UCHAR * DebugNtStatus(NTSTATUS Value)
Return the description of an NTSTATUS code.
unsigned char DbgBuffer[DBG_MAX_BUFFER][DBG_MAX_BUFFERLEN]
void cbm_get_debugging_flags(const char *ModuleName)
Set the debugging flags.
struct DEVICE_EXTENSION_s * PDEVICE_EXTENSION
@@@
VOID DbgInit(VOID)
Initialise debugging system.
#define DBG_MAX_BUFFER
the maximum number of buffers to be used for debugging
VOID DbgFreeMemoryBuffer(VOID)
Free storage area for debugging output.