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.

172 lines
4.3 KiB

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