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.

152 lines
4.2 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. PVOID thisBuf = MmGetSystemAddressForMdl(mdl);
  83. ULONG thisBufLen = MmGetMdlByteCount(mdl);
  84. DbgShowBytes(" <MDL buffer>", thisBuf, thisBufLen);
  85. mdl = mdl->Next;
  86. }
  87. }
  88. }
  89. DbgDumpPacketList(PUCHAR msg, PLIST_ENTRY listHead)
  90. {
  91. PLIST_ENTRY listEntry;
  92. USBPACKET *packet;
  93. ULONG timeNow = DbgGetSystemTime_msec();
  94. DbgPrint("\n %s: ", msg);
  95. for (listEntry = listHead->Flink; listEntry != listHead; listEntry = listEntry->Flink){
  96. packet = CONTAINING_RECORD(listEntry, USBPACKET, listEntry);
  97. 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);
  98. }
  99. }
  100. VOID DbgDumpPacketStates(ADAPTEREXT *adapter)
  101. {
  102. if (dbgDumpPktStatesOnEmpty){
  103. KIRQL oldIrql;
  104. KeAcquireSpinLock(&adapter->adapterSpinLock, &oldIrql);
  105. DbgPrint("\n *** USB8023 RAN OUT OF PACKETS, dumping packet states: *** ");
  106. DbgDumpPacketList("PENDING READ packets", &adapter->usbPendingReadPackets);
  107. DbgDumpPacketList("PENDING WRITE packets", &adapter->usbPendingWritePackets);
  108. DbgDumpPacketList("COMPLETED READ packets", &adapter->usbCompletedReadPackets);
  109. DbgDumpPacketList("FREE packets", &adapter->usbFreePacketPool);
  110. DbgPrint("\n hit 'g' to continue ...");
  111. DbgBreakPoint();
  112. KeReleaseSpinLock(&adapter->adapterSpinLock, oldIrql);
  113. }
  114. }
  115. #endif