Leaked source code of windows server 2003
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.

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