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.

92 lines
1.5 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. #if DBG
  9. /* _Assert(fExpr, szFile, iLine)
  10. *
  11. * If <fExpr> is TRUE, then do nothing. If <fExpr> is FALSE, then display
  12. * an "assertion failed" message box allowing the user to abort the program,
  13. * enter the debugger (the "Retry" button), or igore the error.
  14. *
  15. * <szFile> is the name of the source file; <iLine> is the line number
  16. * containing the _Assert() call.
  17. */
  18. #ifdef I386
  19. #pragma optimize("", off)
  20. #endif
  21. BOOL FAR PASCAL
  22. _Assert(BOOL fExpr, LPSTR szFile, int iLine)
  23. {
  24. static char ach[300]; // debug output (avoid stack overflow)
  25. int id;
  26. /* check if assertion failed */
  27. if (fExpr)
  28. return fExpr;
  29. /* display error message */
  30. wsprintfA(ach, "File %s, line %d", (LPSTR) szFile, iLine);
  31. MessageBeep(MB_ICONHAND);
  32. id = MessageBoxA(NULL, ach, "Assertion Failed",
  33. MB_SYSTEMMODAL | MB_ICONHAND | MB_ABORTRETRYIGNORE);
  34. /* abort, debug, or ignore */
  35. switch (id)
  36. {
  37. case IDABORT:
  38. /* kill this application */
  39. ExitProcess(1);
  40. break;
  41. case IDRETRY:
  42. /* break into the debugger */
  43. DebugBreak();
  44. break;
  45. case IDIGNORE:
  46. /* ignore the assertion failure */
  47. break;
  48. }
  49. return FALSE;
  50. }
  51. #ifdef I386
  52. #pragma optimize("", on)
  53. #endif
  54. int ssDebugLevel = 1;
  55. void
  56. dbgPrintf(char * szFormat, ...)
  57. {
  58. char buf[256];
  59. va_list va;
  60. va_start(va, szFormat);
  61. wvsprintfA(buf, szFormat, va);
  62. va_end(va);
  63. OutputDebugStringA("SUMSERVE:");
  64. OutputDebugStringA(buf);
  65. OutputDebugStringA("\r\n");
  66. }
  67. #endif