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.

375 lines
14 KiB

  1. /******************************Module*Header**********************************\
  2. *
  3. * *******************
  4. * * SAMPLE CODE *
  5. * *******************
  6. *
  7. * Module Name: debug.h
  8. *
  9. * Content: Debugging support macros and structures
  10. *
  11. * Copyright (c) 1994-1999 3Dlabs Inc. Ltd. All rights reserved.
  12. * Copyright (c) 1995-2003 Microsoft Corporation. All rights reserved.
  13. \*****************************************************************************/
  14. #ifndef __DEBUG_H
  15. #define __DEBUG_H
  16. //-----------------------------------------------------------------------------
  17. //
  18. // **************************** DISPDBG LEVELS ********************************
  19. //
  20. //-----------------------------------------------------------------------------
  21. // Global warning levels. We can easily modify any source file to dump all of
  22. // its debug messages by undef'ing and redefining this symbols.
  23. #define DBGLVL 4
  24. #define WRNLVL 2
  25. #define ERRLVL 0
  26. //-----------------------------------------------------------------------------
  27. //
  28. // ************************* DEBUG SUPPORT SWITCHES **************************
  29. //
  30. //-----------------------------------------------------------------------------
  31. //-----------------------------------------------------------------------------
  32. //
  33. // FUNCTION ENTRY/EXIT TRACKING
  34. //
  35. // In order to activate function entry/exit tracking , you need to define
  36. // DBG_TRACK_FUNCS to 1, and (unfortunately) instrument your code so that it
  37. // uses DBG_ENTRY and DBG_EXIT right after entry and right before exit from
  38. // the functions you are interested in.
  39. //
  40. // DBG_EXIT can also be supplied a DWORD result which can be tracked in order
  41. // to know the result of different calls (but the mechanism already tracks
  42. // function returns happening in different lines of code for you).
  43. //
  44. // After gathering results, Debug_Func_Report_And_Reset has to be called in
  45. // order to dump them into the remote debugger output. This is done in this
  46. // sample driver within the DrvEscape GDI callback and using the dispdbg.exe
  47. // program to send the right escape codes. You can modify this to suit your
  48. // needs.
  49. //
  50. // After Debug_Func_Report_And_Reset is done reporting results, it will reset
  51. // all of its counters in order to retstart another cycle.
  52. //
  53. // Be aware that DEBUG_MAX_FUNC_COUNT and DEBUG_MAX_RETVALS govern how many
  54. // function calls and function return results can be stored as a maximum. They
  55. // may be adjusted too to suit your own needs. Any data that doesn't fit
  56. // within those maximums will be thrown away.
  57. //
  58. //-----------------------------------------------------------------------------
  59. #define DBG_TRACK_FUNCS 0
  60. //-----------------------------------------------------------------------------
  61. //
  62. // CODE COVERAGE TRACKING
  63. //
  64. // In order to do code coverage tracking, you need to define DBG_TRACK_CODE to 1
  65. // NO CODE INSTRUMENTATION IS NECESSARY!. This will track all if and while
  66. // statements executed in the code and which branch (TRUE or FALSE) was taken,
  67. // and how many times it was taken.
  68. //
  69. // Be aware that the below defined DBG_TRACK_CODE is just a default for all
  70. // files that include debug.h. If you want to exclude (or include) a file
  71. // manually, you can define DBG_TRACK_CODE inside it just before including
  72. // debug.h . You cannot activate/deactivate code tracking for individual
  73. // functions or sections of code, just on a per-file basis.
  74. //
  75. // After gathering results, Debug_Code_Report_And_Reset has to be called in
  76. // order to dump them into the remote debugger output. This is done in this
  77. // sample driver within the DrvEscape GDI callback and using the dispdbg.exe
  78. // program to send the right escape codes. You can modify this to suit your
  79. // needs.
  80. //
  81. // After Debug_Code_Report_And_Reset is done reporting results, it will reset
  82. // all of its counters in order to retstart another cycle.
  83. //
  84. // If DBG_TRACK_CODE_REPORT_PROBLEMS_ONLY is set to 1, only branch statements
  85. // that are potential trouble makers (like if branches that might have been
  86. // never taken or while bodies never entered into) will be reported. If set to
  87. // 0, all gathered data will be dumped (this is quite a lot of data!)
  88. //
  89. // Be aware that DEBUG_MAX_CODE_COUNT governs how many statements (branches)
  90. // can be stored as a maximum. It may be adjusted too to suit your own needs.
  91. // Any data that doesn't fit within the maximum will be thrown away.
  92. //
  93. //-----------------------------------------------------------------------------
  94. #ifndef DBG_TRACK_CODE
  95. #define DBG_TRACK_CODE 0
  96. #define DBG_DEFAULT_TRACK_CODE DBG_TRACK_CODE
  97. #endif
  98. #if (DBG_DEFAULT_TRACK_CODE == DBG_TRACK_CODE)
  99. #define DBG_TRACK_CODE_NON_DEFAULT 0
  100. #else
  101. // some source file is already using non-default code tracking!
  102. #define DBG_TRACK_CODE_NON_DEFAULT 1
  103. #endif
  104. #define DBG_TRACK_CODE_REPORT_PROBLEMS_ONLY 0
  105. //-----------------------------------------------------------------------------
  106. // Escapes for reporting debugging results through
  107. // the remote debugger using dbgdisp.exe
  108. //-----------------------------------------------------------------------------
  109. #define ESCAPE_TRACK_FUNCTION_COVERAGE 1100
  110. #define ESCAPE_TRACK_CODE_COVERAGE 1101
  111. #define ESCAPE_TRACK_MEMORY_ALLOCATION 1102
  112. #ifdef DBG_EA_TAGS
  113. #define ESCAPE_EA_TAG 1103
  114. #endif
  115. //-----------------------------------------------------------------------------
  116. //
  117. // ****************** FUNCTION COVERAGE DEBUGGING SUPPORT ********************
  118. //
  119. //-----------------------------------------------------------------------------
  120. #if (DBG_TRACK_FUNCS && DBG)
  121. VOID Debug_Func_Entry(VOID *pFuncAddr,
  122. char *pszFuncName,
  123. DWORD dwLine ,
  124. char *pszFileName);
  125. VOID Debug_Func_Exit(VOID *pFuncAddr,
  126. DWORD dwRetVal,
  127. DWORD dwLine);
  128. VOID Debug_Func_Report_And_Reset(void);
  129. #define DBG_ENTRY(pszFuncName) \
  130. Debug_Func_Entry((VOID *)pszFuncName, \
  131. #pszFuncName, \
  132. __LINE__ , \
  133. __FILE__ )
  134. #define DBG_EXIT(pszFuncName,dwRetVal) \
  135. Debug_Func_Exit((VOID *)pszFuncName, \
  136. dwRetVal, \
  137. __LINE__)
  138. #define DBG_CB_ENTRY DBG_ENTRY
  139. #define DBG_CB_EXIT DBG_EXIT
  140. #else // DBG_TRACK_FUNCS
  141. #define Debug_Func_Report_And_Reset()
  142. #define DBG_ENTRY(pszFuncName) \
  143. DISPDBG((DBGLVL,"Entering %s",#pszFuncName))
  144. #define DBG_EXIT(pszFuncName,dwRetVal) \
  145. DISPDBG((DBGLVL,"Exiting %s dwRetVal = %d",#pszFuncName,dwRetVal))
  146. #ifdef DBG_EA_TAGS
  147. extern DWORD g_dwTag;
  148. #include "EATags.h"
  149. #define DBG_CB_ENTRY(pszFuncName) \
  150. { \
  151. if (g_dwTag == (EA_TAG_ENABLE | pszFuncName##_ID)) \
  152. while (1); \
  153. DISPDBG((DBGLVL,"Entering %s",#pszFuncName)); \
  154. }
  155. #else // DBG_EA_TAGS
  156. #define DBG_CB_ENTRY DBG_ENTRY
  157. #endif // DBG_EA_TAGS
  158. #define DBG_CB_EXIT DBG_EXIT
  159. #endif // DBG_TRACK_FUNCS
  160. //-----------------------------------------------------------------------------
  161. //
  162. // ******************** STATEMENT COVERAGE DEBUGGING SUPPORT ******************
  163. //
  164. //-----------------------------------------------------------------------------
  165. #if (DBG_TRACK_CODE && _X86_ && DBG)
  166. // Never change these values!
  167. #define DBG_IF_CODE 1
  168. #define DBG_WHILE_CODE 2
  169. #define DBG_SWITCH_CODE 3
  170. #define DBG_FOR_CODE 4
  171. BOOL
  172. Debug_Code_Coverage(
  173. DWORD dwCodeType,
  174. DWORD dwLine ,
  175. char *pszFileName,
  176. BOOL bCodeResult);
  177. VOID Debug_Code_Report_And_Reset(void);
  178. #define if(b) \
  179. if(Debug_Code_Coverage(DBG_IF_CODE,__LINE__,__FILE__,(BOOL)(b)))
  180. #define while(b) \
  181. while(Debug_Code_Coverage(DBG_WHILE_CODE,__LINE__,__FILE__,(BOOL)(b)))
  182. #define switch(val) \
  183. switch(Debug_Code_Coverage(DBG_SWITCH_CODE,__LINE__,__FILE__,(val)))
  184. #endif // DBG_TRACK_CODE && _X86_
  185. #if ((DBG_TRACK_CODE || DBG_TRACK_CODE_NON_DEFAULT) && _X86_ && DBG)
  186. VOID Debug_Code_Report_And_Reset(void);
  187. #else
  188. #define Debug_Code_Report_And_Reset()
  189. #endif
  190. //-----------------------------------------------------------------------------
  191. //
  192. // ************************ MEMORY ALLOCATION SUPPORT *************************
  193. //
  194. //-----------------------------------------------------------------------------
  195. #define ENGALLOCMEM(Flags, Size, Tag) EngAllocMem(Flags, Size, Tag)
  196. #define ENGFREEMEM(Pointer) EngFreeMem(Pointer)
  197. //-----------------------------------------------------------------------------
  198. //
  199. // ******************** PUBLIC DATA STRUCTURE DUMPING ************************
  200. //
  201. //-----------------------------------------------------------------------------
  202. extern char *pcSimpleCapsString(DWORD dwCaps);
  203. #if DBG && defined(LPDDRAWI_DDRAWSURFACE_LCL)
  204. extern void DumpD3DBlend(int Level, DWORD i );
  205. extern void DumpD3DMatrix(int Level, D3DMATRIX* pMatrix);
  206. extern void DumpD3DMaterial(int Level, D3DMATERIAL7* pMaterial);
  207. extern void DumpD3DLight(int DebugLevel, D3DLIGHT7* pLight);
  208. extern void DumpDDSurface(int Level, LPDDRAWI_DDRAWSURFACE_LCL lpDDSurface);
  209. extern void DumpDDSurfaceDesc(int DebugLevel, DDSURFACEDESC* pDesc);
  210. extern void DumpDP2Flags( DWORD lvl, DWORD flags );
  211. #define DBGDUMP_DDRAWSURFACE_LCL(a, b) DumpDDSurface(a, b);
  212. #define DBGDUMP_DDSURFACEDESC(a, b) DumpDDSurfaceDesc(a, b);
  213. #define DBGDUMP_D3DMATRIX(a, b) DumpD3DMatrix(a, b);
  214. #define DBGDUMP_D3DMATERIAL7(a, b) DumpD3DMaterial(a, b);
  215. #define DBGDUMP_D3DLIGHT7(a, b) DumpD3DLight(a, b);
  216. #define DBGDUMP_D3DBLEND(a, b) DumpD3DBlend(a, b);
  217. #define DBGDUMP_D3DDP2FLAGS(a, b) DumpDP2Flags(a, b)
  218. // If we are not in a debug environment, we want all of the debug
  219. // information to be stripped out.
  220. #else // DBG
  221. #define DBGDUMP_DDRAWSURFACE_LCL(a, b)
  222. #define DBGDUMP_D3DMATRIX(a, b)
  223. #define DBGDUMP_D3DMATERIAL7(a, b)
  224. #define DBGDUMP_D3DLIGHT7(a, b)
  225. #define DBGDUMP_DDSURFACEDESC(a, b)
  226. #define DBGDUMP_D3DBLEND(a, b)
  227. #define DBGDUMP_D3DDP2FLAGS(a, b)
  228. #endif // DBG
  229. //-----------------------------------------------------------------------------
  230. //
  231. // ********************** LOW LEVEL DEBUGGING SUPPORT ************************
  232. //
  233. //-----------------------------------------------------------------------------
  234. #if DBG
  235. extern LONG P3R3DX_DebugLevel;
  236. #ifdef WNT_DDRAW
  237. extern VOID __cdecl DebugPrintNT(LONG DebugPrintLevel, PCHAR DebugMessage, ...);
  238. #define DebugPrint DebugPrintNT
  239. #else
  240. extern VOID __cdecl DebugPrint(LONG DebugPrintLevel, PCHAR DebugMessage, ...);
  241. #endif // WNT_DDRAW
  242. #define DISPDBG(arg) DebugPrint arg
  243. #if WNT_DDRAW
  244. #define DebugRIP EngDebugBreak
  245. #define RIP(x) { DebugPrint(0, x); EngDebugBreak();}
  246. #else
  247. extern VOID DebugRIP();
  248. #ifdef FULLDEBUG
  249. // Use an int1 per ASSERT, so that we can zap them individually.
  250. #define RIP(x) { DebugPrint(-1000, x); _asm int 1 }
  251. #else
  252. // If only on DEBUG, we don't want to break compiler optimisations.
  253. #define RIP(x) { DebugPrint(-1000, x); DebugRIP();}
  254. #endif // FULLDEBUG
  255. #endif // WNT_DDRAW
  256. #define ASSERTDD(x, y) if (0 == (x)) RIP (y)
  257. #define ASSERTDBG(x, y) do { if( !(x) ) { DebugPrint y; DebugBreak(); }; } while(0)
  258. // If we are not in a debug environment, we want all of the debug
  259. // information to be stripped out.
  260. #else // DBG
  261. #define DISPDBG(arg)
  262. #define RIP(x)
  263. #define ASSERTDD(x, y)
  264. #define ASSERTDBG(x, y) do { ; } while(0)
  265. #endif // DBG
  266. // Makes a label that is only there in the debug build -
  267. // very useful for putting instant named breakpoints at.
  268. #if DBG
  269. #define MAKE_DEBUG_LABEL(label_name) \
  270. { \
  271. goto label_name; \
  272. label_name: \
  273. ; \
  274. }
  275. #else
  276. #define MAKE_DEBUG_LABEL(label_name) NULL
  277. #endif
  278. //-----------------------------------------------------------------------------
  279. //
  280. // ****************** HARDWARE DEPENDENT DEBUGGING SUPPORT *******************
  281. //
  282. //-----------------------------------------------------------------------------
  283. #if DBG
  284. extern BOOL g_bDetectedFIFOError;
  285. extern BOOL CheckFIFOEntries(DWORD a);
  286. extern void ColorArea(ULONG_PTR pBuffer, DWORD dwWidth, DWORD dwHeight,
  287. DWORD dwPitch, int iBitDepth, DWORD dwValue);
  288. extern void CheckChipErrorFlags();
  289. #ifndef WNT_DDRAW
  290. typedef void *GlintDataPtr;
  291. #endif
  292. extern const char *getTagString(GlintDataPtr glintInfo,ULONG tag);
  293. const char *p3r3TagString( ULONG tag );
  294. #define CHECK_ERROR() CheckChipErrorFlags()
  295. #define COLORAREA(a, b, c, d, e, f) ColorArea(a, b, c, d, e, f);
  296. #define CHECK_FIFO(a) \
  297. if (CheckFIFOEntries(a)) \
  298. { \
  299. DISPDBG((ERRLVL,"Out of FIFO/DMA space %s: %d", \
  300. __FILE__, __LINE__)); \
  301. DebugRIP(); \
  302. }
  303. #define GET_TAG_STR(tag) getTagString(glintInfo, tag)
  304. // If we are not in a debug environment, we want all of the debug
  305. // information to be stripped out.
  306. #else // DBG
  307. #define CHECK_ERROR()
  308. #define COLORAREA(a,b,c,d,e,f)
  309. #define CHECK_FIFO(a)
  310. #define GET_TAG_STR(tag)
  311. #endif // DBG
  312. #endif // __DEBUG_H