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.

176 lines
4.5 KiB

  1. #ifndef __DBG_HXX__
  2. #define __DBG_HXX__
  3. #define DEBUG_OUT(x)
  4. #define DECLARE_HEAPCHECKING
  5. #define DEBUGCHECK
  6. #define TRACE(ClassName,MethodName)
  7. #define TRACE_FUNCTION(FunctionName)
  8. #define CHECK_HRESULT(hr)
  9. #define CHECK_LASTERROR(lr)
  10. #define VERIFY(x) x
  11. #define DEBUG_OUT_LASTERROR
  12. #define DEBUG_ASSERT(e)
  13. #define PosDisplay(sz)
  14. #define DbxDisplay(sz)
  15. #define DbxResult(e)
  16. #if DBG==1
  17. #define DEB_TRACE1 DEB_USER1
  18. // debug style : 1 - use dbg out, 2 - use message boxes
  19. #define DBG_STYLE 1
  20. #if defined(_CHICAGO_) && defined(DBX)
  21. #undef DBG_STYLE
  22. #define DBG_STYLE 1
  23. #endif
  24. ////////////////////////////////////////////////////////////////////////////
  25. //
  26. // Style 1: Debug out to stdout
  27. //
  28. #if DBG_STYLE==1
  29. DECLARE_DEBUG(Job)
  30. #undef DEBUG_OUT
  31. #define DEBUG_OUT(x) JobInlineDebugOut x
  32. extern DWORD dwHeapChecking;
  33. #undef DECLARE_HEAPCHECKING
  34. #define DECLARE_HEAPCHECKING DWORD dwHeapChecking = 0
  35. #undef DEBUGCHECK
  36. #define DEBUGCHECK \
  37. if ( (dwHeapChecking & 0x1) == 0x1 ) \
  38. HeapValidate(GetProcessHeap(),0,NULL)
  39. #undef TRACE
  40. #define TRACE(ClassName,MethodName) \
  41. DEBUGCHECK; \
  42. DEBUG_OUT((DEB_TRACE, #ClassName"::"#MethodName"(%x)\n", this));
  43. #undef TRACE_FUNCTION
  44. #define TRACE_FUNCTION(FunctionName) \
  45. DEBUGCHECK; \
  46. DEBUG_OUT((DEB_TRACE, #FunctionName"\n"));
  47. #undef CHECK_HRESULT
  48. #define CHECK_HRESULT(hr) \
  49. if ( FAILED(hr) ) \
  50. { \
  51. DEBUG_OUT((DEB_ERROR, \
  52. "**** ERROR RETURN <%s @line %d> -> %08lx\n", \
  53. __FILE__, \
  54. __LINE__, \
  55. hr)); \
  56. }
  57. #undef CHECK_LASTERROR
  58. #define CHECK_LASTERROR(lr) \
  59. if ( lr != ERROR_SUCCESS ) \
  60. { \
  61. DEBUG_OUT((DEB_ERROR, \
  62. "**** ERROR RETURN <%s @line %d> -> %dL\n", \
  63. __FILE__, \
  64. __LINE__, \
  65. lr)); \
  66. }
  67. #undef VERIFY
  68. #define VERIFY(x) Win4Assert(x)
  69. #undef DEBUG_OUT_LASTERROR
  70. #define DEBUG_OUT_LASTERROR \
  71. DEBUG_OUT((DEB_ERROR, \
  72. "**** ERROR RETURN <%s @line %d> -> %dL\n", \
  73. __FILE__, \
  74. __LINE__, \
  75. GetLastError()));
  76. #undef DEBUG_ASSERT
  77. #define DEBUG_ASSERT(e) \
  78. if ((e) == FALSE) \
  79. { \
  80. DEBUG_OUT((DEB_ERROR, \
  81. "**** ASSERTION <%s> FAILED <%s @line %d>\n", \
  82. #e, \
  83. __FILE__, \
  84. __LINE__)); \
  85. }
  86. #endif // DBG_STYLE==1
  87. ////////////////////////////////////////////////////////////////////////////
  88. //
  89. // Style 2: Debug out to message box
  90. //
  91. #if DBG_STYLE==2
  92. extern TCHAR emsg[300];
  93. #define PRINT_LR(lr) \
  94. wsprintf(emsg, "<%s @ %d> %dL\n", __FILE__, __LINE__, (lr))
  95. #define PRINT_HR(hr) \
  96. wsprintf(emsg, "<%s @ %d> 0x%x\n", __FILE__, __LINE__, (hr))
  97. #define DISP_ERRMSG MessageBox(NULL, emsg, TEXT("**** ERROR ****"), MB_OK)
  98. #define DISP_MSG MessageBox(NULL, emsg, TEXT("**** TRACE ****"), MB_OK)
  99. #undef CHECK_LASTERROR
  100. #define CHECK_LASTERROR(lr) \
  101. if (lr != ERROR_SUCCESS) { PRINT_LR(lr); DISP_ERRMSG; }
  102. #undef DEBUG_OUT_LASTERROR
  103. #define DEBUG_OUT_LASTERROR { PRINT_LR(GetLastError()); DISP_ERRMSG; }
  104. #undef CHECK_HRESULT
  105. #define CHECK_HRESULT(hr) \
  106. if ( FAILED(hr) ) { PRINT_HR(hr); DISP_ERRMSG; }
  107. #undef PosDisplay
  108. #define PosDisplay(e) \
  109. wsprintf(emsg, "<%s @ %d>\n\n\t %s", __FILE__, __LINE__, #e); DISP_MSG
  110. #endif // DBG_STYLE==2
  111. ////////////////////////////////////////////////////////////////////////////
  112. //
  113. // Simple DBX messages
  114. //
  115. #ifdef DBX
  116. #undef DbxDisplay
  117. #define DbxDisplay(sz) MessageBoxA(NULL, sz, "DBX", MB_OK);
  118. #undef DbxResult
  119. #define DbxResult(e) \
  120. { \
  121. char Buff[100]; \
  122. if (FAILED(hr)) \
  123. { \
  124. sprintf(Buff, "%s failed (%x)", #e, hr); \
  125. } \
  126. else \
  127. { \
  128. sprintf(Buff, "%s succeeded", #e); \
  129. } \
  130. MessageBoxA(NULL, Buff, "DBX", MB_OK); \
  131. }
  132. #endif // DBX
  133. #endif // DBG==1
  134. #endif // __DBG_HXX__