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.

854 lines
17 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 WORD State
  239. );
  240. LPSTR
  241. InternetMapHttpStateFlag(
  242. IN WORD Flag
  243. );
  244. LPSTR
  245. InternetMapAsyncRequest(
  246. IN AR_TYPE Type
  247. );
  248. LPSTR
  249. InternetMapHandleType(
  250. IN DWORD HandleType
  251. );
  252. LPSTR
  253. InternetMapScheme(
  254. IN INTERNET_SCHEME Scheme
  255. );
  256. LPSTR
  257. InternetMapOpenType(
  258. IN DWORD OpenType
  259. );
  260. LPSTR
  261. InternetMapService(
  262. IN DWORD Service
  263. );
  264. LPSTR
  265. InternetMapChunkToken(
  266. IN CHUNK_TOKEN_VALUE eToken
  267. );
  268. LPSTR
  269. InternetMapChunkState(
  270. IN CHUNK_DECODE_STATE eState
  271. );
  272. DWORD
  273. InternetHandleCount(
  274. VOID
  275. );
  276. int dprintf(char *, ...);
  277. LPSTR
  278. SourceFilename(
  279. LPSTR Filespec
  280. );
  281. VOID
  282. InitSymLib(
  283. VOID
  284. );
  285. VOID
  286. TermSymLib(
  287. VOID
  288. );
  289. LPSTR
  290. GetDebugSymbol(
  291. DWORD Address,
  292. LPDWORD Offset
  293. );
  294. VOID
  295. x86SleazeCallStack(
  296. OUT LPVOID * lplpvStack,
  297. IN DWORD dwStackCount,
  298. IN LPVOID * Ebp
  299. );
  300. VOID
  301. x86SleazeCallersAddress(
  302. LPVOID* pCaller,
  303. LPVOID* pCallersCaller
  304. );
  305. //
  306. // exceptn.cxx
  307. //
  308. VOID
  309. SetExceptionHandler(
  310. VOID
  311. );
  312. #else
  313. #define dprintf (VOID)
  314. #endif // #ifdef ENABLE_DEBUG
  315. //
  316. // macros
  317. //
  318. #ifdef ENABLE_DEBUG
  319. //
  320. // INET_DEBUG_START - initialize debugging support
  321. //
  322. #define INET_DEBUG_START() \
  323. InternetDebugInitialize()
  324. //
  325. // INET_DEBUG_FINISH - terminate debugging support
  326. //
  327. #define INET_DEBUG_FINISH() \
  328. InternetDebugTerminate()
  329. // RIP(f)
  330. //
  331. // Generates a "RIP at file.c, line x (eval)" message if f is NOT true.
  332. //
  333. // Use RIP() to perform parameter validation, especially when you
  334. // know the function or method may be called by a 3rd party app.
  335. // Typically, RIPs are used to indicate the caller passed in an invalid
  336. // parameter, so the problem is really not in the code itself.
  337. //
  338. // Do *not* use RIP() to verify successful API calls if the APIs can
  339. // legitimately fail due to low resources. For example, LocalAlloc can
  340. // legally fail, so you shouldn't assert that it will never fail.
  341. //
  342. // RIP performs a debugbreak only in the following processes:
  343. //
  344. // explore.exe
  345. // iexplore.exe
  346. // rundll32.exe
  347. // welcome.exe
  348. //
  349. // In any other process, this just spews the debug message, but doesn't stop.
  350. //
  351. // Setting the BF_RIP bit in g_dwBreakFlags will cause the macro to perform
  352. // a DebugBreak() even in non-shell processes.
  353. //
  354. // Default Behavior-
  355. // Retail builds: nothing
  356. // Debug builds: spew (other processes), spew and break (shell processes)
  357. // Full debug builds: spew (other processes), spew and break (shell processes)
  358. //
  359. BOOL CcshellRipA(LPCSTR pszFile, int line, LPCSTR pszEval, BOOL bBreakInside);
  360. BOOL CcshellRipW(LPCWSTR pszFile, int line, LPCWSTR pwszEval, BOOL bBreakInside);
  361. BOOL CDECL CcshellRipMsgA(BOOL bRip, LPCSTR pszMsg, ...);
  362. BOOL CDECL CcshellRipMsgW(BOOL bRip, LPCSTR pszMsg, ...);
  363. // Use this macro to declare message text that will be placed
  364. // in the CODE segment (useful if DS is getting full)
  365. //
  366. // Ex: DEBUGTEXT(szMsg, "Invalid whatever: %d");
  367. //
  368. #define DEBUGTEXT(sz, msg) /* ;Internal */ \
  369. static const TCHAR sz[] = msg
  370. #ifdef UNICODE
  371. #define CcshellRip CcshellRipW
  372. #define CcshellRipMsg CcshellRipMsgW
  373. #else
  374. #define CcshellRip CcshellRipA
  375. #define CcshellRipMsg CcshellRipMsgA
  376. #endif
  377. #ifdef _X86_
  378. // Use int 3 so we stop immediately in the source
  379. #define SH_DEBUG_BREAK do { _try { _asm int 3 } _except (EXCEPTION_EXECUTE_HANDLER) {;} } while (0)
  380. #else
  381. #define SH_DEBUG_BREAK do { _try { DebugBreak(); } _except (EXCEPTION_EXECUTE_HANDLER) {;} __endexcept } while (0)
  382. #endif
  383. #define RIP(f) \
  384. { \
  385. DEBUGTEXT(szFile, TEXT(__FILE__)); \
  386. if (!(f) && CcshellRip(szFile, __LINE__, TEXT(#f), FALSE)) \
  387. { \
  388. SH_DEBUG_BREAK; \
  389. } \
  390. } \
  391. #define RIPMSG CcshellRipMsg
  392. //
  393. // INET_ASSERT - The standard assert, redefined here because Win95 doesn't have
  394. // RtlAssert
  395. //
  396. #if defined(DISABLE_ASSERTS)
  397. #define INET_ASSERT(test) \
  398. /* NOTHING */
  399. #else
  400. #define INET_ASSERT(test) \
  401. do if (!(test)) { \
  402. InternetAssert(#test, __FILE__, __LINE__); \
  403. } while (0)
  404. #endif // defined(RETAIL_LOGGING)
  405. #else // end #ifdef ENABLE_DEBUG
  406. #define INET_DEBUG_START() \
  407. /* NOTHING */
  408. #define INET_DEBUG_FINISH() \
  409. /* NOTHING */
  410. #define INET_ASSERT(test) \
  411. do { } while(0) /* NOTHING */
  412. #define RIP(f)
  413. #define RIPMSG 1 ? (void)0 : (void)
  414. #endif // end #ifndef ENABLE_DEBUG
  415. //
  416. // INET_DEBUG_ASSERT - assert only if INET_DEBUG is set
  417. //
  418. #if INET_DEBUG
  419. #define INET_DEBUG_ASSERT(cond) INET_ASSERT(cond)
  420. #else
  421. #define INET_DEBUG_ASSERT(cond) /* NOTHING */
  422. #endif
  423. #if INET_DEBUG
  424. //
  425. // IF_DEBUG_CODE - always on if INET_DEBUG is set
  426. //
  427. #define IF_DEBUG_CODE() \
  428. if (1)
  429. //
  430. // IF_DEBUG - only execute following code if the specific flag is set
  431. //
  432. #define IF_DEBUG(x) \
  433. if (InternetDebugCategoryFlags & DBG_ ## x)
  434. //
  435. // IF_DEBUG_CONTROL - only execute if control flag is set
  436. //
  437. #define IF_DEBUG_CONTROL(x) \
  438. if (InternetDebugControlFlags & DBG_ ## x)
  439. //
  440. // DEBUG_ENTER - creates an INTERNET_DEBUG_RECORD for this function
  441. //
  442. #if defined(RETAIL_LOGGING)
  443. #define DEBUG_ENTER(ParameterList) \
  444. /* NOTHING */
  445. #define DEBUG_ENTER_API(ParameterList) \
  446. InternetDebugEnter ParameterList
  447. #else
  448. #define DEBUG_ENTER_API DEBUG_ENTER
  449. #define DEBUG_ENTER(ParameterList) \
  450. InternetDebugEnter ParameterList
  451. #endif // defined(RETAIL_LOGGING)
  452. //
  453. // DEBUG_LEAVE - destroys this function's INTERNET_DEBUG_RECORD
  454. //
  455. #if defined(RETAIL_LOGGING)
  456. #define DEBUG_LEAVE(Variable) \
  457. /* NOTHING */
  458. #define DEBUG_LEAVE_API(Variable) \
  459. InternetDebugLeave((DWORD_PTR)Variable, __FILE__, __LINE__)
  460. #else
  461. #define DEBUG_LEAVE_API DEBUG_LEAVE
  462. #define DEBUG_LEAVE(Variable) \
  463. InternetDebugLeave((DWORD_PTR)Variable, __FILE__, __LINE__)
  464. #endif // defined(RETAIL_LOGGING)
  465. //
  466. // DEBUG_ERROR - displays an error and its symbolic name
  467. //
  468. #define DEBUG_ERROR(Category, Error) \
  469. if (InternetDebugCategoryFlags & DBG_ ## Category) { \
  470. InternetDebugError(Error); \
  471. }
  472. //
  473. // DEBUG_PRINT - print debug info if we are at the correct level or we are
  474. // requested to always dump information at, or above, InternetDebugErrorLevel
  475. //
  476. #if defined(RETAIL_LOGGING)
  477. #define DEBUG_PRINT(Category, ErrorLevel, Args) \
  478. /* NOTHING */
  479. #define DEBUG_PRINT_API(Category, ErrorLevel, Args) \
  480. if (((InternetDebugCategoryFlags & DBG_ ## Category) \
  481. && (DBG_ ## ErrorLevel >= InternetDebugErrorLevel)) \
  482. || ((InternetDebugControlFlags & DBG_AT_ERROR_LEVEL) \
  483. && (DBG_ ## ErrorLevel >= InternetDebugErrorLevel))) { \
  484. InternetDebugPrint Args; \
  485. }
  486. #else
  487. #define DEBUG_PRINT_API DEBUG_PRINT
  488. #define DEBUG_PRINT(Category, ErrorLevel, Args) \
  489. if (((InternetDebugCategoryFlags & DBG_ ## Category) \
  490. && (DBG_ ## ErrorLevel >= InternetDebugErrorLevel)) \
  491. || ((InternetDebugControlFlags & DBG_AT_ERROR_LEVEL) \
  492. && (DBG_ ## ErrorLevel >= InternetDebugErrorLevel))) { \
  493. InternetDebugPrint Args; \
  494. }
  495. #endif // defined(RETAIL_LOGGING)
  496. //
  497. // DEBUG_PUT - prints formatted string to debug output stream
  498. //
  499. #if defined(RETAIL_LOGGING)
  500. #define DEBUG_PUT(Args) \
  501. /* NOTHING */
  502. #else
  503. #define DEBUG_PUT(Args) \
  504. InternetDebugPrintf Args
  505. #endif // defined(RETAIL_LOGGING)
  506. //
  507. // DEBUG_DUMP - dump data
  508. //
  509. #if defined(RETAIL_LOGGING)
  510. #define DEBUG_DUMP(Category, Text, Address, Length) \
  511. /* NOTHING */
  512. #define DEBUG_DUMP_API(Category, Text, Address, Length) \
  513. if (InternetDebugCategoryFlags & DBG_ ## Category) { \
  514. InternetDebugDump(Text, (LPBYTE)Address, Length); \
  515. }
  516. #else
  517. #define DEBUG_DUMP_API DEBUG_DUMP
  518. #define DEBUG_DUMP(Category, Text, Address, Length) \
  519. if (InternetDebugCategoryFlags & DBG_ ## Category) { \
  520. InternetDebugDump(Text, (LPBYTE)Address, Length); \
  521. }
  522. #endif // defined(RETAIL_LOGGING)
  523. //
  524. // DEBUG_BREAK - break into debugger if break flag is set for this module
  525. //
  526. #define DEBUG_BREAK(Module) \
  527. if (InternetDebugBreakFlags & DBG_ ## Module) { \
  528. InternetDebugPrintf("Breakpoint. File %s Line %d\n", \
  529. __FILE__, \
  530. __LINE__ \
  531. ); \
  532. DebugBreak(); \
  533. }
  534. //
  535. // WAIT_FOR_SINGLE_OBJECT - perform WaitForSingleObject and check we didn't
  536. // get a timeout
  537. //
  538. #define WAIT_FOR_SINGLE_OBJECT(Object, Error) \
  539. Error = WaitForSingleObject((Object), DEBUG_WAIT_TIME); \
  540. if (Error == WAIT_TIMEOUT) { \
  541. InternetDebugPrintf("single object timeout\n"); \
  542. DebugBreak(); \
  543. }
  544. //
  545. // DEBUG_WAIT_TIMER - create DWORD variable for holding time
  546. //
  547. #define DEBUG_WAIT_TIMER(TimerVar) \
  548. DWORD TimerVar
  549. //
  550. // DEBUG_START_WAIT_TIMER - get current tick count
  551. //
  552. #define DEBUG_START_WAIT_TIMER(TimerVar) \
  553. TimerVar = GetTickCountWrap()
  554. //
  555. // DEBUG_CHECK_WAIT_TIMER - get the current number of ticks, subtract from the
  556. // previous value recorded by DEBUG_START_WAIT_TIMER and break to debugger if
  557. // outside the predefined range
  558. //
  559. #define DEBUG_CHECK_WAIT_TIMER(TimerVar, MilliSeconds) \
  560. TimerVar = (GetTickCountWrap() - TimerVar); \
  561. if (TimerVar > MilliSeconds) { \
  562. InternetDebugPrintf("Wait time (%d mSecs) exceeds acceptable value (%d mSecs)\n", \
  563. TimerVar, \
  564. MilliSeconds \
  565. ); \
  566. DebugBreak(); \
  567. }
  568. #define DEBUG_DATA(Type, Name, InitialValue) \
  569. Type Name = InitialValue
  570. #define DEBUG_DATA_EXTERN(Type, Name) \
  571. extern Type Name
  572. #define DEBUG_LABEL(label) \
  573. label:
  574. #define DEBUG_GOTO(label) \
  575. goto label
  576. #define DEBUG_ONLY(x) \
  577. x
  578. #if defined(i386)
  579. #define GET_CALLERS_ADDRESS(p, pp) x86SleazeCallersAddress(p, pp)
  580. #define GET_CALL_STACK(p) x86SleazeCallStack((LPVOID *)&p, ARRAY_ELEMENTS(p), 0)
  581. #else
  582. #define GET_CALLERS_ADDRESS(p, pp)
  583. #define GET_CALL_STACK(p)
  584. #endif // defined(i386)
  585. #else // end #if INET_DEBUG
  586. #define IF_DEBUG_CODE() \
  587. if (0)
  588. #define IF_DEBUG(x) \
  589. if (0)
  590. #define IF_DEBUG_CONTROL(x) \
  591. if (0)
  592. #define DEBUG_ENTER(ParameterList) \
  593. /* NOTHING */
  594. #define DEBUG_ENTER_API(ParameterList) \
  595. /* NOTHING */
  596. #define DEBUG_LEAVE(Variable) \
  597. /* NOTHING */
  598. #define DEBUG_LEAVE_API(Variable) \
  599. /* NOTHING */
  600. #define DEBUG_ERROR(Category, Error) \
  601. /* NOTHING */
  602. #define DEBUG_PRINT(Category, ErrorLevel, Args) \
  603. /* NOTHING */
  604. #define DEBUG_PRINT_API(Category, ErrorLevel, Args) \
  605. /* NOTHING */
  606. #define DEBUG_PUT(Args) \
  607. /* NOTHING */
  608. #define DEBUG_DUMP(Category, Text, Address, Length) \
  609. /* NOTHING */
  610. #define DEBUG_DUMP_API(Category, Text, Address, Length) \
  611. /* NOTHING */
  612. #define DEBUG_BREAK(module) \
  613. /* NOTHING */
  614. #define WAIT_FOR_SINGLE_OBJECT(Object, Error) \
  615. Error = WaitForSingleObject((Object), INFINITE)
  616. #define DEBUG_WAIT_TIMER(TimerVar) \
  617. /* NOTHING */
  618. #define DEBUG_START_WAIT_TIMER(TimerVar) \
  619. /* NOTHING */
  620. #define DEBUG_CHECK_WAIT_TIMER(TimerVar, MilliSeconds) \
  621. /* NOTHING */
  622. #define DEBUG_DATA(Type, Name, InitialValue) \
  623. /* NOTHING */
  624. #define DEBUG_DATA_EXTERN(Type, Name) \
  625. /* NOTHING */
  626. #define DEBUG_LABEL(label) \
  627. /* NOTHING */
  628. #define DEBUG_GOTO(label) \
  629. /* NOTHING */
  630. #define DEBUG_ONLY(x) \
  631. /* NOTHING */
  632. #endif // INET_DEBUG
  633. #if defined(__cplusplus)
  634. }
  635. #endif