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.

171 lines
3.1 KiB

  1. /*******************************************************************/
  2. /* Copyright(c) 1993 Microsoft Corporation */
  3. /*******************************************************************/
  4. //***
  5. //
  6. // Filename: ipxcpdbg.c
  7. //
  8. // Description: Debug Stuff
  9. //
  10. // Author: Stefan Solomon (stefans) October 27, 1995.
  11. //
  12. // Revision History:
  13. //
  14. //***
  15. #include "precomp.h"
  16. #pragma hdrstop
  17. //*** TRACE ID FOR RIP ***
  18. DWORD IpxCpTraceID;
  19. DWORD DbgLevel = DEFAULT_DEBUG;
  20. HANDLE DbgLogFileHandle = INVALID_HANDLE_VALUE;
  21. //
  22. // Debug switch which directs debug output to console or file
  23. //
  24. // values:
  25. // 1 - Console Debug
  26. // > 1 - log file: ipxcpdbg.log in the root directory
  27. // 2 - resets the log file for each new connection
  28. DWORD DebugLog;
  29. #if DBG
  30. VOID
  31. SsDbgInitialize(VOID)
  32. {
  33. if (DebugLog == 1) {
  34. CONSOLE_SCREEN_BUFFER_INFO csbi;
  35. COORD coord;
  36. (VOID)AllocConsole( );
  37. (VOID)GetConsoleScreenBufferInfo(
  38. GetStdHandle(STD_OUTPUT_HANDLE),
  39. &csbi
  40. );
  41. coord.X = (SHORT)(csbi.srWindow.Right - csbi.srWindow.Left + 1);
  42. coord.Y = (SHORT)((csbi.srWindow.Bottom - csbi.srWindow.Top + 1) * 20);
  43. (VOID)SetConsoleScreenBufferSize(
  44. GetStdHandle(STD_OUTPUT_HANDLE),
  45. coord
  46. );
  47. }
  48. if(DebugLog > 1) {
  49. DbgLogFileHandle = CreateFile("\\ipxcpdbg.log",
  50. GENERIC_READ | GENERIC_WRITE,
  51. FILE_SHARE_READ,
  52. NULL,
  53. CREATE_ALWAYS,
  54. 0,
  55. NULL);
  56. }
  57. }
  58. #endif
  59. #if DBG
  60. VOID
  61. SsResetDbgLogFile(VOID)
  62. {
  63. if(DebugLog == 2) {
  64. // reset the debug log file at the beginning for each new connection
  65. if(DbgLogFileHandle != INVALID_HANDLE_VALUE) {
  66. SetFilePointer(DbgLogFileHandle, 0, NULL, FILE_BEGIN);
  67. }
  68. }
  69. }
  70. #endif
  71. #if DBG
  72. VOID
  73. SsAssert(
  74. IN PVOID FailedAssertion,
  75. IN PVOID FileName,
  76. IN ULONG LineNumber
  77. )
  78. {
  79. SS_PRINT(("\nAssertion failed: %s\n at line %ld of %s\n",
  80. FailedAssertion, LineNumber, FileName));
  81. DbgUserBreakPoint( );
  82. } // SsAssert
  83. #endif
  84. #if DBG
  85. VOID
  86. SsPrintf (
  87. char *Format,
  88. ...
  89. )
  90. {
  91. va_list arglist;
  92. char OutputBuffer[1024];
  93. ULONG length;
  94. va_start( arglist, Format );
  95. vsprintf( OutputBuffer, Format, arglist );
  96. va_end( arglist );
  97. length = strlen( OutputBuffer );
  98. WriteFile( GetStdHandle(STD_OUTPUT_HANDLE), (LPVOID )OutputBuffer, length, &length, NULL );
  99. if(DbgLogFileHandle != INVALID_HANDLE_VALUE) {
  100. WriteFile(DbgLogFileHandle, (LPVOID )OutputBuffer, length, &length, NULL );
  101. }
  102. } // SsPrintf
  103. #endif
  104. VOID
  105. StartTracing(VOID)
  106. {
  107. IpxCpTraceID = TraceRegister("IPXCP");
  108. }
  109. VOID
  110. TraceIpx(ULONG ComponentID,
  111. char *Format,
  112. ...)
  113. {
  114. va_list arglist;
  115. va_start(arglist, Format);
  116. TraceVprintfEx(IpxCpTraceID,
  117. ComponentID | TRACE_USE_MASK,
  118. Format,
  119. arglist);
  120. va_end(arglist);
  121. }
  122. VOID
  123. StopTracing(VOID)
  124. {
  125. TraceDeregister(IpxCpTraceID);
  126. }