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.

234 lines
7.7 KiB

  1. #ifndef __APPMAN_DEBUG_
  2. #define __APPMAN_DEBUG_
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <windows.h>
  7. #include <stdio.h>
  8. #include <crtdbg.h>
  9. #include <tchar.h>
  10. #include "Win32API.h"
  11. #include "AppMan.h"
  12. #define REGPATH_APPMAN _T("Software\\Microsoft\\AppMan")
  13. #ifdef _DEBUG
  14. #define _TRACEON TRUE
  15. #else
  16. #define _TRACEON FALSE
  17. #endif
  18. //////////////////////////////////////////////////////////////////////////////////////////////
  19. //
  20. // Make sure to define the different trace message types
  21. //
  22. //////////////////////////////////////////////////////////////////////////////////////////////
  23. // 0: Error useful for application developers.
  24. // 1: Warning useful for application developers.
  25. // 2: API Entered
  26. // 3: API parameters, API return values
  27. // 4: Driver conversation
  28. //
  29. // 5: Deeper program flow notifications
  30. // 6: Dump structures
  31. //
  32. // Debug Level
  33. //
  34. #define DBGLVL_ERROR 0
  35. #define DBGLVL_WARNING 1
  36. #define DBGLVL_APIENTRY 2
  37. #define DBGLVL_APIPARAMS 3
  38. #define DBGLVL_DRIVER 4
  39. #define DBGLVL_INTERNAL 5
  40. #define DBGLVL_DUMPSTRUCTS 6
  41. //
  42. // Debug Type (Not set in Registry)
  43. //
  44. #define DBG_ERROR 0x00000001 // Maps to Level 0
  45. #define DBG_THROW 0x00000002 // Maps to Level 0
  46. #define DBG_CATCH 0x00000004 // Maps to Level 0
  47. #define DBG_WARNING 0x00000008 // Maps to Level 1
  48. #define DBG_FUNCENTRY 0x00000010 // Maps to Level 2
  49. #define DBG_FUNCEXIT 0x00000020 // Maps to Level 2
  50. #define DBG_CONSTRUCTOR 0x00000040 // Maps to Level 2
  51. #define DBG_DESTRUCTOR 0x00000080 // Maps to Level 2
  52. #define DBG_MSG 0x00000100 // Maps to Level 5
  53. #define DBG_EXTERNAL 0x00000200
  54. #define DBG_LEVEL (DBG_ERROR | DBG_THROW | DBG_CATCH | DBG_WARNING | DBG_FUNCENTRY | DBG_FUNCEXIT | DBG_CONSTRUCTOR | DBG_DESTRUCTOR | DBG_MSG | DBG_EXTERNAL)
  55. #define DBG_ENTRY (DBG_FUNCENTRY | DBG_FUNCEXIT | DBG_CONSTRUCTOR | DBG_DESTRUCTOR)
  56. //
  57. // Debug Sources Flags
  58. //
  59. #define DBG_APPENTRY 0x00001000
  60. #define DBG_APPMAN 0x00002000
  61. #define DBG_APPMANROOT 0x00008000
  62. #define DBG_APPMANADMIN 0x00004000
  63. #define DBG_LOCK 0x00010000
  64. #define DBG_EXCEPTION 0x00020000
  65. #define DBG_FAPPMAN 0x00040000
  66. #define DBG_INFOMAN 0x00080000
  67. #define DBG_REGISTRY 0x00100000
  68. #define DBG_WIN32 0x00400000
  69. #define DBG_EMPTYVOLUMECACHE 0x00800000
  70. #define DBG_WAITEVENT 0x01000000
  71. #define DBG_APPMANDP 0x02000000
  72. #define DBG_ALL_MODULES (DBG_APPENTRY | DBG_APPMAN | DBG_APPMANROOT | DBG_APPMANADMIN | DBG_LOCK | DBG_EXCEPTION | DBG_FAPPMAN | DBG_INFOMAN | DBG_REGISTRY | DBG_WIN32 | DBG_EMPTYVOLUMECACHE | DBG_WAITEVENT | DBG_APPMANDP)
  73. #define DBG_STD_MODULES (DBG_APPENTRY | DBG_APPMAN | DBG_APPMANADMIN | DBG_FAPPMAN | DBG_INFOMAN | DBG_WAITEVENT)
  74. //
  75. // Debug Operations Flags
  76. //
  77. #define OP_NOTHING 0x00000000
  78. #define OP_OUTPUTPARAMETERS 0x00000001
  79. #define OP_OUTPUTTIMESTAMP 0x00000002
  80. #define OP_OUTPUTFILENAME 0x00000004
  81. #define OP_OUTPUTLINENUMBER 0x00000008
  82. #define OP_OUTPUTPTID 0x00000010
  83. #define OP_OUTPUTMODULENAME 0x00000020
  84. #define OP_OUTPUTINDENT 0x00000040
  85. //
  86. // Debug Report Mode (Not set in Registry)
  87. //
  88. #define DBGMODE_FILE _CRTDBG_MODE_FILE //0x1
  89. #define DBGMODE_DBGR _CRTDBG_MODE_DEBUG //0x2
  90. #define DBGMODE_WNDW _CRTDBG_MODE_WNDW //0x4
  91. #define DBG_MODULE 0x00000000 //By default, have all off.
  92. #if _TRACEON == TRUE
  93. #define PROF_SECT_APPMAN "ApplicationManager"
  94. //////////////////////////////////////////////////////////////////////////////////////////////
  95. //
  96. // Define the CAppManDebugHandler class
  97. //
  98. //////////////////////////////////////////////////////////////////////////////////////////////
  99. class CAppManDebugHandler
  100. {
  101. public :
  102. CAppManDebugHandler(void);
  103. ~CAppManDebugHandler(void);
  104. void DebugPrintf(const DWORD dwMsgType, const DWORD dwLineNumber, LPCSTR szFilename, const TCHAR * szFormat, ...);
  105. void DebugPrintfW(const DWORD dwMsgType, const DWORD dwLineNumber, LPCSTR szFilename, const wchar_t * wszFormat, ...);
  106. BOOL DebugAccessTest(void);
  107. void InitDebug(void);
  108. void SetSourceFlags(const DWORD dwFilter);
  109. void SetOperationalFlags(const DWORD dwOperationalFlags);
  110. void SetOutputFilename(LPCSTR szFilename);
  111. DWORD GetSourceFlags(void);
  112. DWORD GetOperationalFlags(void);
  113. void GetOutputFilename(LPSTR szFilename);
  114. private :
  115. HANDLE m_MutexHandle;
  116. DWORD m_dwReportMode;
  117. DWORD m_dwOperationalFlags;
  118. DWORD m_dwSourceFlags;
  119. DWORD m_dwFunctionDepth;
  120. DWORD m_dwDebugLevel;
  121. DWORD m_dwDebugInternal;
  122. CHAR m_szOutputFilename[MAX_PATH_CHARCOUNT];
  123. BOOL m_fDebugInitialized;
  124. };
  125. //////////////////////////////////////////////////////////////////////////////////////////////
  126. //
  127. // Define the CAutoTrace class. This class is use to track function entry and exit
  128. // automatically
  129. //
  130. //////////////////////////////////////////////////////////////////////////////////////////////
  131. class CAutoTrace
  132. {
  133. public :
  134. CAutoTrace(DWORD dwModule, LPSTR lpFunctionName, INT iLine, LPSTR lpFileName);
  135. ~CAutoTrace(void);
  136. private :
  137. char m_szFunctionName[MAX_PATH_CHARCOUNT];
  138. char m_szFilename[MAX_PATH_CHARCOUNT];
  139. DWORD m_dwModule;
  140. };
  141. //////////////////////////////////////////////////////////////////////////////////////////////
  142. //
  143. // Share some global variables
  144. //
  145. //////////////////////////////////////////////////////////////////////////////////////////////
  146. extern CAppManDebugHandler g_oDebugHandler;
  147. extern CHAR g_szDebugString[256];
  148. //////////////////////////////////////////////////////////////////////////////////////////////
  149. //
  150. // Share some global functions
  151. //
  152. //////////////////////////////////////////////////////////////////////////////////////////////
  153. extern CHAR * MakeDebugString(const CHAR * szFormat, ...);
  154. //////////////////////////////////////////////////////////////////////////////////////////////
  155. //
  156. //////////////////////////////////////////////////////////////////////////////////////////////
  157. #define FUNCTION(a) CAutoTrace sAutoTrace(DBG_MODULE, (a), __LINE__, __FILE__)
  158. #define TRACE(a,b) g_oDebugHandler.DebugPrintf((a) | DBG_MSG, __LINE__, __FILE__, (b))
  159. #define THROWEXCEPTION(a) g_oDebugHandler.DebugPrintf(DBG_MODULE | DBG_THROW, __LINE__, __FILE__, "EXCEPTION: Severity= 0x%08x", (a))
  160. #define DPF g_oDebugHandler.DebugPrintf
  161. #define DPFW g_oDebugHandler.DebugPrintfW
  162. #define DPFMSG(a) g_oDebugHandler.DebugPrintf(DBG_MODULE | DBG_MSG, __LINE__, __FILE__, (a))
  163. #define DPFERR(a) g_oDebugHandler.DebugPrintf(DBG_MODULE | DBG_ERROR, __LINE__, __FILE__, (a))
  164. #define DPFWARN(a) g_oDebugHandler.DebugPrintf(DBG_MODULE | DBG_WARNING, __LINE__, __FILE__, (a))
  165. #define DPFCONSTRUCTOR(a) g_oDebugHandler.DebugPrintf(DBG_MODULE | DBG_CONSTRUCTOR, __LINE__, __FILE__, (a))
  166. #define DPFDESTRUCTOR(a) g_oDebugHandler.DebugPrintf(DBG_MODULE | DBG_DESTRUCTOR, __LINE__, __FILE__, (a))
  167. #else
  168. #define FUNCTION(a)
  169. #define TRACE(a, b)
  170. #define THROWEXCEPTION(a)
  171. #define DPF
  172. #define DPFW
  173. #define DPFMSG(a)
  174. #define DPFERR(a)
  175. #define DPFWARN(a)
  176. #define DPFCONSTRUCTOR(a)
  177. #define DPFDESTRUCTOR(a)
  178. #endif // _TRACEON
  179. #ifdef __cplusplus
  180. }
  181. #endif
  182. #endif // __APPMAN_DEBUG_