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.6 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. Debug.h
  6. Abstract:
  7. New debug services for spooler.
  8. Author:
  9. Albert Ting (AlbertT) 15-Jan-1995
  10. Revision History:
  11. --*/
  12. #ifndef _DBGLOG_H
  13. #define _DBGLOG_H
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. typedef DWORD GENERROR, *PGENERROR;
  18. /********************************************************************
  19. DBGCHK
  20. Wraps any function that returns an unsigned 4 byte
  21. quantity with debug logging.
  22. Arguments:
  23. expr - function/expression that needs to be tested
  24. uDbgLevel - print/break error level
  25. exprSuccess - expression that indicates function success
  26. (GenError may be used as the expr return value)
  27. cgeFail - Count of items in pgeFails array
  28. pgeFails - Array of error return values (GenError) used
  29. when simulating failures (must be an array, not
  30. a pointer).
  31. pdwLastErrors - Array of error returned from GetLastError used
  32. when simulating failures, zero terminated.
  33. argsPrint - Arguments to print/log in printf format.
  34. Return Value:
  35. Result of the wrapped function or a simulated failure code.
  36. Usage:
  37. lReturn = RegCreateKey( hKey,
  38. L"SubKey",
  39. &hKeyResult );
  40. should be re-written as:
  41. lReturn = DBGCHK( RegCreateKey( hKey,
  42. L"SubKey",
  43. &hKeyResult ),
  44. DBG_ERROR,
  45. GenError == ERROR_SUCCESS,
  46. 2, { ERROR_ACCESS_DENIED, ERROR_INVALID_PARAMETER },
  47. NULL,
  48. ( "CreateError 0x%x", hKey ));
  49. dwReturn = DBGCHK( GetProfileString( pszSection,
  50. pszKey,
  51. pszDefault,
  52. szReturnBuffer,
  53. COUNTOF( szReturnBuffer )),
  54. DBG_WARN,
  55. GenError != 0,
  56. 1, { 0 },
  57. { ERROR_CODE_1, ERROR_CODE_2, 0 },
  58. ( "GetProfileString: %s, %s, %s",
  59. pszSection,
  60. pszKey,
  61. pszDefault ));
  62. ********************************************************************/
  63. #define DBGCHK( expr, \
  64. uDbgLevel, \
  65. exprSuccess, \
  66. cgeFail, \
  67. pgeFails, \
  68. pdwLastErrors, \
  69. argsPrint ) \
  70. { \
  71. GENERROR GenError; \
  72. LPSTR pszFileA = __FILE__; \
  73. \
  74. if( !bDbgGenFail( pszFileA, \
  75. __LINE__, \
  76. cgeFail, \
  77. pgeFails, \
  78. pdwLastErrors, \
  79. &GenError )){ \
  80. \
  81. GenError = (GENERROR)(expr); \
  82. \
  83. if( !( exprSuccess )){ \
  84. \
  85. vDbgLogError( MODULE_DEBUG, \
  86. uDbgLevel, \
  87. __LINE__, \
  88. pszFileA, \
  89. MODULE, \
  90. pszDbgAllocMsgA argsPrint ); \
  91. } \
  92. } \
  93. GenError; \
  94. }
  95. LPSTR
  96. pszDbgAllocMsgA(
  97. LPCSTR pszMsgFormatA,
  98. ...
  99. );
  100. BOOL
  101. bDbgGenFail(
  102. LPCSTR pszFileA,
  103. UINT uLine,
  104. UINT cgeFails,
  105. PGENERROR pgeFails,
  106. PDWORD pdwLastErrors
  107. );
  108. #ifdef __cplusplus
  109. }
  110. #endif
  111. #endif // _DBGLOG_H