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.

149 lines
4.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: debug.hxx
  7. //
  8. // Contents: Debug routines.
  9. //
  10. // Classes: None.
  11. //
  12. // Functions: TBD : Fill in.
  13. //
  14. // History: 08-Sep-95 EricB Created.
  15. // 01-Dec-95 MarkBl Split from util.hxx.
  16. //
  17. //----------------------------------------------------------------------------
  18. #ifndef __DEBUG_HXX__
  19. #define __DEBUG_HXX__
  20. void SchMsg(TCHAR * pwszMsg, int iStringID, ...);
  21. void SchError(int iStringID, int iParam = 0);
  22. // macros
  23. //+----------------------------------------------------------------------------
  24. // Macro: LOGICAL_NE
  25. // Purpose: any non-zero is true, so compare them logically
  26. //-----------------------------------------------------------------------------
  27. #define LOGICAL_NE(x, y) ((x != 0) != (y != 0))
  28. //+----------------------------------------------------------------------------
  29. // Macro: TESTHR
  30. // Purpose: tests the HRESULT for error, takes "action" if found
  31. //-----------------------------------------------------------------------------
  32. #define TESTHR(hr, str, action) \
  33. if (FAILED(hr)) \
  34. { \
  35. schDebugOut((DEB_ERROR, #str " failed with error 0x%x\n", hr)); \
  36. action; \
  37. }
  38. //+----------------------------------------------------------------------------
  39. // Macro: WIN32FAIL
  40. // Purpose: tests the arg x for NULL, takes 'action' if true
  41. //-----------------------------------------------------------------------------
  42. #define WIN32FAIL(x, str, action) \
  43. if (x == NULL) \
  44. { \
  45. DWORD dwErr = GetLastError(); \
  46. schDebugOut((DEB_ERROR, #str " failed with error %lu", dwErr)); \
  47. action; \
  48. }
  49. //+----------------------------------------------------------------------------
  50. // Macro: LOAD_STRING
  51. // Purpose: attempts to load a string, takes "action" if fails
  52. //-----------------------------------------------------------------------------
  53. #define LOAD_STRING(ids, wcs, len, action) \
  54. if (!LoadString(g_hInstance, ids, wcs, len - 1)) \
  55. { \
  56. DWORD dwErr = GetLastError(); \
  57. schDebugOut((DEB_ERROR, "LoadString of " #ids " failed with error %lu", dwErr)); \
  58. action; \
  59. }
  60. //
  61. // debugging support
  62. //
  63. #if DBG == 1
  64. DECLARE_DEBUG(Sched)
  65. #define schDebugOut(x) SchedInlineDebugOut x
  66. #define schAssert(x) Win4Assert(x);
  67. #define InitDebug() InitializeDebugging()
  68. #ifdef UNICODE
  69. #define FMT_TSTR "%S"
  70. #else
  71. #define FMT_TSTR "%s"
  72. #endif
  73. #define ERR_OUT(msg, hr) \
  74. if (hr == 0) { \
  75. schDebugOut((DEB_ERROR, #msg "\n")); \
  76. } else { \
  77. schDebugOut((DEB_ERROR, #msg " failed with error 0x%x\n", hr)); \
  78. }
  79. #define CHECK_HRESULT(hr) \
  80. if ( FAILED(hr) ) \
  81. { \
  82. schDebugOut((DEB_ERROR, \
  83. "**** ERROR RETURN <%s @line %d> -> %08lx\n", \
  84. __FILE__, \
  85. __LINE__, \
  86. hr)); \
  87. }
  88. #define TRACE(ClassName,MethodName) \
  89. schDebugOut((DEB_ITRACE, #ClassName"::"#MethodName"(0x%x)\n", this)); \
  90. if (SchedInfoLevel & DEB_USER1) HeapValidate(GetProcessHeap(), 0, NULL);
  91. #define TRACE2(ClassName,MethodName) \
  92. schDebugOut((DEB_USER2, #ClassName"::"#MethodName"(0x%x)\n", this)); \
  93. if (SchedInfoLevel & DEB_USER1) HeapValidate(GetProcessHeap(), 0, NULL);
  94. #define TRACE3(ClassName,MethodName) \
  95. schDebugOut((DEB_USER3, #ClassName"::"#MethodName"(0x%x)\n", this)); \
  96. if (SchedInfoLevel & DEB_USER1) HeapValidate(GetProcessHeap(), 0, NULL);
  97. #define TRACE_FUNCTION(FunctionName) \
  98. schDebugOut((DEB_ITRACE, #FunctionName"\n"));
  99. #define TRACE_FUNCTION3(FunctionName) \
  100. schDebugOut((DEB_USER3, #FunctionName"\n"));
  101. #define DBG_OUT(String) \
  102. schDebugOut((DEB_ITRACE, String "\n"));
  103. #define DBG_OUT3(String) \
  104. schDebugOut((DEB_USER3, String "\n"));
  105. #define DEB_IDLE DEB_USER4
  106. #else
  107. #define schDebugOut(x)
  108. #define schedDebugOut(x)
  109. #define schAssert(x)
  110. #define schAssertAndAction(x, action)
  111. #define InitDebug()
  112. #define ERR_OUT(msg, hr)
  113. #define CHECK_HRESULT(hr)
  114. #define TRACE(ClassName,MethodName)
  115. #define TRACE2(ClassName,MethodName)
  116. #define TRACE3(ClassName,MethodName)
  117. #define TRACE_FUNCTION(FunctionName)
  118. #define TRACE_FUNCTION3(FunctionName)
  119. #define DBG_OUT(String)
  120. #define DBG_OUT3(String)
  121. #endif // DBG == 1
  122. #endif // __DEBUG_HXX__