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.

253 lines
7.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: T R A C E . H
  7. //
  8. // Contents: Class definition for CTracing
  9. //
  10. // Notes:
  11. //
  12. // Author: jeffspr 15 Apr 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. #include "tracetag.h"
  17. #include "stldeque.h"
  18. #ifdef ENABLETRACE
  19. // This is needed for TraceHr, since we can't use a macro (vargs), but we
  20. // need to get the file and line from the source.
  21. #define FAL __FILE__,__LINE__,__FUNCTION__
  22. // The Trace Stack functions
  23. #if defined (_IA64_)
  24. #include <ia64reg.h>
  25. extern "C" unsigned __int64 __getReg(int whichReg);
  26. extern "C" void __setReg(int whichReg, __int64 value);
  27. #pragma intrinsic(__getReg)
  28. #pragma intrinsic(__setReg)
  29. #define GetR32 __getReg(CV_IA64_IntR32)
  30. #define GetR33 __getReg(CV_IA64_IntR33)
  31. #define GetR34 __getReg(CV_IA64_IntR34)
  32. #endif // defined(_IA64_)
  33. class CTracingIndent;
  34. class CTracingFuncCall
  35. {
  36. public:
  37. #if defined (_X86_)
  38. CTracingFuncCall(LPCSTR szFunctionName, LPCSTR szFunctionDName, LPCSTR szFile, const DWORD dwLine, const DWORD dwFramePointer);
  39. #elif defined (_IA64_)
  40. CTracingFuncCall(LPCSTR szFunctionName, LPCSTR szFunctionDName, LPCSTR szFile, const DWORD dwLine, const __int64 Args1, const __int64 Args2, const __int64 Args3);
  41. #else
  42. CTracingFuncCall(LPCSTR szFunctionName, LPCSTR szFunctionDName, LPCSTR szFile, const DWORD dwLine);
  43. #endif
  44. CTracingFuncCall(const CTracingFuncCall& TracingFuncCall);
  45. ~CTracingFuncCall();
  46. public:
  47. LPSTR m_szFunctionName;
  48. LPSTR m_szFunctionDName;
  49. LPSTR m_szFile;
  50. DWORD m_dwLine;
  51. #if defined (_X86_)
  52. DWORD m_arguments[3];
  53. #elif defined (_IA64_ )
  54. __int64 m_arguments[3];
  55. #else
  56. // ... add other processors here
  57. #endif
  58. DWORD m_dwFramePointer;
  59. DWORD m_dwThreadId;
  60. friend CTracingIndent;
  61. };
  62. class CTracingThreadInfo
  63. {
  64. public:
  65. CTracingThreadInfo();
  66. ~CTracingThreadInfo();
  67. public:
  68. LPVOID m_pfnStack;
  69. DWORD m_dwLevel;
  70. DWORD m_dwThreadId;
  71. friend CTracingIndent;
  72. };
  73. class CTracingIndent
  74. {
  75. LPSTR m_szFunctionDName;
  76. DWORD m_dwFramePointer;
  77. BOOL bFirstTrace;
  78. public:
  79. #if defined (_X86_)
  80. void AddTrace(LPCSTR szFunctionName, LPCSTR szFunctionDName, LPCSTR szFile, const DWORD dwLine, const DWORD dwFramePointer);
  81. #elif defined (_IA64_)
  82. void AddTrace(LPCSTR szFunctionName, LPCSTR szFunctionDName, LPCSTR szFile, const DWORD dwLine, const __int64 Args1, const __int64 Args2, const __int64 Args3);
  83. #else
  84. void AddTrace(LPCSTR szFunctionName, LPCSTR szFunctionDName, LPCSTR szFile, const DWORD dwLine);
  85. #endif
  86. void RemoveTrace(LPCSTR szFunctionDName, const DWORD dwFramePointer);
  87. CTracingIndent();
  88. ~CTracingIndent();
  89. static CTracingThreadInfo* GetThreadInfo();
  90. static DWORD getspaces();
  91. static void TraceStackFn(TRACETAGID TraceTagId);
  92. };
  93. #define IDENT_ADD2(x) indent ## x
  94. #define IDENT_ADD(x) IDENT_ADD2(x)
  95. #define __INDENT__ IDENT_ADD(__LINE__)
  96. #define FP_ADD2(x) FP ## x
  97. #define FP_ADD(x) FP_ADD2(x)
  98. #define __FP__ FP_ADD(__LINE__)
  99. #if defined (_X86_)
  100. #define AddTraceLevel \
  101. __if_not_exists(NetCfgFramePointer) \
  102. { \
  103. DWORD NetCfgFramePointer; \
  104. BOOL fForceC4715Check = TRUE; \
  105. } \
  106. if (fForceC4715Check) \
  107. { \
  108. __asm { mov NetCfgFramePointer, ebp }; \
  109. } \
  110. __if_not_exists(NetCfgIndent) \
  111. { \
  112. CTracingIndent NetCfgIndent; \
  113. } \
  114. NetCfgIndent.AddTrace(__FUNCTION__, __FUNCDNAME__, __FILE__, __LINE__, NetCfgFramePointer);
  115. #elif defined (_IA64_)
  116. #define AddTraceLevel \
  117. __if_not_exists(NetCfgIndent) \
  118. { \
  119. CTracingIndent NetCfgIndent; \
  120. } \
  121. NetCfgIndent.AddTrace(__FUNCTION__, __FUNCDNAME__, __FILE__, __LINE__, GetR32, GetR33, GetR34);
  122. #else
  123. #define AddTraceLevel \
  124. __if_not_exists(NetCfgIndent) \
  125. { \
  126. CTracingIndent NetCfgIndent; \
  127. } \
  128. NetCfgIndent.AddTrace(__FUNCTION__, __FUNCDNAME__, __FILE__, __LINE__);
  129. #endif
  130. // Trace error functions. The leaading _ is to establish the real function,
  131. // while adding a new macro so we can add __FILE__ and __LINE__ to the output.
  132. //
  133. VOID WINAPI TraceErrorFn (PCSTR pszaFile, INT nLine, PCSTR psza, HRESULT hr);
  134. VOID WINAPI TraceErrorOptionalFn (PCSTR pszaFile, INT nLine, PCSTR psza, HRESULT hr, BOOL fOpt);
  135. VOID WINAPI TraceErrorSkipFn (PCSTR pszaFile, INT nLine, PCSTR psza, HRESULT hr, UINT c, ...);
  136. VOID WINAPIV TraceLastWin32ErrorFn (PCSTR pszaFile, INT nLine, PCSTR psza);
  137. #define TraceError(sz, hr) TraceErrorFn(__FILE__, __LINE__, sz, hr);
  138. #define TraceErrorOptional(sz, hr, _bool) TraceErrorOptionalFn(__FILE__, __LINE__, sz, hr, _bool);
  139. #define TraceErrorSkip1(sz, hr, hr1) TraceErrorSkipFn(__FILE__, __LINE__, sz, hr, 1, hr1);
  140. #define TraceErrorSkip2(sz, hr, hr1, hr2) TraceErrorSkipFn(__FILE__, __LINE__, sz, hr, 2, hr1, hr2);
  141. #define TraceErrorSkip3(sz, hr, hr1, hr2, hr3) TraceErrorSkipFn(__FILE__, __LINE__, sz, hr, 3, hr1, hr2, hr3);
  142. #define TraceLastWin32Error(sz) TraceLastWin32ErrorFn(__FILE__,__LINE__, sz);
  143. VOID
  144. WINAPIV
  145. TraceHrFn (
  146. TRACETAGID ttid,
  147. PCSTR pszaFile,
  148. INT nLine,
  149. HRESULT hr,
  150. BOOL fIgnore,
  151. PCSTR pszaFmt,
  152. ...);
  153. VOID
  154. WINAPIV
  155. TraceHrFn (
  156. TRACETAGID ttid,
  157. PCSTR pszaFile,
  158. INT nLine,
  159. PCSTR pszaFunc,
  160. HRESULT hr,
  161. BOOL fIgnore,
  162. PCSTR pszaFmt,
  163. ...);
  164. VOID
  165. WINAPIV
  166. TraceTagFn (
  167. TRACETAGID ttid,
  168. PCSTR pszaFmt,
  169. ...);
  170. VOID
  171. WINAPIV
  172. TraceFileFuncFn (
  173. TRACETAGID ttid);
  174. #define TraceFileFunc(ttidWhich) AddTraceLevel; TraceFileFuncFn(ttidWhich);
  175. #define TraceStack(ttidWhich) AddTraceLevel; CTracingIndent::TraceStackFn(ttidWhich);
  176. #define TraceHr AddTraceLevel; TraceHrFn
  177. #define TraceTag AddTraceLevel; TraceTagFn
  178. #define TraceException(hr, szExceptionName) TraceHr(ttidError, FAL, hr, FALSE, "A (%s) exception occurred", szExceptionName);
  179. LPCSTR DbgEvents(DWORD Event);
  180. LPCSTR DbgEventManager(DWORD EventManager);
  181. LPCSTR DbgNcm(DWORD ncm);
  182. LPCSTR DbgNcs(DWORD ncs);
  183. LPCSTR DbgNccf(DWORD nccf);
  184. LPCSTR DbgNcsm(DWORD ncsm);
  185. #else // !ENABLETRACE
  186. #define FAL (void)0
  187. #define TraceError(_sz, _hr)
  188. #define TraceErrorOptional(_sz, _hr, _bool)
  189. #define TraceErrorSkip1(_sz, _hr, _hr1)
  190. #define TraceErrorSkip2(_sz, _hr, _hr1, _hr2)
  191. #define TraceErrorSkip3(_sz, _hr, _hr1, _hr2, _hr3)
  192. #define TraceLastWin32Error(_sz)
  193. #define TraceHr NOP_FUNCTION
  194. #define TraceTag NOP_FUNCTION
  195. #define TraceFileFunc(ttidWhich) NOP_FUNCTION
  196. #define TraceException(hr, szExceptionName) NOP_FUNCTION
  197. #define TraceStack(ttidWhich) NOP_FUNCTION
  198. #define DbgEvents(Event) ""
  199. #define DbgEventManager(EventManager) ""
  200. #define DbgNcm(ncm) ""
  201. #define DbgNcs(ncs) ""
  202. #define DbgNccf(nccf) ""
  203. #define DbgNcsm(nccf) ""
  204. #endif // ENABLETRACE
  205. #ifdef ENABLETRACE
  206. //---[ Initialization stuff ]-------------------------------------------------
  207. HRESULT HrInitTracing();
  208. HRESULT HrUnInitTracing();
  209. HRESULT HrOpenTraceUI(HWND hwndOwner);
  210. #endif // ENABLETRACE