|
|
1.1 ! root 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: ! 13: #include <stdio.h> ! 14: #include <windows.h> ! 15: #include "mcitest.h" ! 16: #include <stdarg.h> ! 17: ! 18: #if DBG ! 19: ! 20: #define DEFAULTDEBUGLEVEL 2 ! 21: int __iDebugLevel = DEFAULTDEBUGLEVEL; ! 22: ! 23: void dDbgSetDebugMenuLevel(int i) ! 24: { ! 25: HMENU hMenu; ! 26: UINT m; ! 27: ! 28: if ((i < 0) || (i > 4)) i = 4; ! 29: hMenu = GetMenu(hwndMainDlg); ! 30: for (m=IDM_DEBUG0; m<=IDM_DEBUG4; m++) { ! 31: CheckMenuItem(hMenu, m, MF_UNCHECKED); ! 32: } ! 33: CheckMenuItem(hMenu, (UINT)(i + IDM_DEBUG0), MF_CHECKED); ! 34: __iDebugLevel = i; ! 35: dprintf3("Debug level set to %d", i); ! 36: } ! 37: ! 38: /*************************************************************************** ! 39: ! 40: @doc INTERNAL ! 41: ! 42: @api void | dDbgOut | This function sends output to the current ! 43: debug output device. ! 44: ! 45: @parm LPSTR | lpszFormat | Pointer to a printf style format string. ! 46: @parm ??? | ... | Args. ! 47: ! 48: @rdesc There is no return value. ! 49: ! 50: ****************************************************************************/ ! 51: ! 52: void dDbgOut(LPSTR lpszFormat, ...) ! 53: { ! 54: int i; ! 55: char buf[256]; ! 56: va_list va; ! 57: ! 58: i = wsprintf(buf, "%s: ", aszAppName); ! 59: ! 60: va_start(va, lpszFormat); ! 61: i += vsprintf(buf+i, lpszFormat, va); ! 62: va_end(va); ! 63: ! 64: buf[i++] = '\n'; ! 65: buf[i] = 0; ! 66: ! 67: OutputDebugString(buf); ! 68: } ! 69: ! 70: /*************************************************************************** ! 71: ! 72: @doc INTERNAL ! 73: ! 74: @api int | dDbgGetLevel | This function gets the current debug level ! 75: for a module. ! 76: ! 77: @parm LPSTR | lpszModule | The name of the module. ! 78: ! 79: @rdesc The return value is the current debug level. ! 80: ! 81: @comm The information is kept in the [debug] section of WIN.INI ! 82: ! 83: ****************************************************************************/ ! 84: ! 85: int dDbgGetLevel(LPSTR lpszAppName) ! 86: { ! 87: return GetProfileInt("mmdebug", lpszAppName, DEFAULTDEBUGLEVEL); ! 88: } ! 89: ! 90: /*************************************************************************** ! 91: ! 92: @doc INTERNAL ! 93: ! 94: @api int | dDbgSaveLevel | This function saves the current debug level ! 95: for a module. ! 96: ! 97: @parm LPSTR | lpszModule | The name of the module. ! 98: @parm int | iLevel | The value to save. ! 99: ! 100: @rdesc There is no return value. ! 101: ! 102: @comm The information is kept in the [debug] section of WIN.INI ! 103: ! 104: ****************************************************************************/ ! 105: ! 106: void dDbgSaveLevel(LPSTR lpszAppName, int iLevel) ! 107: { ! 108: char buf[80]; ! 109: ! 110: sprintf(buf, "%d", iLevel); ! 111: WriteProfileString("debug", lpszAppName, buf); ! 112: } ! 113: ! 114: /*************************************************************************** ! 115: ! 116: @doc INTERNAL ! 117: ! 118: @api void | dDbgAssert | This function shows an assert message box. ! 119: ! 120: @parm LPSTR | exp | Pointer to the expression string. ! 121: @parm LPSTR | file | Pointer to the file name. ! 122: @parm int | line | The line number. ! 123: ! 124: @rdesc There is no return value. ! 125: ! 126: @comm We try to use the current active window as the parent. If ! 127: this fails we use the desktop window. The box is system ! 128: modal to avoid any trouble. ! 129: ! 130: ****************************************************************************/ ! 131: ! 132: void dDbgAssert(LPSTR exp, LPSTR file, int line) ! 133: { ! 134: char bufTmp[256]; ! 135: int iResponse; ! 136: HWND hWnd; ! 137: ! 138: sprintf(bufTmp, ! 139: "Expression: %s\nFile: %s, Line: %d\n\nAbort: Exit Process\nRetry: Enter Debugger\nIgnore: Continue", ! 140: exp, file, line); ! 141: ! 142: // try to use the active window, but NULL is ok if there ! 143: // isn't one. ! 144: ! 145: hWnd = GetActiveWindow(); ! 146: ! 147: iResponse = MessageBox(hWnd, ! 148: bufTmp, ! 149: "Assertion Failure", ! 150: MB_TASKMODAL ! 151: | MB_ICONEXCLAMATION ! 152: | MB_DEFBUTTON3 ! 153: | MB_ABORTRETRYIGNORE); ! 154: ! 155: switch (iResponse) { ! 156: case 0: ! 157: dprintf1("Assert message box failed"); ! 158: dprintf2(" Expression: %s", exp); ! 159: dprintf2(" File: %s, Line: %d", file, line); ! 160: break; ! 161: case IDABORT: ! 162: ExitProcess(1); ! 163: break; ! 164: case IDRETRY: ! 165: DebugBreak(); ! 166: break; ! 167: case IDIGNORE: ! 168: break; ! 169: } ! 170: } ! 171: ! 172: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.