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.

317 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. trace.hxx
  6. Abstract:
  7. Holds logging routines.
  8. Author:
  9. Albert Ting (AlbertT) 24-May-1996
  10. Revision History:
  11. --*/
  12. #ifndef _TRACE_HXX
  13. #define _TRACE_HXX
  14. #ifdef __cplusplus
  15. enum COMPARE {
  16. kLess = -1,
  17. kEqual = 0,
  18. kGreater = 1
  19. };
  20. extern CRITICAL_SECTION gcsBackTrace;
  21. #ifdef TRACE_ENABLED
  22. class TMemBlock;
  23. class TBackTraceDB {
  24. SIGNATURE( 'btdb' )
  25. public:
  26. enum CONSTANTS {
  27. kBlockSize = 0x4000
  28. };
  29. TBackTraceDB(
  30. VOID
  31. );
  32. ~TBackTraceDB(
  33. VOID
  34. );
  35. BOOL
  36. bValid(
  37. VOID
  38. );
  39. HANDLE
  40. hStore(
  41. ULONG ulHash,
  42. PVOID pvBackTrace
  43. );
  44. PLONG
  45. plGetCount(
  46. HANDLE hData
  47. );
  48. private:
  49. class TTrace {
  50. friend TDebugExt;
  51. public:
  52. COMPARE
  53. eCompareHash(
  54. ULONG ulHash
  55. ) const;
  56. COMPARE
  57. eCompareBackTrace(
  58. PVOID pvBackTrace
  59. ) const;
  60. static
  61. TTrace*
  62. pNew(
  63. TBackTraceDB *pBackTraceDB,
  64. ULONG ulHash,
  65. PVOID pvBackTrace,
  66. TTrace ** ppTrace
  67. );
  68. VAR( TTrace*, pLeft );
  69. VAR( TTrace*, pRight );
  70. VAR( ULONG, ulHash );
  71. VAR( LONG, lCount );
  72. PVOID apvBackTrace[1];
  73. private:
  74. //
  75. // Don't allow instantiation.
  76. //
  77. TTrace();
  78. ~TTrace();
  79. };
  80. TTrace*
  81. ptFind(
  82. ULONG ulHash,
  83. PVOID pvBackTrace,
  84. TTrace ***pppTrace
  85. );
  86. TTrace *_pTraceHead;
  87. TMemBlock *_pMemBlock;
  88. friend TTrace;
  89. friend TDebugExt;
  90. };
  91. #endif // TRACE_ENABLED
  92. class VBackTrace {
  93. friend TDebugExt;
  94. SIGNATURE( 'vbt' )
  95. ALWAYS_VALID
  96. public:
  97. enum CONSTANTS {
  98. //
  99. // fOptions.
  100. //
  101. kString = 0x1,
  102. kMaxDepth = 0xd
  103. };
  104. VBackTrace(
  105. ULONG_PTR fOptions1 = 0,
  106. ULONG_PTR fOptions2 = 0
  107. );
  108. virtual
  109. ~VBackTrace(
  110. VOID
  111. );
  112. virtual
  113. HANDLE
  114. hCapture(
  115. ULONG_PTR Info1,
  116. ULONG_PTR Info2,
  117. ULONG_PTR Info3 = 0,
  118. PULONG pHash = NULL
  119. )
  120. #ifdef TRACE_ENABLED
  121. = 0
  122. #endif
  123. ;
  124. static
  125. BOOL
  126. bInit(
  127. VOID
  128. );
  129. static
  130. VOID
  131. vDone(
  132. VOID
  133. );
  134. PLONG
  135. plGetCount(
  136. HANDLE hData
  137. );
  138. protected:
  139. struct TLine {
  140. HANDLE _hTrace;
  141. ULONG_PTR _Info1;
  142. ULONG_PTR _Info2;
  143. ULONG_PTR _Info3;
  144. DWORD _ThreadId;
  145. ULONG_PTR _TickCount;
  146. };
  147. ULONG_PTR _fOptions1;
  148. ULONG_PTR _fOptions2;
  149. static BOOL gbInitialized;
  150. };
  151. #ifdef TRACE_ENABLED
  152. /********************************************************************
  153. Backtracing to memory.
  154. ********************************************************************/
  155. class TBackTraceMem : public VBackTrace {
  156. friend TDebugExt;
  157. friend VBackTrace;
  158. SIGNATURE( 'btm' )
  159. ALWAYS_VALID
  160. public:
  161. enum {
  162. kMaxCall = 0x800,
  163. kBlockSize = 0x4000
  164. };
  165. TBackTraceMem(
  166. ULONG_PTR fOptions1 = 0,
  167. ULONG_PTR fOptions2 = 0
  168. );
  169. ~TBackTraceMem(
  170. VOID
  171. );
  172. HANDLE
  173. hCapture(
  174. ULONG_PTR Info1,
  175. ULONG_PTR Info2,
  176. ULONG_PTR Info3 = 0,
  177. PULONG pHash = NULL
  178. );
  179. private:
  180. VOID
  181. vCaptureLine(
  182. TLine* pLine,
  183. ULONG_PTR Info1,
  184. ULONG_PTR Info2,
  185. ULONG_PTR Info3,
  186. PVOID apvBackTrace[VBackTrace::kMaxDepth+1],
  187. PULONG pulHash
  188. );
  189. UINT _uNextFree;
  190. TLine* _pLines;
  191. };
  192. /********************************************************************
  193. Backtracing to file.
  194. ********************************************************************/
  195. class TBackTraceFile : public VBackTrace {
  196. friend TDebugExt;
  197. SIGNATURE( 'btf' )
  198. ALWAYS_VALID
  199. public:
  200. TBackTraceFile(
  201. ULONG_PTR fOptions1 = 0,
  202. ULONG_PTR fOptions2 = 0
  203. );
  204. ~TBackTraceFile(
  205. VOID
  206. );
  207. HANDLE
  208. hCapture(
  209. ULONG_PTR Info1,
  210. ULONG_PTR Info2,
  211. ULONG_PTR Info3 = 0,
  212. PULONG pHash = NULL
  213. );
  214. private:
  215. enum {
  216. kMaxPath = MAX_PATH,
  217. kMaxLineStr = 512
  218. };
  219. HANDLE _hFile;
  220. static COUNT gcInstances;
  221. };
  222. #else // TRACE_ENABLED
  223. class TBackTraceFile : public VBackTrace
  224. {
  225. };
  226. class TBackTraceMem : public VBackTrace
  227. {
  228. };
  229. #endif
  230. #endif // #ifdef __cplusplus
  231. #endif // #ifdef _TRACE_HXX