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.

170 lines
5.5 KiB

  1. /*
  2. * C A L D B G . H
  3. *
  4. * Debugging support header
  5. * Support functions are implemented in CALDBG.C.
  6. *
  7. * Copyright 1986-1997 Microsoft Corporation. All Rights Reserved.
  8. */
  9. #ifndef _CALDBG_H_
  10. #define _CALDBG_H_
  11. #include <malloc.h>
  12. /*
  13. * Debugging Macros -------------------------------------------------------
  14. *
  15. * IFDBG(x) Results in the expression x if DBG is defined, or
  16. * to nothing if DBG is not defined
  17. *
  18. * IFNDBG(x) Results in the expression x if DBG is not defined,
  19. * or to nothing if DBG is defined
  20. *
  21. * Unreferenced(a) Causes a to be referenced so that the compiler
  22. * doesn't issue warnings about unused local variables
  23. * which exist but are reserved for future use (eg
  24. * ulFlags in many cases)
  25. */
  26. #if defined(DBG)
  27. #define IFDBG(x) x
  28. #define IFNDBG(x)
  29. #else
  30. #define IFDBG(x)
  31. #define IFNDBG(x) x
  32. #endif
  33. #ifdef __cplusplus
  34. #define EXTERN_C_BEGIN extern "C" {
  35. #define EXTERN_C_END }
  36. #else
  37. #define EXTERN_C_BEGIN
  38. #define EXTERN_C_END
  39. #endif
  40. /*
  41. * Assert Macros ------------------------------------------------------------
  42. *
  43. * Assert(a) Displays a message indicating the file and line number
  44. * of this Assert() if a == 0. OK'ing an assert traps
  45. * into the debugger.
  46. *
  47. * AssertSz(a,sz) Works like an Assert(), but displays the string sz
  48. * along with the file and line number.
  49. *
  50. * Side asserts A side assert works like an Assert(), but evaluates
  51. * 'a' even when asserts are not enabled.
  52. */
  53. #if defined(DBG) || defined(ASSERTS_ENABLED)
  54. #define IFTRAP(x) x
  55. #else
  56. #define IFTRAP(x) 0
  57. #endif
  58. #define Trap() IFTRAP(DebugTrapFn(1,__FILE__,__LINE__,"Trap"))
  59. #define TrapSz(psz) IFTRAP(DebugTrapFn(1,__FILE__,__LINE__,psz))
  60. #define Assert(t) IFTRAP(((t) ? 0 : DebugTrapFn(1,__FILE__,__LINE__,"Assertion Failure: " #t),0))
  61. #define AssertSz(t,psz) IFTRAP(((t) ? 0 : DebugTrapFn(1,__FILE__,__LINE__,psz),0))
  62. #define SideAssert(t) ((t) ? 0 : IFTRAP(DebugTrapFn(1,__FILE__,__LINE__,"Assertion Failure: " #t)),0)
  63. #define SideAssertSz(t,psz) ((t) ? 0 : IFTRAP(DebugTrapFn(1,__FILE__,__LINE__,psz)),0)
  64. /*
  65. * Trace Macros -------------------------------------------------------------
  66. *
  67. * DebugTrace Use for arbitrary formatted output. It
  68. * takes exactly the same arguments as the
  69. * Windows wsprintf() function.
  70. * DebugTraceNoCRLF Same as DebugTrace, but doesn't add "\r\n".
  71. * Good for writing a trace that is part of a longer line.
  72. * TraceError DebugTrace the function name (_func, any string)
  73. * INI file entries allow you to filter based on the
  74. * error code's failing/succeeding status.
  75. */
  76. #if defined(DBG) || defined(TRACES_ENABLED)
  77. #define IFTRACE(x) x
  78. #define DebugTrace DebugTraceFn
  79. #define DebugTraceCRLF DebugTraceCRLFFn
  80. #define DebugTraceNoCRLF DebugTraceNoCRLFFn
  81. #define TraceErrorEx(_err,_func,_flag) TraceErrorFn(_err,_func,__FILE__,__LINE__,_flag)
  82. #define TraceError(_err,_func) TraceErrorEx(_err,_func,FALSE)
  83. #else
  84. #define IFTRACE(x) 0
  85. #define DebugTrace NOP_FUNCTION
  86. #define DebugTraceCRLF NOP_FUNCTION
  87. #define DebugTraceNoCRLF NOP_FUNCTION
  88. #define TraceErrorEx(_err,_func,_flag) NOP_FUNCTION
  89. #define TraceError(_err,_func) TraceErrorEx(_err,_func,FALSE)
  90. #endif
  91. /* ------------------------------------------------------------------------
  92. *
  93. * .INI triggered traces
  94. */
  95. #ifdef DBG
  96. #define DEFINE_TRACE(trace) __declspec(selectany) int g_fTrace##trace = FALSE
  97. #define DO_TRACE(trace) !g_fTrace##trace ? 0 : DebugTraceFn
  98. #define INIT_TRACE(trace) g_fTrace##trace = GetPrivateProfileInt( gc_szDbgTraces, #trace, FALSE, gc_szDbgIni )
  99. // Convenience macro for DBG code. Will cause an error on non-debug builds.
  100. #define DEBUG_TRACE_TEST(trace) g_fTrace##trace
  101. #else
  102. #define DEFINE_TRACE(trace)
  103. #define DO_TRACE(trace) DebugTrace
  104. #define INIT_TRACE(trace)
  105. //#define DEBUG_TRACETEST(trace) // Purposefully cause an error on non-debug builds
  106. #endif
  107. /* Debugging Functions ---------------------------------------------------- */
  108. #define EXPORTDBG
  109. EXTERN_C_BEGIN
  110. INT EXPORTDBG __cdecl DebugTrapFn (int fFatal, char *pszFile, int iLine, char *pszFormat, ...);
  111. INT EXPORTDBG __cdecl DebugTraceFn (char *pszFormat, ...);
  112. INT EXPORTDBG __cdecl DebugTraceCRLFFn (char *pszFormat, ...);
  113. INT EXPORTDBG __cdecl DebugTraceNoCRLFFn (char *pszFormat, ...);
  114. INT EXPORTDBG __cdecl TraceErrorFn (DWORD error, char *pszFunction,
  115. char *pszFile, int iLine,
  116. BOOL fEcTypeError);
  117. EXTERN_C_END
  118. /* Debugging Strings ------------------------------------------------------ */
  119. EXTERN_C_BEGIN
  120. // Inifile name -- must be set by calling code!
  121. extern const CHAR gc_szDbgIni[];
  122. extern const INT gc_cchDbgIni;
  123. // Strings set in caldbg.c for use in calling code.
  124. extern const CHAR gc_szDbgDebugTrace[];
  125. extern const CHAR gc_szDbgEventLog[];
  126. extern const CHAR gc_szDbgGeneral[];
  127. extern const CHAR gc_szDbgLogFile[];
  128. extern const CHAR gc_szDbgTraces[];
  129. extern const CHAR gc_szDbgUseVirtual[];
  130. EXTERN_C_END
  131. /* Virtual Allocations ---------------------------------------------------- */
  132. EXTERN_C_BEGIN
  133. VOID * EXPORTDBG __cdecl VMAlloc(ULONG);
  134. VOID * EXPORTDBG __cdecl VMAllocEx(ULONG, ULONG);
  135. VOID * EXPORTDBG __cdecl VMRealloc(VOID *, ULONG);
  136. VOID * EXPORTDBG __cdecl VMReallocEx(VOID *, ULONG, ULONG);
  137. ULONG EXPORTDBG __cdecl VMGetSize(VOID *);
  138. ULONG EXPORTDBG __cdecl VMGetSizeEx(VOID *, ULONG);
  139. VOID EXPORTDBG __cdecl VMFree(VOID *);
  140. VOID EXPORTDBG __cdecl VMFreeEx(VOID *, ULONG);
  141. EXTERN_C_END
  142. #endif