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.

316 lines
9.2 KiB

  1. /*++=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. debug.h
  5. Abstract:
  6. Debug logging routines for W3spoof project.
  7. Author:
  8. Paul M Midgen (pmidge) 15-May-2000
  9. Revision History:
  10. 15-May-2000 pmidge
  11. Created
  12. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--*/
  13. #ifndef __DEBUG_H__
  14. #define __DEBUG_H__
  15. #include "common.h"
  16. //
  17. // always build this stuff.
  18. //
  19. #define CASE_OF(constant) case constant: return # constant
  20. #define CASE_OF_MUTATE(val, name) case val: return # name
  21. #define CASE_IID(riid, iid) if(IsEqualIID(riid, iid)) return # iid
  22. LPSTR MapDispidToString(DISPID dispid);
  23. LPSTR MapScriptDispidToString(SCRIPTDISPID sd);
  24. LPSTR MapIOTYPEToString(IOTYPE iot);
  25. LPSTR MapErrorToString(int error);
  26. LPSTR MapTPOToString(DWORD option);
  27. LPSTR MapHResultToString(HRESULT hr);
  28. LPSTR MapStateToString(STATE st);
  29. LPSTR MapStateToString(SERVERSTATE st);
  30. LPSTR MapStateToString(SCRIPTSTATE st);
  31. LPSTR MapIIDToString(REFIID riid);
  32. LPSTR MapInvokeFlagsToString(WORD flags);
  33. LPSTR MapVariantTypeToString(VARIANT* pvar);
  34. int DebugDataDumpFormat(LPSTR buffer, LPBYTE data, DWORD len);
  35. #ifdef _DEBUG
  36. //
  37. // manifests
  38. //
  39. #if defined(__DBG_TO_CONSOLE__)
  40. #define OUTPUT_FLAGS DBG_TO_DEBUGGER
  41. #else
  42. #define OUTPUT_FLAGS DBG_TO_FILE
  43. #endif
  44. #if defined(__FULL_DEBUG__)
  45. #define DEBUG_DEFAULT_FLAGS ( \
  46. DBG_MEM \
  47. | DBG_REFCOUNT \
  48. | DBG_W3SOBJ \
  49. | DBG_FACTORY \
  50. | DBG_W3SUI \
  51. | DBG_APP \
  52. | DBG_RUNTIME \
  53. | DBG_WORKER \
  54. | DBG_SESSION \
  55. | DBG_SOCKET \
  56. | DBG_REQUEST \
  57. | DBG_RESPONSE \
  58. | DBG_URL \
  59. | DBG_ENTITY \
  60. | DBG_HEADERS \
  61. | DBG_UTILS \
  62. | DBG_THREAD_INFO \
  63. | DBG_CALL_INFO \
  64. | DBG_CALL_DEPTH \
  65. | DBG_TIMESTAMP \
  66. | DBG_NEST_CALLS \
  67. | OUTPUT_FLAGS)
  68. #elif defined(__RELEASE_DEBUG__)
  69. #define DEBUG_DEFAULT_FLAGS ( \
  70. DBG_RUNTIME \
  71. | DBG_SESSION \
  72. | DBG_SOCKET \
  73. | DBG_REQUEST \
  74. | DBG_RESPONSE \
  75. | DBG_URL \
  76. | DBG_ENTITY \
  77. | DBG_HEADERS \
  78. | DBG_UTILS \
  79. | DBG_THREAD_INFO \
  80. | DBG_CALL_INFO \
  81. | DBG_CALL_DEPTH \
  82. | DBG_TIMESTAMP \
  83. | DBG_NEST_CALLS \
  84. | OUTPUT_FLAGS)
  85. #else
  86. #define DEBUG_DEFAULT_FLAGS ( \
  87. DBG_MEM \
  88. | DBG_W3SOBJ \
  89. | DBG_RUNTIME \
  90. | DBG_WORKER \
  91. | DBG_SESSION \
  92. | DBG_SOCKET \
  93. | DBG_REQUEST \
  94. | DBG_RESPONSE \
  95. | DBG_URL \
  96. | DBG_ENTITY \
  97. | DBG_HEADERS \
  98. | DBG_UTILS \
  99. | DBG_THREAD_INFO \
  100. | DBG_CALL_INFO \
  101. | DBG_CALL_DEPTH \
  102. | DBG_TIMESTAMP \
  103. | DBG_NEST_CALLS \
  104. | OUTPUT_FLAGS)
  105. #endif
  106. // category flags
  107. #define DBG_APP 0x00000001
  108. #define DBG_WORKER 0x00000002
  109. #define DBG_REGISTRY 0x00000004
  110. #define DBG_MEM 0x00000008
  111. #define DBG_W3SOBJ 0x00000010
  112. #define DBG_REFCOUNT 0x00000020
  113. #define DBG_FACTORY 0x00000040
  114. #define DBG_W3SUI 0x00000080
  115. #define DBG_SESSION 0x00000100
  116. #define DBG_UTILS 0x00000200
  117. #define DBG_SOCKET 0x00000400
  118. #define DBG_REQUEST 0x00000800
  119. #define DBG_RUNTIME 0x00001000
  120. #define DBG_URL 0x00002000
  121. #define DBG_ENTITY 0x00004000
  122. #define DBG_HEADERS 0x00008000
  123. #define DBG_RESPONSE 0x00010000
  124. #define DBG_DISPATCH 0x00020000
  125. // control flags
  126. #define DBG_THROWDBGALERT 0x00800000
  127. #define DBG_THREAD_INFO 0x01000000
  128. #define DBG_CALL_DEPTH 0x02000000 // remove
  129. #define DBG_TIMESTAMP 0x04000000
  130. #define DBG_NEST_CALLS 0x08000000
  131. #define DBG_TO_FILE 0x10000000
  132. #define DBG_TO_DEBUGGER 0x20000000
  133. #define DBG_CALL_INFO 0x40000000
  134. #define DBG_NO_DEBUG 0x80000000
  135. //
  136. // types
  137. //
  138. typedef struct _memusage
  139. {
  140. CRITICAL_SECTION lock;
  141. DWORD total;
  142. MEMORYSTATUS status;
  143. }
  144. MEMUSAGE, *PMEMUSAGE;
  145. typedef enum _rettype
  146. {
  147. rt_void,
  148. rt_bool,
  149. rt_dword,
  150. rt_hresult,
  151. rt_string
  152. }
  153. RETTYPE, *LPRETTYPE;
  154. typedef struct _callinfo
  155. {
  156. struct _callinfo* next;
  157. struct _callinfo* last;
  158. DWORD category;
  159. LPCSTR fname;
  160. RETTYPE rettype;
  161. }
  162. CALLINFO, *LPCALLINFO;
  163. typedef struct _threadinfo
  164. {
  165. DWORD threadid;
  166. DWORD threadcat;
  167. DWORD depth;
  168. LPCALLINFO stack;
  169. }
  170. THREADINFO, *LPTHREADINFO;
  171. //
  172. // prototypes
  173. //
  174. void DebugInitialize(void);
  175. void DebugTerminate(void);
  176. void DebugMemInitialize(void);
  177. void DebugMemTerminate(void);
  178. void DebugMemAlloc(void* pv);
  179. void DebugMemFree(void* pv);
  180. void DebugEnter(int category, RETTYPE rt, LPCSTR function, const char* format, ...);
  181. void DebugLeave(int retval);
  182. void DebugTrace(const char* format, ...);
  183. void DebugAssert(LPSTR condition, LPSTR file, int line);
  184. void DebugDataDump(LPSTR title, LPBYTE data, DWORD len);
  185. void DebugThrowDbgAlert(void);
  186. void AcquireDebugFileLock(void);
  187. void ReleaseDebugFileLock(void);
  188. LPTHREADINFO GetThreadInfo(void);
  189. LPCALLINFO SetCallInfo(LPTHREADINFO pti, DWORD category, RETTYPE rt, LPCSTR function);
  190. LPCALLINFO GetCallInfo(LPTHREADINFO pti);
  191. void DeleteCallInfo(LPCALLINFO pci);
  192. LPSTR FormatCallReturnString(LPCALLINFO pci, int retval);
  193. LPSTR MapCategoryToString(int category);
  194. LPSTR MapCompKeyToString(int key);
  195. void _debugout(LPTHREADINFO pti, BOOL fRaw, BOOL fTrace, const char* format, ...);
  196. char* _gettimestamp(void);
  197. char* _getwhitespace(int spaces);
  198. BOOL _opendebugfile(void);
  199. void _closedebugfile(void);
  200. //
  201. // macros
  202. //
  203. #define DEBUG_INITIALIZE() DebugInitialize()
  204. #define DEBUG_TERMINATE() DebugTerminate()
  205. #define DEBUG_ENTER(parameters) \
  206. DebugEnter parameters
  207. #define DEBUG_LEAVE(retval) \
  208. DebugLeave(retval)
  209. #define DEBUG_ALLOC(block) \
  210. DebugMemAlloc(block)
  211. #define DEBUG_FREE(block) \
  212. DebugMemFree(block)
  213. extern DWORD g_dwDebugFlags;
  214. #define DEBUG_TRACE(category, parameters) \
  215. if( DBG_##category & g_dwDebugFlags ) \
  216. DebugTrace parameters
  217. #define DEBUG_DATA_DUMP(category, parameters) \
  218. if(DBG_##category & g_dwDebugFlags ) \
  219. DebugDataDump parameters
  220. #define DEBUG_ADDREF(objname, refcount) \
  221. if( DBG_REFCOUNT & g_dwDebugFlags ) \
  222. DebugTrace("%s [%#x] addref: %d", objname, this, refcount)
  223. #define DEBUG_RELEASE(objname, refcount) \
  224. if( DBG_REFCOUNT & g_dwDebugFlags ) \
  225. DebugTrace("%s [%#x] release: %d", objname, this, refcount)
  226. #define DEBUG_FINALRELEASE(objname) \
  227. if( DBG_REFCOUNT & g_dwDebugFlags ) \
  228. DebugTrace("%s [%#x] final release!", objname, this)
  229. #define DEBUG_DUMPWSOCKSTATS(wsd) \
  230. if( DBG_APP & g_dwDebugFlags ) \
  231. DebugTrace(\
  232. "%s (v%d.%d in use) is %s",\
  233. wsd.szDescription,\
  234. (wsd.wVersion & 0x00FF),\
  235. ((wsd.wVersion & 0xFF00) >> 8),\
  236. wsd.szSystemStatus)
  237. #define DEBUG_ASSERT(condition) \
  238. if( !(condition) ) \
  239. DebugAssert(#condition, __FILE__, __LINE__)
  240. #else
  241. // we will get rebuked for the bogus
  242. // arglists in the debug macros
  243. #pragma warning( disable : 4002 )
  244. #pragma warning( disable : 4003 )
  245. #define DEBUG_ASSERT(x, y, z)
  246. #define DEBUG_INITIALIZE()
  247. #define DEBUG_TERMINATE()
  248. #define DEBUG_ALLOC(x)
  249. #define DEBUG_FREE(x)
  250. #define DEBUG_ENTER(x)
  251. #define DEBUG_LEAVE(x)
  252. #define DEBUG_TRACE(x)
  253. #define DEBUG_ADDREF(x)
  254. #define DEBUG_RELEASE(x)
  255. #define DEBUG_FINALRELEASE(x)
  256. #define DEBUG_DUMPWSOCKSTATS(x)
  257. #define DEBUG_DATA_DUMP(X)
  258. #endif /* _DEBUG */
  259. #endif /* __DEBUG_H__ */