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.

343 lines
9.6 KiB

  1. #ifndef _WINSDBG_
  2. #define _WINSDBG_
  3. /*++
  4. Copyright (c) 1989 Microsoft Corporation
  5. Module Name:
  6. winsdbg.h
  7. Abstract:
  8. This file contains debug related macros and functions for the
  9. WINS server
  10. Functions:
  11. Portability:
  12. This header is portable.
  13. Author:
  14. Pradeep Bahl (PradeepB) Feb-1993
  15. Revision History:
  16. Modification Date Person Description of Modification
  17. ------------------ ------- ---------------------------
  18. --*/
  19. /*
  20. includes
  21. */
  22. /*
  23. defines
  24. */
  25. #ifdef CPLUSPLUS
  26. extern "C" {
  27. #endif
  28. #if DBG
  29. #ifndef WINSDBG
  30. #define WINSDBG
  31. #endif
  32. #define DBGSVC 1
  33. #endif
  34. #ifdef WINSDBG
  35. #define STATIC
  36. #ifdef WINS_INTERACTIVE
  37. #define PRINTF(pstr) {printf ## pstr; }
  38. #else
  39. //#define PRINTF(pstr) WINSEVT_LOG_PRINT_M(pstr)
  40. #ifdef DBGSVC
  41. //#define PRINTF(pstr) {if (pNmsDbgFile != NULL) fprintf(pNmsDbgFile, pstr);}
  42. //
  43. // files for storing debugs.
  44. //
  45. extern VOID NmsChkDbgFileSz(VOID);
  46. extern HANDLE NmsDbgFileHdl;
  47. #define PRINTF(pstr) { \
  48. int DbgBytesWritten; \
  49. NmsChkDbgFileSz(); \
  50. if (NmsDbgFileHdl != INVALID_HANDLE_VALUE) WriteFile(NmsDbgFileHdl, pstr, strlen(pstr), (LPDWORD)&DbgBytesWritten, NULL);}
  51. #endif
  52. #endif
  53. #define DBGIF(flag) if(flag)
  54. //
  55. // NOTE: Use RtlQueryEnvironmental function instead of getenv in the macro
  56. // below
  57. //
  58. // FUTURES: Use GetEnvironmentVariable here to be consistent with the general
  59. // usage of WIN32 API
  60. //
  61. #define DBGINIT { \
  62. LPBYTE _pStr; \
  63. _pStr = getenv("DBGFLAGS"); \
  64. WinsDbg = _pStr == NULL ? 0 : atoi(_pStr); \
  65. }
  66. //
  67. // check if replication should be disabled
  68. //
  69. #define DBGCHK_IF_RPL_DISABLED { \
  70. LPBYTE _pStr; \
  71. _pStr = getenv("RPLDISABLED"); \
  72. fWinsCnfRplEnabled = _pStr == NULL ? TRUE : FALSE;\
  73. }
  74. //
  75. // check if scavenging should be disabled
  76. //
  77. #define DBGCHK_IF_SCV_DISABLED { \
  78. LPBYTE _pStr; \
  79. _pStr = getenv("SCVDISABLED"); \
  80. fWinsCnfScvEnabled = _pStr == NULL ? TRUE : FALSE;\
  81. }
  82. //
  83. //FUTURES -- "Make this macro independent of DBG or WINSDBG")
  84. //
  85. // check if Perforamance Monitoring should be disabled
  86. //
  87. #define DBGCHK_IF_PERFMON_ENABLED { \
  88. LPBYTE _pStr; \
  89. _pStr = getenv("PERFMON_ENABLED"); \
  90. fWinsCnfPerfMonEnabled = _pStr == NULL ? FALSE : TRUE;\
  91. }
  92. #define IF_DBG(flag) if (WinsDbg & (DBG_ ## flag))
  93. #ifdef WINS_INTERACTIVE
  94. #define DBGPRINT0(flag, str) {IF_DBG(flag) PRINTF((str));}
  95. #define DBGPRINT1(flag,str, v1) {IF_DBG(flag) PRINTF((str,v1));}
  96. #define DBGPRINT2(flag,str, v1,v2) {IF_DBG(flag) PRINTF((str,v1,v2));}
  97. #define DBGPRINT3(flag,str, v1,v2,v3) {IF_DBG(flag) PRINTF((str,v1,v2,v3));}
  98. #define DBGPRINT4(flag,str, v1,v2,v3,v4) {IF_DBG(flag) PRINTF((str,v1,v2,v3,v4));}
  99. #define DBGPRINT5(flag,str, v1,v2,v3,v4,v5) {IF_DBG(flag) PRINTF((str,v1,v2,v3,v4,v5));}
  100. #else
  101. #ifdef DBGSVC
  102. #define DBGPRINT0(flag, str) {IF_DBG(flag) {char cstr[500]; sprintf(cstr, str);PRINTF(cstr);}}
  103. #define DBGPRINT1(flag,str, v1) {IF_DBG(flag) {char cstr[500]; sprintf(cstr,str,v1);PRINTF(cstr);}}
  104. #define DBGPRINT2(flag,str, v1,v2) {IF_DBG(flag) {char cstr[500]; sprintf(cstr,str,v1,v2);PRINTF(cstr);}}
  105. #define DBGPRINT3(flag,str, v1,v2,v3) {IF_DBG(flag) {char cstr[500]; sprintf(cstr,str,v1,v2,v3);PRINTF(cstr);}}
  106. #define DBGPRINT4(flag,str, v1,v2,v3,v4) {IF_DBG(flag) {char cstr[500]; sprintf(cstr, str,v1,v2,v3,v4);PRINTF(cstr);}}
  107. #define DBGPRINT5(flag,str, v1,v2,v3,v4,v5) {IF_DBG(flag) {char cstr[500]; sprintf(cstr, str,v1,v2,v3,v4,v5);PRINTF(cstr);}}
  108. #endif
  109. #endif
  110. #define DBGMYNAME(x) { \
  111. PWINSTHD_TLS_T _pTls; \
  112. _pTls = TlsGetValue(WinsTlsIndex); \
  113. if (_pTls == NULL) \
  114. { \
  115. printf("Couldn't get ptr to TLS storage for storing thd name. Error is (%d)\n", GetLastError());\
  116. } \
  117. else \
  118. { \
  119. RtlCopyMemory(_pTls->ThdName, x, strlen(x)); \
  120. _pTls->ThdName[strlen(x)] = EOS; \
  121. } \
  122. }
  123. #define DBGPRINTNAME { \
  124. PWINSTHD_TLS_T _pTls; \
  125. _pTls = TlsGetValue(WinsTlsIndex); \
  126. if (_pTls == NULL) \
  127. { \
  128. DBGPRINT1(ERR, \
  129. "Couldn't get ptr to TLS storage for reading thd name. Error = (%X)\n", GetLastError()); \
  130. } \
  131. else \
  132. { \
  133. DBGPRINT1(FLOW, "%s\n",_pTls->ThdName); \
  134. } \
  135. }
  136. #define DBGPRINTEXC(str) { \
  137. DBGPRINT0(EXC, str); \
  138. DBGPRINT1(EXC, ": Got Exception (%x)\n",\
  139. (DWORD)GetExceptionCode() ); \
  140. }
  141. #define DBGENTER(str) { \
  142. DBGPRINT0(FLOW, "ENTER:") \
  143. DBGPRINT0(FLOW, str); \
  144. }
  145. #define DBGLEAVE(str) { \
  146. DBGPRINT0(FLOW, "LEAVE:") \
  147. DBGPRINT0(FLOW, str); \
  148. }
  149. #define DBGSTART_PERFMON if(fWinsCnfPerfMonEnabled) {
  150. #define DBGEND_PERFMON }
  151. //
  152. // Use this macro in the var. declaration section of the function in which
  153. // performance monitoring needs to be done
  154. //
  155. //
  156. #define DBG_PERFMON_VAR \
  157. LARGE_INTEGER LiStartCnt, LiEndCnt; \
  158. //
  159. // Use this macro at the point from where you wish to start doing performance
  160. // monitoring. Make sure that the macro DBG_PERFMON_VAR is used in the
  161. // variable declaration section of the function
  162. //
  163. #define DBG_START_PERF_MONITORING \
  164. DBGSTART_PERFMON \
  165. if (fWinsCnfHighResPerfCntr) \
  166. { \
  167. printf("MONITOR START\n"); \
  168. QueryPerformanceCounter(&LiStartCnt); \
  169. printf("Current Count = (%x %x)\n", \
  170. LiStartCnt.HighPart, \
  171. LiStartCnt.LowPart \
  172. ); \
  173. } \
  174. DBGEND_PERFMON
  175. //
  176. // Use this macro at the point at which you wich to stop doing the monitoring
  177. // The macro prints out the time spent in the section delimited by
  178. // DBG_START_PERF_MONITORING and this macro
  179. //
  180. //
  181. #define DBG_PRINT_PERF_DATA \
  182. DBGSTART_PERFMON \
  183. LARGE_INTEGER TimeElapsed; \
  184. if (fWinsCnfHighResPerfCntr) \
  185. { \
  186. QueryPerformanceCounter(&LiEndCnt); \
  187. TimeElapsed = LiDiv( \
  188. LiSub(LiEndCnt, LiStartCnt), LiWinsCnfPerfCntrFreq \
  189. ); \
  190. printf("MONITOR END.\nEnd Count = (%x %x)\n", \
  191. LiEndCnt.HighPart, \
  192. LiEndCnt.LowPart \
  193. ); \
  194. printf("Time Elapsed (%d %d)\n", TimeElapsed.HighPart, TimeElapsed.LowPart); \
  195. } \
  196. DBGEND_PERFMON
  197. #define DBGPRINTTIME(Type,Str, Time) \
  198. { \
  199. TIME_ZONE_INFORMATION tzInfo; \
  200. SYSTEMTIME LocalTime; \
  201. GetTimeZoneInformation(&tzInfo); \
  202. SystemTimeToTzSpecificLocalTime(&tzInfo, &(WinsIntfStat.TimeStamps.Time), &LocalTime); \
  203. DBGPRINT5(Type, Str ## "on %d/%d at %d.%d.%d\n", \
  204. LocalTime.wMonth, \
  205. LocalTime.wDay, \
  206. LocalTime.wHour, \
  207. LocalTime.wMinute, \
  208. LocalTime.wSecond \
  209. ); \
  210. }
  211. #define WINSDBG_INC_SEC_COUNT_M(SecCount) (SecCount)++
  212. #else
  213. #define STATIC
  214. //#define STATIC static
  215. #define PRINTF(str)
  216. #define DBGIF(flag)
  217. #define IF_DBG(flag)
  218. #define DBGINIT
  219. #define DBGCHK_IF_RPL_DISABLED
  220. #define DBGCHK_IF_SCV_DISABLED
  221. #define DBGCHK_IF_SCV_ENABLED
  222. #define DBGCHK_IF_PERFMON_ENABLED
  223. #define DBGPRINT0(flag,str)
  224. #define DBGPRINT1(flag,str, v1)
  225. #define DBGPRINT2(flag,str, v1,v2)
  226. #define DBGPRINT3(flag,str, v1,v2,v3)
  227. #define DBGPRINT4(flag,str, v1,v2,v3,v4)
  228. #define DBGPRINT5(flag,str, v1,v2,v3,v4,v5)
  229. #define DBGMYNAME(x)
  230. #define DBGPRINTEXC(x)
  231. #define DBGENTER(x)
  232. #define DBGLEAVE(x)
  233. #define DBGSTART_PERFMON
  234. #define DBGEND_PERFMON
  235. #define DBG_PERFMON_VAR
  236. #define DBG_START_PERF_MONITORING
  237. #define DBG_PRINT_PERF_DATA
  238. #define DBGPRINTTIME(Type, Str, Time)
  239. #define DBGPRINTNAME
  240. #define WINSDBG_INC_SEC_COUNT_M(SecCount)
  241. #endif
  242. #define WINSDBG_FILE TEXT("wins.dbg")
  243. #define WINSDBG_FILE_BK TEXT("wins.bak")
  244. #define DBG_EXC 0x00000001 //exceptions
  245. #define DBG_ERR 0x00000002 //errors that do not result in
  246. //exceptions
  247. #define DBG_FLOW 0x00000004 //Control flow
  248. #define DBG_HEAP 0x00000008 //heap related debugs
  249. #define DBG_SPEC 0x00000010 //for special debugs
  250. #define DBG_DS 0x00000020 //Data structures
  251. #define DBG_DET 0x00000040 //detailed stuff
  252. #define DBG_INIT 0x00000080 //Initialization stuff
  253. #define DBG_REPL 0x00000100 //replication debugs
  254. #define DBG_SCV 0x00000200 //scavenging debugs
  255. #define DBG_HEAP_CRDL 0x00000400 //heap creation/deletion
  256. #define DBG_HEAP_CNTRS 0x00000800 //heap creation/deletion
  257. #define DBG_TM 0x00001000 //time related debugs
  258. #define DBG_CHL 0x00002000 //challenge mgr. related debugs
  259. #define DBG_RPL 0x00004000 //challenge mgr. related debugs
  260. #define DBG_RPLPULL 0x00008000 //challenge mgr. related debugs
  261. #define DBG_RPLPUSH 0x00010000 //challenge mgr. related debugs
  262. #define DBG_UPD_CNTRS 0x01000000 //update counters
  263. #define DBG_TMP 0x02000000 //for temporary debugs
  264. #define DBG_INIT_BRKPNT 0x10000000 //breakpoint at the begining
  265. #define DBG_MTCAST 0x20000000 //mcast debugs
  266. /*
  267. macros
  268. */
  269. /*
  270. externs
  271. */
  272. extern ULONG WinsDbg;
  273. /*
  274. typedef definitions
  275. */
  276. /*
  277. function declarations
  278. */
  279. #ifdef CPLUSPLUS
  280. }
  281. #endif
  282. #endif