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.

327 lines
6.8 KiB

  1. /*
  2. * debspew.h - Debug macros and their retail translations.
  3. */
  4. /* Macros
  5. *********/
  6. /* debug output macros */
  7. /*
  8. * Do not call SPEW_OUT directly. Instead, call TRACE_OUT, WARNING_OUT,
  9. * ERROR_OUT, or FATAL_OUT.
  10. */
  11. /*
  12. * call like printf(), but with an extra pair of parentheses:
  13. *
  14. * ERROR_OUT(("'%s' too big by %d bytes.", pszName, nExtra));
  15. */
  16. #ifdef DEBUG
  17. #define SPEW_OUT(args) \
  18. ((void)(g_pcszSpewFile = __FILE__, \
  19. g_uSpewLine = __LINE__, \
  20. SpewOut args, \
  21. g_pcszSpewFile = NULL, \
  22. g_uSpewLine = 0, \
  23. g_uSpewSev = 0, \
  24. g_dwSpewFlags = 0, \
  25. 0))
  26. #define PLAIN_TRACE_OUT(args) \
  27. (g_dwSpewFlags = 0, \
  28. g_uSpewSev = SPEW_TRACE, \
  29. SPEW_OUT(args))
  30. #define TRACE_OUT(args) \
  31. (g_dwSpewFlags = SPEW_FL_SPEW_PREFIX, \
  32. g_uSpewSev = SPEW_TRACE, \
  33. SPEW_OUT(args))
  34. #define WARNING_OUT(args) \
  35. (g_dwSpewFlags = SPEW_FL_SPEW_PREFIX | SPEW_FL_SPEW_LOCATION, \
  36. g_uSpewSev = SPEW_WARNING, \
  37. SPEW_OUT(args))
  38. #define ERROR_OUT(args) \
  39. (g_dwSpewFlags = SPEW_FL_SPEW_PREFIX | SPEW_FL_SPEW_LOCATION, \
  40. g_uSpewSev = SPEW_ERROR, \
  41. SPEW_OUT(args))
  42. #define FATAL_OUT(args) \
  43. (g_dwSpewFlags = SPEW_FL_SPEW_PREFIX | SPEW_FL_SPEW_LOCATION, \
  44. g_uSpewSev = SPEW_FATAL, \
  45. SPEW_OUT(args))
  46. #else
  47. #define PLAIN_TRACE_OUT(args)
  48. #define TRACE_OUT(args)
  49. #define WARNING_OUT(args)
  50. #define ERROR_OUT(args)
  51. #define FATAL_OUT(args)
  52. #endif
  53. /* parameter validation macros */
  54. /*
  55. * call as:
  56. *
  57. * bPTwinOK = IS_VALID_READ_PTR(ptwin, CTWIN);
  58. *
  59. * bHTwinOK = IS_VALID_HANDLE(htwin, TWIN);
  60. */
  61. #ifdef DEBUG
  62. #define IS_VALID_READ_PTR(ptr, type) \
  63. (IsBadReadPtr((ptr), sizeof(type)) ? \
  64. (ERROR_OUT(("invalid %s read pointer - %#08lx", (PCSTR)"P"#type, (ptr))), FALSE) : \
  65. TRUE)
  66. #define IS_VALID_WRITE_PTR(ptr, type) \
  67. (IsBadWritePtr((PVOID)(ptr), sizeof(type)) ? \
  68. (ERROR_OUT(("invalid %s write pointer - %#08lx", (PCSTR)"P"#type, (ptr))), FALSE) : \
  69. TRUE)
  70. #define IS_VALID_STRING_PTR(ptr, type) \
  71. (IsBadStringPtr((ptr), (UINT)-1) ? \
  72. (ERROR_OUT(("invalid %s pointer - %#08lx", (PCSTR)"P"#type, (ptr))), FALSE) : \
  73. TRUE)
  74. #define IS_VALID_CODE_PTR(ptr, type) \
  75. (IsBadCodePtr((FARPROC)(ptr)) ? \
  76. (ERROR_OUT(("invalid %s code pointer - %#08lx", (PCSTR)#type, (ptr))), FALSE) : \
  77. TRUE)
  78. #define IS_VALID_READ_BUFFER_PTR(ptr, type, len) \
  79. (IsBadReadPtr((ptr), len) ? \
  80. (ERROR_OUT(("invalid %s read pointer - %#08lx", (PCSTR)"P"#type, (ptr))), FALSE) : \
  81. TRUE)
  82. #define IS_VALID_WRITE_BUFFER_PTR(ptr, type, len) \
  83. (IsBadWritePtr((ptr), len) ? \
  84. (ERROR_OUT(("invalid %s write pointer - %#08lx", (PCSTR)"P"#type, (ptr))), FALSE) : \
  85. TRUE)
  86. #define FLAGS_ARE_VALID(dwFlags, dwAllFlags) \
  87. (((dwFlags) & (~(dwAllFlags))) ? \
  88. (ERROR_OUT(("invalid flags set - %#08lx", ((dwFlags) & (~(dwAllFlags))))), FALSE) : \
  89. TRUE)
  90. #else
  91. #define IS_VALID_READ_PTR(ptr, type) \
  92. (! IsBadReadPtr((ptr), sizeof(type)))
  93. #define IS_VALID_WRITE_PTR(ptr, type) \
  94. (! IsBadWritePtr((PVOID)(ptr), sizeof(type)))
  95. #define IS_VALID_STRING_PTR(ptr, type) \
  96. (! IsBadStringPtr((ptr), (UINT)-1))
  97. #define IS_VALID_CODE_PTR(ptr, type) \
  98. (! IsBadCodePtr((FARPROC)(ptr)))
  99. #define IS_VALID_READ_BUFFER_PTR(ptr, type, len) \
  100. (! IsBadReadPtr((ptr), len))
  101. #define IS_VALID_WRITE_BUFFER_PTR(ptr, type, len) \
  102. (! IsBadWritePtr((ptr), len))
  103. #define FLAGS_ARE_VALID(dwFlags, dwAllFlags) \
  104. (((dwFlags) & (~(dwAllFlags))) ? FALSE : TRUE)
  105. #endif
  106. /* handle validation macros */
  107. #ifdef DEBUG
  108. #define IS_VALID_HANDLE(hnd, type) \
  109. (IsValidH##type(hnd) ? \
  110. TRUE : \
  111. (ERROR_OUT(("invalid H" #type " - %#08lx", (hnd))), FALSE))
  112. #else
  113. #define IS_VALID_HANDLE(hnd, type) \
  114. (IsValidH##type(hnd))
  115. #endif
  116. /* structure validation macros */
  117. #ifdef VSTF
  118. #ifdef DEBUG
  119. #define IS_VALID_STRUCT_PTR(ptr, type) \
  120. (IsValidP##type(ptr) ? \
  121. TRUE : \
  122. (ERROR_OUT(("invalid %s pointer - %#08lx", (PCSTR)"P"#type, (ptr))), FALSE))
  123. #else
  124. #define IS_VALID_STRUCT_PTR(ptr, type) \
  125. (IsValidP##type(ptr))
  126. #endif
  127. #else
  128. #define IS_VALID_STRUCT_PTR(ptr, type) \
  129. (! IsBadReadPtr((ptr), sizeof(type)))
  130. #endif
  131. /* OLE interface validation macro */
  132. #define IS_VALID_INTERFACE_PTR(ptr, iface) \
  133. IS_VALID_STRUCT_PTR(ptr, C##iface)
  134. /* debug break */
  135. #ifdef DEBUG
  136. #define DebugBreak() \
  137. __try \
  138. { \
  139. DebugBreak(); \
  140. } __except (EXCEPTION_CONTINUE_EXECUTION) {}
  141. #else
  142. #define DebugBreak()
  143. #endif
  144. /* debug exported function entry */
  145. #ifdef DEBUG
  146. #define DebugEntry(szFunctionName) \
  147. (TRACE_OUT((#szFunctionName "() entered.")), \
  148. StackEnter())
  149. #else
  150. #define DebugEntry(szFunctionName)
  151. #endif
  152. /* debug exported function exit */
  153. #ifdef DEBUG
  154. #define DebugExit(szFunctionName, szResult) \
  155. (StackLeave(), \
  156. TRACE_OUT(("%s() exiting, returning %s.", #szFunctionName, szResult)))
  157. #define DebugExitBOOL(szFunctionName, bool) \
  158. DebugExit(szFunctionName, GetBOOLString(bool))
  159. #define DebugExitCOMPARISONRESULT(szFunctionName, cr) \
  160. DebugExit(szFunctionName, GetCOMPARISONRESULTString(cr))
  161. #define DebugExitDWORD(szFunctionName, dw) \
  162. DebugExitULONG(szFunctionName, dw)
  163. #define DebugExitHRESULT(szFunctionName, hr) \
  164. DebugExit(szFunctionName, GetHRESULTString(hr))
  165. #define DebugExitINT(szFunctionName, n) \
  166. DebugExit(szFunctionName, GetINTString(n))
  167. #define DebugExitULONG(szFunctionName, ul) \
  168. DebugExit(szFunctionName, GetULONGString(ul))
  169. #define DebugExitVOID(szFunctionName) \
  170. (StackLeave(), \
  171. TRACE_OUT(("%s() exiting.", #szFunctionName)))
  172. #else
  173. #define DebugExit(szFunctionName, szResult)
  174. #define DebugExitBOOL(szFunctionName, bool)
  175. #define DebugExitCOMPARISONRESULT(szFunctionName, cr)
  176. #define DebugExitDWORD(szFunctionName, dw)
  177. #define DebugExitHRESULT(szFunctionName, hr)
  178. #define DebugExitINT(szFunctionName, n)
  179. #define DebugExitULONG(szFunctionName, ul)
  180. #define DebugExitVOID(szFunctionName)
  181. #endif
  182. /* Types
  183. ********/
  184. /* g_dwSpewFlags flags */
  185. typedef enum _spewflags
  186. {
  187. SPEW_FL_SPEW_PREFIX = 0x0001,
  188. SPEW_FL_SPEW_LOCATION = 0x0002,
  189. ALL_SPEW_FLAGS = (SPEW_FL_SPEW_PREFIX |
  190. SPEW_FL_SPEW_LOCATION)
  191. }
  192. SPEWFLAGS;
  193. /* g_uSpewSev values */
  194. typedef enum _spewsev
  195. {
  196. SPEW_TRACE,
  197. SPEW_WARNING,
  198. SPEW_ERROR,
  199. SPEW_FATAL
  200. }
  201. SPEWSEV;
  202. /* Prototypes
  203. *************/
  204. /* debspew.c */
  205. #ifdef DEBUG
  206. extern BOOL SetDebugModuleIniSwitches(void);
  207. extern BOOL InitDebugModule(void);
  208. extern void ExitDebugModule(void);
  209. extern void StackEnter(void);
  210. extern void StackLeave(void);
  211. extern ULONG GetStackDepth(void);
  212. extern void SpewOut(PCSTR pcszFormat, ...);
  213. #endif
  214. /* Global Variables
  215. *******************/
  216. #ifdef DEBUG
  217. /* debspew.c */
  218. extern DWORD g_dwSpewFlags;
  219. extern UINT g_uSpewSev;
  220. extern UINT g_uSpewLine;
  221. extern PCSTR g_pcszSpewFile;
  222. /* defined by client */
  223. extern PCSTR g_pcszSpewModule;
  224. #endif