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.

252 lines
6.6 KiB

  1. //+---------------------------------------------------------------------------
  2. // Copyright (C) 1991, Microsoft Corporation.
  3. //
  4. // File: assert.cxx
  5. //
  6. // Contents: Debugging output routines for idsmgr.dll
  7. //
  8. // Functions: _Assert
  9. // _PopUpError
  10. //
  11. // History: 23-Jul-91 KyleP Created.
  12. // 09-Oct-91 KevinRo Major changes and comments added
  13. // 18-Oct-91 vich moved debug print routines out
  14. // 10-Jun-92 BryanT Switched to w4crt.h instead of wchar.h
  15. //
  16. //----------------------------------------------------------------------------
  17. //
  18. // This one file **always** uses debugging options
  19. //
  20. #if DBG == 1
  21. #include <stdarg.h>
  22. # include <debnot.h>
  23. # include "dprintf.h" // w4printf, w4dprintf prototypes
  24. extern "C"
  25. {
  26. #include <windows.h>
  27. #ifndef WIN32
  28. #define MessageBoxA MessageBox
  29. #define wsprintfA wsprintf
  30. #endif
  31. }
  32. int APINOT _PopUpError(char const FAR *szMsg,
  33. int iLine,
  34. char const FAR *szFile);
  35. unsigned long Win4InfoLevel = DEF_INFOLEVEL;
  36. unsigned long Win4InfoMask = 0xffffffff;
  37. unsigned long Win4AssertLevel = ASSRT_MESSAGE | ASSRT_BREAK | ASSRT_POPUP;
  38. //+---------------------------------------------------------------------------
  39. //
  40. // Function: _asdprintf
  41. //
  42. // Synopsis: Calls vdprintf to output a formatted message.
  43. //
  44. // History: 18-Oct-91 vich Created
  45. //
  46. //----------------------------------------------------------------------------
  47. inline void _asdprintf(char const FAR *pszfmt, ...)
  48. {
  49. va_list va;
  50. va_start(va, pszfmt);
  51. vdprintf(DEB_FORCE, "Assert", pszfmt, va);
  52. va_end(va);
  53. }
  54. //+---------------------------------------------------------------------------
  55. //
  56. // Function: _Win4Assert, private
  57. //
  58. // Synopsis: Display assertion information
  59. //
  60. // Effects: Called when an assertion is hit.
  61. //
  62. // History: 12-Jul-91 AlexT Created.
  63. // 05-Sep-91 AlexT Catch Throws and Catches
  64. // 19-Oct-92 HoiV Added events for TOM
  65. //
  66. //----------------------------------------------------------------------------
  67. void APINOT _Win4Assert(char const FAR * szFile,
  68. int iLine,
  69. char const FAR * szMessage)
  70. {
  71. if (Win4AssertLevel & ASSRT_MESSAGE)
  72. {
  73. _asdprintf("%s File: %s Line: %u\n", szMessage, szFile, iLine);
  74. }
  75. if (Win4AssertLevel & ASSRT_POPUP)
  76. {
  77. int id = _PopUpError(szMessage,iLine,szFile);
  78. if (id == IDCANCEL)
  79. {
  80. #ifndef FLAT
  81. _asm int 3;
  82. #else
  83. DebugBreak();
  84. #endif
  85. }
  86. }
  87. else if (Win4AssertLevel & ASSRT_BREAK)
  88. {
  89. #ifndef FLAT
  90. _asm int 3;
  91. #else
  92. DebugBreak();
  93. #endif
  94. }
  95. }
  96. //+------------------------------------------------------------
  97. // Function: _SetWin4InfoLevel(unsigned long ulNewLevel)
  98. //
  99. // Synopsis: Sets the global info level for debugging output
  100. // Returns: Old info level
  101. //
  102. //-------------------------------------------------------------
  103. unsigned long APINOT _SetWin4InfoLevel(unsigned long ulNewLevel)
  104. {
  105. unsigned long ul;
  106. ul = Win4InfoLevel;
  107. Win4InfoLevel = ulNewLevel;
  108. return(ul);
  109. }
  110. //+------------------------------------------------------------
  111. // Function: _SetWin4InfoMask(unsigned long ulNewMask)
  112. //
  113. // Synopsis: Sets the global info mask for debugging output
  114. // Returns: Old info mask
  115. //
  116. //-------------------------------------------------------------
  117. unsigned long APINOT _SetWin4InfoMask(unsigned long ulNewMask)
  118. {
  119. unsigned long ul;
  120. ul = Win4InfoMask;
  121. Win4InfoMask = ulNewMask;
  122. return(ul);
  123. }
  124. //+------------------------------------------------------------
  125. // Function: _SetWin4AssertLevel(unsigned long ulNewLevel)
  126. //
  127. // Synopsis: Sets the global assert level for debugging output
  128. // Returns: Old assert level
  129. //
  130. //-------------------------------------------------------------
  131. unsigned long APINOT _SetWin4AssertLevel(unsigned long ulNewLevel)
  132. {
  133. unsigned long ul;
  134. ul = Win4AssertLevel;
  135. Win4AssertLevel = ulNewLevel;
  136. return(ul);
  137. }
  138. //+------------------------------------------------------------
  139. // Function: _PopUpError
  140. //
  141. // Synopsis: Displays a dialog box using provided text,
  142. // and presents the user with the option to
  143. // continue or cancel.
  144. //
  145. // Arguments:
  146. // szMsg -- The string to display in main body of dialog
  147. // iLine -- Line number of file in error
  148. // szFile -- Filename of file in error
  149. //
  150. // Returns:
  151. // IDCANCEL -- User selected the CANCEL button
  152. // IDOK -- User selected the OK button
  153. //-------------------------------------------------------------
  154. int APINOT _PopUpError(char const FAR *szMsg,int iLine, char const FAR *szFile)
  155. {
  156. int id;
  157. static char szAssertCaption[100];
  158. wsprintfA(szAssertCaption, "File: %s line %u", szFile,iLine);
  159. id = MessageBoxA(NULL,
  160. (char FAR *) szMsg,
  161. (LPSTR) szAssertCaption,
  162. MB_TASKMODAL | MB_ICONEXCLAMATION | MB_OKCANCEL);
  163. return id;
  164. }
  165. //+------------------------------------------------------------
  166. // Function: vdprintf
  167. //
  168. // Synopsis: Prints debug output using a pointer to the
  169. // variable information. Used primarily by the
  170. // xxDebugOut macros
  171. //
  172. // Arguements:
  173. // ulCompMask -- Component level mask used to determine
  174. // output ability
  175. // pszComp -- String const of component prefix.
  176. // ppszfmt -- Pointer to output format and data
  177. //
  178. //-------------------------------------------------------------
  179. void APINOT vdprintf(unsigned long ulCompMask,
  180. char const FAR *pszComp,
  181. char const FAR *ppszfmt,
  182. va_list pargs)
  183. {
  184. if ((ulCompMask & DEB_FORCE) == DEB_FORCE ||
  185. ((ulCompMask | Win4InfoLevel) & Win4InfoMask))
  186. {
  187. if (! (ulCompMask & DEB_NOCOMPNAME))
  188. {
  189. #ifdef WIN32
  190. #if defined(_CHICAGO_)
  191. //
  192. // Hex Process/Thread ID's are better for Chicago since both
  193. // are memory addresses.
  194. //
  195. w4dprintf("%08x.%08x> %s: ",
  196. #else
  197. w4dprintf("%03d.%03d> %s: ",
  198. #endif
  199. GetCurrentProcessId(),
  200. GetCurrentThreadId(),
  201. pszComp);
  202. #else
  203. w4dprintf("%07x> %s: ",
  204. GetCurrentTask(),
  205. pszComp);
  206. #endif
  207. }
  208. w4vdprintf(ppszfmt, pargs);
  209. // Chicago and Win32s debugging is usually through wdeb386
  210. // which needs carriage returns
  211. #if WIN32 == 50 || WIN32 == 200
  212. w4dprintf("\r");
  213. #endif
  214. }
  215. }
  216. #endif // DBG == 1