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.

223 lines
7.7 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999 - 2001 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dndbg.h
  6. * Content: debug support functions for DirectNet
  7. *
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 05-20-99 aarono Created
  12. * 07-16-99 johnkan Added DEBUG_ONLY, DBG_CASSERT, fixed DPFERR to take an argument
  13. * 02-17-00 rodtoll Added Memory / String validation routines
  14. * 05-23-00 RichGr IA64: Changed some DWORDs to DWORD_PTRs to make va_arg work OK.
  15. * 07-27-00 masonb Rewrite to make sub-component stuff work, improve perf
  16. * 08/28/2000 masonb Voice Merge: Part of header guard was missing (#define _DNDBG_H_)
  17. * 10/25/2001 vanceo Use NT build friendly BUGBUG, TODO, plus add PRINTVALUE.
  18. *
  19. ***************************************************************************/
  20. #ifndef _DNDBG_H_
  21. #define _DNDBG_H_
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif // __cplusplus
  25. // DEBUG_BREAK()
  26. #if defined(DBG) || defined(DPINST)
  27. #define DEBUG_BREAK() DebugBreak()
  28. #endif // defined(DBG) || defined(DPINST)
  29. //==================================================================================
  30. // Useful macros based on some DNet code (which was taken from code by ToddLa)
  31. //==================================================================================
  32. //
  33. // Macros that generate compile time messages. Use these with #pragma:
  34. //
  35. // #pragma TODO(vanceo, "Fix this later")
  36. // #pragma BUGBUG(vanceo, "Busted!")
  37. // #pragma PRINTVALUE(DPERR_SOMETHING)
  38. //
  39. // To turn them off, define TODO_OFF, BUGBUG_OFF, PRINTVALUE_OFF in your project
  40. // preprocessor defines.
  41. //
  42. //
  43. // If we're building under VC, (as denoted by the preprocessor define
  44. // DPNBUILD_ENV_NT), these expand to look like:
  45. //
  46. // D:\directory\file.cpp(101) : BUGBUG: vanceo: Busted!
  47. //
  48. // in your output window, and you should be able to double click on it to jump
  49. // directly to that location (line 101 of D:\directory\file.cpp).
  50. //
  51. // If we're building under the NT build environment, these expand to look like:
  52. //
  53. // BUGBUG: vanceo: D:\directory\file.cpp(101) : Busted!
  54. //
  55. // because (at least right now) the build process thinks that a failure occurred if
  56. // a message beginning with a filename and line number is printed. It used to work
  57. // just fine, but who knows.
  58. //
  59. #ifdef DPNBUILD_ENV_NT
  60. #define __TODO(user, msgstr, n) message("TODO: " #user ": " __FILE__ "(" #n ") : " msgstr)
  61. #define __BUGBUG(user, msgstr, n) message("BUGBUG: " #user ": " __FILE__ "(" #n ") : " msgstr)
  62. #define __PRINTVALUE(itemnamestr, itemvaluestr, n) message("PRINTVALUE: " __FILE__ "(" #n ") : " itemnamestr " = " itemvaluestr)
  63. #else // ! DPNBUILD_ENV_NT
  64. #define __TODO(user, msgstr, n) message(__FILE__ "(" #n ") : TODO: " #user ": " msgstr)
  65. #define __BUGBUG(user, msgstr, n) message(__FILE__ "(" #n ") : BUGBUG: " #user ": " msgstr)
  66. #define __PRINTVALUE(itemnamestr, itemvaluestr, n) message(__FILE__ "(" #n ") : PRINTVALUE: " itemnamestr " = " itemvaluestr)
  67. #endif // ! DPNBUILD_ENV_NT
  68. #define _TODO(user, msgstr, n) __TODO(user, msgstr, n)
  69. #define _BUGBUG(user, msgstr, n) __BUGBUG(user, msgstr, n)
  70. #define _PRINTVALUE(itemstr, item, n) __PRINTVALUE(itemstr, #item, n)
  71. #ifdef TODO_OFF
  72. #define TODO(user, msgstr)
  73. #else
  74. #define TODO(user, msgstr) _TODO(user, msgstr, __LINE__)
  75. #endif // TODO_OFF
  76. #ifdef BUGBUG_OFF
  77. #define BUGBUG(user, msgstr)
  78. #else
  79. #define BUGBUG(user, msgstr) _BUGBUG(user, msgstr, __LINE__)
  80. #endif // BUGBUG_OFF
  81. #ifdef PRINTVALUE_OFF
  82. #define PRINTVALUE(item)
  83. #else
  84. #define PRINTVALUE(item) _PRINTVALUE(#item, item, __LINE__)
  85. #endif // PRINTVALUE_OFF
  86. //========================
  87. // Debug Logging support
  88. //========================
  89. /*=============================================================================
  90. Usage:
  91. In code, you can use DPF to print to the log or the debug windows of the
  92. running application. The format of DPF (debug printf) is as follows:
  93. DPFX(DPFPREP,level, string *fmt, arg1, arg2, ...);
  94. level specifies how important this debug printf is. The standard convention
  95. for debug levels is as follows. This is no way strictly enforced for
  96. personal use, but by the time the code is checked in, it should be as close
  97. to this as possible...
  98. DPF_ERRORLEVEL: Error useful for application developers.
  99. DPF_WARNINGLEVEL: Warning useful for application developers.
  100. DPF_ENTRYLEVEL: API Entered
  101. DPF_APIPARAM: API parameters, API return values
  102. DPF_LOCKS: Driver conversation
  103. DPF_INFOLEVEL: Deeper program flow notifications
  104. DPF_STRUCTUREDUMP: Dump structures
  105. DPF_TRACELEVEL: Trace messages
  106. When printing a critical error, you can use:
  107. DPERR( "String" );
  108. which will print a string at debug level zero.
  109. In order to cause the code to stop and break in. You can use ASSERT() or
  110. DEBUG_BREAK(). In order for ASSERT to break in, you must have
  111. BreakOnAssert set in the win.ini file section (see osindep.cpp).
  112. =============================================================================*/
  113. #define DPF_ERRORLEVEL 0
  114. #define DPF_WARNINGLEVEL 1
  115. #define DPF_ENTRYLEVEL 2
  116. #define DPF_APIPARAM 3
  117. #define DPF_LOCKS 4
  118. #define DPF_INFOLEVEL 5
  119. #define DPF_STRUCTUREDUMP 6
  120. #define DPF_TRACELEVEL 9
  121. // For Voice
  122. #define DVF_ERRORLEVEL 0
  123. #define DVF_WARNINGLEVEL 1
  124. #define DVF_ENTRYLEVEL 2
  125. #define DVF_APIPARAM 3
  126. #define DVF_LOCKS 4
  127. #define DVF_INFOLEVEL 5
  128. #define DVF_STRUCTUREDUMP 6
  129. #define DVF_TRACELEVEL 9
  130. #define DN_SUBCOMP_GLOBAL 0
  131. #define DN_SUBCOMP_CORE 1
  132. #define DN_SUBCOMP_ADDR 2
  133. #define DN_SUBCOMP_LOBBY 3
  134. #define DN_SUBCOMP_PROTOCOL 4
  135. #define DN_SUBCOMP_VOICE 5
  136. #define DN_SUBCOMP_DPNSVR 6
  137. #define DN_SUBCOMP_WSOCK 7
  138. #define DN_SUBCOMP_MODEM 8
  139. #define DN_SUBCOMP_COMMON 9
  140. #define DN_SUBCOMP_NATHELP 10
  141. #define DN_SUBCOMP_TOOLS 11
  142. #define DN_SUBCOMP_THREADPOOL 12
  143. #ifdef DBG
  144. extern void DebugPrintfX(LPCTSTR szFile, DWORD dwLineNumber,LPCTSTR szFnName, DWORD dwSubComp, DWORD dwDetail, ...);
  145. extern void _DNAssert(LPCTSTR szFile, DWORD dwLineNumber, LPCTSTR szFnName, DWORD dwSubComp, LPCTSTR szCondition, DWORD dwLevel);
  146. #define DPFX DebugPrintfX
  147. #define DPFPREP _T(__FILE__),__LINE__,_T(DPF_MODNAME), DPF_SUBCOMP
  148. #define DPFERR(a) DebugPrintfX(DPFPREP, DPF_ERRORLEVEL, a )
  149. #ifdef DPNBUILD_USEASSUME
  150. #define DNASSERT(condition) __assume(condition)
  151. #define DNASSERTX(condition, level) DBG_CASSERT(level > 1); if (!(condition)) _DNAssert(DPFPREP, _T(#condition), level)
  152. #else // ! DPNBUILD_USEASSUME
  153. #define DNASSERT(condition) if (!(condition)) _DNAssert(DPFPREP, _T(#condition), 1)
  154. #define DNASSERTX(condition, level) if (!(condition)) _DNAssert(DPFPREP, _T(#condition), level)
  155. #endif // ! DPNBUILD_USEASSUME
  156. #define DBG_CASSERT(exp) switch (0) case 0: case exp:
  157. #define DEBUG_ONLY(arg) arg
  158. #define DPF_RETURN(a) DPFX(DPFPREP,DPF_APIPARAM,"Returning: 0x%lx",a); return a;
  159. #define DPF_ENTER() DPFX(DPFPREP,DPF_TRACELEVEL, "Enter");
  160. #define DPF_EXIT() DPFX(DPFPREP,DPF_TRACELEVEL, "Exit");
  161. #else // NOT DBG
  162. // C4002: too many actual parameters for macro 'identifier'
  163. #pragma warning(disable:4002)
  164. #define DPFX()
  165. #define DPFERR(a)
  166. #ifdef DPNBUILD_USEASSUME
  167. #define DNASSERT(condition) __assume(condition)
  168. #define DNASSERTX(condition, level)
  169. #else // ! DPNBUILD_USEASSUME
  170. #define DNASSERT(condition)
  171. #define DNASSERTX(condition, level)
  172. #endif // ! DPNBUILD_USEASSUME
  173. #define DBG_CASSERT(exp)
  174. #define DEBUG_ONLY(arg)
  175. #define DPF_RETURN(a) return a;
  176. #define DPF_ENTER()
  177. #define DPF_EXIT()
  178. #endif // DBG
  179. #ifdef __cplusplus
  180. } //extern "C"
  181. #endif // __cplusplus
  182. #endif // _DNDBG_H_