Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
8.1 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. debug.h
  5. Abstract:
  6. This file contains definitions related to debugging.
  7. Author:
  8. Forrest Foltz (forrestf)
  9. Ervin P.
  10. Revision History:
  11. --*/
  12. #define BAD_POINTER ((PVOID) (ULONG_PTR)-0x50)
  13. #define ISPTR(ptr) ((ptr) && ((ptr) != BAD_POINTER))
  14. #if DBG
  15. #define DBG_LEADCHAR '\'' // required for kd debugger routing on NT
  16. #define TRAP \
  17. { \
  18. DbgPrint("%cHIDCLASS> Code coverage trap: file %s, line %d \n", DBG_LEADCHAR, __FILE__, __LINE__ ); \
  19. DbgBreakPoint(); \
  20. }
  21. #define SS_TRAP \
  22. { \
  23. if (dbgTrapOnSS) { \
  24. DbgPrint("%cHIDCLASS> Selective suspend trap: file %s, line %d \n", DBG_LEADCHAR, __FILE__, __LINE__ ); \
  25. DbgBreakPoint(); \
  26. }\
  27. }
  28. extern BOOLEAN dbgTrapOnWarn;
  29. extern BOOLEAN dbgTrapOnSS;
  30. extern BOOLEAN dbgInfo;
  31. extern BOOLEAN dbgVerbose;
  32. extern BOOLEAN dbgSkipSecurity;
  33. extern BOOLEAN dbgTrapOnHiccup;
  34. #define DBGWARN(args_in_parens) \
  35. { \
  36. DbgPrint("%cHIDCLASS> *** WARNING *** (file %s, line %d)\n", DBG_LEADCHAR, __FILE__, __LINE__ ); \
  37. DbgPrint("%c > ", DBG_LEADCHAR); \
  38. DbgPrint args_in_parens; \
  39. DbgPrint("\n"); \
  40. if (dbgTrapOnWarn){ \
  41. DbgBreakPoint(); \
  42. } \
  43. }
  44. #define DBGERR(args_in_parens) \
  45. { \
  46. DbgPrint("%cHIDCLASS> *** ERROR *** (file %s, line %d)\n", DBG_LEADCHAR, __FILE__, __LINE__ ); \
  47. DbgPrint("%c > ", DBG_LEADCHAR); \
  48. DbgPrint args_in_parens; \
  49. DbgPrint("\n"); \
  50. DbgBreakPoint(); \
  51. }
  52. #define DBGASSERT(check, args_in_parens, trap) \
  53. { \
  54. if (!(check)) { \
  55. if (trap) { \
  56. DBGERR(args_in_parens); \
  57. } else { \
  58. DBGWARN(args_in_parens); \
  59. } \
  60. } \
  61. }
  62. #define DBGSTATE(current, expected, trap) \
  63. DBGASSERT(current == expected, \
  64. ("Expected state %d, got state %d", expected, current), \
  65. trap)
  66. #define DBGSUCCESS(status, trap) \
  67. DBGASSERT(NT_SUCCESS(status), \
  68. ("Not STATUS_SUCCESS, actual status = %x", status), \
  69. trap)
  70. #define DBGOUT(args_in_parens) \
  71. { \
  72. DbgPrint("%cHIDCLASS> ", DBG_LEADCHAR); \
  73. DbgPrint args_in_parens; \
  74. DbgPrint("\n"); \
  75. }
  76. #define DBGVERBOSE(args_in_parens) if (dbgVerbose){ DBGOUT(args_in_parens); }
  77. #define DBGINFO(args_in_parens) if (dbgInfo){ DBGOUT(args_in_parens); }
  78. typedef struct {
  79. // exactly 16 bytes long for easy debugger viewing
  80. PDEVICE_OBJECT devObj;
  81. #define dbgDevObjRecord_STRINGSIZE 12
  82. CHAR str[dbgDevObjRecord_STRINGSIZE];
  83. } dbgDevObjRecord;
  84. typedef struct {
  85. // exactly 16 bytes long for easy debugger viewing
  86. ULONG marker;
  87. ULONG reportId;
  88. ULONG type;
  89. ULONG completed;
  90. } dbgFeatureRecord;
  91. typedef struct {
  92. // exactly 16 bytes long for easy debugger viewing
  93. ULONG_PTR irpPtr;
  94. ULONG length;
  95. ULONG reportId;
  96. ULONG completed;
  97. } dbgReadRecord;
  98. typedef struct {
  99. // exactly 16 bytes long for easy debugger viewing
  100. ULONG_PTR irpPtr;
  101. ULONG func;
  102. ULONG isForCollectionPdo;
  103. ULONG status;
  104. } dbgPnPIrpRecord;
  105. typedef struct {
  106. // exactly 16 bytes long for easy debugger viewing
  107. UCHAR collectionNumber;
  108. UCHAR numRecipients;
  109. UCHAR reportBytes[14];
  110. } dbgReportRecord;
  111. extern ULONG dbgLastEntry;
  112. VOID DbgCommonEntryExit(BOOLEAN isEntering);
  113. VOID DbgRecordDevObj(PDEVICE_OBJECT devObj, PCHAR str);
  114. VOID DbgRecordReport(ULONG reportId, ULONG controlCode, BOOLEAN isComplete);
  115. VOID DbgRecordRead(PIRP irp, ULONG length, ULONG reportId, ULONG completed);
  116. VOID DbgLogIrpMajor(ULONG_PTR irpPtr, ULONG majorFunc, ULONG isForCollectionPdo, ULONG isComplete, ULONG status);
  117. VOID DbgLogPnpIrp(ULONG_PTR irpPtr, ULONG minorFunc, ULONG isForCollectionPdo, ULONG isComplete, ULONG status);
  118. VOID DbgLogPowerIrp(PVOID devExt, UCHAR minorFunc, ULONG isClientPdo, ULONG isComplete, PCHAR type, ULONG powerState, ULONG status);
  119. VOID DbgLogReport(ULONG collectionNumber, ULONG numRecipients, ULONG numPending, ULONG numFailed, PUCHAR report, ULONG reportLength);
  120. VOID DbgLogIoctl(ULONG_PTR fdo, ULONG ioControlCode, ULONG status);
  121. #define DBG_COMMON_ENTRY() DbgCommonEntryExit(TRUE);
  122. #define DBG_COMMON_EXIT() DbgCommonEntryExit(FALSE);
  123. #define DBG_RECORD_DEVOBJ(devObj, str) DbgRecordDevObj(devObj, str);
  124. #define DBG_RECORD_REPORT(reportId, controlCode, isComplete) \
  125. DbgRecordReport(reportId, controlCode, isComplete);
  126. #define DBG_RECORD_READ(irp, length, reportId, completed) \
  127. DbgRecordRead(irp, length, reportId, completed);
  128. #define DBG_LOG_IRP_MAJOR(irp, majorFunc, isForCollectionPdo, isComplete, status) \
  129. DbgLogIrpMajor((ULONG_PTR)(irp), (ULONG)(majorFunc), (ULONG)(isForCollectionPdo), (ULONG)(isComplete), (ULONG)(status));
  130. #define DBG_LOG_PNP_IRP(irp, minorFunc, isForCollectionPdo, isComplete, status) \
  131. DbgLogPnpIrp((ULONG_PTR)(irp), (ULONG)(minorFunc), (ULONG)(isForCollectionPdo), (ULONG)(isComplete), (ULONG)(status));
  132. #define DBG_LOG_POWER_IRP(devExt, minorFunc, isClientPdo, isComplete, type, powerState, status) \
  133. DbgLogPowerIrp(devExt, minorFunc, isClientPdo, isComplete, type, powerState, status);
  134. #define DBG_LOG_REPORT(collectionNumber, numRecipients, numPending, numFailed, report, reportLength) \
  135. DbgLogReport(collectionNumber, numRecipients, numPending, numFailed, report, reportLength);
  136. #define DBG_LOG_IOCTL(fdo, ioControlCode, status) \
  137. DbgLogIoctl((ULONG_PTR)fdo, ioControlCode, status);
  138. #define RUNNING_DISPATCH() \
  139. if (KeGetCurrentIrql() != DISPATCH_LEVEL) { \
  140. KdPrint(( "EX: Pageable code called at IRQL %d\n", KeGetCurrentIrql() )); \
  141. ASSERT(FALSE); \
  142. }
  143. #else
  144. #define DBGSTATE(current, expected, trap)
  145. #define DBGSUCCESS(status, trap)
  146. #define DBGASSERT(check, args_in_parens, trap)
  147. #define DBGWARN(args_in_parens)
  148. #define DBGERR(args_in_parens)
  149. #define DBGOUT(args_in_parens)
  150. #define DBGVERBOSE(args_in_parens)
  151. #define DBGINFO(args_in_parens)
  152. #define TRAP
  153. #define SS_TRAP
  154. #define DBG_COMMON_ENTRY()
  155. #define DBG_COMMON_EXIT()
  156. #define DBG_RECORD_DEVOBJ(devObj, str)
  157. #define DBG_RECORD_REPORT(reportId, controlCode, isComplete)
  158. #define DBG_RECORD_READ(irp, length, reportId, completed)
  159. #define DBG_LOG_IRP_MAJOR(irp, majorFunc, isForCollectionPdo, isComplete, status)
  160. #define DBG_LOG_PNP_IRP(irp, minorFunc, isForCollectionPdo, isComplete, status)
  161. #define DBG_LOG_POWER_IRP(devExt, minorFunc, isClientPdo, isComplete, type, powerState, status)
  162. #define DBG_LOG_REPORT(collectionNumber, numRecipients, numPending, numFailed, report, reportLength)
  163. #define DBG_LOG_IOCTL(fdo, ioControlCode, status)
  164. #define RUNNING_DISPATCH()
  165. #endif