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.

249 lines
8.0 KiB

  1. // confdbg.h - Conferencing Debug Functions and Macros
  2. /*
  3. The main macros are:
  4. ASSERT - display error if parameter evalulates to FALSE.
  5. e.g. ASSERT(x == y);
  6. ERROR_OUT - always print this error. Messagebox is optional.
  7. e.g. ERROR_OUT(("Unable to FooBar! Err=%d", dwErr));
  8. WARNING_OUT - warning message, not an error (App must call InitDebugModule)
  9. e.g. WARNING_OUT(("FooBar is not available. Using %s", szAlt));
  10. TRACE_OUT - debug message (App must call InitDebugModule)
  11. e.g. TRACE_OUT(("dwFoo=%d, dwBar=%d", dwFoo, dwBar));
  12. DBGMSG - debug message for a specific zone
  13. e.g. DBGMSG(ghZoneFoo, ZONE_BAR, ("Setting dwFoo=%d", dwFoo));
  14. Important Functions:
  15. VOID DbgInit(HDBGZONE * phDbgZone, PTCHAR * psz, UINT cZone);
  16. VOID DbgDeInit(HDBGZONE * phDbgZone);
  17. VOID WINAPI DbgPrintf(PCSTR pszPrefix, PCSTR pszFormat, va_list ap);
  18. PSTR WINAPI DbgZPrintf(HDBGZONE hZone, UINT iZone, PSTR pszFormat,...);
  19. Note: The strings in these functions, in particular the module and
  20. zone names, are always ANSI strings, even in Unicode components. The
  21. input strings to DBGINIT should not be wrapped in TEXT macros.
  22. */
  23. #ifndef _CONFDBG_H_
  24. #define _CONFDBG_H_
  25. #include <nmutil.h>
  26. #include <stock.h>
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. #include <pshpack8.h> /* Assume 8 byte packing throughout */
  31. // deal with including "debug.h" before and after
  32. #ifdef DEBUGMSG
  33. #undef DEBUGMSG
  34. #endif
  35. #define _DEBUG_H
  36. // MFC also defines this - use our version
  37. #ifdef ASSERT
  38. #undef ASSERT
  39. #endif
  40. #ifdef DEBUG
  41. #ifndef NM_DEBUG
  42. #define NM_DEBUG
  43. #endif
  44. #endif /* DEBUG */
  45. // Special NetMeeting Debug definitions
  46. #ifdef NM_DEBUG
  47. //////////////////////////////////////
  48. //Debug Zones
  49. #define MAXNUM_OF_MODULES 64
  50. #define MAXSIZE_OF_MODULENAME 32
  51. #define MAXNUM_OF_ZONES 16
  52. #define MAXSIZE_OF_ZONENAME 32
  53. #define ZONEINFO_SIGN 0x12490000
  54. // Zone information for a module
  55. typedef struct _ZoneInfo
  56. {
  57. ULONG ulSignature;
  58. ULONG ulRefCnt;
  59. ULONG ulZoneMask; //the zone mask
  60. BOOL bInUse;
  61. CHAR pszModule[MAXSIZE_OF_MODULENAME]; //name against which the zones are registered
  62. CHAR szZoneNames[MAXNUM_OF_ZONES][MAXSIZE_OF_ZONENAME]; //names of the zones
  63. CHAR szFile[MAX_PATH]; // output file, specific to this module
  64. }ZONEINFO,*PZONEINFO;
  65. // DBGZONEPARAM replaced by ZONEINFO
  66. #define DBGZONEINFO ZONEINFO
  67. #define PDBGZONEINFO PZONEINFO
  68. typedef PVOID HDBGZONE;
  69. // size of the memory mapped file
  70. #define CBMMFDBG (sizeof(ZONEINFO) * MAXNUM_OF_MODULES + sizeof(NMDBG))
  71. // General information at end of memory-mapped file (after all zone data)
  72. typedef struct _NmDbg {
  73. BOOL fOutputDebugString; // OutputDebugString is enabled
  74. BOOL fWinOutput; // Window Output is enabled
  75. HWND hwndCtrl; // Window that handles output
  76. UINT msgDisplay; // Message to post to hwndCtrl
  77. BOOL fFileOutput; // File Output is enabled
  78. CHAR szFile[MAX_PATH]; // File name for output
  79. UINT uShowTime; // Format date/time (see DBG_FMTTIME_*)
  80. BOOL fShowThreadId; // Dump ThreadId with each message
  81. BOOL fShowModule; // Dump Module:Zone with each message
  82. } NMDBG;
  83. typedef NMDBG * PNMDBG;
  84. #define DBG_FMTTIME_NONE 0 // Do not format the time
  85. #define DBG_FMTTIME_TICK 1 // Old format (tick count)
  86. #define DBG_FMTTIME_FULL 2 // Full Year/Month/Day Hour:Min:Sec.ms
  87. #define DBG_FMTTIME_DAY 3 // Hour:Minute:Second.ms
  88. extern BOOL WINAPI NmDbgRegisterCtl(HWND hwnd, UINT uDisplayMsg);
  89. extern BOOL WINAPI NmDbgDeregisterCtl(HWND hwnd);
  90. extern BOOL WINAPI NmDbgSetLoggingOptions(HWND hwnd, UINT uOptions);
  91. extern void WINAPI NmDbgFlushFileLog();
  92. extern BOOL WINAPI NmDbgGetAllZoneParams(PDBGZONEINFO *plpZoneParam, UINT * puCnt);
  93. extern BOOL WINAPI NmDbgFreeZoneParams(PDBGZONEINFO pZoneParam);
  94. extern HDBGZONE WINAPI NmDbgCreateZone(LPSTR pszName);
  95. extern VOID WINAPI NmDbgDeleteZone(LPSTR pszName, HDBGZONE hDbgZone);
  96. extern BOOL WINAPI NmDbgSetZone(HDBGZONE hDbgZone,PDBGZONEINFO pZoneParam);
  97. extern PNMDBG WINAPI GetPNmDbg(void);
  98. extern VOID WINAPI NmDbgSetZoneFileName(HDBGZONE hDbgZone, LPCSTR pszFile);
  99. extern PZONEINFO NMINTERNAL FindZoneForModule(LPCSTR pszModule);
  100. extern PZONEINFO NMINTERNAL AllocZoneForModule(LPCSTR pszModule);
  101. extern PZONEINFO NMINTERNAL MapDebugZoneArea(void);
  102. extern VOID NMINTERNAL UnMapDebugZoneArea(void);
  103. extern VOID NMINTERNAL InitDbgZone(void);
  104. extern VOID NMINTERNAL DeInitDbgZone(void);
  105. extern VOID NMINTERNAL SetDbgFlags(void);
  106. // Special reserved strings
  107. #define SZ_DBG_MAPPED_ZONE TEXT("_NmDebugZoneMap")
  108. #define SZ_DBG_FILE_MUTEX TEXT("_NmDbgFileMutex")
  109. #define SZ_DBG_ZONE_MUTEX TEXT("_NmDbgZoneMutex")
  110. #define GETZONEMASK(z) ((z) ? (((PZONEINFO)(z))->ulZoneMask) : 0 )
  111. #define IS_ZONE_ENABLED(z, f) ((((PZONEINFO)(z))->ulZoneMask) & (f))
  112. // Macro to check if zone is enabled: h = ghZone, i = zone index
  113. #define F_ZONE_ENABLED(h, i) ((NULL != h) && IS_ZONE_ENABLED(h, (1 << i)))
  114. // Standard Zones
  115. #define ZONE_WARNING 0
  116. #define ZONE_TRACE 1
  117. #define ZONE_FUNCTION 2
  118. #define ZONE_WARNING_FLAG 0x01
  119. #define ZONE_TRACE_FLAG 0x02
  120. #define ZONE_FUNCTION_FLAG 0x04
  121. ////////////////////////////////////////////
  122. // Functions
  123. VOID WINAPI DbgPrintf(PCSTR pszPrefix, PCSTR pszFormat, va_list ap);
  124. PSTR WINAPI DbgZPrintf(HDBGZONE hZone, UINT iZone, PSTR pszFormat,...);
  125. PSTR WINAPI DbgZVPrintf(HDBGZONE hZone, UINT iZone, PSTR pszFormat, va_list ap);
  126. VOID NMINTERNAL DbgInitEx(HDBGZONE * phDbgZone, PCHAR * psz, UINT cZone, long ulZoneDefault);
  127. VOID NMINTERNAL DbgDeInit(HDBGZONE * phDbgZone);
  128. INLINE VOID DbgInit(HDBGZONE * phDbgZone, PCHAR * psz, UINT cZones)
  129. {
  130. DbgInitEx(phDbgZone, psz, cZones, 0);
  131. }
  132. PSTR PszPrintf(PCSTR pszFormat,...);
  133. #endif /* NM_DEBUG */
  134. ////////////////////////////////////////////
  135. // Main Macros
  136. #ifdef DEBUG
  137. #define DBGINIT(phZone, psz) DbgInit(phZone, psz, (sizeof(psz)/sizeof(PCHAR))-1)
  138. #define DBGDEINIT(phZone) DbgDeInit(phZone)
  139. #define ASSERT(exp) (!(exp) ? ERROR_OUT(("ASSERT failed on %s line %u:\n\r"#exp, __FILE__, __LINE__)) : 0)
  140. VOID WINAPI DbgZPrintError(PSTR pszFormat,...);
  141. VOID WINAPI DbgZPrintWarning(PSTR pszFormat,...);
  142. VOID WINAPI DbgZPrintTrace(PSTR pszFormat,...);
  143. VOID WINAPI DbgZPrintFunction(PSTR pszFormat,...);
  144. #define ERROR_OUT(s) DbgZPrintError s
  145. #define WARNING_OUT(s) DbgZPrintWarning s
  146. #define TRACE_OUT(s) DbgZPrintTrace s
  147. #define DBGENTRY(s) DbgZPrintFunction("Enter " #s);
  148. #define DBGEXIT(s) DbgZPrintFunction("Exit " #s);
  149. #define DBGEXIT_HR(s,hr) DbgZPrintFunction("Exit " #s " (result=%s)", GetHRESULTString(hr));
  150. #define DBGEXIT_BOOL(s,f) DbgZPrintFunction("Exit " #s " (result=%s)", GetBOOLString(f));
  151. #define DBGEXIT_INT(s,i) DbgZPrintFunction("Exit " #s " (result=%s)", GetINTString(i));
  152. #define DBGEXIT_ULONG(s,u) DbgZPrintFunction("Exit " #s " (result=%s)", GetULONGString((ULONG)u));
  153. #define DBGMSG(z, i, s) \
  154. { \
  155. if ((NULL != z) && (((PZONEINFO)(z))->ulZoneMask & (1<<i)) ) \
  156. { \
  157. LocalFree(DbgZPrintf(z, i, PszPrintf s)); \
  158. } \
  159. }
  160. // e.g. DBGMSG(ghZone, ZONE_FOO, ("bar=%d", dwBar))
  161. #else
  162. #define DBGINIT(phZone, psz)
  163. #define DBGDEINIT(phZone)
  164. #define ASSERT(exp)
  165. #define ERROR_OUT(s)
  166. #define WARNING_OUT(s)
  167. #define TRACE_OUT(s)
  168. #define DBGENTRY(s)
  169. #define DBGEXIT(s)
  170. #define DBGEXIT_HR(s,hr)
  171. #define DBGEXIT_BOOL(s,f)
  172. #define DBGEXIT_INT(s,i)
  173. #define DBGEXIT_ULONG(s,u)
  174. #ifndef DBGMSG
  175. #define DBGMSG(z, f, s)
  176. #endif
  177. #endif /* DEBUG */
  178. #include <poppack.h> /* End byte packing */
  179. #ifdef __cplusplus
  180. }
  181. #endif
  182. #endif /* _CONFDBG_H_ */
  183.