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.

344 lines
9.5 KiB

  1. //
  2. // Copyright(c) 1997 - 1999. Microsoft Corporation.
  3. //
  4. #ifndef __usp_dbg__
  5. #define __usp_dbg__
  6. #include <windows.h>
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. //// USP_DBG.HXX
  11. //
  12. // We define three levels of debug support:
  13. //
  14. // Highest DBG=1, TRC=1 Invasive debug
  15. // Middle DBG=0, TRC=1 Safe debug
  16. // Lowest DBG=0, TRC=0 No debug
  17. //
  18. // Safe debugging
  19. //
  20. // o Assertions and other failure trace messages
  21. // o Flag controlled trace messages
  22. //
  23. // Invasive debugging adds
  24. //
  25. // o Unflagged trace messages
  26. // o Extra cross checking fields in internal structures
  27. // o Extra win32 api calls for validity checking
  28. // o Performance measurements
  29. //
  30. // As long as no error situations occur, safe debugging should produce
  31. // no messages on the debugging terminal.
  32. //
  33. // 'Checked' builds are always compiled with DBG=1, TRC=1.
  34. //
  35. // 'Free' builds are compiled with safe debugging until
  36. // shortly before release, then for the last releases with no debugging.
  37. //
  38. // Care should be taken to ensure that the presence of safe debugging
  39. // code does not change operation in any way, as there is little time
  40. // at the end of the project to validate this.
  41. #undef ASSERT
  42. #undef ASSERTS
  43. #undef ASSERTHR
  44. #undef TRACEMSG
  45. #undef TRACE
  46. #undef LPKPUTS
  47. #undef THROW
  48. #undef BIDIPUTS
  49. // Debug support requires tracing support
  50. #if DBG
  51. #define TRC 1
  52. #endif
  53. #if !TRC
  54. /// No debug or tracing support
  55. #define TRACEMSG(a)
  56. #define TRACE(a,b)
  57. #define ASSERT(x)
  58. #define ASSERTS(a,b)
  59. #define ASSERTHR(a,b)
  60. #define TIMEENTRY(id, charcount)
  61. #define TIMEEXIT(id)
  62. #define TIMESUSPEND
  63. #define TIMERESUME
  64. __inline HRESULT HRESULT_FROM_LAST_WIN32_ERROR() {
  65. int iWin32Error = GetLastError();
  66. if (FAILED(HRESULT_FROM_WIN32(iWin32Error))) {
  67. return HRESULT_FROM_WIN32(iWin32Error);
  68. } else {
  69. return E_FAIL; // Guarantee that a Win32 error is always treated as failure
  70. }
  71. }
  72. #else
  73. //// Safe debug support
  74. //
  75. //
  76. /// Trace constants - each flag is separately controlled through the
  77. // global variable 'Debug'.
  78. //
  79. // The checked build initialises debug from the registry.
  80. // Create a key named 'SOFTWARE\\Microsoft\\Uniscribe'
  81. // Add a DWORD value named 'Debug' containg the flags as below.
  82. #define TRACE_API 0x00000001u // USP APIs
  83. #define TRACE_BIDI 0x00000002u // Bidi shaper - CNTXFSM.C
  84. #define TRACE_EDIT 0x00000004u // Edit control
  85. #define TRACE_FASC 0x00000008u // Font association
  86. #define TRACE_FONT 0x00000010u // Font analysis
  87. #define TRACE_GDI 0x00000020u // GDI interface calls
  88. #define TRACE_ITEM 0x00000040u // Item analysis FSM
  89. #define TRACE_NLS 0x00000080u // NLS Info
  90. #define TRACE_POSN 0x00000100u // GAD positioning functions
  91. #define TRACE_SSA 0x00000200u // ScriptStringAnalyse
  92. #define TRACE_SSO 0x00000400u // ScriptStringOut
  93. #define TRACE_THAI 0x00000800u // Thai shaper
  94. #define TRACE_CACHE 0x00001000u // Font caching
  95. #define TRACE_TIME 0x00002000u // Timing entry/exit points
  96. #define TRACE_CDM 0x00004000u // CDM Shaper
  97. #define TRACE_ALLOC 0x00008000u // Memory allocation and deallocation
  98. #define DEBUG_IGNOREREALIZATIONID 0x80000000u
  99. #define DEBUG_IGNOREREGETCHARABCWIDTHSI 0x40000000u
  100. #define DEBUG_TIMINGREPORT 0x20000000u
  101. /// Tracing and assertion macros
  102. //
  103. #define TRACEMSG(a) {DG.psFile=__FILE__; DG.iLine=__LINE__; DebugMsg a;}
  104. #define TRACE(a,b) {if (!DG.fDebugInitialised){DbgReadRegistrySettings();};if (debug & TRACE_##a) TRACEMSG(b);}
  105. #define ASSERT(a) {if (!(a)) TRACEMSG(("Assertion failure: "#a));}
  106. #define ASSERTS(a,b) {if (!(a)) TRACEMSG(("Assertion failure: "#a" - "#b));}
  107. #define ASSERTHR(a,b) {if (!SUCCEEDED(a)) {DG.psFile=__FILE__; \
  108. DG.iLine=__LINE__; DG.hrLastError=a; DebugHr b;}}
  109. #define HRESULT_FROM_LAST_WIN32_ERROR() ( \
  110. DG.psFile=__FILE__, DG.iLine=__LINE__, \
  111. HrFromLastErrorDbg())
  112. /// Debug variables
  113. //
  114. struct DebugGlobals {
  115. char *psFile;
  116. int iLine;
  117. HRESULT hrLastError; // Last hresult from GDI
  118. CHAR sLastError[100];
  119. int nAllocs;
  120. int nFrees;
  121. int nTotalBytesRequested;
  122. int nCurrentBytesAllocated;
  123. int nMaxBytesAllocated;
  124. BOOL fDebugInitialised; // Don't read registry settings until after process attach
  125. };
  126. /// Debug function prototypes
  127. //
  128. BOOL WINAPI DebugInit();
  129. void WINAPIV DebugMsg(char *fmt, ...);
  130. void WINAPIV DebugHr(char *fmt, ...);
  131. HRESULT WINAPI HrFromLastErrorDbg();
  132. #ifdef USP_DLL
  133. extern DebugGlobals DG;
  134. extern UINT debug;
  135. #else
  136. extern __declspec(dllimport) DebugGlobals DG;
  137. extern __declspec(dllimport) UINT debug;
  138. #endif
  139. #if DBG
  140. void WINAPI DbgReadRegistrySettings();
  141. #endif
  142. //// Performance tracking
  143. //
  144. // Defines macros TIMEENTRY and TIMEEXIT to time code sequences.
  145. //
  146. // If an inner level TIMENTRY is encountered while a more global
  147. // code sequence is being timed, the more global timing is stopped
  148. // until the inner level TIMEXIT.
  149. // I.e. timings reported for a given TIMENTRY/TIMEEXIT pair exclude
  150. // time spent in nested timed sequences.
  151. #if !DBG || !defined(i386)
  152. #define DbgTimeEntry(a, b)
  153. #define DbgTimeExit(a)
  154. #define DbgTimeSuspend()
  155. #define DbgTimeResume()
  156. #define DbgTimingReport()
  157. #define TIMEENTRY(id, charcount)
  158. #define TIMEEXIT(id)
  159. #define TIMESUSPEND
  160. #define TIMERESUME
  161. #define TIMINGINFOHERE
  162. #else
  163. #define TIME_LSA 0
  164. #define TIME_SSA 1
  165. #define TIME_RNS 2
  166. #define TIME_SSAGDI 3
  167. #define TIME_SI 4
  168. #define TIME_SS 5
  169. #define TIME_SP 6
  170. #define TIME_UC 7
  171. #define TIME_GFD 8
  172. #define TIME_ACMAP 9
  173. #define TIME_FCMAP 10
  174. #define TIME_GETUNAM 11
  175. #define TIME_GRI 12
  176. #define TIME_PCW 13
  177. #define TIME_LGM 14
  178. #define TIME_USPALLOCCACHE 15
  179. #define TIME_USPALLOCTEMP 16
  180. #define TIME_USPFREE 17
  181. #define TIME_SSO 18
  182. #define TIME_SSOSBL 19
  183. #define TIME_ETOBGC 20
  184. #define TIME_ETOCOD 21
  185. #define TIME_SSOSFF 22
  186. #define TIME_STO 23
  187. #define TIME_STOETO 24
  188. #define TIME_MAX 25
  189. typedef struct tagTimingInfo {
  190. PSTR pcTitle;
  191. __int64 i64TotalClocksUsed;
  192. __int64 i64ClocksAtLastEntry;
  193. __int64 i64NumTimesEntered;
  194. __int64 i64CharCountProcessed;
  195. int iCaller; // Who was active when we started, -1 if none,
  196. } TIMINGINFO;
  197. void WINAPI DbgTimeEntry(int id, int charcount);
  198. void WINAPI DbgTimeExit(int id);
  199. void WINAPI DbgTimeSuspend();
  200. void WINAPI DbgTimeResume();
  201. void WINAPI DbgTimingReport();
  202. #define TIMEENTRY(id, charcount) DbgTimeEntry(TIME_##id, charcount)
  203. #define TIMEEXIT(id) DbgTimeExit(TIME_##id)
  204. #define TIMESUSPEND DbgTimeSuspend()
  205. #define TIMERESUME DbgTimeResume()
  206. #define TIMINGINFOHERE \
  207. \
  208. TIMINGINFO ti[] = { \
  209. {"LpkStringAnalyze", 0, 0, 0, 0, -1}, \
  210. {"ScriptStringAnalyze", 0, 0, 0, 0, -1}, \
  211. {"ReadNLSScriptSettings", 0, 0, 0, 0, -1}, \
  212. {"SSA gdi calls", 0, 0, 0, 0, -1}, \
  213. {"ScriptItemize", 0, 0, 0, 0, -1}, \
  214. {"ScriptShape", 0, 0, 0, 0, -1}, \
  215. {"ScriptPlace", 0, 0, 0, 0, -1}, \
  216. {"UpdateCache", 0, 0, 0, 0, -1}, \
  217. {"GetFontDetails", 0, 0, 0, 0, -1}, \
  218. {"Allocate CMAP", 0, 0, 0, 0, -1}, \
  219. {"Fill CMAP", 0, 0, 0, 0, -1}, \
  220. {"Get Unicode Name and Metrics",0, 0, 0, 0, -1}, \
  221. {"GetRealizationInfo", 0, 0, 0, 0, -1}, \
  222. {"Preload common widths", 0, 0, 0, 0, -1}, \
  223. {"LoadGlyphMetrics", 0, 0, 0, 0, -1}, \
  224. {"USPALLOCCACHE", 0, 0, 0, 0, -1}, \
  225. {"USPALLOCTEMP", 0, 0, 0, 0, -1}, \
  226. {"USPFREE", 0, 0, 0, 0, -1}, \
  227. {"ScriptStringOut", 0, 0, 0, 0, -1}, \
  228. {"ScriptStringOut - StBtchLm", 0, 0, 0, 0, -1}, \
  229. {"ScriptStringOut - bkg clr", 0, 0, 0, 0, -1}, \
  230. {"ScriptStringOut - end pnts", 0, 0, 0, 0, -1}, \
  231. {"ScriptStringOut - slctflbck", 0, 0, 0, 0, -1}, \
  232. {"ScriptTextOut", 0, 0, 0, 0, -1}, \
  233. {"SimpleTextOut - ETO", 0, 0, 0, 0, -1}, \
  234. }; \
  235. \
  236. int iStdParent[TIME_MAX] = \
  237. {-1,-1,-1,-1, \
  238. -1,-1,-1,-1, \
  239. -1,-1,-1,-1, \
  240. -1,-1,-1,-1, \
  241. -1,-1,-1,-1, \
  242. -1,-1,-1,-1, \
  243. -1};
  244. #endif
  245. #endif
  246. #ifdef __cplusplus
  247. }
  248. #endif
  249. #endif