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.

184 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. #ifndef __DEBUG_H__
  37. #define __DEBUG_H__
  38. //+----------------------------------------------------------------------
  39. //
  40. // DECLARE_DEBUG(comp)
  41. // DECLARE_INFOLEVEL(comp)
  42. //
  43. // This macro defines xxDebugOut where xx is the component prefix
  44. // to be defined. This declares a static variable 'xxInfoLevel', which
  45. // can be used to control the type of xxDebugOut messages printed to
  46. // the terminal. For example, xxInfoLevel may be set at the debug terminal.
  47. // This will enable the user to turn debugging messages on or off, based
  48. // on the type desired. The predefined types are defined below. Component
  49. // specific values should use the upper 24 bits
  50. //
  51. // To Use:
  52. //
  53. // 1) In your components main include file, include the line
  54. // DECLARE_DEBUG(comp)
  55. // where comp is your component prefix
  56. //
  57. // 2) In one of your components source files, include the line
  58. // DECLARE_INFOLEVEL(comp)
  59. // where comp is your component prefix. This will define the
  60. // global variable that will control output.
  61. //
  62. // It is suggested that any component define bits be combined with
  63. // existing bits. For example, if you had a specific error path that you
  64. // wanted, you might define DEB_<comp>_ERRORxxx as being
  65. //
  66. // (0x100 | DEB_ERROR)
  67. //
  68. // This way, we can turn on DEB_ERROR and get the error, or just 0x100
  69. // and get only your error.
  70. //
  71. //-----------------------------------------------------------------------
  72. #if DBG==1
  73. class CDbg
  74. {
  75. public:
  76. CDbg(LPTSTR str);
  77. ~CDbg();
  78. void __cdecl Trace(PWSTR pszfmt, ...);
  79. void __cdecl Trace(LPSTR pszfmt, ...);
  80. void __cdecl DebugOut(unsigned long fDebugMask, LPSTR pszfmt, ...);
  81. void __cdecl DebugOut(unsigned long fDebugMask, PWSTR pszfmt, ...);
  82. void DebugMsg(LPSTR file, unsigned long line, PWSTR msg);
  83. void DebugMsg(LPSTR file, unsigned long line, LPSTR msg);
  84. void DebugErrorL(LPSTR file, ULONG line, LONG err);
  85. void DebugErrorX(LPSTR file, ULONG line, LONG err);
  86. void IncIndent();
  87. void DecIndent();
  88. static void AssertEx(LPSTR pszFile, int iLine, LPTSTR pszMsg);
  89. static ULONG s_idxTls;
  90. private:
  91. ULONG
  92. _GetIndent();
  93. unsigned long m_flInfoLevel; // must be the first data member
  94. unsigned long m_flOutputOptions;
  95. LPTSTR m_InfoLevelString;
  96. }; // class CDbg
  97. class CIndenter
  98. {
  99. public:
  100. CIndenter(CDbg *pdbg): m_pDbg(pdbg) { m_pDbg->IncIndent(); }
  101. ~CIndenter() { m_pDbg->DecIndent(); m_pDbg = NULL; }
  102. private:
  103. CDbg *m_pDbg;
  104. };
  105. #define DECLARE_DEBUG(comp) extern "C" CDbg comp##InfoLevel;
  106. #define DECLARE_INFOLEVEL(comp) CDbg comp##InfoLevel(_T(#comp));
  107. #define Win4Assert(x) (void)((x) || (CDbg::AssertEx(THIS_FILE,__LINE__, _T(#x)),0))
  108. #else // ! DBG==1
  109. #define DECLARE_DEBUG(comp)
  110. #define DECLARE_INFOLEVEL(comp)
  111. #define Win4Assert(x) NULL
  112. #endif // ! DBG==1
  113. ////////////////////////////////////////////////////////////////////////////
  114. ////////////////////////////////////////////////////////////////////////////
  115. //
  116. // Debug info levels
  117. //
  118. ////////////////////////////////////////////////////////////////////////////
  119. ////////////////////////////////////////////////////////////////////////////
  120. #define DEB_ERROR 0x00000001 // exported error paths
  121. #define DEB_WARN 0x00000002 // exported warnings
  122. #define DEB_TRACE 0x00000004 // exported trace messages
  123. #define DEB_DBGOUT 0x00000010 // Output to debugger
  124. #define DEB_STDOUT 0x00000020 // Output to stdout
  125. #define DEB_IERROR 0x00000100 // internal error paths
  126. #define DEB_IWARN 0x00000200 // internal warnings
  127. #define DEB_ITRACE 0x00000400 // internal trace messages
  128. #define DEB_USER1 0x00010000 // User defined
  129. #define DEB_USER2 0x00020000 // User defined
  130. #define DEB_USER3 0x00040000 // User defined
  131. #define DEB_USER4 0x00080000 // User defined
  132. #define DEB_USER5 0x00100000 // User defined
  133. #define DEB_USER6 0x00200000 // User defined
  134. #define DEB_USER7 0x00400000 // User defined
  135. #define DEB_FUNCTION 0x00800000
  136. #define DEB_RESOURCE 0x01000000
  137. #define DEB_METHOD 0x02000000
  138. #define DEB_USER8 0x04000000
  139. #define DEB_USER9 0x08000000
  140. #define DEB_USER10 0x10000000 // text processing
  141. #define DEB_ELAPSEDTIME 0x20000000 // output elapsed time
  142. #define DEB_NOCOMPNAME 0x40000000 // suppress component name
  143. #define DEB_FORCE 0x1fffffff // force message
  144. #define ASSRT_MESSAGE 0x00000001 // Output a message
  145. #define ASSRT_BREAK 0x00000002 // Int 3 on assertion
  146. #define ASSRT_POPUP 0x00000004 // And popup message
  147. #ifndef DEF_INFOLEVEL
  148. #define DEF_INFOLEVEL (DEB_ERROR | DEB_WARN)
  149. #endif
  150. #endif // __DEBUG_H__