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.

196 lines
6.5 KiB

  1. //+---------------------------------------------------------------------------
  2. // Copyright (C) 1996, Microsoft Corporation.
  3. //
  4. // File: AdminDbg.h
  5. //
  6. // Contents: Debugging macros. Stolen from old Cairo debnot.h with the
  7. // following history...
  8. //
  9. // History: 23-Jul-91 KyleP Created.
  10. // 15-Oct-91 KevinRo Major changes and comments added
  11. // 18-Oct-91 vich Consolidated win4p.hxx
  12. // 29-Apr-92 BartoszM Moved from win4p.h
  13. // 18-Jun-94 AlexT Make Assert a better statement
  14. // 7-Oct-94 BruceFo Stole and ripped out everything except
  15. // debug prints and asserts.
  16. // 20-Oct-95 EricB Set component debug level in the
  17. // registry.
  18. // 26-Feb-96 EricB Renamed Win4xxx exported fcns to not
  19. // conflict with ole32.lib.
  20. //
  21. //
  22. // NOTE: you must call the InitializeDebugging() API before calling any other
  23. // APIs!
  24. //
  25. // To set a non-default debug info level outside of the debugger, create the
  26. // below registry key:
  27. //
  28. // "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AdminDebug"
  29. //
  30. // and in it create a value whose name is the component's debugging tag name
  31. // (the "comp" parameter to the DECLARE_INFOLEVEL macro) and whose data is
  32. // the desired infolevel in REG_DWORD format.
  33. // e.g. Sched = REG_DWORD 0x707
  34. //
  35. //----------------------------------------------------------------------------
  36. #include <winldap.h>
  37. #ifndef __DEBUG_H__
  38. #define __DEBUG_H__
  39. //+----------------------------------------------------------------------
  40. //
  41. // DECLARE_DEBUG(comp)
  42. // DECLARE_INFOLEVEL(comp)
  43. //
  44. // This macro defines xxDebugOut where xx is the component prefix
  45. // to be defined. This declares a static variable 'xxInfoLevel', which
  46. // can be used to control the type of xxDebugOut messages printed to
  47. // the terminal. For example, xxInfoLevel may be set at the debug terminal.
  48. // This will enable the user to turn debugging messages on or off, based
  49. // on the type desired. The predefined types are defined below. Component
  50. // specific values should use the upper 24 bits
  51. //
  52. // To Use:
  53. //
  54. // 1) In your components main include file, include the line
  55. // DECLARE_DEBUG(comp)
  56. // where comp is your component prefix
  57. //
  58. // 2) In one of your components source files, include the line
  59. // DECLARE_INFOLEVEL(comp)
  60. // where comp is your component prefix. This will define the
  61. // global variable that will control output.
  62. //
  63. // It is suggested that any component define bits be combined with
  64. // existing bits. For example, if you had a specific error path that you
  65. // wanted, you might define DEB_<comp>_ERRORxxx as being
  66. //
  67. // (0x100 | DEB_ERROR)
  68. //
  69. // This way, we can turn on DEB_ERROR and get the error, or just 0x100
  70. // and get only your error.
  71. //
  72. //-----------------------------------------------------------------------
  73. #if DBG==1
  74. class CDbg
  75. {
  76. public:
  77. CDbg(LPTSTR str);
  78. ~CDbg();
  79. void Trace(PWSTR pszfmt, ...);
  80. void Trace(LPSTR pszfmt, ...);
  81. void DebugOut(unsigned long fDebugMask, PWSTR pszfmt, ...);
  82. void DebugOut(unsigned long fDebugMask, LPSTR pszfmt, ...);
  83. void DebugMsg(LPSTR file, unsigned long line, PWSTR msg);
  84. void DebugMsg(LPSTR file, unsigned long line, LPSTR msg);
  85. void DebugErrorL(LPSTR file, ULONG line, LONG err);
  86. void DebugErrorX(LPSTR file, ULONG line, LONG err);
  87. // void PingDc(LPSTR msg);
  88. void IncIndent();
  89. void DecIndent();
  90. static void AssertEx(LPSTR pszFile, int iLine, LPTSTR pszMsg);
  91. static ULONG s_idxTls;
  92. private:
  93. ULONG
  94. _GetIndent();
  95. unsigned long m_flInfoLevel; // must be the first data member
  96. unsigned long m_flOutputOptions;
  97. LPTSTR m_InfoLevelString;
  98. /*
  99. //
  100. // Members used by PingDc
  101. //
  102. LDAP *m_pldap;
  103. */
  104. }; // class CDbg
  105. class CIndenter
  106. {
  107. public:
  108. CIndenter(CDbg *pdbg): m_pDbg(pdbg) { m_pDbg->IncIndent(); }
  109. ~CIndenter() { m_pDbg->DecIndent(); }
  110. private:
  111. CDbg *m_pDbg;
  112. };
  113. #define DECLARE_DEBUG(comp) extern "C" CDbg comp##InfoLevel;
  114. #define DECLARE_INFOLEVEL(comp) CDbg comp##InfoLevel(_T(#comp));
  115. #define Win4Assert(x) (void)((x) || (CDbg::AssertEx(THIS_FILE,__LINE__, _T(#x)),0))
  116. #else // ! DBG==1
  117. #define DECLARE_DEBUG(comp)
  118. #define DECLARE_INFOLEVEL(comp)
  119. #define Win4Assert(x) NULL
  120. #endif // ! DBG==1
  121. ////////////////////////////////////////////////////////////////////////////
  122. ////////////////////////////////////////////////////////////////////////////
  123. //
  124. // Debug info levels
  125. //
  126. ////////////////////////////////////////////////////////////////////////////
  127. ////////////////////////////////////////////////////////////////////////////
  128. #define DEB_ERROR 0x00000001 // exported error paths
  129. #define DEB_WARN 0x00000002 // exported warnings
  130. #define DEB_TRACE 0x00000004 // exported trace messages
  131. #define DEB_DBGOUT 0x00000010 // Output to debugger
  132. #define DEB_STDOUT 0x00000020 // Output to stdout
  133. #define DEB_IERROR 0x00000100 // internal error paths
  134. #define DEB_IWARN 0x00000200 // internal warnings
  135. #define DEB_ITRACE 0x00000400 // internal trace messages
  136. #define DEB_USER1 0x00010000 // User defined
  137. #define DEB_USER2 0x00020000 // User defined
  138. #define DEB_USER3 0x00040000 // User defined
  139. #define DEB_USER4 0x00080000 // User defined
  140. #define DEB_USER5 0x00100000 // User defined
  141. #define DEB_USER6 0x00200000 // User defined
  142. #define DEB_USER7 0x00400000 // User defined
  143. #define DEB_FUNCTION 0x00800000
  144. #define DEB_RESOURCE 0x01000000
  145. #define DEB_METHOD 0x02000000
  146. #define DEB_DSOBJECT 0x04000000
  147. #define DEB_DATAOBJECT 0x08000000
  148. #define DEB_RICHEDIT 0x10000000 // text processing
  149. #define DEB_ENABLEPING 0x20000000 // enable DC pings
  150. #define DEB_ELAPSEDTIME 0x40000000 // output elapsed time
  151. #define DEB_NOCOMPNAME 0x80000000 // suppress component name
  152. #define DEB_FORCE 0x1fffffff // force message
  153. #define ASSRT_MESSAGE 0x00000001 // Output a message
  154. #define ASSRT_BREAK 0x00000002 // Int 3 on assertion
  155. #define ASSRT_POPUP 0x00000004 // And popup message
  156. #ifndef DEF_INFOLEVEL
  157. #define DEF_INFOLEVEL (DEB_ERROR | DEB_WARN)
  158. #endif
  159. #endif // __DEBUG_H__