📄 debug.h
字号:
/*++
Copyright (c) 1995 Microsoft Corporation
Module Name:
debug.h
Abstract:
debug defines shared between the KD extensions and the driver
Author:
Jim Mateer 4/1/97
Revision History:
--*/
#ifndef _DEBUG_
#define _DEBUG_
//
// Debug Level and Mask definitions.
//
#define DBG_DEATH 1
#define DBG_CRITICAL_ERROR 2
#define DBG_FAILURE 4
#define DBG_INFO 6
#define DBG_TRACE 8
#define DBG_VERBOSE 10
#define DBG_INIT 0x00000001
#define DBG_MINIPORT 0x00000002
#define DBG_PROTOCOL 0x00000004
#define DBG_SEND 0x00000008
#define DBG_RECEIVE 0x00000010
#define DBG_IO 0x00000020
#define DBG_MEMORY 0x00000040
#define DBG_CM 0x00000080
#define DBG_REFCNTS 0x00000100
#define DBG_VC 0x00000200
#define DBG_TIMERQ 0x00000400
#define DBG_ALL 0xFFFFFFFF
//
// these tags are used in Lookaside lists therefore need to be available regardless of
// the type of build
//
extern ULONG NdisRequestTag;
extern ULONG NdisReqCompletionCtxtTag;
extern ULONG PLogTag;
extern ULONG AdapterVCTag;
extern ULONG ClientVCTag;
#if BINARY_COMPATIBLE
//
// Win9X defines
//
#if DBG
#define STATIC
//
// signatures for data structures
//
extern ULONG AdapterTag;
extern ULONG ClientTag;
extern ULONG CMParamsTag;
extern ULONG DevInstanceTag;
extern ULONG LookaheadBufferTag;
extern ULONG MediaAreaTag;
extern ULONG PacketArrayTag;
extern ULONG PacketContextTag;
extern ULONG PacketTag;
extern ULONG ResidualBufferTag;
extern ULONG WQItemTag;
extern CHAR VersionNumber[];
extern CHAR VersionHerald[];
extern CHAR VersionTimestamp[];
//
// these correspond to DebugLevel and DebugMask in Psched\Parameters
//
extern ULONG DbgTraceLevel;
extern ULONG DbgTraceMask;
#define ImDbgOut(_DebugLevel, _DebugMask, _Out) { \
if ((DbgTraceLevel >= _DebugLevel) && \
((_DebugMask) & DbgTraceMask)) { \
DbgPrint("IMSamp: "); \
DbgPrint _Out; \
} \
}
#define ImDbgOutNoID(_DebugLevel, _DebugMask, _Out) { \
if ((DbgTraceLevel >= _DebugLevel) && \
((_DebugMask) & DbgTraceMask)) { \
DbgPrint _Out; \
} \
}
#define KdPrint( x ) DbgPrint x
#define DEBUGCHK _asm { int 3 }
#define STRUCT_TAG ULONG Tag
#define IMSetTag( s, t ) (s)->Tag = t##Tag
#define IMStructAssert( _tag ) if ((_tag) != NULL && (_tag)->Tag != _tag##Tag) {\
DbgPrint( "IMSamp: structure assertion failure for type " #_tag " in file " __FILE__ " line %d\n", __LINE__ );\
DEBUGCHK;\
}
// same thing but when structure name is different from tag name
#define IMStructAssert1( _struct, _tag ) if ((_struct) != NULL && (_struct)->Tag != _tag##Tag) {\
DbgPrint( "IMSamp: structure assertion failure for type " #_tag " in file " __FILE__ " line %d\n", __LINE__ );\
DEBUGCHK;\
}
#define IMAssert(c) if (!(c)) {\
DbgPrint( "IMSamp: assertion @ line %d in file " __FILE__ " \n", __LINE__ );\
DEBUGCHK;\
}
//
// allocate memory and set the tag in the checked version of the structure.
// NdisFreeMemory needs the size in order to free a block of memory (duh).
// add sizeof(ULONG) to the length and store the structure size in the first
// ULONG, returning the next ULONG as the start of the allocated area. Some
// structures are dynamic in length and figuring out their lengths when
// freeing them could be a pain. Besides, I didn't account for needing the
// size when freeing the struct so this is basically a hack to get around this
//
#define IMAllocatePool( _addr, _size, _tag ) \
{ \
NDIS_PHYSICAL_ADDRESS HighAddress = NDIS_PHYSICAL_ADDRESS_CONST( -1, -1 ); \
PCHAR _Temp; \
ULONG _Size = (_size) + sizeof(ULONG); \
NdisAllocateMemory( &_Temp, _Size, 0, HighAddress); \
if ( _Temp ) { \
NdisZeroMemory( _Temp, _Size ); \
*(PULONG)_Temp = _Size; \
(PCHAR)(_addr) = _Temp + sizeof(ULONG); \
_addr->Tag = _tag##Tag; \
ImDbgOut( DBG_VERBOSE, DBG_MEMORY, ("Mem Alloc'ed %08x for %6d bytes\n", _addr, _size ));\
} else { \
(PCHAR)(_addr) = _Temp; \
} \
}
#define IMAllocatePoolNoStructTag( _addr, _size, _tag ) \
{ \
NDIS_PHYSICAL_ADDRESS HighAddress = NDIS_PHYSICAL_ADDRESS_CONST( -1, -1 ); \
PCHAR _Temp; \
ULONG _Size = (_size) + sizeof(ULONG); \
NdisAllocateMemory( &_Temp, _Size, 0, HighAddress); \
if ( _Temp ) { \
NdisZeroMemory( _Temp, _Size ); \
*(PULONG)_Temp = _Size; \
(PCHAR)(_addr) = _Temp + sizeof(ULONG); \
ImDbgOut( DBG_VERBOSE, DBG_MEMORY, ("Mem Alloc'ed %08x for %6d bytes\n", _addr, _size ));\
} else { \
(PCHAR)(_addr) = _Temp; \
} \
}
#define IMFreePool( _addr ) \
{ \
PCHAR _Temp = (PCHAR)(_addr) - sizeof(ULONG); \
ULONG _Size = *(PULONG)_Temp; \
NdisFreeMemory( _Temp, _Size, 0 ); \
ImDbgOut( DBG_VERBOSE, DBG_MEMORY, ("Mem Freed %08x\n", _addr )); \
}
#else // DBG
#define DEBUGCHK
#define ImDbgOut(s,t,u)
#define ImDbgOutNoID(s,t,u)
#define KdPrint( x )
#define STRUCT_TAG /##/
#define IMSetTag( s, t )
#define IMStructAssert( t )
#define IMStructAssert1( s, t )
#define IMAssert(c)
//
// see explanation in dbg section for why all this hacking is being done.
//
#define IMAllocatePool( _addr, _size, _tag ) \
{ \
NDIS_PHYSICAL_ADDRESS HighAddress = NDIS_PHYSICAL_ADDRESS_CONST( -1, -1 ); \
PCHAR _Temp; \
ULONG _Size = (_size) + sizeof(ULONG); \
NdisAllocateMemory( &_Temp, _Size, 0, HighAddress); \
if ( _Temp ) { \
NdisZeroMemory( _Temp, _Size ); \
*(PULONG)_Temp = _Size; \
(PCHAR)(_addr) = _Temp + sizeof(ULONG); \
} else { \
(PCHAR)(_addr) = _Temp; \
} \
}
#define IMAllocatePoolNoStructTag( _addr, _size, _tag ) \
{ \
NDIS_PHYSICAL_ADDRESS HighAddress = NDIS_PHYSICAL_ADDRESS_CONST( -1, -1 ); \
PCHAR _Temp; \
ULONG _Size = (_size) + sizeof(ULONG); \
NdisAllocateMemory( &_Temp, _Size, 0, HighAddress); \
if ( _Temp ) { \
NdisZeroMemory( _Temp, _Size ); \
*(PULONG)_Temp = _Size; \
(PCHAR)(_addr) = _Temp + sizeof(ULONG); \
} else { \
(PCHAR)(_addr) = _Temp; \
} \
}
#define IMFreePool( _addr ) \
{ \
PCHAR _Temp = (PCHAR)(_addr) - sizeof(ULONG); \
ULONG _Size = *(PULONG)_Temp; \
NdisFreeMemory( _Temp, _Size, 0 ); \
}
#define STATIC static
#endif // DBG
#else // BINARY_COMPATIBLE
//
// NT Debugging routines
//
#if DBG
//
// signatures for data structures
//
extern ULONG AdapterTag;
extern ULONG AdapterVCTag;
extern ULONG ClientTag;
extern ULONG ClientVCTag;
extern ULONG CMParamsTag;
extern ULONG DevInstanceTag;
extern ULONG LookaheadBufferTag;
extern ULONG MediaAreaTag;
extern ULONG PacketArrayTag;
extern ULONG PacketContextTag;
extern ULONG PacketTag;
extern ULONG ResidualBufferTag;
extern ULONG WQItemTag;
extern CHAR VersionNumber[];
extern CHAR VersionHerald[];
extern CHAR VersionTimestamp[];
#define DEBUGCHK DbgBreakPoint()
#define STATIC
//
// these correspond to DebugLevel and DebugMask in ImSamp\Parameters
//
extern ULONG DbgTraceLevel;
extern ULONG DbgTraceMask;
#define ImDbgOut(_DebugLevel, _DebugMask, _Out) { \
if ((DbgTraceLevel >= _DebugLevel) && \
((_DebugMask) & DbgTraceMask)) { \
DbgPrint("IMSamp: "); \
DbgPrint _Out; \
} \
}
#define ImDbgOutNoID(_DebugLevel, _DebugMask, _Out) { \
if ((DbgTraceLevel >= _DebugLevel) && \
((_DebugMask) & DbgTraceMask)) { \
DbgPrint _Out; \
} \
}
#define KdPrint( x ) DbgPrint x
#define STRUCT_TAG ULONG Tag
#define IMSetTag( s, t ) (s)->Tag = t##Tag
#define IMStructAssert( _tag ) if ((_tag) != NULL && (_tag)->Tag != _tag##Tag) {\
DbgPrint( "IMSamp: structure assertion failure for type " #_tag " in file " __FILE__ " line %d\n", __LINE__ );\
DEBUGCHK;\
}
// same thing but when structure name is different from tag name
#define IMStructAssert1( _struct, _tag ) if ((_struct) != NULL && (_struct)->Tag != _tag##Tag) {\
DbgPrint( "IMSamp: structure assertion failure for type " #_tag " in file " __FILE__ " line %d\n", __LINE__ );\
DEBUGCHK;\
}
#define IMAssert(c) if (!(c)) {\
DbgPrint( "IMSamp: assertion @ line %d in file " __FILE__ " \n", __LINE__ );\
DEBUGCHK;\
}
//
// allocate memory from nonpaged pool and set the tag in the checked
// version of the structure
//
#define IMAllocatePool( _addr, _size, _tag ) \
_addr = ExAllocatePoolWithTag( NonPagedPool, (_size), (_tag##Tag)); \
if ( _addr ) { \
NdisZeroMemory( _addr, _size ); \
_addr->Tag = _tag##Tag; \
ImDbgOut( DBG_VERBOSE, DBG_MEMORY, ("Mem Alloc'ed %08x for %6d bytes\n", _addr, _size )); \
}
#define IMAllocatePoolNoStructTag( _addr, _size, _tag ) \
_addr = ExAllocatePoolWithTag( NonPagedPool, (_size), (_tag##Tag)); \
if ( _addr ) { \
NdisZeroMemory( _addr, _size ); \
ImDbgOut( DBG_VERBOSE, DBG_MEMORY, ("Mem Alloc'ed %08x for %6d bytes\n", _addr, _size )); \
}
#define IMFreePool( _addr ) \
ExFreePool( _addr ); \
ImDbgOut( DBG_VERBOSE, DBG_MEMORY, ("Mem Freed %08x\n", _addr ))
#else // DBG
#define DEBUGCHK
#define ImDbgOut(s,t,u)
#define ImDbgOutNoID(s,t,u)
#define KdPrint( x )
#define STRUCT_TAG /##/
#define IMSetTag( s, t )
#define IMStructAssert( t )
#define IMStructAssert1( s, t )
#define IMAssert(c)
#define IMAllocatePool( _addr, _size, _tag ) \
_addr = ExAllocatePool( NonPagedPool, (_size)); \
if ( _addr ) { \
NdisZeroMemory( _addr, _size ); \
}
#define IMAllocatePoolNoStructTag( _addr, _size, _tag ) \
_addr = ExAllocatePool( NonPagedPool, (_size)); \
if ( _addr ) { \
NdisZeroMemory( _addr, _size ); \
}
#define IMFreePool( _addr ) ExFreePool( _addr )
#define STATIC static
#endif // DBG
#endif // BINARY_COMPATIBLE
#endif /* _DEBUG_ */
/* end debug.h */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -