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.

193 lines
4.6 KiB

  1. /* Copyright (c) 1992 Microsoft Corporation */
  2. /*
  3. * debug.c
  4. *
  5. * debugging menu support
  6. *
  7. * Debug level info is in WIN.INI in the [debug] section:
  8. *
  9. * [debug]
  10. * App=0 level for App
  11. *
  12. */
  13. #include "mcihwnd.h"
  14. #include <stdarg.h>
  15. // mcihwnd pulls in the other needed files
  16. #if DBG
  17. char aszAppName[] = "MciHwnd";
  18. int __iDebugLevel = 1;
  19. /***************************************************************************
  20. @doc INTERNAL
  21. @api void | dDbgOut | This function sends output to the current
  22. debug output device.
  23. @parm LPSTR | lpszFormat | Pointer to a printf style format string.
  24. @parm ??? | ... | Args.
  25. @rdesc There is no return value.
  26. ****************************************************************************/
  27. void dDbgOut(LPSTR lpszFormat, ...)
  28. {
  29. int i;
  30. char buf[256];
  31. va_list va;
  32. sprintf(buf, "%s: ", aszAppName);
  33. OutputDebugString(buf);
  34. va_start(va, lpszFormat);
  35. i = vsprintf(buf, lpszFormat, va);
  36. va_end(va);
  37. OutputDebugString(buf);
  38. OutputDebugString("\n");
  39. }
  40. /***************************************************************************
  41. @doc INTERNAL
  42. @api int | dGetDebugLevel | This function gets the current debug level
  43. for a module.
  44. @parm LPSTR | lpszModule | The name of the module.
  45. @rdesc The return value is the current debug level.
  46. @comm The information is kept in the [debug] section of WIN.INI
  47. ****************************************************************************/
  48. int dGetDebugLevel(LPSTR lpszAppName)
  49. {
  50. return GetProfileInt("MMDEBUG", lpszAppName, 3);
  51. }
  52. /***************************************************************************
  53. @doc INTERNAL
  54. @api int | dDbgSaveLevel | This function saves the current debug level
  55. for a module.
  56. @parm LPSTR | lpszModule | The name of the module.
  57. @parm int | iLevel | The value to save.
  58. @rdesc There is no return value.
  59. @comm The information is kept in the [debug] section of WIN.INI
  60. ****************************************************************************/
  61. void dDbgSaveLevel(LPSTR lpszAppName, int iLevel)
  62. {
  63. char buf[80];
  64. sprintf(buf, "%d", iLevel);
  65. WriteProfileString("MMDEBUG", lpszAppName, buf);
  66. }
  67. /***************************************************************************
  68. @doc INTERNAL
  69. @api void | dDbgAssert | This function shows an assert message box.
  70. @parm LPSTR | exp | Pointer to the expression string.
  71. @parm LPSTR | file | Pointer to the file name.
  72. @parm int | line | The line number.
  73. @rdesc There is no return value.
  74. @comm We try to use the current active window as the parent. If
  75. this fails we use the desktop window. The box is system
  76. modal to avoid any trouble.
  77. ****************************************************************************/
  78. void dDbgAssert(LPSTR exp, LPSTR file, int line)
  79. {
  80. char bufTmp[256];
  81. int iResponse;
  82. HWND hWnd;
  83. sprintf(bufTmp,
  84. "Expression: %s\nFile: %s, Line: %d\n\nAbort: Exit Process\nRetry: Enter Debugger\nIgnore: Continue",
  85. exp, file, line);
  86. // try to use the active window, but NULL is ok if there
  87. // isn't one. Use the debug console as well
  88. dprintf(bufTmp);
  89. hWnd = GetActiveWindow();
  90. iResponse = MessageBox(hWnd,
  91. bufTmp,
  92. "Assertion Failure",
  93. MB_TASKMODAL
  94. | MB_ICONEXCLAMATION
  95. | MB_DEFBUTTON3
  96. | MB_ABORTRETRYIGNORE);
  97. switch (iResponse) {
  98. case 0:
  99. dprintf1("Assert message box failed");
  100. dprintf2(" Expression: %s", exp);
  101. dprintf2(" File: %s, Line: %d", file, line);
  102. break;
  103. case IDABORT:
  104. ExitProcess(1);
  105. break;
  106. case IDRETRY:
  107. DebugBreak();
  108. break;
  109. case IDIGNORE:
  110. break;
  111. }
  112. }
  113. #endif
  114. #if DBG
  115. /***************************************************************************
  116. @doc INTERNAL
  117. @api void | winmmDbgOut | This function sends output to the current
  118. debug output device.
  119. @parm LPSTR | lpszFormat | Pointer to a printf style format string.
  120. @parm ??? | ... | Args.
  121. @rdesc There is no return value.
  122. ****************************************************************************/
  123. void winmmDbgOut(LPSTR lpszFormat, ...)
  124. {
  125. char buf[256];
  126. UINT n;
  127. va_list va;
  128. n = wsprintf(buf, "MciHwnd: ");
  129. va_start(va, lpszFormat);
  130. n += vsprintf(buf+n, lpszFormat, va);
  131. va_end(va);
  132. buf[n++] = '\n';
  133. buf[n] = 0;
  134. OutputDebugString(buf);
  135. }
  136. #endif