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.

169 lines
3.8 KiB

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