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.

435 lines
9.8 KiB

  1. /*++
  2. Copyright (c) 1991-1993 Microsoft Corporation
  3. Module Name:
  4. NetDebug.h
  5. Abstract:
  6. This header file declares various debug routines for use in the
  7. networking code.
  8. Author:
  9. John Rogers (JohnRo) 11-Mar-1991
  10. Environment:
  11. ifdef'ed for NT, any ANSI C environment, or none of the above (which
  12. implies nondebug). The interface is portable (Win/32).
  13. Requires ANSI C extensions: slash-slash comments, long external names.
  14. Revision History:
  15. 11-Mar-1991 JohnRo
  16. Created.
  17. 25-Mar-1991 JohnRo
  18. Added more FORMAT_ strings. Got rid of tabs in file.
  19. 28-Mar-1991 JohnRo
  20. Added FORMAT_HEX_ strings.
  21. 08-Apr-1991 JohnRo
  22. Added temporary versions of wide char stuff (FORMAT_LPTSTR, etc).
  23. 16-Apr-1991 JohnRo
  24. Added PC-LINT version of NetpAssert(), to avoid occasional constant
  25. Boolean value messages. Added wrappers for NT debug code, to avoid
  26. recompile hits from <nt.h> all over the place.
  27. 25-Apr-1991 JohnRo
  28. Created procedure version of NetpDbgHexDump().
  29. 13-May-1991 JohnRo
  30. Added FORMAT_LPVOID to replace FORMAT_POINTER. Changed nondebug
  31. definition of NetpDbgHexDump() to avoid evaluating parameters.
  32. 15-May-1991 JohnRo
  33. FORMAT_HEX_WORD was wrong.
  34. 19-May-1991 JohnRo
  35. Improve LINT handling of assertions.
  36. 21-May-1991 JohnRo
  37. Added NetpDbgReasonable() for partial hex dumps.
  38. 13-Jun-1991 JohnRo
  39. Added NetpDbgDisplay routines.
  40. Moved DBGSTATIC here from <Rxp.h>.
  41. 02-Jul-1991 JohnRo
  42. Added display routines for print job, print queue, and print dest.
  43. 05-Jul-1991 JohnRo
  44. Avoid FORMAT_WORD name (used by MIPS header files).
  45. 22-Jul-1991 JohnRo
  46. Implement downlevel NetConnectionEnum.
  47. 25-Jul-1991 JohnRo
  48. Wksta debug support.
  49. 03-Aug-1991 JohnRo
  50. Rename wksta display routine for consistency.
  51. 20-Aug-1991 JohnRo
  52. Allow use in nondebug builds.
  53. 20-Aug-1991 JohnRo
  54. Downlevel NetFile APIs.
  55. 11-Sep-1991 JohnRo
  56. Downlevel NetService APIs. Added UNICODE versions of some FORMAT_
  57. equates. Added FORMAT_ULONG for NT use.
  58. 13-Sep-1991 JohnRo
  59. Change "reasonable" debug amount to be an even number of lines.
  60. Create an equate for it. Added LPDEBUG_STRING and a FORMAT_ for that.
  61. 15-Oct-1991 JohnRo
  62. Implement remote NetSession APIs.
  63. 11-Nov-1991 JohnRo
  64. Implement remote NetWkstaUserEnum(). Added FORMAT_RPC_STATUS.
  65. 26-Dec-1991 JohnRo
  66. Added stuff for replicator APIs.
  67. 07-Jan-1992 JohnRo
  68. Added NetpDbgDisplayWStr() for UNICODE strings.
  69. Added NetpDbgDisplayTStr() to be consistent.
  70. 26-Feb-1992 JohnRo
  71. Added NetpDbgDisplayTimestamp() (seconds since 1970).
  72. 15-Apr-1992 JohnRo
  73. Moved FORMAT_ equates into /nt/private/inc/debugfmt.h (so they
  74. can be used by the service controller as well).
  75. 13-Jun-1992 JohnRo
  76. RAID 10324: net print vs. UNICODE.
  77. 16-Aug-1992 JohnRo
  78. RAID 2920: Support UTC timezone in net code.
  79. 24-Aug-1992 JohnRo
  80. Fixed free build again (misnamed repl import/export display macros).
  81. 02-Oct-1992 JohnRo
  82. RAID 3556: DosPrintQGetInfo (from downlevel) level=3 rc=124.
  83. (Added NetpDbgDisplayPrintQArray.)
  84. 05-Jan-1993 JohnRo
  85. Repl WAN support (get rid of repl name list limits).
  86. Made changes suggested by PC-LINT 5.0
  87. 04-Mar-1993 JohnRo
  88. RAID 12237: replicator tree depth exceeded (add display of FILETIME
  89. and LARGE_INTEGER time).
  90. 31-Mar-1993 JohnRo
  91. Allow others to display replicator state too.
  92. --*/
  93. #ifndef _NETDEBUG_
  94. #define _NETDEBUG_
  95. // These must be included first:
  96. #include <windef.h> // BOOL, DWORD, FALSE, LPBYTE, etc.
  97. // These may be included in any order:
  98. #include <debugfmt.h> // Most FORMAT_ equates.
  99. #include <stdarg.h>
  100. #if DBG
  101. // Normal netlib debug version. No extra includes.
  102. #else // not DBG
  103. #ifdef CDEBUG
  104. // ANSI C debug version.
  105. #include <assert.h> // assert().
  106. #include <stdio.h> // printf().
  107. #else // ndef CDEBUG
  108. // Nondebug version.
  109. #endif // ndef CDEBUG
  110. #endif // not DBG
  111. #if !DBG || defined(lint) || defined(_lint)
  112. #define DBGSTATIC static // hidden function
  113. #else
  114. #define DBGSTATIC // visible for use in debugger.
  115. #endif
  116. //
  117. // printf-style format strings for some possibly nonportable stuff...
  118. // These are passed to NetpDbgPrint(); use with other routines at your
  119. // own risk.
  120. //
  121. // Most FORMAT_ equates now reside in /nt/private/inc/debugfmt.h.
  122. //
  123. typedef LPSTR LPDEBUG_STRING;
  124. #define FORMAT_API_STATUS "%lu"
  125. #define FORMAT_LPDEBUG_STRING "%s"
  126. #ifdef __cplusplus
  127. extern "C" {
  128. #endif
  129. // NetpAssert: continue if Predicate is true; otherwise print debug message
  130. // (if possible) and hit a breakpoint (if possible). Do nothing at all if
  131. // this is a nondebug build.
  132. //
  133. // VOID
  134. // NetpAssert(
  135. // IN BOOL Predicate
  136. // );
  137. //
  138. #if DBG
  139. VOID
  140. NetpAssertFailed(
  141. IN LPDEBUG_STRING FailedAssertion,
  142. IN LPDEBUG_STRING FileName,
  143. IN DWORD LineNumber,
  144. IN LPDEBUG_STRING Message OPTIONAL
  145. );
  146. // Normal networking debug version.
  147. #define NetpAssert(Predicate) \
  148. { \
  149. /*lint -save -e506 */ /* don't complain about constant values here */ \
  150. if (!(Predicate)) \
  151. NetpAssertFailed( #Predicate, __FILE__, __LINE__, NULL ); \
  152. /*lint -restore */ \
  153. }
  154. #else // not DBG
  155. #ifdef CDEBUG
  156. // ANSI C debug version.
  157. #define NetpAssert(Predicate) assert(Predicate)
  158. #else // ndef CDEBUG
  159. // Nondebug version.
  160. #define NetpAssert(Predicate) /* no output; ignore arguments */
  161. #endif // ndef CDEBUG
  162. #endif // not DBG
  163. // NetpBreakPoint: if this is a debug version of some sort, cause a breakpoint
  164. // somehow. (This may just be an assertion failure in ANSI C.) Do nothing at
  165. // all in nondebug builds.
  166. //
  167. // VOID
  168. // NetpBreakPoint(
  169. // VOID
  170. // );
  171. //
  172. #if DBG
  173. // NT debug version. Calls DbgBreakPoint.
  174. VOID
  175. NetpBreakPoint(
  176. VOID
  177. );
  178. #else // not DBG
  179. #ifdef CDEBUG
  180. // ANSI C debug version.
  181. #define NetpBreakPoint NetpAssert(FALSE)
  182. #else // ndef CDEBUG
  183. // Nondebug version.
  184. #define NetpBreakPoint() /* no effect. */
  185. #endif // ndef CDEBUG
  186. #endif // not DBG
  187. #if DBG
  188. VOID
  189. NetpDbgDisplayDword(
  190. IN LPDEBUG_STRING Tag,
  191. IN DWORD Value
  192. );
  193. VOID
  194. NetpDbgDisplayDwordHex(
  195. IN LPDEBUG_STRING Tag,
  196. IN DWORD Value
  197. );
  198. VOID
  199. NetpDbgDisplayLong(
  200. IN LPDEBUG_STRING Tag,
  201. IN LONG Value
  202. );
  203. VOID
  204. NetpDbgDisplayString(
  205. IN LPDEBUG_STRING Tag,
  206. IN LPTSTR Value
  207. );
  208. VOID
  209. NetpDbgDisplayTag(
  210. IN LPDEBUG_STRING Tag
  211. );
  212. VOID
  213. NetpDbgDisplayTimestamp(
  214. IN LPDEBUG_STRING Tag,
  215. IN DWORD Time // Seconds since 1970.
  216. );
  217. VOID
  218. NetpDbgDisplayTod(
  219. IN LPDEBUG_STRING Tag,
  220. IN LPVOID TimePtr // LPTIME_OF_DAY_INFO.
  221. );
  222. #else // not DBG
  223. #define NetpDbgDisplayDword(Tag,Value) /* nothing */
  224. #define NetpDbgDisplayDwordHex(Tag,Value) /* nothing */
  225. #define NetpDbgDisplayLong(Tag,Value) /* nothing */
  226. #define NetpDbgDisplayString(Tag,Value) /* nothing */
  227. #define NetpDbgDisplayTimestamp(Tag,Time) /* nothing */
  228. #define NetpDbgDisplayTag(Tag) /* nothing */
  229. #define NetpDbgDisplayTod(Tag,Tod) /* nothing */
  230. #endif // not DBG
  231. //
  232. // NetpKdPrint() & NetpDbgPrint() are net equivalents of
  233. // KdPrint() & DbgPrint(). Suggested usage:
  234. //
  235. // NetpKdPrint() & KdPrint() - OK
  236. // NetpDbgPrint() - so,so; produces warnings in the free build
  237. // DbgPrint - bad
  238. //
  239. #if DBG
  240. #define NetpKdPrint(_x_) NetpDbgPrint _x_
  241. VOID
  242. NetpDbgPrint(
  243. IN LPDEBUG_STRING FORMATSTRING, // PRINTF()-STYLE FORMAT STRING.
  244. ... // OTHER ARGUMENTS ARE POSSIBLE.
  245. );
  246. VOID
  247. NetpHexDump(
  248. LPBYTE Buffer,
  249. DWORD BufferSize
  250. );
  251. #else // not DBG
  252. #ifdef CDEBUG
  253. // ANSI C debug version.
  254. #define NetpKdPrint(_x_) NetpDbgPrint _x_
  255. #define NetpDbgPrint (void) printf
  256. #else // ndef CDEBUG
  257. // Nondebug version. Note that NetpKdPrint() eliminates all its
  258. // arguments.
  259. #define NetpKdPrint(_x_)
  260. #endif // ndef CDEBUG
  261. #endif // not DBG
  262. // NetpDbgHexDump: do a hex dump of some number of bytes to the debug
  263. // terminal or whatever. This is a no-op in a nondebug build.
  264. #if DBG || defined(CDEBUG)
  265. VOID
  266. NetpDbgHexDump(
  267. IN LPBYTE StartAddr,
  268. IN DWORD Length
  269. );
  270. #else
  271. #define NetpDbgHexDump(StartAddr,Length) // no output; ignore arguments
  272. #endif
  273. //
  274. // Define a number of bytes to dump for partial dumps. Each line dumps
  275. // 16 bytes, so do an even number of lines.
  276. //
  277. #define REASONABLE_DUMP_SIZE (6*16)
  278. // NetpDbgReasonable: pick a number for partial hex dumps.
  279. //
  280. // DWORD
  281. // NetpDbgReasonable(
  282. // IN DWORD MaxSize
  283. // );
  284. #define NetpDbgReasonable(MaxSize) \
  285. /*lint -save -e506 */ /* don't complain about constant values here */ \
  286. ( ((MaxSize) < REASONABLE_DUMP_SIZE) ? (MaxSize) : REASONABLE_DUMP_SIZE ) \
  287. /*lint -restore */
  288. #ifdef __cplusplus
  289. }
  290. #endif
  291. //
  292. // Generic log managment funtions. Present in debug and free builds.
  293. // All logs are relative to %WINDIR%\\debug\\. DebugLog will automatically
  294. // have a .LOG appended
  295. //
  296. VOID
  297. NetpInitializeLogFile(
  298. VOID
  299. );
  300. VOID
  301. NetpShutdownLogFile(
  302. VOID
  303. );
  304. HANDLE
  305. NetpOpenDebugFile(
  306. IN LPWSTR DebugLog,
  307. IN BOOLEAN ReopenFlag
  308. );
  309. VOID
  310. NetpCloseDebugFile(
  311. IN HANDLE LogHandle
  312. );
  313. VOID
  314. NetpLogPrintRoutine(
  315. IN HANDLE LogHandle,
  316. IN LPSTR Format,
  317. ...
  318. );
  319. VOID
  320. NetpLogPrintRoutineVEx(
  321. IN HANDLE LogHandle,
  322. IN PDWORD OpenLogThreadId OPTIONAL,
  323. IN LPSTR Format,
  324. IN va_list arglist
  325. );
  326. VOID
  327. NetpLogPrintRoutineV(
  328. IN HANDLE LogHandle,
  329. IN LPSTR Format,
  330. IN va_list arglist
  331. );
  332. VOID
  333. NetpResetLog(
  334. IN HANDLE LogHandle
  335. );
  336. #endif // ndef _NETDEBUG_