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.

163 lines
3.8 KiB

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