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.

190 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 200 Microsoft Corporation
  3. Module Name:
  4. assrt.cxx
  5. Abstract:
  6. assertion code used by BS_ASSERT
  7. Author:
  8. Revision History:
  9. Name Date Comments
  10. brianb 04/19/2000 created
  11. aoltean 06/20/2000 Adding VssSetDebugReport
  12. --*/
  13. extern "C" {
  14. #include <nt.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. }
  18. #include <windows.h>
  19. #include <stdio.h>
  20. #define STRSAFE_NO_DEPRECATE
  21. #include <strsafe.h>
  22. #undef ASSERT
  23. #include "vs_assert.hxx"
  24. #include "vs_trace.hxx"
  25. #include "vssmsg.h"
  26. ////////////////////////////////////////////////////////////////////////
  27. // Standard foo for file name aliasing. This code block must be after
  28. // all includes of VSS header files.
  29. //
  30. #ifdef VSS_FILE_ALIAS
  31. #undef VSS_FILE_ALIAS
  32. #endif
  33. #define VSS_FILE_ALIAS "TRCASRTC"
  34. //
  35. ////////////////////////////////////////////////////////////////////////
  36. // Size of a constant array
  37. #define SIZEOF_ARRAY(_array) (sizeof (_array) / sizeof ((_array)[0]))
  38. // First two parameters to StringCChPrintf routines.
  39. #define STRING_CCH_PARAM(_array) _array, (SIZEOF_ARRAY(_array))
  40. // No MP protection...
  41. static LONG g_lVssDebugReportFlags = VSS_DBG_TO_DEBUG_CONSOLE | VSS_DBG_MESSAGE_BOX;
  42. const CHAR x_szEventLogVssSourceName[] = "VSS";
  43. VOID
  44. AssertFail
  45. (
  46. IN LPCSTR FileName,
  47. IN UINT LineNumber,
  48. IN LPCSTR Condition
  49. )
  50. {
  51. int i;
  52. CHAR Title[4096];
  53. CHAR Msg[4096];
  54. DWORD dwCurrentProcessId = GetCurrentProcessId();
  55. DWORD dwCurrentThreadId = GetCurrentThreadId();
  56. if (g_lVssDebugReportFlags & VSS_DBG_TO_DEBUG_CONSOLE)
  57. {
  58. StringCchPrintfA(
  59. STRING_CCH_PARAM(Msg),
  60. "VSS(PID:%ld,TID:%ld): %s(%d): *** Assertion failure *** %s\n",
  61. dwCurrentProcessId,
  62. dwCurrentThreadId,
  63. FileName,
  64. LineNumber,
  65. Condition
  66. );
  67. ::OutputDebugStringA(Msg);
  68. /*
  69. ::DbgPrintEx(
  70. DPFLTR_VSS_ID,
  71. 1,
  72. Msg
  73. );
  74. */
  75. }
  76. if (g_lVssDebugReportFlags & VSS_DBG_MESSAGE_BOX)
  77. {
  78. LPSTR szCommandLine = GetCommandLineA();
  79. //
  80. // Print the assertion and the command line
  81. //
  82. StringCchPrintfA(
  83. STRING_CCH_PARAM(Msg),
  84. "Assertion failure: %s\nFile: %s\nLine: %u\nCommand: %s\nProcess ID: %ld\nThread ID: %ld",
  85. Condition,
  86. FileName,
  87. LineNumber,
  88. szCommandLine,
  89. dwCurrentProcessId,
  90. dwCurrentThreadId
  91. );
  92. // Get a handle to use with ReportEvent()
  93. HANDLE hEventSource = ::RegisterEventSourceA(
  94. NULL, // IN LPCWSTR lpUNCServerName,
  95. x_szEventLogVssSourceName // IN LPCWSTR lpSourceName
  96. );
  97. if (hEventSource)
  98. {
  99. LPCSTR ppszStringTable[1];
  100. ppszStringTable[0] = const_cast<LPCSTR>(Msg);
  101. // Write to event log. Ignore return code.
  102. ::ReportEventA(
  103. hEventSource, // IN HANDLE hEventLog,
  104. EVENTLOG_ERROR_TYPE, // IN WORD wType,
  105. 0, // IN WORD wCategory,
  106. VSS_ERROR_ASSERT, // IN DWORD dwEventID,
  107. NULL, // IN PSID lpUserSid,
  108. 1, // IN WORD wNumStrings,
  109. 0, // IN DWORD dwDataSize,
  110. ppszStringTable, // IN LPCWSTR *lpStrings,
  111. NULL // IN LPVOID lpRawData
  112. );
  113. // Close the handle to the event log
  114. ::DeregisterEventSource( hEventSource );
  115. }
  116. //
  117. // Use dll name as caption
  118. //
  119. StringCchPrintfA(
  120. STRING_CCH_PARAM(Title),
  121. "Volume Snapshots (PID:%ld,TID:%ld)",
  122. dwCurrentProcessId,
  123. dwCurrentThreadId
  124. );
  125. //
  126. // Print the assertion and the command line
  127. //
  128. StringCchPrintfA(
  129. STRING_CCH_PARAM(Msg),
  130. "Assertion failure at line %u in file %s: %s\n\nCommand line: %s\n\nHit Cancel to break into the debugger.",
  131. LineNumber,
  132. FileName,
  133. Condition,
  134. szCommandLine
  135. );
  136. i = MessageBoxA
  137. (
  138. NULL,
  139. Msg,
  140. Title,
  141. MB_SYSTEMMODAL | MB_ICONSTOP | MB_OKCANCEL | MB_SERVICE_NOTIFICATION
  142. );
  143. if(i == IDCANCEL)
  144. DebugBreak();
  145. }
  146. }
  147. void VssSetDebugReport( LONG lDebugReportFlags )
  148. {
  149. g_lVssDebugReportFlags = lDebugReportFlags;
  150. }