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.

180 lines
4.7 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. #undef ASSERT
  21. #include "vs_assert.hxx"
  22. #include "vs_trace.hxx"
  23. //#include "vssmsg.h"
  24. ////////////////////////////////////////////////////////////////////////
  25. // Standard foo for file name aliasing. This code block must be after
  26. // all includes of VSS header files.
  27. //
  28. #ifdef VSS_FILE_ALIAS
  29. #undef VSS_FILE_ALIAS
  30. #endif
  31. #define VSS_FILE_ALIAS "TRCASRTC"
  32. //
  33. ////////////////////////////////////////////////////////////////////////
  34. // No MP protection...
  35. static LONG g_lVssDebugReportFlags = VSS_DBG_TO_DEBUG_CONSOLE | VSS_DBG_MESSAGE_BOX;
  36. const CHAR x_szEventLogVssSourceName[] = "VSS";
  37. VOID
  38. AssertFail
  39. (
  40. IN LPCSTR FileName,
  41. IN UINT LineNumber,
  42. IN LPCSTR Condition
  43. )
  44. {
  45. int i;
  46. CHAR Title[4096];
  47. CHAR Msg[4096];
  48. DWORD dwCurrentProcessId = GetCurrentProcessId();
  49. DWORD dwCurrentThreadId = GetCurrentThreadId();
  50. if (g_lVssDebugReportFlags & VSS_DBG_TO_DEBUG_CONSOLE)
  51. {
  52. sprintf(
  53. Msg,
  54. "VSS(PID:%ld,TID:%ld): %s(%d): *** Assertion failure *** %s\n",
  55. dwCurrentProcessId,
  56. dwCurrentThreadId,
  57. FileName,
  58. LineNumber,
  59. Condition
  60. );
  61. ::OutputDebugStringA(Msg);
  62. /*
  63. ::DbgPrintEx(
  64. DPFLTR_VSS_ID,
  65. 1,
  66. Msg
  67. );
  68. */
  69. }
  70. if (g_lVssDebugReportFlags & VSS_DBG_MESSAGE_BOX)
  71. {
  72. LPSTR szCommandLine = GetCommandLineA();
  73. //
  74. // Print the assertion and the command line
  75. //
  76. sprintf(
  77. Msg,
  78. "Assertion failure: %s\nFile: %s\nLine: %u\nCommand: %s\nProcess ID: %ld\nThread ID: %ld",
  79. Condition,
  80. FileName,
  81. LineNumber,
  82. szCommandLine,
  83. dwCurrentProcessId,
  84. dwCurrentThreadId
  85. );
  86. #ifdef LOG_ERROR
  87. // Get a handle to use with ReportEvent()
  88. HANDLE hEventSource = ::RegisterEventSourceA(
  89. NULL, // IN LPCWSTR lpUNCServerName,
  90. x_szEventLogVssSourceName // IN LPCWSTR lpSourceName
  91. );
  92. if (hEventSource)
  93. {
  94. LPCSTR ppszStringTable[1];
  95. ppszStringTable[0] = const_cast<LPCSTR>(Msg);
  96. // Write to event log. Ignore return code.
  97. ::ReportEventA(
  98. hEventSource, // IN HANDLE hEventLog,
  99. EVENTLOG_ERROR_TYPE, // IN WORD wType,
  100. 0, // IN WORD wCategory,
  101. VSS_ERROR_ASSERT, // IN DWORD dwEventID,
  102. NULL, // IN PSID lpUserSid,
  103. 1, // IN WORD wNumStrings,
  104. 0, // IN DWORD dwDataSize,
  105. ppszStringTable, // IN LPCWSTR *lpStrings,
  106. NULL // IN LPVOID lpRawData
  107. );
  108. // Close the handle to the event log
  109. ::DeregisterEventSource( hEventSource );
  110. }
  111. #endif
  112. //
  113. // Use dll name as caption
  114. //
  115. sprintf(
  116. Title,
  117. "File Services WMI Provider (PID:%ld,TID:%ld)",
  118. dwCurrentProcessId,
  119. dwCurrentThreadId
  120. );
  121. //
  122. // Print the assertion and the command line
  123. //
  124. sprintf(
  125. Msg,
  126. "Assertion failure at line %u in file %s: %s\n\nCommand line: %s\n\nHit Cancel to break into the debugger.",
  127. LineNumber,
  128. FileName,
  129. Condition,
  130. szCommandLine
  131. );
  132. i = MessageBoxA
  133. (
  134. NULL,
  135. Msg,
  136. Title,
  137. MB_SYSTEMMODAL | MB_ICONSTOP | MB_OKCANCEL | MB_SERVICE_NOTIFICATION
  138. );
  139. if(i == IDCANCEL)
  140. DebugBreak();
  141. }
  142. }
  143. void VssSetDebugReport( LONG lDebugReportFlags )
  144. {
  145. g_lVssDebugReportFlags = lDebugReportFlags;
  146. }