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.

164 lines
3.9 KiB

  1. // Copyright (c) 1997, Microsoft Corporation, all rights reserved
  2. // Copyright (c) 1997, Parallel Technologies, Inc., all rights reserved
  3. //
  4. // debug.c
  5. // DirectParallel WAN mini-port/call-manager driver
  6. // Debug utilities and globals
  7. //
  8. // 01/07/97 Steve Cobb
  9. // 09/15/97 Jay Lowe, Parallel Technologies, Inc.
  10. #include "ptiwan.h"
  11. //-----------------------------------------------------------------------------
  12. // Global data definitions
  13. //-----------------------------------------------------------------------------
  14. #ifdef TESTMODE
  15. #pragma message( "TESTMODE defined, building private spew" )
  16. #define DEFAULTTRACELEVEL TL_N
  17. #define DEFAULTTRACEMASK TM_Base
  18. #else
  19. #define DEFAULTTRACELEVEL TL_None
  20. #define DEFAULTTRACEMASK TM_Base
  21. #endif
  22. // Active debug trace level and active trace set mask. Set these variables
  23. // with the debugger at startup to enable and filter the debug output. All
  24. // messages with (TL_*) level less than or equal to 'g_ulTraceLevel' are
  25. // displayed. All messages from any (TM_*) set(s) present in 'g_ulTraceMask'
  26. // are displayed.
  27. //
  28. ULONG g_ulTraceLevel = DEFAULTTRACELEVEL;
  29. ULONG g_ulTraceMask = DEFAULTTRACEMASK;
  30. //-----------------------------------------------------------------------------
  31. // Routines
  32. //-----------------------------------------------------------------------------
  33. #if DBG
  34. VOID
  35. CheckList(
  36. IN LIST_ENTRY* pList,
  37. IN BOOLEAN fShowLinks )
  38. // Tries to detect corruption in list 'pList', printing verbose linkage
  39. // output if 'fShowLinks' is set.
  40. //
  41. {
  42. LIST_ENTRY* pLink;
  43. ULONG ul;
  44. ul = 0;
  45. for (pLink = pList->Flink;
  46. pLink != pList;
  47. pLink = pLink->Flink)
  48. {
  49. if (fShowLinks)
  50. {
  51. DbgPrint( "RASPTI: CheckList($%p) Flink(%d)=$%p\n",
  52. pList, ul, pLink );
  53. }
  54. ++ul;
  55. }
  56. for (pLink = pList->Blink;
  57. pLink != pList;
  58. pLink = pLink->Blink)
  59. {
  60. if (fShowLinks)
  61. {
  62. DbgPrint( "RASPTI: CheckList($%p) Blink(%d)=$%p\n",
  63. pList, ul, pLink );
  64. }
  65. --ul;
  66. }
  67. if (ul)
  68. {
  69. DbgBreakPoint();
  70. }
  71. }
  72. #endif
  73. #if DBG
  74. VOID
  75. Dump(
  76. IN CHAR* p,
  77. IN ULONG cb,
  78. IN BOOLEAN fAddress,
  79. IN ULONG ulGroup )
  80. // Hex dump 'cb' bytes starting at 'p' grouping 'ulGroup' bytes together.
  81. // For example, with 'ulGroup' of 1, 2, and 4:
  82. //
  83. // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
  84. // 0000 0000 0000 0000 0000 0000 0000 0000 |................|
  85. // 00000000 00000000 00000000 00000000 |................|
  86. //
  87. // If 'fAddress' is true, the memory address dumped is prepended to each
  88. // line.
  89. //
  90. {
  91. while (cb)
  92. {
  93. INT cbLine;
  94. cbLine = (cb < DUMP_BytesPerLine) ? cb : DUMP_BytesPerLine;
  95. DumpLine( p, cbLine, fAddress, ulGroup );
  96. cb -= cbLine;
  97. p += cbLine;
  98. }
  99. }
  100. #endif
  101. #if DBG
  102. VOID
  103. DumpLine(
  104. IN CHAR* p,
  105. IN ULONG cb,
  106. IN BOOLEAN fAddress,
  107. IN ULONG ulGroup )
  108. {
  109. CHAR* pszDigits = "0123456789ABCDEF";
  110. CHAR szHex[ ((2 + 1) * DUMP_BytesPerLine) + 1 ];
  111. CHAR* pszHex = szHex;
  112. CHAR szAscii[ DUMP_BytesPerLine + 1 ];
  113. CHAR* pszAscii = szAscii;
  114. ULONG ulGrouped = 0;
  115. if (fAddress)
  116. DbgPrint( "RASPTI: %p: ", p );
  117. else
  118. DbgPrint( "RASPTI: " );
  119. while (cb)
  120. {
  121. *pszHex++ = pszDigits[ ((UCHAR )*p) / 16 ];
  122. *pszHex++ = pszDigits[ ((UCHAR )*p) % 16 ];
  123. if (++ulGrouped >= ulGroup)
  124. {
  125. *pszHex++ = ' ';
  126. ulGrouped = 0;
  127. }
  128. *pszAscii++ = (*p >= 32 && *p < 128) ? *p : '.';
  129. ++p;
  130. --cb;
  131. }
  132. *pszHex = '\0';
  133. *pszAscii = '\0';
  134. DbgPrint(
  135. "%-*s|%-*s|\n",
  136. (2 * DUMP_BytesPerLine) + (DUMP_BytesPerLine / ulGroup), szHex,
  137. DUMP_BytesPerLine, szAscii );
  138. }
  139. #endif