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.

161 lines
5.2 KiB

  1. // --------------------------------------------------------------------------------
  2. // Msoedbg.cpp
  3. // Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  4. // --------------------------------------------------------------------------------
  5. #include "pch.hxx"
  6. #ifdef DEBUG
  7. LPSTR PathClipFile(LPSTR pszSrc, LPSTR pszDest, DWORD cchSize)
  8. {
  9. LPSTR pszT=pszSrc;
  10. int cDirs=0;
  11. if (pszSrc)
  12. {
  13. // compact path
  14. pszT = pszSrc + lstrlen(pszSrc)-1;
  15. while (pszT != pszSrc)
  16. {
  17. if (*pszT == '\\' && ++cDirs == 3)
  18. break;
  19. pszT--;
  20. }
  21. if (pszSrc != pszT)
  22. {
  23. // if we clipped the path, show a ~
  24. StrCpyNA(pszDest, "~", cchSize);
  25. StrCpyNA(pszDest+1, pszT+1, cchSize-1);
  26. return pszDest;
  27. }
  28. }
  29. return pszSrc;
  30. }
  31. // --------------------------------------------------------------------------------
  32. // GetDebugTraceTagMask
  33. // --------------------------------------------------------------------------------
  34. DWORD GetDebugTraceTagMask(LPCSTR pszTag, SHOWTRACEMASK dwDefaultMask)
  35. {
  36. // Locals
  37. HRESULT hr=S_OK;
  38. DWORD dwMask=dwDefaultMask;
  39. HKEY hKeyOpen=NULL;
  40. DWORD dwType;
  41. DWORD cb;
  42. // Tracing
  43. TraceCall("GetDebugTraceTagMask");
  44. // Invalid Arg
  45. Assert(pszTag);
  46. // Open the Key
  47. if (ERROR_SUCCESS != RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Outlook Express\\Tracing", NULL, NULL, NULL, KEY_ALL_ACCESS, NULL, &hKeyOpen, &cb))
  48. {
  49. TraceResult(E_FAIL);
  50. goto exit;
  51. }
  52. // Query
  53. cb = sizeof(DWORD);
  54. if (ERROR_SUCCESS == RegQueryValueEx(hKeyOpen, pszTag, NULL, &dwType, (LPBYTE)&dwMask, &cb))
  55. goto exit;
  56. // Set to default value
  57. if (ERROR_SUCCESS != RegSetValueEx(hKeyOpen, pszTag, 0, REG_DWORD, (LPBYTE)&dwDefaultMask, sizeof(DWORD)))
  58. {
  59. TraceResult(E_FAIL);
  60. goto exit;
  61. }
  62. exit:
  63. // Cleanup
  64. if (hKeyOpen)
  65. RegCloseKey(hKeyOpen);
  66. // Done
  67. return dwMask;
  68. }
  69. // --------------------------------------------------------------------------------
  70. // DebugTraceEx
  71. // --------------------------------------------------------------------------------
  72. HRESULT DebugTraceEx(SHOWTRACEMASK dwMask, TRACEMACROTYPE tracetype, LPTRACELOGINFO pLog,
  73. HRESULT hr, LPSTR pszFile, INT nLine, LPCSTR pszMsg, LPCSTR pszFunc)
  74. {
  75. TCHAR rgchClip[MAX_PATH];
  76. // If pLog, reset dwMask
  77. if (pLog)
  78. dwMask = pLog->dwMask;
  79. // TRACE_CALL
  80. if (TRACE_CALL == tracetype)
  81. {
  82. // Trace Calls
  83. if (ISFLAGSET(dwMask, SHOW_TRACE_CALL) && pszFunc)
  84. {
  85. // No Message
  86. if (NULL == pszMsg)
  87. {
  88. // Do a Debug Trace
  89. DebugTrace("0x%08X: Call: %s(%d) - %s\r\n", GetCurrentThreadId(), PathClipFile(pszFile, rgchClip, ARRAYSIZE(rgchClip)), nLine, pszFunc);
  90. }
  91. // Do a message
  92. else
  93. {
  94. // Do a Debug Trace
  95. DebugTrace("0x%08X: Call: %s(%d) - %s - %s\r\n", GetCurrentThreadId(), PathClipFile(pszFile, rgchClip, ARRAYSIZE(rgchClip)), nLine, pszFunc, pszMsg);
  96. }
  97. }
  98. }
  99. // TRACE_INFO
  100. else if (TRACE_INFO == tracetype)
  101. {
  102. // Should we log
  103. if (ISFLAGSET(dwMask, SHOW_TRACE_INFO))
  104. {
  105. // Do a Debug Trace
  106. if (pszFunc)
  107. DebugTrace("0x%08X: Info: %s(%d) - %s - %s\r\n", GetCurrentThreadId(), PathClipFile(pszFile, rgchClip, ARRAYSIZE(rgchClip)), nLine, pszFunc, pszMsg);
  108. else
  109. DebugTrace("0x%08X: Info: %s(%d) - %s\r\n", GetCurrentThreadId(), PathClipFile(pszFile, rgchClip, ARRAYSIZE(rgchClip)), nLine, pszMsg);
  110. }
  111. }
  112. // TRACE_RESULT
  113. else
  114. {
  115. // No Message
  116. if (NULL == pszMsg)
  117. {
  118. // Do a Debug Trace
  119. if (pszFunc)
  120. DebugTrace("0x%08X: Result: %s(%d) - HRESULT(0x%08X) - GetLastError() = %d in %s\r\n", GetCurrentThreadId(), PathClipFile(pszFile, rgchClip, ARRAYSIZE(rgchClip)), nLine, hr, GetLastError(), pszFunc);
  121. else
  122. DebugTrace("0x%08X: Result: %s(%d) - HRESULT(0x%08X) - GetLastError() = %d\r\n", GetCurrentThreadId(), PathClipFile(pszFile, rgchClip, ARRAYSIZE(rgchClip)), nLine, hr, GetLastError());
  123. }
  124. // Do a message
  125. else
  126. {
  127. // Do a Debug Trace
  128. if (pszFunc)
  129. DebugTrace("0x%08X: Result: %s(%d) - HRESULT(0x%08X) - GetLastError() = %d - %s in %s\r\n", GetCurrentThreadId(), PathClipFile(pszFile, rgchClip, ARRAYSIZE(rgchClip)), nLine, hr, GetLastError(), pszMsg, pszFunc);
  130. else
  131. DebugTrace("0x%08X: Result: %s(%d) - HRESULT(0x%08X) - GetLastError() = %d - %s\r\n", GetCurrentThreadId(), PathClipFile(pszFile, rgchClip, ARRAYSIZE(rgchClip)), nLine, hr, GetLastError(), pszMsg);
  132. }
  133. }
  134. // Log File
  135. if (pLog && pLog->pLog)
  136. pLog->pLog->TraceLog(dwMask, tracetype, nLine, hr, pszMsg);
  137. // Done
  138. return hr;
  139. }
  140. #endif