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.

157 lines
4.4 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. miscdbg.h
  5. Abstract:
  6. Environment:
  7. Win32, User Mode
  8. --*/
  9. #ifndef DBG
  10. //
  11. // Debugging code for critical sections
  12. //
  13. #define DBG_CRITICAL_SECTION CRITICAL_SECTION
  14. #define Dbg_InitializeCriticalSection InitializeCriticalSection
  15. #define Dbg_TryEnterCriticalSection TryEnterCriticalSection
  16. #define Dbg_EnterCriticalSection EnterCriticalSection
  17. #define Dbg_LeaveCriticalSection LeaveCriticalSection
  18. #define Dbg_DeleteCriticalSection DeleteCriticalSection
  19. #define Dbg_CriticalSectionOwned(p) FALSE
  20. #define Dbg_CriticalSectionUnowned(p) FALSE
  21. #else
  22. typedef struct _DBG_WINDBG_CRITICAL_SECTION {
  23. CRITICAL_SECTION cs;
  24. int nLockCount;
  25. DWORD OwnerId;
  26. PTSTR pszName;
  27. PTSTR pszLock_LastFile;
  28. int nLock_LastFile;
  29. PTSTR pszUnlock_LastFile;
  30. int nUnlock_LastFile;
  31. void
  32. Initialize(
  33. PTSTR pszCritSecName
  34. )
  35. {
  36. //
  37. // Initialize the structure here to rather than in the CPP file,
  38. // because it is common to add member variables and forget to initialize
  39. // them in the CPP file. So we do it here.
  40. //
  41. nLockCount = 0;
  42. OwnerId = 0;
  43. pszName = _tcsdup(pszCritSecName);
  44. pszLock_LastFile = NULL;
  45. nLock_LastFile = 0;
  46. pszUnlock_LastFile = NULL;
  47. nUnlock_LastFile = 0;
  48. }
  49. void
  50. Delete()
  51. {
  52. free(pszName);
  53. }
  54. } DBG_WINDBG_CRITICAL_SECTION, *PDBG_WINDBG_CRITICAL_SECTION;
  55. #define DBG_CRITICAL_SECTION _DBG_WINDBG_CRITICAL_SECTION
  56. #define Dbg_InitializeCriticalSection(p) Dbg_Windbg_InitializeCriticalSection(p, _T(#p), _T(__FILE__), __LINE__);
  57. #define Dbg_TryEnterCriticalSection(p) Dbg_Windbg_TryEnterCriticalSection(p, _T(__FILE__), __LINE__);
  58. #define Dbg_EnterCriticalSection(p) Dbg_Windbg_EnterCriticalSection(p, _T(__FILE__), __LINE__);
  59. #define Dbg_LeaveCriticalSection(p) Dbg_Windbg_LeaveCriticalSection(p, _T(__FILE__), __LINE__);
  60. #define Dbg_DeleteCriticalSection(p) Dbg_Windbg_DeleteCriticalSection(p, _T(__FILE__), __LINE__);
  61. #define Dbg_CriticalSectionOwned(p) ((p)->OwnerId == GetCurrentThreadId())
  62. #define Dbg_CriticalSectionUnowned(p) ((p)->OwnerId == 0)
  63. VOID Dbg_Windbg_InitializeCriticalSection(PDBG_WINDBG_CRITICAL_SECTION, PTSTR, PTSTR, int);
  64. BOOL Dbg_Windbg_TryEnterCriticalSection(PDBG_WINDBG_CRITICAL_SECTION, PTSTR, int);
  65. VOID Dbg_Windbg_EnterCriticalSection(PDBG_WINDBG_CRITICAL_SECTION, PTSTR, int);
  66. VOID Dbg_Windbg_LeaveCriticalSection(PDBG_WINDBG_CRITICAL_SECTION, PTSTR, int);
  67. VOID Dbg_Windbg_DeleteCriticalSection(PDBG_WINDBG_CRITICAL_SECTION, PTSTR, int);
  68. //
  69. // Code to aid in outputing messages
  70. //
  71. #define DP_CRITSEC_WARN 0x00000001
  72. #define DP_CRITSEC_ERROR 0x00000002
  73. #define DP_CRITSEC_INFO 0x00000004
  74. #define DP_CRITSEC_VERBOSE 0x00000008
  75. #define DP_FATAL_ERROR 0x00000010
  76. #define DP_CRITSEC_ALL ( DP_CRITSEC_WARN | DP_CRITSEC_ERROR | DP_CRITSEC_INFO | DP_CRITSEC_VERBOSE )
  77. #define MIN_VERBOSITY_LEVEL (DP_FATAL_ERROR | DP_CRITSEC_ERROR)
  78. extern DWORD dwVerboseLevel;
  79. #define DPRINT(dwFlag, args) \
  80. if (dwFlag & dwVerboseLevel) { \
  81. (DebugPrint) args; \
  82. }
  83. #endif
  84. void DebugPrint(PTSTR, ...);
  85. //
  86. //
  87. // RTTI: Used for sanity checks, to be removed from the retail version.
  88. // Used to verify the type of object we are referencing.
  89. //
  90. // ei:
  91. // AssertType(pPointer, ClassFoo *);
  92. // Verify that the pointer we have is of that type.
  93. //
  94. // AssertType(*pPointer, ClassFoo);
  95. // Verify that what we are pointing to, is of that object.
  96. //
  97. // AssertChildOf(*pPointer, ClassFoo);
  98. // Verify that pPointer points to a class derived from ClassFoo.
  99. //
  100. #ifdef _CPPRTTI
  101. BOOL RttiTypesEqual(const type_info & t1, const type_info & t2);
  102. #define AssertType(Obj1, Obj2) Assert( RttiTypesEqual(typeid(Obj1), typeid(Obj2)) )
  103. #define AssertNotType(Obj1, Obj2) Assert( !RttiTypesEqual(typeid(Obj1), typeid(Obj2)) )
  104. #else
  105. #define AssertType(Obj1, Obj2) ((void)0)
  106. #define AssertNotType(Obj1, Obj2) ((void)0)
  107. #endif