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.

194 lines
4.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: oledsdbg.cxx
  7. //
  8. // Contents:
  9. //
  10. //
  11. // History:
  12. //
  13. //----------------------------------------------------------------------------
  14. #include "dswarn.h"
  15. #include <ADs.hxx>
  16. #if DBG==1
  17. #include <stdio.h>
  18. #include <printf.h>
  19. unsigned long Win4InfoLevel = DEF_INFOLEVEL;
  20. unsigned long Win4InfoMask = 0xffffffff;
  21. unsigned long Win4AssertLevel = ASSRT_MESSAGE | ASSRT_BREAK | ASSRT_POPUP;
  22. CRITICAL_SECTION g_csDP; // used by debug print routines
  23. //+------------------------------------------------------------
  24. // Function: vdprintf
  25. //
  26. // Synopsis: Prints debug output using a pointer to the
  27. // variable information. Used primarily by the
  28. // xxDebugOut macros
  29. //
  30. // Arguments:
  31. // ulCompMask -- Component level mask used to determine
  32. // output ability
  33. // pszComp -- String const of component prefix.
  34. // ppszfmt -- Pointer to output format and data
  35. //
  36. //-------------------------------------------------------------
  37. void APINOT
  38. vdprintf(
  39. unsigned long ulCompMask,
  40. char const *pszComp,
  41. char const *ppszfmt,
  42. va_list pargs
  43. )
  44. {
  45. if ((ulCompMask & DEB_FORCE) == DEB_FORCE ||
  46. ((ulCompMask | Win4InfoLevel) & Win4InfoMask))
  47. {
  48. EnterCriticalSection(&g_csDP);
  49. DWORD tid = GetCurrentThreadId();
  50. if ((Win4InfoLevel & (DEB_DBGOUT | DEB_STDOUT)) != DEB_STDOUT)
  51. {
  52. if (! (ulCompMask & DEB_NOCOMPNAME))
  53. {
  54. w4dprintf( "%03d> ", tid );
  55. w4dprintf("%s: ", pszComp);
  56. }
  57. w4vdprintf(ppszfmt, pargs);
  58. }
  59. if (Win4InfoLevel & DEB_STDOUT)
  60. {
  61. if (! (ulCompMask & DEB_NOCOMPNAME))
  62. {
  63. w4printf( "%03d> ", tid );
  64. w4printf("%s: ", pszComp);
  65. }
  66. w4vprintf(ppszfmt, pargs);
  67. }
  68. LeaveCriticalSection(&g_csDP);
  69. }
  70. }
  71. //+---------------------------------------------------------------------------
  72. //
  73. // Function: _asdprintf
  74. //
  75. // Synopsis: Calls vdprintf to output a formatted message.
  76. //
  77. // History: 18-Oct-91 vich Created
  78. //
  79. //----------------------------------------------------------------------------
  80. inline void __cdecl
  81. _asdprintf(
  82. char const *pszfmt, ...)
  83. {
  84. va_list va;
  85. va_start(va, pszfmt);
  86. vdprintf(DEB_FORCE, "Assert", pszfmt, va);
  87. va_end(va);
  88. }
  89. //+------------------------------------------------------------
  90. // Function: PopUpError
  91. //
  92. // Synopsis: Displays a dialog box using provided text,
  93. // and presents the user with the option to
  94. // continue or cancel.
  95. //
  96. // Arguments:
  97. // szMsg -- The string to display in main body of dialog
  98. // iLine -- Line number of file in error
  99. // szFile -- Filename of file in error
  100. //
  101. // Returns:
  102. // IDCANCEL -- User selected the CANCEL button
  103. // IDOK -- User selected the OK button
  104. //-------------------------------------------------------------
  105. int APINOT
  106. PopUpError(
  107. char const *szMsg,
  108. int iLine,
  109. char const *szFile
  110. )
  111. {
  112. int id;
  113. static char szAssertCaption[100];
  114. DWORD tid = GetCurrentThreadId();
  115. sprintf(szAssertCaption,"File: %s line %u, thread id %d",
  116. szFile, iLine, tid);
  117. id = MessageBoxA(
  118. NULL,
  119. (char *) szMsg,
  120. (LPSTR) szAssertCaption,
  121. MB_SETFOREGROUND |
  122. MB_TASKMODAL | MB_ICONEXCLAMATION | MB_OKCANCEL
  123. );
  124. return id;
  125. }
  126. //+---------------------------------------------------------------------------
  127. //
  128. // Function: _Win4Assert, private
  129. //
  130. // Synopsis: Display assertion information
  131. //
  132. // Effects: Called when an assertion is hit.
  133. //
  134. // History:
  135. //
  136. //----------------------------------------------------------------------------
  137. void APINOT
  138. Win4AssertEx(
  139. char const * szFile,
  140. int iLine,
  141. char const * szMessage
  142. )
  143. {
  144. if (Win4AssertLevel & ASSRT_MESSAGE)
  145. {
  146. DWORD tid = GetCurrentThreadId();
  147. _asdprintf("%s File: %s Line: %u, thread id %d\n",
  148. szMessage, szFile, iLine, tid);
  149. }
  150. if (Win4AssertLevel & ASSRT_POPUP)
  151. {
  152. int id = PopUpError(szMessage,iLine,szFile);
  153. if (id == IDCANCEL)
  154. {
  155. DebugBreak();
  156. }
  157. }
  158. else if (Win4AssertLevel & ASSRT_BREAK)
  159. {
  160. DebugBreak();
  161. }
  162. }
  163. #endif