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.

345 lines
7.2 KiB

  1. /*
  2. * debspew.h - Debug macros and their retail translations.
  3. *
  4. * Taken from URL code by ChrisPi 9-11-95
  5. *
  6. */
  7. #ifndef _DEBSPEW_H_
  8. #define _DEBSPEW_H_
  9. #include <nmutil.h>
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif /* __cplusplus */
  13. #include <tchar.h>
  14. #include <limits.h>
  15. #include <shlobj.h>
  16. #include "stock.h"
  17. #include "olestock.h"
  18. #ifdef DEBUG
  19. #include "inifile.h"
  20. #include "resstr.h"
  21. #endif /* DEBUG */
  22. #include "valid.h"
  23. #include "olevalid.h"
  24. #define DATA_SEG_READ_ONLY ".text"
  25. #define DATA_SEG_PER_INSTANCE ".data"
  26. #define DATA_SEG_SHARED ".shared"
  27. /* parameter validation macros */
  28. /*
  29. * call as:
  30. *
  31. * bPTwinOK = IS_VALID_READ_PTR(ptwin, CTWIN);
  32. *
  33. * bHTwinOK = IS_VALID_HANDLE(htwin, TWIN);
  34. */
  35. #ifdef DEBUG
  36. #define IS_VALID_READ_PTR(ptr, type) \
  37. (IsBadReadPtr((ptr), sizeof(type)) ? \
  38. (ERROR_OUT(("invalid %s read pointer - %#08lx", (PCSTR)"P"#type, (ptr))), FALSE) : \
  39. TRUE)
  40. #define IS_VALID_WRITE_PTR(ptr, type) \
  41. (IsBadWritePtr((PVOID)(ptr), sizeof(type)) ? \
  42. (ERROR_OUT(("invalid %s write pointer - %#08lx", (PCSTR)"P"#type, (ptr))), FALSE) : \
  43. TRUE)
  44. #define IS_VALID_STRING_PTR_A(ptr, type) \
  45. (IsBadStringPtrA((ptr), (UINT)-1) ? \
  46. (ERROR_OUT(("invalid %s pointer - %#08lx", (PCSTR)"P"#type, (ptr))), FALSE) : \
  47. TRUE)
  48. #define IS_VALID_STRING_PTR_W(ptr, type) \
  49. (IsBadStringPtrW((ptr), (UINT)-1) ? \
  50. (ERROR_OUT(("invalid %s pointer - %#08lx", (PCSTR)"P"#type, (ptr))), FALSE) : \
  51. TRUE)
  52. #if defined(UNICODE)
  53. #define IS_VALID_STRING_PTR IS_VALID_STRING_PTR_W
  54. #else // defined(UNICODE)
  55. #define IS_VALID_STRING_PTR IS_VALID_STRING_PTR_A
  56. #endif // defined(UNICODE)
  57. #define IS_VALID_CODE_PTR(ptr, type) \
  58. (IsBadCodePtr((FARPROC)(ptr)) ? \
  59. (ERROR_OUT(("invalid %s code pointer - %#08lx", (PCSTR)#type, (ptr))), FALSE) : \
  60. TRUE)
  61. #define IS_VALID_READ_BUFFER_PTR(ptr, type, len) \
  62. (IsBadReadPtr((ptr), len) ? \
  63. (ERROR_OUT(("invalid %s read pointer - %#08lx", (PCSTR)"P"#type, (ptr))), FALSE) : \
  64. TRUE)
  65. #define IS_VALID_WRITE_BUFFER_PTR(ptr, type, len) \
  66. (IsBadWritePtr((ptr), len) ? \
  67. (ERROR_OUT(("invalid %s write pointer - %#08lx", (PCSTR)"P"#type, (ptr))), FALSE) : \
  68. TRUE)
  69. #define FLAGS_ARE_VALID(dwFlags, dwAllFlags) \
  70. (((dwFlags) & (~(dwAllFlags))) ? \
  71. (ERROR_OUT(("invalid flags set - %#08lx", ((dwFlags) & (~(dwAllFlags))))), FALSE) : \
  72. TRUE)
  73. #else
  74. #define IS_VALID_READ_PTR(ptr, type) \
  75. (! IsBadReadPtr((ptr), sizeof(type)))
  76. #define IS_VALID_WRITE_PTR(ptr, type) \
  77. (! IsBadWritePtr((PVOID)(ptr), sizeof(type)))
  78. #define IS_VALID_STRING_PTR(ptr, type) \
  79. (! IsBadStringPtr((ptr), (UINT)-1))
  80. #define IS_VALID_CODE_PTR(ptr, type) \
  81. (! IsBadCodePtr((FARPROC)(ptr)))
  82. #define IS_VALID_READ_BUFFER_PTR(ptr, type, len) \
  83. (! IsBadReadPtr((ptr), len))
  84. #define IS_VALID_WRITE_BUFFER_PTR(ptr, type, len) \
  85. (! IsBadWritePtr((ptr), len))
  86. #define FLAGS_ARE_VALID(dwFlags, dwAllFlags) \
  87. (((dwFlags) & (~(dwAllFlags))) ? FALSE : TRUE)
  88. #endif
  89. /* handle validation macros */
  90. #ifdef DEBUG
  91. #define IS_VALID_HANDLE(hnd, type) \
  92. (IsValidH##type(hnd) ? \
  93. TRUE : \
  94. (ERROR_OUT(("invalid H" #type " - %#08lx", (hnd))), FALSE))
  95. #else
  96. #define IS_VALID_HANDLE(hnd, type) \
  97. (IsValidH##type(hnd))
  98. #endif
  99. /* structure validation macros */
  100. #ifdef VSTF
  101. #ifdef DEBUG
  102. #define IS_VALID_STRUCT_PTR(ptr, type) \
  103. (IsValidP##type(ptr) ? \
  104. TRUE : \
  105. (ERROR_OUT(("invalid %s pointer - %#08lx", (PCSTR)"P"#type, (ptr))), FALSE))
  106. #else
  107. #define IS_VALID_STRUCT_PTR(ptr, type) \
  108. (IsValidP##type(ptr))
  109. #endif
  110. #else
  111. #define IS_VALID_STRUCT_PTR(ptr, type) \
  112. (! IsBadReadPtr((ptr), sizeof(type)))
  113. #endif
  114. /* OLE interface validation macro */
  115. #define IS_VALID_INTERFACE_PTR(ptr, iface) \
  116. IS_VALID_STRUCT_PTR(ptr, C##iface)
  117. #ifdef DEBUG
  118. #define CALLTRACE_OUT(s) DbgZPrintFunction s
  119. #define DebugEntry(szFunctionName) \
  120. (CALLTRACE_OUT((#szFunctionName "() entered.")), \
  121. StackEnter())
  122. #define DebugExit(szFunctionName, szResult) \
  123. (StackLeave(), \
  124. CALLTRACE_OUT(("%s() exiting, returning %s.", #szFunctionName, szResult)))
  125. #define DebugExitBOOL(szFunctionName, bool) \
  126. DebugExit(szFunctionName, GetBOOLString(bool))
  127. #define DebugExitCOMPARISONRESULT(szFunctionName, cr) \
  128. DebugExit(szFunctionName, GetCOMPARISONRESULTString(cr))
  129. #define DebugExitDWORD(szFunctionName, dw) \
  130. DebugExitULONG(szFunctionName, dw)
  131. #define DebugExitHRESULT(szFunctionName, hr) \
  132. DebugExit(szFunctionName, GetHRESULTString(hr))
  133. #define DebugExitINT(szFunctionName, n) \
  134. DebugExit(szFunctionName, GetINTString(n))
  135. #define DebugExitINT_PTR(szFunctionName, n) \
  136. DebugExit(szFunctionName, GetINT_PTRString(n))
  137. #define DebugExitULONG(szFunctionName, ul) \
  138. DebugExit(szFunctionName, GetULONGString(ul))
  139. #define DebugExitVOID(szFunctionName) \
  140. (StackLeave(), \
  141. CALLTRACE_OUT(("%s() exiting.", #szFunctionName)))
  142. #define DebugExitPVOID(szFunctionName, ptr) \
  143. DebugExit(szFunctionName, GetPVOIDString(ptr))
  144. #else
  145. #define DebugEntry(szFunctionName)
  146. #define DebugExit(szFunctionName, szResult)
  147. #define DebugExitBOOL(szFunctionName, bool)
  148. #define DebugExitCOMPARISONRESULT(szFunctionName, cr)
  149. #define DebugExitDWORD(szFunctionName, dw)
  150. #define DebugExitHRESULT(szFunctionName, hr)
  151. #define DebugExitINT(szFunctionName, n)
  152. #define DebugExitINT_PTR(szFunctionName, n)
  153. #define DebugExitULONG(szFunctionName, ul)
  154. #define DebugExitVOID(szFunctionName)
  155. #define DebugExitPVOID(szFunctionName, ptr)
  156. #endif
  157. /* Types
  158. ********/
  159. /* g_dwSpewFlags flags */
  160. typedef enum _spewflags
  161. {
  162. SPEW_FL_SPEW_PREFIX = 0x0001,
  163. SPEW_FL_SPEW_LOCATION = 0x0002,
  164. ALL_SPEW_FLAGS = (SPEW_FL_SPEW_PREFIX |
  165. SPEW_FL_SPEW_LOCATION)
  166. }
  167. SPEWFLAGS;
  168. /* g_uSpewSev values */
  169. typedef enum _spewsev
  170. {
  171. SPEW_TRACE,
  172. SPEW_CALLTRACE,
  173. SPEW_WARNING,
  174. SPEW_ERROR,
  175. SPEW_FATAL
  176. }
  177. SPEWSEV;
  178. /* Prototypes
  179. *************/
  180. /* debspew.c */
  181. #ifdef DEBUG
  182. extern BOOL SetDebugModuleIniSwitches(void);
  183. extern BOOL NMINTERNAL InitDebugModule(PCSTR);
  184. extern void NMINTERNAL ExitDebugModule(void);
  185. extern void NMINTERNAL StackEnter(void);
  186. extern void NMINTERNAL StackLeave(void);
  187. extern ULONG_PTR NMINTERNAL GetStackDepth(void);
  188. extern void SpewOut(PCSTR pcszFormat, ...);
  189. extern DWORD NMINTERNAL GetDebugOutputFlags(VOID);
  190. extern VOID NMINTERNAL SetDebugOutputFlags(DWORD dw);
  191. #else // DEBUG
  192. #define SetDebugModuleIniSwitches()
  193. #define InitDebugModule(str)
  194. #define ExitDebugModule()
  195. #define StackEnter()
  196. #define StackLeave()
  197. #define GetStackDepth()
  198. //#define SpewOut(fmt, ...)
  199. #define GetDebugOutputFlags()
  200. #define SetDebugOutputFlags(dw)
  201. #endif // DEBUG
  202. /* Global Variables
  203. *******************/
  204. #ifdef DEBUG
  205. /* dbg.cpp */
  206. extern HDBGZONE ghDbgZone;
  207. /* debspew.c */
  208. extern DWORD g_dwSpewFlags;
  209. extern UINT g_uSpewSev;
  210. extern UINT g_uSpewLine;
  211. extern PCSTR g_pcszSpewFile;
  212. extern WINDOWPLACEMENT g_wpSpew;
  213. /* defined by client */
  214. extern PCSTR g_pcszSpewModule;
  215. #endif
  216. /*
  217. * EVAL() may only be used as a logical expression.
  218. *
  219. * E.g.,
  220. *
  221. * if (EVAL(exp))
  222. * bResult = TRUE;
  223. */
  224. #ifdef DEBUG
  225. #define EVAL(exp) \
  226. ((exp) || \
  227. (ERROR_OUT(("evaluation failed '%s'", (PCSTR)#exp)), 0))
  228. #else
  229. #define EVAL(exp) \
  230. ((exp) != 0)
  231. #endif /* DEBUG */
  232. #ifdef __cplusplus
  233. }
  234. #endif /* __cplusplus */
  235. #endif /* _DEBSPEW_H_ */