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.

158 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. debug.c
  5. Author:
  6. ervinp
  7. Environment:
  8. Kernel mode
  9. Revision History:
  10. --*/
  11. #include <WDM.H>
  12. #include <usbdi.h>
  13. #include <usbdlib.h>
  14. #include <usbioctl.h>
  15. #include "usb8023.h"
  16. #include "debug.h"
  17. #if DBG
  18. BOOLEAN dbgTrapOnWarn = FALSE;
  19. BOOLEAN dbgVerbose = FALSE;
  20. BOOLEAN dbgDumpBytes = FALSE; // show all packets; slows us down too much to run
  21. BOOLEAN dbgDumpPktStatesOnEmpty = TRUE;
  22. VOID InitDebug()
  23. {
  24. #if DBG_WRAP_MEMORY
  25. InitializeListHead(&dbgAllMemoryList);
  26. #endif
  27. }
  28. VOID DbgShowBytes(PUCHAR msg, PUCHAR buf, ULONG len)
  29. {
  30. #define PRNT(ch) ((((ch) < ' ') || ((ch) > '~')) ? '.' : (ch))
  31. if (dbgDumpBytes){
  32. ULONG i;
  33. DbgPrint("%s (len %xh @ %p): \r\n", msg, len, buf);
  34. for (i = 0; i < len; i += 16){
  35. DbgPrint(" ");
  36. if (len-i >= 16){
  37. PUCHAR ptr = buf+i;
  38. DbgPrint("%02x %02x %02x %02x %02x %02x %02x %02x "
  39. "%02x %02x %02x %02x %02x %02x %02x %02x "
  40. " "
  41. "%c%c%c%c%c%c%c%c %c%c%c%c%c%c%c%c",
  42. ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7],
  43. ptr[8], ptr[9], ptr[10], ptr[11], ptr[12], ptr[13], ptr[14], ptr[15],
  44. PRNT(ptr[0]), PRNT(ptr[1]), PRNT(ptr[2]), PRNT(ptr[3]),
  45. PRNT(ptr[4]), PRNT(ptr[5]), PRNT(ptr[6]), PRNT(ptr[7]),
  46. PRNT(ptr[8]), PRNT(ptr[9]), PRNT(ptr[10]), PRNT(ptr[11]),
  47. PRNT(ptr[12]), PRNT(ptr[13]), PRNT(ptr[14]), PRNT(ptr[15])
  48. );
  49. }
  50. else {
  51. ULONG j;
  52. for (j = 0; j < 16; j++){
  53. if (j == 8) DbgPrint(" ");
  54. if (i+j < len){
  55. DbgPrint("%02x ", (ULONG)buf[i+j]);
  56. }
  57. else {
  58. DbgPrint(" ");
  59. }
  60. }
  61. DbgPrint(" ");
  62. for (j = 0; j < 16; j++){
  63. if (j == 8) DbgPrint(" ");
  64. if (i+j < len){
  65. UCHAR ch = buf[i+j];
  66. DbgPrint("%c", PRNT(ch));
  67. }
  68. else {
  69. // DbgPrint(" ");
  70. }
  71. }
  72. }
  73. DbgPrint("\r\n");
  74. }
  75. }
  76. }
  77. VOID DbgShowMdlBytes(PUCHAR msg, PMDL mdl)
  78. {
  79. if (dbgDumpBytes){
  80. DbgPrint("\n %s (MDL @ %p): \r\n", msg, mdl);
  81. while (mdl){
  82. #if defined(SPECIAL_WIN98SE_BUILD) || defined(SPECIAL_WINME_BUILD)
  83. PVOID thisBuf = MmGetSystemAddressForMdl(mdl);
  84. #else
  85. PVOID thisBuf = MmGetSystemAddressForMdlSafe(mdl, NormalPoolPriority);
  86. #endif
  87. ULONG thisBufLen = MmGetMdlByteCount(mdl);
  88. if (thisBuf) {
  89. DbgShowBytes(" <MDL buffer>", thisBuf, thisBufLen);
  90. }
  91. mdl = mdl->Next;
  92. }
  93. }
  94. }
  95. DbgDumpPacketList(PUCHAR msg, PLIST_ENTRY listHead)
  96. {
  97. PLIST_ENTRY listEntry;
  98. USBPACKET *packet;
  99. ULONG timeNow = DbgGetSystemTime_msec();
  100. DbgPrint("\n %s: ", msg);
  101. for (listEntry = listHead->Flink; listEntry != listHead; listEntry = listEntry->Flink){
  102. packet = CONTAINING_RECORD(listEntry, USBPACKET, listEntry);
  103. DbgPrint("\n packet #%d @%p - buf @%p, len=%xh, (msg:%xh), age=%d msec", packet->packetId, packet, packet->dataBuffer, packet->dataBufferCurrentLength, *(PULONG)packet->dataBuffer, timeNow-packet->timeStamp);
  104. }
  105. }
  106. VOID DbgDumpPacketStates(ADAPTEREXT *adapter)
  107. {
  108. if (dbgDumpPktStatesOnEmpty){
  109. KIRQL oldIrql;
  110. KeAcquireSpinLock(&adapter->adapterSpinLock, &oldIrql);
  111. DbgPrint("\n *** USB8023 RAN OUT OF PACKETS, dumping packet states: *** ");
  112. DbgDumpPacketList("PENDING READ packets", &adapter->usbPendingReadPackets);
  113. DbgDumpPacketList("PENDING WRITE packets", &adapter->usbPendingWritePackets);
  114. DbgDumpPacketList("COMPLETED READ packets", &adapter->usbCompletedReadPackets);
  115. DbgDumpPacketList("FREE packets", &adapter->usbFreePacketPool);
  116. DbgPrint("\n hit 'g' to continue ...");
  117. DbgBreakPoint();
  118. KeReleaseSpinLock(&adapter->adapterSpinLock, oldIrql);
  119. }
  120. }
  121. #endif