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.

208 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. debug.c
  5. Abstract:
  6. Contains debug functions.
  7. Author:
  8. Madan Appiah (madana) 15-Nov-1994
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. --*/
  13. #if DBG
  14. #include <windows.h>
  15. #include <winnt.h>
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <debug.h>
  19. DWORD GlobalDebugFlag = 0;
  20. CRITICAL_SECTION GlobalDebugCritSect;
  21. VOID
  22. TcpsvcsDbgPrintRoutine(
  23. IN DWORD DebugFlag,
  24. IN LPSTR Format,
  25. ...
  26. )
  27. {
  28. #define MAX_PRINTF_LEN 1024 // Arbitrary.
  29. va_list arglist;
  30. char OutputBuffer[MAX_PRINTF_LEN];
  31. ULONG length;
  32. static BeginningOfLine = TRUE;
  33. LPSTR Text;
  34. //
  35. // If we aren't debugging this functionality, just return.
  36. //
  37. if ( DebugFlag != 0 && (GlobalDebugFlag & DebugFlag) == 0 ) {
  38. return;
  39. }
  40. length = 0;
  41. //
  42. // Handle the beginning of a new line.
  43. //
  44. //
  45. if ( BeginningOfLine ) {
  46. length += (ULONG) sprintf( &OutputBuffer[length], "[Cache] "
  47. );
  48. //
  49. // Put the timestamp at the begining of the line.
  50. //
  51. IF_DEBUG( TIMESTAMP ) {
  52. SYSTEMTIME SystemTime;
  53. GetLocalTime( &SystemTime );
  54. length += (ULONG) sprintf( &OutputBuffer[length],
  55. "%02u/%02u %02u:%02u:%02u ",
  56. SystemTime.wMonth,
  57. SystemTime.wDay,
  58. SystemTime.wHour,
  59. SystemTime.wMinute,
  60. SystemTime.wSecond );
  61. }
  62. //
  63. // Indicate the type of message on the line
  64. //
  65. switch (DebugFlag) {
  66. case DEBUG_ERRORS:
  67. Text = "ERROR";
  68. break;
  69. case DEBUG_REGISTRY:
  70. Text = "LEASE";
  71. break;
  72. case DEBUG_MISC:
  73. Text = "MISC";
  74. break;
  75. case DEBUG_SCAVENGER:
  76. Text = "SCAVENGER";
  77. break;
  78. case DEBUG_SORT:
  79. Text = "SORT";
  80. break;
  81. case DEBUG_CONTAINER:
  82. Text = "CONTAINER";
  83. break;
  84. case DEBUG_APIS:
  85. Text = "APIS";
  86. break;
  87. case DEBUG_FILE_VALIDATE:
  88. Text = "FILE_VALIDATE";
  89. break;
  90. case DEBUG_MEM_ALLOC:
  91. Text = "MEM_ALLOC";
  92. break;
  93. default:
  94. Text = NULL;
  95. break;
  96. }
  97. if ( Text != NULL ) {
  98. length += (ULONG) sprintf( &OutputBuffer[length], "[%s] ", Text );
  99. }
  100. }
  101. //
  102. // Put a the information requested by the caller onto the line
  103. //
  104. //
  105. // vsprintf isn't multithreaded + we don't want to intermingle output
  106. // from different threads.
  107. //
  108. EnterCriticalSection( &GlobalDebugCritSect );
  109. va_start(arglist, Format);
  110. length += (ULONG) vsprintf(&OutputBuffer[length], Format, arglist);
  111. BeginningOfLine = (length > 0 && OutputBuffer[length-1] == '\n' );
  112. va_end(arglist);
  113. TcpsvcsDbgAssert(length <= MAX_PRINTF_LEN);
  114. //
  115. // Output to the debug terminal,
  116. //
  117. (void) DEBUG_PRINT( (PCH) OutputBuffer);
  118. LeaveCriticalSection( &GlobalDebugCritSect );
  119. }
  120. VOID
  121. TcpsvcsDbgAssertFailed(
  122. LPSTR FailedAssertion,
  123. LPSTR FileName,
  124. DWORD LineNumber,
  125. LPSTR Message
  126. )
  127. /*++
  128. Routine Description:
  129. Assertion failed.
  130. Arguments:
  131. FailedAssertion :
  132. FileName :
  133. LineNumber :
  134. Message :
  135. Return Value:
  136. none.
  137. --*/
  138. {
  139. TcpsvcsDbgPrint(( 0, "Assert @ %s \n", FailedAssertion ));
  140. TcpsvcsDbgPrint(( 0, "Assert Filename, %s \n", FileName ));
  141. TcpsvcsDbgPrint(( 0, "Line Num. = %ld.\n", LineNumber ));
  142. TcpsvcsDbgPrint(( 0, "Message is %s\n", Message ));
  143. DebugBreak();
  144. }
  145. #endif // DBG
  146.