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.

787 lines
14 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. inetdbg.h
  5. Abstract:
  6. Manifests, macros, types and prototypes for Windows Internet client DLL
  7. debugging functions
  8. Author:
  9. Richard L Firth (rfirth) 11-Oct-1994
  10. Revision History:
  11. 11-Oct-1994 rfirth
  12. Created
  13. --*/
  14. #if defined(__cplusplus)
  15. extern "C" {
  16. #endif
  17. //
  18. // misc. debug manifests
  19. //
  20. #define DEBUG_WAIT_TIME (2 * 60 * 1000)
  21. //
  22. // Checked builds get INET_DEBUG set by default; retail builds get no debugging
  23. // by default
  24. //
  25. #if DBG
  26. #if !defined(INET_DEBUG)
  27. #define INET_DEBUG 1
  28. #endif // INET_DEBUG
  29. #else
  30. #if !defined(INET_DEBUG)
  31. #define INET_DEBUG 0
  32. #endif // INET_DEBUG
  33. #endif // DBG
  34. //
  35. // types
  36. //
  37. //
  38. // DEBUG_FUNCTION_RETURN_TYPE - Type of result (scalar) that a function returns
  39. //
  40. #ifdef ENABLE_DEBUG
  41. typedef enum {
  42. None,
  43. Bool,
  44. Int,
  45. Dword,
  46. String,
  47. Handle,
  48. Pointer
  49. } DEBUG_FUNCTION_RETURN_TYPE;
  50. //
  51. // INTERNET_DEBUG_RECORD - for each thread, we maintain a LIFO stack of these,
  52. // describing the functions we have visited
  53. //
  54. typedef struct _INTERNET_DEBUG_RECORD {
  55. //
  56. // Stack - a LIFO stack of debug records is maintained in the debug version
  57. // of the INTERNET_THREAD_INFO
  58. //
  59. struct _INTERNET_DEBUG_RECORD* Stack;
  60. //
  61. // Category - the function's category flag(s)
  62. //
  63. DWORD Category;
  64. //
  65. // ReturnType - type of value returned by function
  66. //
  67. DEBUG_FUNCTION_RETURN_TYPE ReturnType;
  68. //
  69. // Function - name of the function
  70. //
  71. LPCSTR Function;
  72. //
  73. // LastTime - if we are dumping times as deltas, keeps the last tick count
  74. //
  75. DWORD LastTime;
  76. } INTERNET_DEBUG_RECORD, *LPINTERNET_DEBUG_RECORD;
  77. //
  78. // INTERNET_FUNCTION_TRIGGER - if we are required to trigger on a function, this
  79. // structure maintains the debugging flags
  80. //
  81. typedef struct _INTERNET_FUNCTION_TRIGGER {
  82. //
  83. // Next - we maintain a singly-linked list of INTERNET_FUNCTION_TRIGGERs
  84. //
  85. struct _INTERNET_FUNCTION_TRIGGER* Next;
  86. //
  87. // Hash - hash value for the function name, to cut-down strcmp's to 1
  88. //
  89. DWORD Hash;
  90. //
  91. // Function - name of the function - must match exactly
  92. //
  93. LPCSTR Function;
  94. //
  95. // Category - category debug flags to use when this function triggers
  96. //
  97. DWORD MajorCategory;
  98. } INTERNET_FUNCTION_TRIGGER, *LPINTERNET_FUNCTION_TRIGGER;
  99. //
  100. // data
  101. //
  102. extern DWORD InternetDebugErrorLevel;
  103. extern DWORD InternetDebugControlFlags;
  104. extern DWORD InternetDebugCategoryFlags;
  105. extern DWORD InternetDebugBreakFlags;
  106. //
  107. // prototypes
  108. //
  109. //
  110. // inetdbg.cxx
  111. //
  112. VOID
  113. InternetDebugInitialize(
  114. VOID
  115. );
  116. VOID
  117. InternetDebugTerminate(
  118. VOID
  119. );
  120. DWORD
  121. InternetGetDebugInfo(
  122. OUT LPINTERNET_DEBUG_INFO lpBuffer,
  123. IN OUT LPDWORD lpdwBufferLength
  124. );
  125. DWORD
  126. InternetSetDebugInfo(
  127. IN LPINTERNET_DEBUG_INFO lpBuffer,
  128. IN DWORD dwBufferLength
  129. );
  130. BOOL
  131. InternetOpenDebugFile(
  132. VOID
  133. );
  134. BOOL
  135. InternetReopenDebugFile(
  136. IN LPSTR Filename
  137. );
  138. VOID
  139. InternetCloseDebugFile(
  140. VOID
  141. );
  142. VOID
  143. InternetFlushDebugFile(
  144. VOID
  145. );
  146. VOID
  147. InternetDebugSetControlFlags(
  148. IN DWORD dwFlags
  149. );
  150. VOID
  151. InternetDebugResetControlFlags(
  152. IN DWORD dwFlags
  153. );
  154. VOID
  155. InternetDebugEnter(
  156. IN DWORD Category,
  157. IN DEBUG_FUNCTION_RETURN_TYPE ReturnType,
  158. IN LPCSTR Function,
  159. IN LPCSTR ParameterList,
  160. IN ...
  161. );
  162. VOID
  163. InternetDebugLeave(
  164. IN DWORD_PTR Variable,
  165. IN LPCSTR Filename,
  166. IN DWORD LineNumber
  167. );
  168. VOID
  169. InternetDebugError(
  170. IN DWORD Error
  171. );
  172. VOID
  173. InternetDebugPrint(
  174. IN LPSTR Format,
  175. ...
  176. );
  177. VOID
  178. InternetDebugPrintValist(
  179. IN LPSTR Format,
  180. IN va_list valist
  181. );
  182. VOID
  183. InternetDebugPrintf(
  184. IN LPSTR Format,
  185. IN ...
  186. );
  187. VOID
  188. InternetDebugOut(
  189. IN LPSTR Buffer,
  190. IN BOOL Assert
  191. );
  192. VOID
  193. InternetDebugDump(
  194. IN LPSTR Text,
  195. IN LPBYTE Address,
  196. IN DWORD Size
  197. );
  198. DWORD
  199. InternetDebugDumpFormat(
  200. IN LPBYTE Address,
  201. IN DWORD Size,
  202. IN DWORD ElementSize,
  203. OUT LPSTR Buffer
  204. );
  205. VOID
  206. InternetAssert(
  207. IN LPSTR Condition,
  208. IN LPSTR Filename,
  209. IN DWORD LineNumber
  210. );
  211. VOID
  212. InternetGetDebugVariable(
  213. IN LPSTR lpszVariableName,
  214. OUT LPDWORD lpdwVariable
  215. );
  216. LPSTR
  217. InternetMapError(
  218. IN DWORD Error
  219. );
  220. LPSTR
  221. InternetMapStatus(
  222. IN DWORD Status
  223. );
  224. LPSTR
  225. InternetMapOption(
  226. IN DWORD Option
  227. );
  228. LPSTR
  229. InternetMapSSPIError(
  230. IN DWORD Status
  231. );
  232. LPSTR
  233. InternetMapHttpOption(
  234. IN DWORD Option
  235. );
  236. LPSTR
  237. InternetMapHttpState(
  238. IN DWORD State
  239. );
  240. LPSTR
  241. InternetMapHttpStateFlag(
  242. IN DWORD Flag
  243. );
  244. LPSTR
  245. InternetMapAuthScheme(
  246. IN DWORD Scheme
  247. );
  248. LPSTR
  249. InternetMapAuthState(
  250. IN DWORD State
  251. );
  252. LPSTR
  253. InternetMapAsyncRequest(
  254. IN AR_TYPE Type
  255. );
  256. LPSTR
  257. InternetMapHandleType(
  258. IN DWORD HandleType
  259. );
  260. LPSTR
  261. InternetMapScheme(
  262. IN INTERNET_SCHEME Scheme
  263. );
  264. LPSTR
  265. InternetMapOpenType(
  266. IN DWORD OpenType
  267. );
  268. LPSTR
  269. InternetMapService(
  270. IN DWORD Service
  271. );
  272. LPSTR
  273. InternetMapWinsockCallbackType(
  274. IN DWORD CallbackType
  275. );
  276. LPSTR
  277. InternetMapChunkToken(
  278. IN CHUNK_TOKEN ctToken
  279. );
  280. LPSTR
  281. InternetMapChunkState(
  282. IN CHUNK_STATE csState
  283. );
  284. DWORD
  285. InternetHandleCount(
  286. VOID
  287. );
  288. int dprintf(char *, ...);
  289. LPSTR
  290. SourceFilename(
  291. LPSTR Filespec
  292. );
  293. VOID
  294. InitSymLib(
  295. VOID
  296. );
  297. VOID
  298. TermSymLib(
  299. VOID
  300. );
  301. LPSTR
  302. GetDebugSymbol(
  303. DWORD Address,
  304. LPDWORD Offset
  305. );
  306. VOID
  307. x86SleazeCallStack(
  308. OUT LPVOID * lplpvStack,
  309. IN DWORD dwStackCount,
  310. IN LPVOID * Ebp
  311. );
  312. VOID
  313. x86SleazeCallersAddress(
  314. LPVOID* pCaller,
  315. LPVOID* pCallersCaller
  316. );
  317. #else
  318. #define dprintf (VOID)
  319. #endif // #ifdef ENABLE_DEBUG
  320. //
  321. // macros
  322. //
  323. #ifdef ENABLE_DEBUG
  324. //
  325. // INET_DEBUG_START - initialize debugging support
  326. //
  327. #define INET_DEBUG_START() \
  328. InternetDebugInitialize()
  329. //
  330. // INET_DEBUG_FINISH - terminate debugging support
  331. //
  332. #define INET_DEBUG_FINISH() \
  333. InternetDebugTerminate()
  334. //
  335. // INET_ASSERT - The standard assert, redefined here because Win95 doesn't have
  336. // RtlAssert
  337. //
  338. #if defined(DISABLE_ASSERTS)
  339. #define INET_ASSERT(test) \
  340. /* NOTHING */
  341. #else
  342. #define INET_ASSERT(test) \
  343. do if (!(test)) { \
  344. InternetAssert(#test, __FILE__, __LINE__); \
  345. } while (0)
  346. #endif // defined(RETAIL_LOGGING)
  347. #else // end #ifdef ENABLE_DEBUG
  348. #define INET_DEBUG_START() \
  349. /* NOTHING */
  350. #define INET_DEBUG_FINISH() \
  351. /* NOTHING */
  352. #define INET_ASSERT(test) \
  353. do { } while(0) /* NOTHING */
  354. #endif // end #ifndef ENABLE_DEBUG
  355. //
  356. // INET_DEBUG_ASSERT - assert only if INET_DEBUG is set
  357. //
  358. #if INET_DEBUG
  359. #define INET_DEBUG_ASSERT(cond) INET_ASSERT(cond)
  360. #else
  361. #define INET_DEBUG_ASSERT(cond) /* NOTHING */
  362. #endif
  363. #if INET_DEBUG
  364. //
  365. // IF_DEBUG_CODE - always on if INET_DEBUG is set
  366. //
  367. #define IF_DEBUG_CODE() \
  368. if (1)
  369. //
  370. // IF_DEBUG - only execute following code if the specific flag is set
  371. //
  372. #define IF_DEBUG(x) \
  373. if (InternetDebugCategoryFlags & DBG_ ## x)
  374. //
  375. // IF_DEBUG_CONTROL - only execute if control flag is set
  376. //
  377. #define IF_DEBUG_CONTROL(x) \
  378. if (InternetDebugControlFlags & DBG_ ## x)
  379. //
  380. // DEBUG_ENTER - creates an INTERNET_DEBUG_RECORD for this function
  381. //
  382. #if defined(RETAIL_LOGGING)
  383. #define DEBUG_ENTER(ParameterList) \
  384. /* NOTHING */
  385. #define DEBUG_ENTER_API(ParameterList) \
  386. InternetDebugEnter ParameterList
  387. #else
  388. #define DEBUG_ENTER_API DEBUG_ENTER
  389. #define DEBUG_ENTER(ParameterList) \
  390. InternetDebugEnter ParameterList
  391. #endif // defined(RETAIL_LOGGING)
  392. //
  393. // DEBUG_LEAVE - destroys this function's INTERNET_DEBUG_RECORD
  394. //
  395. #if defined(RETAIL_LOGGING)
  396. #define DEBUG_LEAVE(Variable) \
  397. /* NOTHING */
  398. #define DEBUG_LEAVE_API(Variable) \
  399. InternetDebugLeave((DWORD_PTR)Variable, __FILE__, __LINE__)
  400. #else
  401. #define DEBUG_LEAVE_API DEBUG_LEAVE
  402. #define DEBUG_LEAVE(Variable) \
  403. InternetDebugLeave((DWORD_PTR)Variable, __FILE__, __LINE__)
  404. #endif // defined(RETAIL_LOGGING)
  405. //
  406. // DEBUG_ERROR - displays an error and its symbolic name
  407. //
  408. #define DEBUG_ERROR(Category, Error) \
  409. if (InternetDebugCategoryFlags & DBG_ ## Category) { \
  410. InternetDebugError(Error); \
  411. }
  412. //
  413. // DEBUG_PRINT - print debug info if we are at the correct level or we are
  414. // requested to always dump information at, or above, InternetDebugErrorLevel
  415. //
  416. #if defined(RETAIL_LOGGING)
  417. #define DEBUG_PRINT(Category, ErrorLevel, Args) \
  418. /* NOTHING */
  419. #define DEBUG_PRINT_API(Category, ErrorLevel, Args) \
  420. if (((InternetDebugCategoryFlags & DBG_ ## Category) \
  421. && (DBG_ ## ErrorLevel >= InternetDebugErrorLevel)) \
  422. || ((InternetDebugControlFlags & DBG_AT_ERROR_LEVEL) \
  423. && (DBG_ ## ErrorLevel >= InternetDebugErrorLevel))) { \
  424. InternetDebugPrint Args; \
  425. }
  426. #else
  427. #define DEBUG_PRINT_API DEBUG_PRINT
  428. #define DEBUG_PRINT(Category, ErrorLevel, Args) \
  429. if (((InternetDebugCategoryFlags & DBG_ ## Category) \
  430. && (DBG_ ## ErrorLevel >= InternetDebugErrorLevel)) \
  431. || ((InternetDebugControlFlags & DBG_AT_ERROR_LEVEL) \
  432. && (DBG_ ## ErrorLevel >= InternetDebugErrorLevel))) { \
  433. InternetDebugPrint Args; \
  434. }
  435. #endif // defined(RETAIL_LOGGING)
  436. //
  437. // DEBUG_PUT - prints formatted string to debug output stream
  438. //
  439. #if defined(RETAIL_LOGGING)
  440. #define DEBUG_PUT(Args) \
  441. /* NOTHING */
  442. #else
  443. #define DEBUG_PUT(Args) \
  444. InternetDebugPrintf Args
  445. #endif // defined(RETAIL_LOGGING)
  446. //
  447. // DEBUG_DUMP - dump data
  448. //
  449. #if defined(RETAIL_LOGGING)
  450. #define DEBUG_DUMP(Category, Text, Address, Length) \
  451. /* NOTHING */
  452. #define DEBUG_DUMP_API(Category, Text, Address, Length) \
  453. if (InternetDebugCategoryFlags & DBG_ ## Category) { \
  454. InternetDebugDump(Text, (LPBYTE)Address, Length); \
  455. }
  456. #else
  457. #define DEBUG_DUMP_API DEBUG_DUMP
  458. #define DEBUG_DUMP(Category, Text, Address, Length) \
  459. if (InternetDebugCategoryFlags & DBG_ ## Category) { \
  460. InternetDebugDump(Text, (LPBYTE)Address, Length); \
  461. }
  462. #endif // defined(RETAIL_LOGGING)
  463. //
  464. // DEBUG_BREAK - break into debugger if break flag is set for this module
  465. //
  466. #define DEBUG_BREAK(Module) \
  467. if (InternetDebugBreakFlags & DBG_ ## Module) { \
  468. InternetDebugPrintf("Breakpoint. File %s Line %d\n", \
  469. __FILE__, \
  470. __LINE__ \
  471. ); \
  472. DebugBreak(); \
  473. }
  474. //
  475. // WAIT_FOR_SINGLE_OBJECT - perform WaitForSingleObject and check we didn't
  476. // get a timeout
  477. //
  478. #define WAIT_FOR_SINGLE_OBJECT(Object, Error) \
  479. Error = WaitForSingleObject((Object), DEBUG_WAIT_TIME); \
  480. if (Error == WAIT_TIMEOUT) { \
  481. InternetDebugPrintf("single object timeout\n"); \
  482. DebugBreak(); \
  483. }
  484. //
  485. // DEBUG_WAIT_TIMER - create DWORD variable for holding time
  486. //
  487. #define DEBUG_WAIT_TIMER(TimerVar) \
  488. DWORD TimerVar
  489. //
  490. // DEBUG_START_WAIT_TIMER - get current tick count
  491. //
  492. #define DEBUG_START_WAIT_TIMER(TimerVar) \
  493. TimerVar = GetTickCountWrap()
  494. //
  495. // DEBUG_CHECK_WAIT_TIMER - get the current number of ticks, subtract from the
  496. // previous value recorded by DEBUG_START_WAIT_TIMER and break to debugger if
  497. // outside the predefined range
  498. //
  499. #define DEBUG_CHECK_WAIT_TIMER(TimerVar, MilliSeconds) \
  500. TimerVar = (GetTickCountWrap() - TimerVar); \
  501. if (TimerVar > MilliSeconds) { \
  502. InternetDebugPrintf("Wait time (%d mSecs) exceeds acceptable value (%d mSecs)\n", \
  503. TimerVar, \
  504. MilliSeconds \
  505. ); \
  506. DebugBreak(); \
  507. }
  508. #define DEBUG_DATA(Type, Name, InitialValue) \
  509. Type Name = InitialValue
  510. #define DEBUG_DATA_EXTERN(Type, Name) \
  511. extern Type Name
  512. #define DEBUG_LABEL(label) \
  513. label:
  514. #define DEBUG_GOTO(label) \
  515. goto label
  516. #define DEBUG_ONLY(x) \
  517. x
  518. #if defined(i386)
  519. #define GET_CALLERS_ADDRESS(p, pp) x86SleazeCallersAddress(p, pp)
  520. #define GET_CALL_STACK(p) x86SleazeCallStack((LPVOID *)&p, ARRAY_ELEMENTS(p), 0)
  521. #else
  522. #define GET_CALLERS_ADDRESS(p, pp)
  523. #define GET_CALL_STACK(p)
  524. #endif // defined(i386)
  525. #else // end #if INET_DEBUG
  526. #define IF_DEBUG_CODE() \
  527. if (0)
  528. #define IF_DEBUG(x) \
  529. if (0)
  530. #define IF_DEBUG_CONTROL(x) \
  531. if (0)
  532. #define DEBUG_ENTER(ParameterList) \
  533. /* NOTHING */
  534. #define DEBUG_ENTER_API(ParameterList) \
  535. /* NOTHING */
  536. #define DEBUG_LEAVE(Variable) \
  537. /* NOTHING */
  538. #define DEBUG_LEAVE_API(Variable) \
  539. /* NOTHING */
  540. #define DEBUG_ERROR(Category, Error) \
  541. /* NOTHING */
  542. #define DEBUG_PRINT(Category, ErrorLevel, Args) \
  543. /* NOTHING */
  544. #define DEBUG_PRINT_API(Category, ErrorLevel, Args) \
  545. /* NOTHING */
  546. #define DEBUG_PUT(Args) \
  547. /* NOTHING */
  548. #define DEBUG_DUMP(Category, Text, Address, Length) \
  549. /* NOTHING */
  550. #define DEBUG_DUMP_API(Category, Text, Address, Length) \
  551. /* NOTHING */
  552. #define DEBUG_BREAK(module) \
  553. /* NOTHING */
  554. #define WAIT_FOR_SINGLE_OBJECT(Object, Error) \
  555. Error = WaitForSingleObject((Object), INFINITE)
  556. #define DEBUG_WAIT_TIMER(TimerVar) \
  557. /* NOTHING */
  558. #define DEBUG_START_WAIT_TIMER(TimerVar) \
  559. /* NOTHING */
  560. #define DEBUG_CHECK_WAIT_TIMER(TimerVar, MilliSeconds) \
  561. /* NOTHING */
  562. #define DEBUG_DATA(Type, Name, InitialValue) \
  563. /* NOTHING */
  564. #define DEBUG_DATA_EXTERN(Type, Name) \
  565. /* NOTHING */
  566. #define DEBUG_LABEL(label) \
  567. /* NOTHING */
  568. #define DEBUG_GOTO(label) \
  569. /* NOTHING */
  570. #define DEBUG_ONLY(x) \
  571. /* NOTHING */
  572. #endif // INET_DEBUG
  573. #if defined(__cplusplus)
  574. }
  575. #endif