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.

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