debug.c
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 2k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. #include <windows.h>
  2. #include "debug.h"
  3. // #define DEBUG_BREAK        __try { _asm { int 3 } } __except (EXCEPTION_EXECUTE_HANDLER) {;}
  4. #define DEBUG_BREAK        _try { DebugBreak(); } _except (EXCEPTION_EXECUTE_HANDLER) {;}
  5. #ifdef _DEBUG
  6. UINT g_fDebugMask = 0x00ff;
  7. UINT SetDebugMask(UINT mask)
  8. {
  9.     UINT wOld = g_fDebugMask;
  10.     g_fDebugMask = mask;
  11.     return wOld;
  12. }
  13. UINT GetDebugMask()
  14. {
  15.     return g_fDebugMask;
  16. }
  17. void AssertFailed(LPCSTR pszFile, int line)
  18. {
  19.     LPCSTR psz;
  20.     char ach[256];
  21.     static char szAssertFailed[] = "Assertion failed in %s on line %drn";
  22.     // Strip off path info from filename string, if present.
  23.     //
  24.     if (g_fDebugMask & DM_ASSERT)
  25.     {
  26.         for (psz = pszFile + lstrlen(pszFile); psz != pszFile; psz=AnsiPrev(pszFile, psz))
  27.         {
  28.             if ((AnsiPrev(pszFile, psz)!= (psz-2)) && *(psz - 1) == '\')
  29.                 break;
  30.         }
  31.         wsprintf(ach, szAssertFailed, psz, line);
  32.         OutputDebugString(ach);
  33. DEBUG_BREAK
  34.     }
  35. }
  36. void _cdecl _AssertMsg(BOOL f, LPCSTR pszMsg, ...)
  37. {
  38.     char ach[256];
  39.     if (!f && (g_fDebugMask & DM_ASSERT))
  40.     {
  41.         wvsprintf(ach, pszMsg, (LPVOID)(&pszMsg + 1));
  42.         lstrcat(ach, "rn");
  43.         OutputDebugString(ach);
  44. DEBUG_BREAK
  45.     }
  46. }
  47. void _cdecl _DebugMsg(UINT mask, LPCSTR pszMsg, ...)
  48. {
  49.     char ach[2*MAX_PATH+40];  // Handles 2*largest path + slop for message
  50.     if (g_fDebugMask & mask)
  51.     {
  52.         wvsprintf(ach, pszMsg, (LPVOID)(&pszMsg + 1));
  53.         lstrcat(ach, "rn");
  54.         OutputDebugString(ach);
  55.     }
  56. }
  57. #endif // _DEBUG