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.

132 lines
2.3 KiB

  1. /* Debug.c
  2. *
  3. * Debug printf and assertion functions
  4. */
  5. #include <windows.h>
  6. #include <stdarg.h>
  7. #include <stdio.h>
  8. #include "debug.h"
  9. #ifdef _DEBUG
  10. DWORD ModuleDebugLevel = 1; // 0 to turn it off, but valid level go up to 4
  11. DWORD ModuleDebugStamp = 0; // Turn on to print __FILE__.__LINE__
  12. /* _Assert(fExpr, szFile, iLine)
  13. *
  14. * If <fExpr> is TRUE, then do nothing. If <fExpr> is FALSE, then display
  15. * an "assertion failed" message box allowing the user to abort the program,
  16. * enter the debugger (the "Retry" button), or igore the error.
  17. *
  18. * <szFile> is the name of the source file; <iLine> is the line number
  19. * containing the _Assert() call.
  20. */
  21. #ifdef I386
  22. #pragma optimize("", off)
  23. #endif
  24. BOOL FAR PASCAL
  25. _Assert(
  26. BOOL fExpr,
  27. TCHAR * szFile, //LPSTR szFile,
  28. int iLine,
  29. TCHAR * szExpr) // LPSTR szExpr)
  30. {
  31. static TCHAR achTitle[256];
  32. int id;
  33. /* check if assertion failed */
  34. if (fExpr)
  35. return fExpr;
  36. /* display error message */
  37. wsprintf(achTitle, TEXT("AssertFailed: %d:%s\n"), iLine, (LPSTR) szFile);
  38. id = MessageBox(NULL, szExpr, achTitle, MB_SYSTEMMODAL | MB_ICONHAND | MB_ABORTRETRYIGNORE);
  39. /* abort, debug, or ignore */
  40. switch (id)
  41. {
  42. case IDABORT:
  43. /* kill this application */
  44. ExitProcess(1);
  45. break;
  46. case IDRETRY:
  47. /* break into the debugger */
  48. DebugBreak();
  49. break;
  50. case IDIGNORE:
  51. /* ignore the assertion failure */
  52. break;
  53. }
  54. return FALSE;
  55. }
  56. #ifdef I386
  57. #pragma optimize("", on)
  58. #endif
  59. DWORD dbgSetDebugLevel(int dbgLevel) {
  60. DWORD oldlevel = ModuleDebugLevel;
  61. ModuleDebugLevel = dbgLevel;
  62. return(oldlevel);
  63. }
  64. void PlaceStamp(
  65. TCHAR * lpszFile, // LPSTR lpszFile,
  66. int iLineNum)
  67. {
  68. TCHAR szBuf[256];
  69. int i;
  70. TCHAR * lpszFilename = lpszFile;
  71. if (ModuleDebugLevel == 0)
  72. return;
  73. if(ModuleDebugStamp) {
  74. for (i=0; i < lstrlen(lpszFile); i++)
  75. if (*(lpszFile+i) == '\\')
  76. lpszFilename = (lpszFile+i);
  77. if(wsprintf(szBuf, TEXT("MsYuv %12s %4d "), lpszFilename, iLineNum) > 0)
  78. OutputDebugString(szBuf);
  79. } else {
  80. OutputDebugString(TEXT("MsYuv.."));
  81. }
  82. }
  83. void dbgPrintf(TCHAR * szFormat, ...)
  84. {
  85. TCHAR szBuf[256];
  86. va_list va;
  87. if (ModuleDebugLevel == 0)
  88. return;
  89. va_start(va, szFormat);
  90. wvsprintf(
  91. szBuf,
  92. szFormat,
  93. va);
  94. va_end(va);
  95. OutputDebugString(szBuf);
  96. }
  97. #endif // _DEBUG