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.

198 lines
3.8 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1998.
  5. //
  6. // File: debug.cxx
  7. //
  8. // Contents: Debugging routines
  9. //
  10. // History: 09-04-1997 DavidMun Created
  11. //
  12. //---------------------------------------------------------------------------
  13. #include "headers.h"
  14. #pragma hdrstop
  15. DECLARE_INFOLEVEL(role)
  16. #if (DBG == 1)
  17. ULONG CDbg::s_idxTls;
  18. void __cdecl
  19. CTimer::Init(LPCSTR pszTitleFmt, ...)
  20. {
  21. va_list va;
  22. va_start(va, pszTitleFmt);
  23. m_ulStart = GetTickCount();
  24. WCHAR wzTitleFmt[MAX_PATH];
  25. MultiByteToWideChar(CP_ACP,
  26. 0,
  27. pszTitleFmt,
  28. -1,
  29. wzTitleFmt,
  30. ARRAYLEN(wzTitleFmt));
  31. int iRet = _vsnwprintf(m_wzTitle, ARRAYLEN(m_wzTitle), wzTitleFmt, va);
  32. if (iRet == -1)
  33. {
  34. // resulting string too large and was truncated. ensure null
  35. // termination.
  36. m_wzTitle[ARRAYLEN(m_wzTitle) - 1] = L'\0';
  37. }
  38. va_end(va);
  39. }
  40. CTimer::~CTimer()
  41. {
  42. ULONG ulStop = GetTickCount();
  43. ULONG ulElapsedMS = ulStop - m_ulStart;
  44. ULONG ulSec = ulElapsedMS / 1000;
  45. ULONG ulMillisec = ulElapsedMS - (ulSec * 1000);
  46. Dbg(DEB_PERF, "Timer: %ws took %u.%03us\n", m_wzTitle, ulSec, ulMillisec);
  47. }
  48. PCWSTR
  49. NextNonWs(
  50. PCWSTR pwzCur)
  51. {
  52. while (wcschr(L" \t\n", *pwzCur))
  53. {
  54. pwzCur++;
  55. }
  56. return pwzCur;
  57. }
  58. //+--------------------------------------------------------------------------
  59. //
  60. // Function: IsSingleBitFlag
  61. //
  62. // Synopsis: Return TRUE if exactly one bit in [flags] is set, FALSE
  63. // otherwise.
  64. //
  65. // History: 08-31-1998 DavidMun Created
  66. //
  67. //---------------------------------------------------------------------------
  68. BOOL
  69. IsSingleBitFlag(
  70. ULONG flags)
  71. {
  72. if (!flags)
  73. {
  74. return FALSE;
  75. }
  76. while (!(flags & 1))
  77. {
  78. flags >>= 1;
  79. }
  80. return !(flags & ~1UL);
  81. }
  82. #define DUMP_IF_SET(fl, bit) \
  83. if (((fl) & (bit)) == (bit)) \
  84. { \
  85. Dbg(DEB_TRACE, " %hs\n", #bit); \
  86. }
  87. void
  88. IIDtoString(
  89. REFIID riid,
  90. CString *pstr)
  91. {
  92. HRESULT hr = S_OK;
  93. ULONG lResult;
  94. LPOLESTR pwzIID = NULL;
  95. HKEY hkInterface = NULL;
  96. HKEY hkIID = NULL;
  97. do
  98. {
  99. hr = StringFromIID(riid, &pwzIID);
  100. if (FAILED(hr)) break;
  101. lResult = RegOpenKey(HKEY_CLASSES_ROOT, L"Interface", &hkInterface);
  102. if (lResult != NO_ERROR) break;
  103. lResult = RegOpenKey(hkInterface, pwzIID, &hkIID);
  104. if (lResult != NO_ERROR) break;
  105. WCHAR wzInterfaceName[MAX_PATH] = L"";
  106. ULONG cbData = sizeof(wzInterfaceName);
  107. lResult = RegQueryValueEx(hkIID,
  108. NULL,
  109. NULL,
  110. NULL,
  111. (PBYTE)wzInterfaceName,
  112. &cbData);
  113. if (*wzInterfaceName)
  114. {
  115. *pstr = wzInterfaceName;
  116. }
  117. else
  118. {
  119. *pstr = pwzIID;
  120. }
  121. } while (0);
  122. if (hkIID)
  123. {
  124. RegCloseKey(hkIID);
  125. }
  126. if (hkInterface)
  127. {
  128. RegCloseKey(hkInterface);
  129. }
  130. CoTaskMemFree(pwzIID);
  131. }
  132. void
  133. SayNoItf(
  134. PCSTR szComponent,
  135. REFIID riid)
  136. {
  137. CString strIID;
  138. IIDtoString(riid, &strIID);
  139. Dbg(DEB_ERROR, "%hs::QI no interface %ws\n", szComponent, strIID);
  140. }
  141. #endif // (DBG == 1)