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.

306 lines
8.1 KiB

  1. /*
  2. * DEBUG code - Contains declarations and macros for include debug support;
  3. * Contains null definitions when !_DEBUG
  4. */
  5. #ifndef _DEBUG_H_
  6. #define _DEBUG_H_
  7. #ifndef RC_INVOKED
  8. #ifdef _DEBUG
  9. #define DBGSTATE " Debug is on"
  10. #else
  11. #define DBGSTATE " Debug is off"
  12. #endif
  13. #endif /* RC_INVOKED */
  14. #include <ole2dbg.h>
  15. //these are bogus APIs (they do nothing)
  16. STDAPI_(BOOL) ValidateAllObjects( BOOL fSuspicious );
  17. STDAPI_(void) DumpAllObjects( void );
  18. #ifdef _DEBUG
  19. BOOL InstallHooks(void);
  20. BOOL UnInstallHooks(void);
  21. #undef ASSERTDATA
  22. #ifdef _MAC
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. void OutputDebugString(const char *);
  27. #ifdef __cplusplus
  28. }
  29. #endif
  30. #endif
  31. #define ASSERTDATA static char _szAssertFile[]= __FILE__;
  32. #undef Assert
  33. // MAC compiler barfs on '(void)0'.
  34. #ifdef _MAC
  35. #define Assert(a) { if (!(a)) FnAssert(#a, NULL, _szAssertFile, __LINE__); }
  36. #undef AssertSz
  37. #define AssertSz(a, b) { if (!(a)) FnAssert(#a, b, _szAssertFile, __LINE__); }
  38. #else
  39. #undef AssertSz
  40. #define AssertSz(a,b) ((a) ? NOERROR : FnAssert(#a, b, _szAssertFile, __LINE__))
  41. #endif
  42. #undef Verify
  43. #define Verify(a) Assert(a)
  44. #undef Puts
  45. #define Puts(s) OutputDebugString(s)
  46. #define ASSERT(cond, msg)
  47. #else // !_DEBUG
  48. #define ASSERTDATA
  49. #define Assert(a)
  50. #define AssertSz(a, b)
  51. #define Verify(a) (a)
  52. #define ASSERT(cond, msg)
  53. #define Puts(s)
  54. #endif // _DEBUG
  55. #ifdef __cplusplus
  56. interface IDebugStream;
  57. /*
  58. * Class CBool wraps boolean values in such a way that they are
  59. * readily distinguishable fron integers by the compiler so we can
  60. * overload the stream << operator.
  61. */
  62. class FAR CBool
  63. {
  64. BOOL value;
  65. public:
  66. CBool (BOOL& b) {value = b;}
  67. operator BOOL( void ) { return value; }
  68. };
  69. /*
  70. * Class CHwnd wraps HWND values in such a way that they are
  71. * readily distinguishable from UINTS by the compiler so we can
  72. * overload the stream << operator
  73. */
  74. class FAR CHwnd
  75. {
  76. HWND m_hwnd;
  77. public:
  78. CHwnd (HWND hwnd) {m_hwnd = hwnd; }
  79. operator HWND( void ) {return m_hwnd;}
  80. };
  81. /*
  82. * Class CAtom wraps ATOM values in such a way that they are
  83. * readily distinguishable from UINTS by the compiler so we can
  84. * overload the stream << operator
  85. */
  86. class FAR CAtom
  87. {
  88. ATOM m_atom;
  89. public:
  90. CAtom (ATOM atom) {m_atom = atom; }
  91. operator ATOM( void ) {return m_atom; }
  92. };
  93. /*
  94. * IDebugStream is a stream to be used for debug output. One
  95. * implementation uses the OutputDebugString function of Windows.
  96. *
  97. * The style is modeled on that of AT&T streams, and so uses
  98. * overloaded operators. You can write to a stream in the
  99. * following ways:
  100. *
  101. * *pdbstm << pUnk; // calls the IDebug::Dump function to
  102. * display the object, if IDebug is supported.
  103. * int n;
  104. * *pdbstm << n; // writes n in decimal
  105. *
  106. * LPSTR sz;
  107. * *pdbstm << sz; // writes a string
  108. *
  109. * CBool b(TRUE);
  110. * *pdbstm << b; // writes True or False
  111. *
  112. * void FAR * pv;
  113. * *pdbstm << pv; // writes the address pv in hex
  114. *
  115. * char ch;
  116. * *pdbstm << ch; // writes the character
  117. *
  118. * ATOM atom;
  119. * *pdbstm << CAtom(atom); // writes the string extracted from the atom
  120. *
  121. * HWND hwnd;
  122. * *pdbstm << CHwnd(hwnd); // writes the info about a window handle
  123. *
  124. * These can be chained together, as such (somewhat artificial
  125. * example):
  126. *
  127. * REFCLSID rclsid;
  128. * pUnk->GetClass(&rclsid);
  129. * *pdbstm << rclsid << " at " << (void FAR *)pUnk <<':' << pUnk;
  130. *
  131. * This produces something like:
  132. *
  133. * CFoo at A7360008: <description of object>
  134. *
  135. * The other useful feature is the Indent and UnIndent functions
  136. * which allow an object to print some information, indent, print
  137. * the info on its member objects, and unindent. This gives
  138. * nicely formatted output.
  139. *
  140. * WARNING: do not (while implementing Dump) write
  141. *
  142. * *pdbstm << pUnkOuter
  143. *
  144. * since this will do a QueryInterface for IDebug, and start
  145. * recursing! It is acceptable to write
  146. *
  147. * *pdbstm << (VOID FAR *)pUnkOuter
  148. *
  149. * as this will simply write the address of pUnkOuter.
  150. *
  151. */
  152. interface IDebugStream : public IUnknown
  153. {
  154. STDMETHOD_(IDebugStream&, operator << ) ( IUnknown FAR * pDebug ) = 0;
  155. STDMETHOD_(IDebugStream&, operator << ) ( REFCLSID rclsid ) = 0;
  156. STDMETHOD_(IDebugStream&, operator << ) ( int n ) = 0;
  157. STDMETHOD_(IDebugStream&, operator << ) ( long l ) = 0;
  158. STDMETHOD_(IDebugStream&, operator << ) ( ULONG l ) = 0;
  159. STDMETHOD_(IDebugStream&, operator << ) ( LPSTR sz ) = 0;
  160. STDMETHOD_(IDebugStream&, operator << ) ( char ch ) = 0;
  161. STDMETHOD_(IDebugStream&, operator << ) ( void FAR * pv ) = 0;
  162. STDMETHOD_(IDebugStream&, operator << ) ( CBool b ) = 0;
  163. STDMETHOD_(IDebugStream&, operator << ) ( CHwnd hwnd ) = 0;
  164. STDMETHOD_(IDebugStream&, operator << ) ( CAtom atom ) = 0;
  165. STDMETHOD_(IDebugStream&, Tab )( void ) = 0;
  166. STDMETHOD_(IDebugStream&, Indent )( void ) = 0;
  167. STDMETHOD_(IDebugStream&, UnIndent )( void ) = 0;
  168. STDMETHOD_(IDebugStream&, Return )( void ) = 0;
  169. STDMETHOD_(IDebugStream&, LF )( void ) = 0;
  170. };
  171. STDAPI_(IDebugStream FAR*) MakeDebugStream( short margin=70, short tabsize=4, BOOL fHeader=1);
  172. interface IDebug
  173. {
  174. STDMETHOD_(void, Dump )( IDebugStream FAR * pdbstm ) = 0;
  175. STDMETHOD_(BOOL, IsValid )( BOOL fSuspicious = FALSE ) = 0;
  176. #ifdef NEVER
  177. __export IDebug(void);
  178. __export ~IDebug(void);
  179. private:
  180. #if _DEBUG
  181. IDebug FAR * pIDPrev;
  182. IDebug FAR * pIDNext;
  183. friend void STDAPICALLTYPE DumpAllObjects( void );
  184. friend BOOL STDAPICALLTYPE ValidateAllObjects( BOOL fSuspicious );
  185. #endif
  186. #endif
  187. };
  188. #ifdef _MAC
  189. typedef short HFILE;
  190. #endif
  191. /*************************************************************************
  192. ** The following functions can be used to log debug messages to a file
  193. ** and simutaneously write them to the dbwin debug window.
  194. ** The CDebugStream implementation automatically writes to a debug
  195. ** log file called "debug.log" in the current working directory.
  196. ** NOTE: The functions are only intended for C programmers. C++
  197. ** programmers should use the "MakeDebugStream" instead.
  198. *************************************************************************/
  199. // Open a log file.
  200. STDAPI_(HFILE) DbgLogOpen(LPSTR lpszFile, LPSTR lpszMode);
  201. // Close the log file.
  202. STDAPI_(void) DbgLogClose(HFILE fh);
  203. // Write to debug log and debug window (used with cvw.exe or dbwin.exe).
  204. STDAPI_(void) DbgLogOutputDebugString(HFILE fh, LPSTR lpsz);
  205. // Write to debug log only.
  206. STDAPI_(void) DbgLogWrite(HFILE fh, LPSTR lpsz);
  207. // Write the current Date and Time to the log file.
  208. STDAPI_(void) DbgLogTimeStamp(HFILE fh, LPSTR lpsz);
  209. // Write a banner separater to the log to separate sections.
  210. STDAPI_(void) DbgLogWriteBanner(HFILE fh, LPSTR lpsz);
  211. /*
  212. * STDDEBDECL macro - helper for debug declaration
  213. *
  214. */
  215. #ifdef _DEBUG
  216. #ifdef _MAC
  217. //#define STDDEBDECL(cclassname,classname)
  218. //#if 0
  219. #define STDDEBDECL(cclassname,classname) NESTED_CLASS(cclassname, CDebug):IDebug { public: \
  220. NC1(cclassname,CDebug)( cclassname FAR * p##classname ) { m_p##classname = p##classname;} \
  221. ~##NC1(cclassname,CDebug)(void){} \
  222. STDMETHOD_(void, Dump)(THIS_ IDebugStream FAR * pdbstm ); \
  223. STDMETHOD_(BOOL, IsValid)(THIS_ BOOL fSuspicious ); \
  224. private: cclassname FAR* m_p##classname; }; \
  225. DECLARE_NC2(cclassname, CDebug) \
  226. NC(cclassname, CDebug) m_Debug;
  227. //#endif
  228. #else // _MAC
  229. #define STDDEBDECL(ignore, classname ) implement CDebug:public IDebug { public: \
  230. CDebug( C##classname FAR * p##classname ) { m_p##classname = p##classname;} \
  231. ~CDebug(void) {} \
  232. STDMETHOD_(void, Dump)(IDebugStream FAR * pdbstm ); \
  233. STDMETHOD_(BOOL, IsValid)(BOOL fSuspicious ); \
  234. private: C##classname FAR* m_p##classname; }; \
  235. DECLARE_NC(C##classname, CDebug) \
  236. CDebug m_Debug;
  237. #endif
  238. //#ifdef _MAC
  239. //#define CONSTRUCT_DEBUG
  240. //#else
  241. #define CONSTRUCT_DEBUG m_Debug(this),
  242. //#endif
  243. #else // _DEBUG
  244. // no debugging
  245. #define STDDEBDECL(cclassname,classname)
  246. #define CONSTRUCT_DEBUG
  247. #endif // _DEBUG
  248. #endif __cplusplus
  249. #endif !_DEBUG_H_