Source code of Windows XP (NT5)
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.

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