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.

187 lines
4.9 KiB

  1. /*
  2. * johnkn's debug logging and assert macros
  3. *
  4. */
  5. #if !defined _INC_MMDEBUG_
  6. #define _INC_MMDEBUG_
  7. //
  8. // prototypes for debug functions.
  9. //
  10. #define SQUAWKNUMZ(num) #num
  11. #define SQUAWKNUM(num) SQUAWKNUMZ(num)
  12. #define SQUAWK __FILE__ "(" SQUAWKNUM(__LINE__) ") ----"
  13. #define DEBUGLINE __FILE__ "(" SQUAWKNUM(__LINE__) ") "
  14. #if defined DEBUG || defined _DEBUG || defined DEBUG_RETAIL
  15. int FAR _cdecl AuxDebugEx(int, LPTSTR, ...);
  16. VOID WINAPI AuxDebugDump (int, LPVOID, int);
  17. int WINAPI DebugSetOutputLevel (int);
  18. #if defined DEBUG_RETAIL
  19. #define INLINE_BREAK
  20. #else
  21. #define INLINE_BREAK _asm {int 3}
  22. #endif
  23. #if 0
  24. #undef assert
  25. #define assert(exp) \
  26. (void)((exp) ? 0 : AuxDebugEx(-2, DEBUGLINE "assert failed: " #exp "\r\n", (int)__LINE__))
  27. #undef assert2
  28. #define assert2(exp,sz) \
  29. (void)((exp) ? 0 : AuxDebugEx(-2, DEBUGLINE "assert failed: " sz "\r\n", (int)__LINE__))
  30. #else
  31. #undef assert
  32. #define assert(exp); {\
  33. if (!(exp)) {\
  34. AuxDebugEx(-2, DEBUGLINE "assert failed: " #exp "\r\n", (int)__LINE__); \
  35. INLINE_BREAK;\
  36. }\
  37. }
  38. #undef assert2
  39. #define assert2(exp,sz); {\
  40. if (!(exp)) {\
  41. AuxDebugEx(-2, DEBUGLINE "assert failed: " sz "\r\n", (int)__LINE__); \
  42. INLINE_BREAK;\
  43. }\
  44. }
  45. #undef assert3
  46. #define assert3(exp,sz,arg); {\
  47. if (!(exp)) {\
  48. AuxDebugEx(-2, DEBUGLINE "assert failed: " sz "\r\n", (int)__LINE__, (arg)); \
  49. INLINE_BREAK;\
  50. }\
  51. }
  52. #endif
  53. #define STATICFN
  54. #else // defined(DEBUG)
  55. #define AuxDebugEx 1 ? (void)0 : (void)
  56. #define AuxDebugDump(a,b,c)
  57. #define assert(a) ((void)0)
  58. #define assert2(a,b) ((void)0)
  59. #define assert3(a,b,c) ((void)0)
  60. #define INLINE_BREAK
  61. #define DebugSetOutputLevel(i)
  62. #define STATICFN static
  63. #endif // defined(DEBUG)
  64. #define AuxDebug(sz) AuxDebugEx (1, DEBUGLINE sz "\r\n")
  65. #define AuxDebug2(sz,a) AuxDebugEx (1, DEBUGLINE sz "\r\n", (a))
  66. #endif //_INC_MMDEBUG_
  67. // =============================================================================
  68. //
  69. // include this in only one module in a DLL or APP
  70. //
  71. #if defined DEBUG || defined _DEBUG || defined DEBUG_RETAIL
  72. #if (defined _INC_MMDEBUG_CODE_) && (_INC_MMDEBUG_CODE_ != FALSE)
  73. #undef _INC_MMDEBUG_CODE_
  74. #define _INC_MMDEBUG_CODE_ FALSE
  75. #include <stdarg.h>
  76. #if !defined WIN32 && !defined wvsprintfA
  77. #define wvsprintfA wvsprintf
  78. #endif
  79. int debug_OutputOn = 0;
  80. /*+ AuxDebug - create a formatted string and output to debug terminal
  81. *
  82. *-=================================================================*/
  83. int FAR _cdecl AuxDebugEx (
  84. int iLevel,
  85. LPTSTR lpFormat,
  86. ...)
  87. {
  88. char szBuf[1024];
  89. int cb;
  90. va_list va;
  91. if (debug_OutputOn >= iLevel)
  92. {
  93. va_start (va, lpFormat);
  94. cb = wvsprintfA (szBuf, lpFormat, va);
  95. va_end (va);
  96. OutputDebugString (szBuf);
  97. }
  98. return cb;
  99. }
  100. /*+ AuxDebugDump -
  101. *
  102. *-=================================================================*/
  103. VOID WINAPI AuxDebugDump (
  104. int iLevel,
  105. LPVOID lpvData,
  106. int nCount)
  107. {
  108. LPBYTE lpData = lpvData;
  109. char szBuf[128];
  110. LPSTR psz;
  111. int cb;
  112. int ix;
  113. BYTE abRow[8];
  114. if (debug_OutputOn <= iLevel || nCount <= 0)
  115. return;
  116. do {
  117. cb = wsprintf (szBuf, "\t%08X: ", lpData);
  118. psz = szBuf + cb;
  119. for (ix = 0; ix < 8; ++ix)
  120. {
  121. LPBYTE lpb = lpData;
  122. abRow[ix] = '.';
  123. if (IsBadReadPtr (lpData + ix, 1))
  124. lstrcpy (psz, ".. ");
  125. else
  126. {
  127. wsprintf (psz, "%02X ", lpData[ix]);
  128. if (lpData[ix] >= 32 && lpData[ix] < 127)
  129. abRow[ix] = lpData[ix];
  130. }
  131. psz += 3;
  132. }
  133. for (ix = 0; ix < 8; ++ix)
  134. *psz++ = abRow[ix];
  135. lstrcpy (psz, "\r\n");
  136. OutputDebugString (szBuf);
  137. } while (lpData += 8, (nCount -= 8) > 0);
  138. return;
  139. }
  140. /*+ DebugSetOutputLevel
  141. *
  142. *-=================================================================*/
  143. BOOL WINAPI DebugSetOutputLevel (
  144. int nLevel)
  145. {
  146. int nOldLevel = debug_OutputOn;
  147. debug_OutputOn = nLevel;
  148. return nOldLevel;
  149. }
  150. #endif // _INC_MMDEBUG_CODE_
  151. #endif // DEBUG || _DEBUG