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.

844 lines
33 KiB

  1. //+-------------------------------------------------------------
  2. // Microsoft OLE
  3. // Copyright (C) Microsoft Corporation, 1994-1995.
  4. //
  5. // File: cdbghelp.hxx
  6. //
  7. // Contents: Class and usage macros for managing debug information.
  8. // Debug info consists of logs, asserts, and tracing.
  9. //
  10. // Classes: CDebugHelp
  11. //
  12. // History: 17-Nov-94 DeanE Created
  13. // 10-Apr-97 SCousens DH_HRERRORCHECK, Tracelvls
  14. //---------------------------------------------------------------
  15. #ifndef __CDBGHELP_HXX__
  16. #define __CDBGHELP_HXX__
  17. // Debug information macros/values
  18. #define CCH_MAX_DBG_CHARS 1024
  19. #define CCH_MAX_LOG_CHARS 1024
  20. #define CCH_MAX_ASSERT_CHARS 400
  21. #define CCH_MAX_INITAG_CHARS 400
  22. #define CCH_MAX_DBGPREFIX 10
  23. #define CCH_MAX_INDENTPRINT 15
  24. #define CCH_MAX_MODULE 400
  25. // Registry Value Names
  26. #define SZ_REG_TRACE_LOC TEXT("TraceLoc")
  27. #define SZ_REG_TRACE_LVL TEXT("TraceLvl")
  28. #define SZ_REG_LOG_LOC TEXT("LogLoc")
  29. #define SZ_REG_VERBOSE TEXT("Verbose")
  30. #define SZ_REG_BREAKMODE TEXT("BreakMode")
  31. #define SZ_REG_LABMODE TEXT("LabMode")
  32. // Default spy window class name
  33. const TCHAR SZ_DEFAULT_SPY_WINDOW_CLASS[] = TEXT("CTSpyClass");
  34. // Default location in the registry for debug options
  35. #define DEFAULT_REG_LOC TEXT("SOFTWARE\\Microsoft\\CTOleUI\\DebugOptions")
  36. // Debug Helper Usage String
  37. extern LPTSTR gptszDebugHelperUsageString; /* defd in cdbghelp.cxx */
  38. inline LPTSTR GetDebugHelperUsage() {return gptszDebugHelperUsageString;};
  39. //+-------------------------------------------------------------
  40. // Class: CDebugHelp
  41. //
  42. // Synopsis: Manages various debug mechanisms tests commonly use.
  43. // This includes tracing messages, error conditions, test
  44. // results, and asserts.
  45. //
  46. // Methods: CDebugHelp
  47. // ~CDebugHelp
  48. // CreateLog
  49. // GetRegDbgInfo
  50. // SetDebugInfo
  51. // SetPopupWindow
  52. // GetLogLoc
  53. // GetTraceLoc
  54. // GetTraceLvl
  55. // GetMode
  56. // TraceMsg
  57. // LabAssertEx
  58. // ReportResult
  59. // ReportStats
  60. // ValidateLoc, private
  61. // ValidateLvl, private
  62. // ValidateMode, private
  63. // SetStats, private
  64. // OutputMsg, private
  65. // GetResultText, private
  66. //
  67. // History: 17-Nov-94 DeanE Created
  68. //---------------------------------------------------------------
  69. class CDebugHelp
  70. {
  71. public:
  72. // Constructor/Destructor
  73. CDebugHelp(void);
  74. ~CDebugHelp(void);
  75. HRESULT Initialize (void);
  76. HRESULT OptionsDialog (HINSTANCE hinstance, HWND hWnd);
  77. HRESULT CreateLog (int argc, char **argv);
  78. HRESULT CreateLog (LPSTR pszCmdline);
  79. HRESULT SetLog (Log *plog);
  80. HRESULT GetRegDbgInfo (LPTSTR pszRegKey);
  81. HRESULT WriteRegDbgInfo(LPTSTR pszRegKey);
  82. HRESULT SetDebugInfo (DWORD fLogLoc,
  83. DWORD fTraceLoc,
  84. DWORD fTraceLvl,
  85. DWORD fMode);
  86. HRESULT SetPopupWindow(HWND hwnd);
  87. HRESULT SetSpyWindowClass(const LPTSTR pszClass);
  88. DWORD GetLogLoc(void) { return(_fLogLoc); };
  89. DWORD GetTraceLoc(void) { return(_fTraceLoc); };
  90. DWORD GetTraceLvl(void) { return(_fTraceLvl); };
  91. DWORD GetMode(void) { return(_fMode); };
  92. LPTSTR GetSpyWindowClass() {return _pszSpyWindowClass;};
  93. void TraceMsg (DWORD fLvl, LPTSTR pszFmt, ...);
  94. void LabAssertEx (LPCTSTR szFile, int nLine, LPCTSTR szMsg);
  95. HRESULT CheckResult (HRESULT hrCheck,
  96. HRESULT hrExpected,
  97. LPTSTR pszFuncName,
  98. LPTSTR pszMsg,
  99. int nLine,
  100. LPTSTR pszFile);
  101. void ReportResult(USHORT fResult, LPTSTR pszFmt, ...);
  102. void ReportStats (void);
  103. static BOOL CALLBACK OptionsDialogProc(
  104. HWND hwndDlg,
  105. UINT uMsg,
  106. WPARAM wParam,
  107. LPARAM lParam);
  108. void SetExpectedError(HRESULT hrExpectedError );
  109. private:
  110. DWORD ValidateLoc (DWORD fLoc);
  111. DWORD ValidateLvl (DWORD fLvl);
  112. DWORD ValidateMode (DWORD fMode);
  113. VOID SetStats (USHORT fResult);
  114. VOID OutputMsg (DWORD fLoc, LPTSTR pszBuffer);
  115. LPCTSTR GetResultText(USHORT usResult);
  116. void UpdateTraceLevels(HWND hwndDlg, DWORD fTraceLvl);
  117. void UpdateLogLocations(HWND hwndDlg, DWORD fLogLoc);
  118. void UpdateTraceLocations(HWND hwndDlg, DWORD fTraceLoc);
  119. void UpdateTraceLevelFromText(HWND hwndDlg, DWORD *pfTraceLvl);
  120. DWORD _fLogLoc;
  121. DWORD _fTraceLoc;
  122. DWORD _fTraceLvl;
  123. DWORD _fMode;
  124. BOOL _fCreatedLog;
  125. BOOL _fSpyWarning;
  126. TCHAR _szDbgPrefix[CCH_MAX_DBGPREFIX];
  127. Log * _plog;
  128. HWND _hwndAssert;
  129. ULONG _cPass;
  130. ULONG _cFail;
  131. ULONG _cAbort;
  132. ULONG _cIndentLevel;
  133. LPTSTR _pszSpyWindowClass;
  134. HRESULT _hrExpectedError;
  135. };
  136. //+-------------------------------------------------------------------------
  137. // Class: CEntryExitTrace ()
  138. //
  139. // Synopsis: Display debug trace information on instantiation and
  140. // destruction
  141. //
  142. // Methods: CEntryExitTrace
  143. // ~CEntryExitTrace
  144. // GetFunctionName
  145. //
  146. // History: 4-13-95 kennethm Created
  147. //--------------------------------------------------------------------------
  148. class CEntryExitTrace
  149. {
  150. public:
  151. CEntryExitTrace(
  152. CDebugHelp *pDebugObject,
  153. PLONG plExitOutput,
  154. DWORD fLvl,
  155. LPTSTR pszFuncName);
  156. ~CEntryExitTrace(void);
  157. LPTSTR GetFunctionName(void) { return(_pszFuncName); };
  158. private:
  159. CDebugHelp *_pDebugObject;
  160. PLONG _plExitOutput;
  161. LPTSTR _pszFuncName;
  162. DWORD _fLvl;
  163. };
  164. //--------------------------------------------------------------
  165. // Trace Location Flags
  166. // Trace messages can be reported to various locations, including
  167. // a debug monitor (via OutputDebugString), a log file, STDOUT,
  168. // and a spy window, or any combinations of these.
  169. //
  170. // DH_LOC_TERM - To debug terminal, via OutputDebugString.
  171. // DH_LOC_LOG - To a log file that the tester must provide.
  172. // DH_LOC_STDOUT - To STDOUT. Note this is only valid for a
  173. // command line program.
  174. // DH_LOC_SPYWIN - To a spy window.
  175. //
  176. // The default value is DH_LOC_TERM.
  177. //
  178. // Setting the Location
  179. // Testers can set the location in two ways: explicitly passing
  180. // in a value (or set of values), or getting them from registry
  181. // settings at run time.
  182. //
  183. // To explicitly set the value, use the DH_SETTRACELOC macro. Pass
  184. // in the flags you want, bitwise-ORing them as necessary.
  185. //
  186. // hr = DH_SETTRACELOC(DH_LOC_TERM|DH_LOC_LOG);
  187. // This sets the location so messages go to both the debug terminal
  188. // and a provided log file. If the log file has not been set up,
  189. // an error will be returned and that location will be ignored,
  190. // although other valid flags will be set.
  191. //
  192. // To explicitly turn a location off, get the current value via
  193. // DH_GETTRACELOC and bitwise-AND it with the compliment of the proper
  194. // flag.
  195. //
  196. // hr = DH_SETTRACELOC(DH_GETLOC&~DH_LOC_STDOUT);
  197. // This gets the current location setting and explicitly turns
  198. // off output to STDOUT, preserving other values.
  199. //
  200. // Note that if tracing to a log is desired, you must set up the log
  201. // via the DH_CREATELOG macro first, then set the trace location to
  202. // point to the log.
  203. //
  204. // Setting Trace Locations via the Registry
  205. // CDebugHelp can obtain trace location from the registry. The key
  206. // passed to the DH_REGINIT macro must have the REG_DWORD value
  207. // 'TraceLoc', and it should be set with the bits for the devices you
  208. // want tracing messages to go to. If this specifies invalid devices
  209. // (a log when the log has not been set up, or an incorrect bit set),
  210. // the value is ignored and the default DH_LOC_TERM is set instead.
  211. // An error is returned in this case.
  212. //
  213. // DBGLOC_NONE and DBGLOC_VALID are both illegal for general use - they
  214. // are used to validate a new location flag. DH_LOC_SAME is for special
  215. // use and should not be used by testers.
  216. //
  217. // NOTE: The LogLoc registry value uses these flags, too. Use the
  218. // DH_SETLOGLOC and DH_GETLOGLOC macros to set and retrieve the location
  219. // for the logging macros.
  220. //---------------------------------------------------------------
  221. #define DH_LOC_NONE 0x0000 // Illegal value
  222. #define DH_LOC_TERM 0x0001 // OutputDebugString
  223. #define DH_LOC_LOG 0x0002 // LogServer log file
  224. #define DH_LOC_STDOUT 0x0004 // wprintf
  225. #define DH_LOC_SPYWIN 0x0008 // Spy window
  226. #define DH_LOC_SAME 0x8000 // Specify existing value
  227. #define DH_LOC_VALID 0x800F // Validation value
  228. #define DH_LOC_INVALID 0x7FF0 // Validation value
  229. //--------------------------------------------------------------
  230. // Tracing Level Flags
  231. // Tracing gives a tester the chance to output particular messages when
  232. // the user asks for them at run time. Every traced message has a level
  233. // with it. The current trace level is used to determine if that message
  234. // actually gets output to the current trace location setting.
  235. //
  236. // Testers can use predefined trace levels, or use one of their own. The
  237. // predefined levels are really intended for common code, but they can
  238. // be used for individual tests as well. If you use them, then messages
  239. // will be reported for components you might not be interested in.
  240. //
  241. //
  242. // Predefined Trace Levels
  243. // DH_LVL_TRACE1 - Common trace level 1.
  244. // DH_LVL_TRACE2 - Common trace level 2.
  245. // DH_LVL_TRACE3 - Common trace level 3.
  246. // DH_LVL_TRACE4 - Common trace level 4.
  247. // DH_LVL_SAME - Special. Indicates 'use the current setting'.
  248. // DH_LVL_ERROR - Error condition messages
  249. // DH_LVL_ALWAYS - Messages you always want reported
  250. //
  251. // Tester-defined Levels
  252. // The trace levels are represented in a DWORD, and non-used bits can
  253. // be utilized by various tests. Some bits are reserved.
  254. //
  255. // bit(s) meaning
  256. // ------ -------
  257. // 0-7 Generic tracing levels
  258. // 8-23 Individual test trace levels
  259. // 24-28 Reserved for future expansion
  260. // 29 SAME - Indicates current setting
  261. // 30 ERROR messages - always on
  262. // 31 ALWAYS messages - always on
  263. //
  264. // To define your own trace level, #define a value with your trace bit
  265. // and no other bits on:
  266. //
  267. // #define DH_LVL_MYTRACE 0x00001000
  268. //
  269. // Initialize the Trace Level flags via DH_SETLVL macro. Note that
  270. // the special bits 24-31 are always on, and you cannot change them
  271. // through the DH_SETLVL macro.
  272. //
  273. // hr = DH_SETLVL(DH_LVL_MYTRACE);
  274. // Turns your trace level on and leaves errors and other special
  275. // level bits on as well.
  276. //
  277. // Reporting TRACE messages
  278. // Use the DH_TRACE macro to report messages. The level you pass
  279. // indicates when to output the messages - if the level isn't set
  280. // to the one passed, the message is ignored.
  281. //
  282. // DH_TRACE((DH_LVL_MYTRACE, TEXT("My tracing on now")));
  283. //
  284. // Note the use of double parens around the message!
  285. //
  286. // Setting Trace Levels via the Registry
  287. // CDebugHelp can obtain trace levels from the registry. The key
  288. // passed to the DH_REGINIT macro must have the REG_DWORD value
  289. // 'TraceLvl', and it should be set with the bits you desire to be
  290. // traced on. Note that bits 0-7 are ignored in this value, the same
  291. // as in DH_SETLVL.
  292. //
  293. // To enable DH_LVL_MYTRACE to be on above, set the TraceLvl value to
  294. // 0x00001000. Then call DH_REGINIT(key) to initialize the value
  295. // automatically. See DH_REGINIT documentation for more information
  296. // on this feature.
  297. //--------------------------------------------------------------
  298. #define DH_LVL_OUTMASK 0xC0FFFFFF // Does message get reported?
  299. #define DH_LVL_INVMASK 0xDF000000 // Is level being set valid?
  300. // DH_LVL_SAME is reserved, but valid!
  301. #define DH_LVL_RESMASK 0xFF000000 // Are reserved bits that can be
  302. // set being set?
  303. // Reserved bits unchangeable.
  304. #define DH_LVL_ALWAYS 0x80000000
  305. #define DH_LVL_ERROR 0x40000000
  306. #define DH_LVL_SAME 0x20000000
  307. #define DH_LVL_RESERVE1 0x10000000
  308. #define DH_LVL_RESERVE2 0x08000000
  309. #define DH_LVL_RESERVE3 0x04000000
  310. #define DH_LVL_RESERVE4 0x02000000
  311. #define DH_LVL_RESERVE5 0x01000000
  312. // General bits for general use
  313. #define DH_LVL_TRACE1 0x00000001
  314. #define DH_LVL_TRACE2 0x00000002
  315. #define DH_LVL_TRACE3 0x00000004
  316. #define DH_LVL_TRACE4 0x00000008
  317. #define DH_LVL_ENTRY 0x00000010
  318. #define DH_LVL_EXIT 0x00000020
  319. #define DH_LVL_ADDREL 0x00000040
  320. #define DH_LVL_QI 0x00000080
  321. #define DH_LVL_INTERF 0x00000100
  322. // Specific bits. These can be overloaded and reused by different components.
  323. // Make sure you comment on where these bits are being used!
  324. #define DH_LVL_DFLIB 0x00100000 /* Storage DFHELP library */
  325. #define DH_LVL_CRCDUMP 0x00200000 /* Storage crc utilities */
  326. #define DH_LVL_STGAPI 0x00001000 /* wrapper for Storage APIs */
  327. //--------------------------------------------------------------
  328. // Lab Mode Flags
  329. // Lab Mode allows asserts to be shunted off to the current Trace
  330. // Location flag settings. If Lab Mode is turned off, asserts will
  331. // appear in a popup MessageBox as well as in the Trace Location
  332. // settings.
  333. //
  334. // Break On Error flags
  335. // Break On Assert calls DebugBreak and breaks into the debugger.
  336. // This will provide a break-on-first-error functinality.
  337. // If you are not interested, just G)o and execution will proceed
  338. // as before. If you want, you can now start debugging. Using
  339. // this setting also provides a way to access and debug the
  340. // debuggee thru a remote terminal.
  341. //
  342. // Verbose Mode Flags
  343. // Verbose Mode allows all calls to DH_TRACE, DH_HRCHECK, and
  344. // DH_HRERRORCHECK to print to the traceloc. This is convenient
  345. // for those rare occations where a very noisy log is desired in
  346. // order to follow the program execution.
  347. //
  348. // To set the above modes, use the DH_SETMODE macro. This can be
  349. // set from registry entries, or the commandline.
  350. //
  351. // Lab Mode flags:
  352. // DH_LABMODE_OFF - Turns the Lab Mode off.
  353. // DH_LABMODE_ON - Turns the Lab Mode on.
  354. //
  355. // Break Mode flags:
  356. // DH_BREAKMODE_OFF - Turns the Break Mode off.
  357. // DH_BREAKMODE_ON - Turns the Break Mode on.
  358. //
  359. // Verbose Mode flags:
  360. // DH_VERBOSE_OFF - Turns the Verbose Mode off.
  361. // DH_VERBOSE_ON - Turns the Verbose Mode on.
  362. //
  363. // Sample Call:
  364. // hr = DH_SETMODE(DH_LABMODE_ON);
  365. // Turns Lab Mode on so asserts will not stop tests from running.
  366. //
  367. // Setting Lab Mode via the Registry
  368. // CDebugHelp can obtain the Lab Mode from the registry. The key
  369. // passed to the DH_REGINIT macro must have the REG_DWORD value
  370. // 'LabMode', 'BreakMode', 'Verbose'. Set the value to 0 to
  371. // turn the Mode off, or non-zero to turn it on.
  372. //
  373. // Implementation:
  374. // Each mode takes two bits. The lowbit is status on/off. The
  375. // highbit is used when changing the mode. If the highbit is
  376. // set in SetDebugInfo, that mode will be set to the status
  377. // of the lowbit. If the highbit is not set, the old setting
  378. // is retained.
  379. //--------------------------------------------------------------
  380. #define DH_MODE_SAME 0x00000000
  381. #define DH_LABMODE 0x00000001
  382. #define DH_LABMODE_SET 0x00000002
  383. #define DH_LABMODE_OFF DH_LABMODE_SET
  384. #define DH_LABMODE_ON (DH_LABMODE_SET | DH_LABMODE)
  385. #define DH_BREAKMODE 0x00000004
  386. #define DH_BREAKMODE_SET 0x00000008
  387. #define DH_BREAKMODE_OFF DH_BREAKMODE_SET
  388. #define DH_BREAKMODE_ON (DH_BREAKMODE_SET | DH_BREAKMODE)
  389. #define DH_VERBOSE 0x00000010
  390. #define DH_VERBOSE_SET 0x00000020
  391. #define DH_VERBOSE_OFF DH_VERBOSE_SET
  392. #define DH_VERBOSE_ON (DH_VERBOSE_SET | DH_VERBOSE)
  393. #define DH_INVMODE 0xFFFFFFC0
  394. //---------------------------------------------------------------
  395. // Global CDebugHelp objects
  396. // One CDebugHelp object can be utilized per program, and it must be
  397. // global so code everywhere can use it. All members are accessed
  398. // through macros that hide the actual name of the global, so we stay
  399. // encapsulated to a good degree. Two macros are necessary to declare
  400. // and define the object.
  401. //
  402. // DH_DECLARE declares a CDebugHelp object. This macro should be
  403. // used in a global header so all files in your project know the name
  404. // of the object.
  405. //
  406. // DH_DECLARE;
  407. // A global object is declared and will be accessed via macros,
  408. // so the name and access is hidden.
  409. //
  410. // DH_DEFINE defines a CDebugHelp object. This should appear
  411. // in one source file, and must have global scope. As a rule, use it
  412. // in the same file as WinMain.
  413. //
  414. // DH_DEFINE;
  415. // A global object is defined. If this macro is used more than once
  416. // in your source files, you'll get multiple object definition errors.
  417. //
  418. // Note the semicolons are required - that is true of all the macros
  419. // that utilize CDebugHelp functionality.
  420. //---------------------------------------------------------------
  421. #define DH_DECLARE \
  422. extern CDebugHelp gdhDebugHelper
  423. #define DH_DEFINE \
  424. CDebugHelp gdhDebugHelper
  425. #define InitializeDebugObject \
  426. gdhDebugHelper.Initialize
  427. #define DebugOptionsDialog \
  428. gdhDebugHelper.OptionsDialog
  429. //---------------------------------------------------------------
  430. // DH_REGINIT
  431. // This macro is used to initialize information from an entry
  432. // in the registry. The key parameter is assumed to be a subkey of
  433. // HKEY_CURRENT_USER. It can be multiple levels deep, just so long
  434. // as it is a valid path.
  435. //
  436. // Three values are obtained from the key; if any is missing the
  437. // CDebugHelp default is used. If errors occur, such as invalid
  438. // permissions or an invalid key path, then default values are used
  439. // and an error code is returned to indicate the problem. It is up
  440. // to the tester to determine if this is catastrophic or not - the
  441. // object can be used, it will just be in the default state.
  442. //
  443. // The keys are:
  444. // Mode - REG_DWORD. Loword are bit flags for available modes.
  445. // TraceLoc - REG_DWORD. Trace location flags.
  446. // TraceLvl - REG_DWORD. Trace level flags.
  447. // LogLoc - REG_DWORD. Logging location flags.
  448. //
  449. // See the comments above for more information about the flag settings.
  450. // If any setting is invalid, the default is used and an error is
  451. // reported.
  452. //
  453. // TraceLoc are the places where DH_TRACE messages go. LogLoc are the
  454. // places where DH_LOG* messages go. They both use the Trace Location
  455. // flags format.
  456. //
  457. // Sample Call:
  458. // hr = DH_REGINIT(TEXT("SOFTWARE\\Microsoft\\CTOleUI\\Marina"));
  459. // The registry subkey HKEY_CURRENT_USER\SOFTWARE\Microsoft\Marina
  460. // is opened, and the LabMode, BreakMode, VerboseMode, TraceLoc,
  461. // and TraceLvl values are used to set their corresponding values
  462. // in CDebugHelp.
  463. //---------------------------------------------------------------
  464. #define DH_REGINIT(key) \
  465. gdhDebugHelper.GetRegDbgInfo(key)
  466. //---------------------------------------------------------------
  467. // DH_REGWRITE
  468. // This macro is the reverse of the previous macro. It writes
  469. // the same keys to the registry.
  470. //
  471. // Sample Call:
  472. // hr = DH_REGWRITE(TEXT("SOFTWARE\\Microsoft\\CTOleUI\\Marina"));
  473. // The registry subkey HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Marina
  474. // is opened, and the LabMode, BreakMode, VerboseMode, TraceLoc,
  475. // and TraceLvl values are written based on the current settings.
  476. //---------------------------------------------------------------
  477. #define DH_REGWRITE(key) \
  478. gdhDebugHelper.WriteRegDbgInfo(key)
  479. //---------------------------------------------------------------
  480. // DH_CREATELOG*
  481. // Use these macros to create a LogServer log file. See log.hxx
  482. // in the $(COMTOOLS) project for more information on what the
  483. // log object is.
  484. //
  485. // The log must be set before setting the trace location or log
  486. // location to DH_LOC_LOG, otherwise an error will result. The
  487. // logging macros will work without a log if the LogLoc settings
  488. // do not specify one.
  489. //
  490. // If you want to pass in an existing log object, use the DH_SETLOG
  491. // macro instead.
  492. //---------------------------------------------------------------
  493. #define DH_CREATELOGARGS(argc, argv) \
  494. gdhDebugHelper.CreateLog(argc, argv)
  495. #define DH_CREATELOGCMDLINE(cmdline) \
  496. gdhDebugHelper.CreateLog(cmdline)
  497. //---------------------------------------------------------------
  498. // DH_SETLOG
  499. // Use this macro to give CDebugHelp an existing log object for it
  500. // to use. See DH_CREATELOG for more comments about logs.
  501. //---------------------------------------------------------------
  502. #define DH_SETLOG(log) \
  503. gdhDebugHelper.SetLog(log)
  504. //---------------------------------------------------------------
  505. // DH_SETLOGLOC
  506. // See 'Trace Location Flags' comments above for usage. The Log
  507. // Location and Trace Location flags are identical, although
  508. // used for different purposes.
  509. //---------------------------------------------------------------
  510. #define DH_SETLOGLOC(loc) \
  511. gdhDebugHelper.SetDebugInfo( \
  512. loc, \
  513. DH_LOC_SAME, \
  514. DH_LVL_SAME, \
  515. DH_MODE_SAME)
  516. //---------------------------------------------------------------
  517. // DH_SETTRACELOC
  518. // See 'Trace Location Flags' comments above for usage.
  519. //---------------------------------------------------------------
  520. #define DH_SETTRACELOC(loc) \
  521. gdhDebugHelper.SetDebugInfo( \
  522. DH_LOC_SAME, \
  523. loc, \
  524. DH_LVL_SAME, \
  525. DH_MODE_SAME)
  526. //---------------------------------------------------------------
  527. // DH_SETLVL
  528. // See 'Trace Level Flags' comments above for usage.
  529. //---------------------------------------------------------------
  530. #define DH_SETLVL(lvl) \
  531. gdhDebugHelper.SetDebugInfo( \
  532. DH_LOC_SAME, \
  533. DH_LOC_SAME, \
  534. lvl, \
  535. DH_MODE_SAME)
  536. //---------------------------------------------------------------
  537. // DH_SETMODE
  538. // See 'Mode Flags' comments above for usage.
  539. //---------------------------------------------------------------
  540. #define DH_SETMODE(mode) \
  541. gdhDebugHelper.SetDebugInfo( \
  542. DH_LOC_SAME, \
  543. DH_LOC_SAME, \
  544. DH_LVL_SAME, \
  545. mode)
  546. //---------------------------------------------------------------
  547. // DH_SETSPYWINDOWCLASS
  548. // Sets the window class that tracing info goes to.
  549. //---------------------------------------------------------------
  550. #define DH_SETSPYWINDOWCLASS(class) \
  551. gdhDebugHelper.SetSpyWindowClass(class)
  552. //---------------------------------------------------------------
  553. // DH_GETLOGLOC
  554. // Returns the currect Log Location flag settings.
  555. //
  556. // Sample Usage:
  557. // DWORD fLogLoc = DH_GETLOGLOC;
  558. //---------------------------------------------------------------
  559. #define DH_GETLOGLOC \
  560. gdhDebugHelper.GetLogLoc()
  561. //---------------------------------------------------------------
  562. // DH_GETTRACELOC
  563. // Returns the currect Trace Location flag settings.
  564. //
  565. // Sample Usage:
  566. // DWORD fTraceLoc = DH_GETTRACELOC;
  567. //---------------------------------------------------------------
  568. #define DH_GETTRACELOC \
  569. gdhDebugHelper.GetTraceLoc()
  570. //---------------------------------------------------------------
  571. // DH_GETTRACELVL
  572. // Returns the current Trace Level flag settings.
  573. //
  574. // Sample Usage:
  575. // DWORD fTraceLvl = DH_GETTRACELVL;
  576. //---------------------------------------------------------------
  577. #define DH_GETTRACELVL \
  578. gdhDebugHelper.GetTraceLvl()
  579. //---------------------------------------------------------------
  580. // DH_GETMODE
  581. // Returns the current Mode flag settings.
  582. // This includes Lab mode, Break mode, Verbose Mode
  583. // If you are interested in only one flag, bitwise
  584. // AND the result with the mode you are interested in.
  585. //
  586. // Sample Usage:
  587. // DWORD fMode = DH_GETMODE;
  588. // DWORD fVerbose = DH_GETMODE & DH_VERBOSE;
  589. //---------------------------------------------------------------
  590. #define DH_GETMODE \
  591. gdhDebugHelper.GetMode()
  592. //---------------------------------------------------------------
  593. // DH_GETSPYWINDOWCLASS
  594. // Gets the window class that tracing info goes to.
  595. //---------------------------------------------------------------
  596. #define DH_GETSPYWINDOWCLASS() \
  597. gdhDebugHelper.GetSpyWindowClass()
  598. //--------------------------------------------------------------------
  599. // Trace Macros
  600. // Use this macro to report trace information. Trace info gets reported
  601. // depending on the Trace Level and the level at which the
  602. // given statement should be reported. Location depends on Trace
  603. // Location.
  604. //
  605. // Sample Usage:
  606. // DH_TRACE((DH_LVL_ERROR,
  607. // TEXT("Expected: %ul string: %s"),
  608. // ulSize,
  609. // pszName));
  610. //
  611. // Note:
  612. // -- double parenthesis
  613. // -- newlines are appended to trace statements
  614. // -- must include semicolon line terminator
  615. //--------------------------------------------------------------------
  616. #define DH_TRACE(data) \
  617. gdhDebugHelper.TraceMsg data
  618. //--------------------------------------------------------------------
  619. // Logging Macros
  620. // Use DH_LOG to report test results. This information gets reported to
  621. // the Log Location setting. Use DH_LOGSTATS to output a summary of
  622. // the passes, fails, and aborts (to the Log Location).
  623. //
  624. // Sample Usage:
  625. // DH_LOG((LOG_PASS,
  626. // TEXT("Level: %ld, Var: %ld, Start Object and Crash"),
  627. // ulLvl,
  628. // ulVar));
  629. // DH_LOGSTATS;
  630. //
  631. // Note:
  632. // -- double parenthesis for DH_LOG
  633. // -- newlines are appended automatically
  634. // -- must include semicolon line terminator
  635. //--------------------------------------------------------------------
  636. #define DH_LOG(data) gdhDebugHelper.ReportResult data
  637. #define DH_LOGSTATS gdhDebugHelper.ReportStats()
  638. //--------------------------------------------------------------------
  639. // DH_SETPOPUPWINDOW
  640. // Associates popup windows with the handle passed. If not set, popups
  641. // are associated with a NULL window and they can go behind an app if
  642. // it is clicked on. If associated with a window, they stay on top of
  643. // that window. This simply replaces an existing association, and
  644. // NULL is a valid value.
  645. //
  646. // Popup windows can occur when DH_ASSERT or DH_HRCHECK are used and
  647. // Lab Mode is off.
  648. //
  649. // Sample Usage:
  650. // DH_SETPOPUPWINDOW(hwnd);
  651. //--------------------------------------------------------------------
  652. #define DH_SETPOPUPWINDOW(hwnd) \
  653. gdhDebugHelper.SetPopupWindow(hwnd)
  654. //--------------------------------------------------------------------
  655. // DH_ASSERT
  656. // If the condition is not true, an assert message occurs. This will
  657. // be a popup if Lab Mode is NOT turned on. If Lab Mode is on, the
  658. // assert gets reported to both the Log Location and Trace Location
  659. // places.
  660. //
  661. // Sample Usage:
  662. // DH_ASSERT(cchGiven < cchMax);
  663. // DH_ASSERT(!TEXT("Impossible Switch Hit!!!"));
  664. //--------------------------------------------------------------------
  665. extern int giAlwaysNegativeOne;
  666. #define DH_ASSERT(cond) \
  667. if (!((giAlwaysNegativeOne) & (cond))) \
  668. { \
  669. gdhDebugHelper.LabAssertEx(TEXT(__FILE__), __LINE__, TEXT(#cond)); \
  670. }
  671. //--------------------------------------------------------------------
  672. // DH_HRCHECK
  673. // Checks if an HR == S_OK. If it does
  674. // not, a message appears translating the problem into the proper
  675. // description via FormatMessage.
  676. //
  677. // Sample Usage:
  678. // DH_HRCHECK(hr, TEXT("OleCreate"));
  679. //
  680. // Note:
  681. // -- DH_FUNCENTRY must have been called in the current scope.
  682. // -- The message in parameter 2 cannot be expanded.
  683. // -- The actual message produced is
  684. // "<function name> calling <msg passed> failed <HR>:
  685. // <HR result string>".
  686. //--------------------------------------------------------------------
  687. #define DH_HRCHECK(hr, msg) \
  688. gdhDebugHelper.CheckResult (hr, \
  689. S_OK, \
  690. _eet.GetFunctionName(), \
  691. msg, \
  692. __LINE__, \
  693. TEXT(__FILE__))
  694. //--------------------------------------------------------------------
  695. // DH_HRERRORCHECK
  696. // Checks if an HR == hr expected. If it does
  697. // not, a message appears translating the problem into the proper
  698. // description via FormatMessage.
  699. //
  700. // Sample Usage:
  701. // DH_HRERRORCHECK(hr, E_FAIL, TEXT("OleCreate"));
  702. //
  703. // Note:
  704. // -- DH_FUNCENTRY must have been called in the current scope.
  705. // -- The message in parameter 2 cannot be expanded.
  706. // -- The actual message produced is
  707. // "<function name> calling <msg passed> failed
  708. // +-hr expected: <hrExp>; hr=<hr>; <hr result string>".
  709. //--------------------------------------------------------------------
  710. #define DH_HRERRORCHECK(hr, hrExp, msg) \
  711. gdhDebugHelper.CheckResult(hr, \
  712. hrExp, \
  713. _eet.GetFunctionName(), \
  714. msg, \
  715. __LINE__, \
  716. TEXT(__FILE__))
  717. //--------------------------------------------------------------------
  718. // DH_FUNCENTRY
  719. // Output debug message at function entry and exit. Prints out
  720. // single dword when the function is exited.
  721. //
  722. // Sample Usage:
  723. // HD_FUNCENTRY(&hr, DH_LVL_TRACE1, TEXT("InsertObject"));
  724. //--------------------------------------------------------------------
  725. #define DH_FUNCENTRY(exitvar, lvl, funcname) \
  726. CEntryExitTrace _eet(&gdhDebugHelper, exitvar, lvl, funcname)
  727. //--------------------------------------------------------------------
  728. // DH_EXPECTEDERROR
  729. // Disables error logging for the specified error code.
  730. //
  731. // Sample Usage:
  732. // DH_EXPECTEDERROR(E_FAIL);
  733. // Somefunction(); // All E_FAILs in this call will be ignored.
  734. // DH_NOEXPECTEDERROR();
  735. //
  736. // Note:
  737. // -- Use this when deliberately generating an error in common
  738. // code, and the usual popups and error logs are not desired.
  739. // -- Normally DH_EXPECTEDERROR/DH_NOEXPECTEDERROR wrap a single
  740. // function call, as shown in the sample above.
  741. // -- This call disables the specified error on all threads.
  742. //--------------------------------------------------------------------
  743. #define DH_EXPECTEDERROR(hr) \
  744. gdhDebugHelper.SetExpectedError(hr)
  745. //--------------------------------------------------------------------
  746. // DH_NOEXPECTEDERROR
  747. // See DH_EXPECTEDERROR above.
  748. //--------------------------------------------------------------------
  749. #define DH_NOEXPECTEDERROR() \
  750. gdhDebugHelper.SetExpectedError(S_OK)
  751. //--------------------------------------------------------------------
  752. // THREAD_VALIDATE_FLAG_ON
  753. //
  754. // Synopsis: Flags used to set/reset the rightmost bit of global variable
  755. // g_fThreadValidate in macros DH_THREAD_VALIDATION_ON, DH_THREAD
  756. // _VALIDATION_OFF. Also used in DH_IS_THREAD_VALIDATION_ON,
  757. // DH_VDATETHREAD macros in testhelp.hxx.
  758. //
  759. // #define THREAD_VALIDATE_FLAG_ON 0x00000001
  760. //
  761. // Other flags may be defined to use other bits of the global
  762. // variable g_fThreadValidate in future e.g.
  763. // #define FLAG_EXAMPLE_1 0x00000002
  764. // #define FLAG_EXAMPLE_2 0x00000004
  765. //
  766. // History: 26-Jan-96 NarindK Created
  767. //--------------------------------------------------------------------
  768. #define THREAD_VALIDATE_FLAG_ON 0x00000001 //Turns on thread validation.
  769. #endif // __CDBGHELP_HXX__