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.

206 lines
5.9 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999 - 1999 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. *
  18. ***************************************************************************/
  19. #ifndef _DNDBG_H_
  20. #define _DNDBG_H_
  21. // Make sure all variations of DEBUG are defined if any one is
  22. #if defined(DEBUG) || defined(DBG) || defined(_DEBUG)
  23. #if !defined(DBG)
  24. #define DBG
  25. #endif // ! DBG
  26. #if !defined(DEBUG)
  27. #define DEBUG
  28. #endif // ! DEBUG
  29. #if !defined(_DEBUG)
  30. #define _DEBUG
  31. #endif // ! _DEBUG
  32. #endif // DEBUG or DBG or _DEBUG
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. // ALWAYS_BREAK
  37. #if defined( _WIN32 ) && !defined(WINNT) && defined(_X86_)
  38. #define ALWAYS_BREAK() _try { _asm { int 3 } } _except (EXCEPTION_EXECUTE_HANDLER) {;}
  39. #else
  40. #define ALWAYS_BREAK() DebugBreak()
  41. #endif
  42. // DEBUG_BREAK()
  43. #if defined(DEBUG)
  44. #define DEBUG_BREAK() ALWAYS_BREAK()
  45. #endif
  46. //
  47. // macros used generate compile time messages
  48. //
  49. // you need to use these with #pragma, example
  50. //
  51. // #pragma TODO(ToddLa, "Fix this later!")
  52. //
  53. #ifndef DNETLOCALBUILD
  54. #define TODO_OFF
  55. #define BUGBUG_OFF
  56. #endif
  57. // to turn this off, set cl = /DTODO_OFF in your environment variables
  58. #define __TODO(e,m,n) message(__FILE__ "(" #n ") : TODO: " #e ": " m)
  59. #define _TODO(e,m,n) __TODO(e,m,n)
  60. #define __BUGBUG(e,m,n) message(__FILE__ "(" #n ") : BUGBUG: " #e ": " m)
  61. #define _BUGBUG(e,m,n) __BUGBUG(e,m,n)
  62. #ifdef TODO_OFF
  63. #define TODO(e,m)
  64. #else
  65. #define TODO(e,m) _TODO(e,m,__LINE__)
  66. #endif
  67. #ifdef BUGBUG_OFF
  68. #define BUGBUG(e,m)
  69. #else
  70. #define BUGBUG(e,m) _BUGBUG(e,m,__LINE__)
  71. #endif
  72. //========================
  73. // Debug Logging support
  74. //========================
  75. /*=============================================================================
  76. Usage:
  77. In code, you can use DPF to print to the log or the debug windows of the
  78. running application. The format of DPF (debug printf) is as follows:
  79. DPFX(DPFPREP,level, string *fmt, arg1, arg2, ...);
  80. level specifies how important this debug printf is. The standard convention
  81. for debug levels is as follows. This is no way strictly enforced for
  82. personal use, but by the time the code is checked in, it should be as close
  83. to this as possible...
  84. DPF_ERRORLEVEL: Error useful for application developers.
  85. DPF_WARNINGLEVEL: Warning useful for application developers.
  86. DPF_ENTRYLEVEL: API Entered
  87. DPF_APIPARAM: API parameters, API return values
  88. DPF_LOCKS: Driver conversation
  89. DPF_INFOLEVEL: Deeper program flow notifications
  90. DPF_STRUCTUREDUMP: Dump structures
  91. DPF_TRACELEVEL: Trace messages
  92. When printing a critical error, you can use:
  93. DPERR( "String" );
  94. which will print a string at debug level zero.
  95. In order to cause the code to stop and break in. You can use ASSERT() or
  96. DEBUG_BREAK(). In order for ASSERT to break in, you must have
  97. BreakOnAssert set in the win.ini file section (see osindep.cpp).
  98. =============================================================================*/
  99. #define DPF_ERRORLEVEL 0
  100. #define DPF_WARNINGLEVEL 1
  101. #define DPF_ENTRYLEVEL 2
  102. #define DPF_APIPARAM 3
  103. #define DPF_LOCKS 4
  104. #define DPF_INFOLEVEL 5
  105. #define DPF_STRUCTUREDUMP 6
  106. #define DPF_TRACELEVEL 9
  107. // For Voice
  108. #define DVF_ERRORLEVEL 0
  109. #define DVF_WARNINGLEVEL 1
  110. #define DVF_ENTRYLEVEL 2
  111. #define DVF_APIPARAM 3
  112. #define DVF_LOCKS 4
  113. #define DVF_INFOLEVEL 5
  114. #define DVF_STRUCTUREDUMP 6
  115. #define DVF_TRACELEVEL 9
  116. #define DN_SUBCOMP_GLOBAL 0
  117. #define DN_SUBCOMP_CORE 1
  118. #define DN_SUBCOMP_ADDR 2
  119. #define DN_SUBCOMP_LOBBY 3
  120. #define DN_SUBCOMP_PROTOCOL 4
  121. #define DN_SUBCOMP_VOICE 5
  122. #define DN_SUBCOMP_DPNSVR 6
  123. #define DN_SUBCOMP_WSOCK 7
  124. #define DN_SUBCOMP_MODEM 8
  125. #define DN_SUBCOMP_COMMON 9
  126. #define DN_SUBCOMP_NATHELP 10
  127. #define DN_SUBCOMP_TOOLS 11
  128. #ifdef DEBUG
  129. extern void DebugPrintfX(LPCSTR szFile, DWORD dwLineNumber,LPCSTR szFnName, DWORD dwSubComp, DWORD dwDetail, ...);
  130. extern void _DNAssert(LPCSTR szFile, DWORD dwLineNumber, LPCSTR szFnName, DWORD dwSubComp, LPCSTR szCondition, DWORD dwLevel);
  131. #define DPFX DebugPrintfX
  132. #ifndef DX_FINAL_RELEASE
  133. #define DPFPREP __FILE__,__LINE__,DPF_MODNAME, DPF_SUBCOMP
  134. #else /* THE FINAL RELEASE - ELIMINATE FILE AND LINE INFO */
  135. #define DPFPREP "",0,DPF_MODNAME, DPF_SUBCOMP
  136. #endif
  137. #define DPFERR( a ) DebugPrintfX(DPFPREP, DPF_ERRORLEVEL, a )
  138. #define DNASSERT(condition) if (!(condition)) _DNAssert(DPFPREP, #condition, 1)
  139. #define DNASSERTX(condition, level) if (!(condition)) _DNAssert(DPFPREP, #condition, level)
  140. #define DBG_CASSERT( exp ) switch (0) case 0: case exp:
  141. #define DEBUG_ONLY( arg ) arg
  142. #define DPF_RETURN(a) DPFX(DPFPREP,DPF_APIPARAM,"Returning: 0x%lx",a); return a;
  143. #define DPF_ENTER() DPFX(DPFPREP,DPF_TRACELEVEL, "Enter");
  144. #define DPF_EXIT() DPFX(DPFPREP,DPF_TRACELEVEL, "Exit");
  145. #else /* NOT DEBUG */
  146. #pragma warning(disable:4002)
  147. #define DPFX()
  148. #define DPF_RETURN(a) return a;
  149. #define DPFERR()
  150. #define DNASSERT()
  151. #define DNASSERTX()
  152. #define DEBUG_ONLY()
  153. #define DBG_CASSERT()
  154. #define DPF_ENTER()
  155. #define DPF_EXIT()
  156. #endif /* DEBUG */
  157. extern BOOL IsValidStringW( const WCHAR * const szString );
  158. extern BOOL IsValidStringA( const CHAR * const swzString );
  159. #define DNVALID_STRING_A(a) IsValidStringA(a)
  160. #define DNVALID_STRING_W(a) IsValidStringW(a)
  161. #define DNVALID_WRITEPTR(a,b) (!IsBadWritePtr(a,b))
  162. #define DNVALID_READPTR(a,b) (!IsBadReadPtr(a,b))
  163. #ifdef __cplusplus
  164. } //extern "C"
  165. #endif
  166. #endif /* _DNDBG_H_ */