Source code of Windows XP (NT5)
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.

167 lines
4.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1999-2000.
  5. //
  6. // File: debug.cpp
  7. //
  8. // Contents: Debugging support
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #if DBG == 1
  13. #define DEBUG_OUTPUT_NONE 0
  14. #define DEBUG_OUTPUT_ERROR 1
  15. #define DEBUG_OUTPUT_WARNING 2
  16. #define DEBUG_OUTPUT_TRACE 3
  17. #define DEBUGKEY L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AdminDebug\\ACLDiag"
  18. #define DEBUGLEVEL L"debugOutput"
  19. static bool g_fDebugOutputLevelInit = false;
  20. static unsigned long g_ulDebugOutput = DEBUG_OUTPUT_NONE;
  21. static int indentLevel = 0;
  22. void TRACE (const wchar_t *format, ... )
  23. {
  24. if ( g_ulDebugOutput > DEBUG_OUTPUT_NONE )
  25. {
  26. va_list arglist;
  27. WCHAR Buffer[512];
  28. int cb;
  29. //
  30. // Format the output into a buffer and then print it.
  31. //
  32. wstring strTabs;
  33. for (int nLevel = 0; nLevel < indentLevel; nLevel++)
  34. strTabs += L" ";
  35. OutputDebugStringW (strTabs.c_str ());
  36. va_start(arglist, format);
  37. cb = _vsnwprintf (Buffer, sizeof(Buffer), format, arglist);
  38. if ( cb )
  39. {
  40. OutputDebugStringW (Buffer);
  41. }
  42. va_end(arglist);
  43. }
  44. }
  45. void _TRACE (int level, const wchar_t *format, ... )
  46. {
  47. if ( g_ulDebugOutput > DEBUG_OUTPUT_NONE )
  48. {
  49. va_list arglist;
  50. WCHAR Buffer[512];
  51. int cb;
  52. if ( level < 0 )
  53. indentLevel += level;
  54. //
  55. // Format the output into a buffer and then print it.
  56. //
  57. wstring strTabs;
  58. for (int nLevel = 0; nLevel < indentLevel; nLevel++)
  59. strTabs += L" ";
  60. OutputDebugStringW (strTabs.c_str ());
  61. va_start(arglist, format);
  62. cb = _vsnwprintf (Buffer, sizeof(Buffer), format, arglist);
  63. if ( cb )
  64. {
  65. OutputDebugStringW (Buffer);
  66. }
  67. va_end(arglist);
  68. if ( level > 0 )
  69. indentLevel += level;
  70. }
  71. }
  72. PCSTR
  73. StripDirPrefixA(
  74. PCSTR pszPathName
  75. )
  76. /*++
  77. Routine Description:
  78. Strip the directory prefix off a filename (ANSI version)
  79. Arguments:
  80. pstrFilename - Pointer to filename string
  81. Return Value:
  82. Pointer to the last component of a filename (without directory prefix)
  83. --*/
  84. {
  85. DWORD dwLen = lstrlenA(pszPathName);
  86. pszPathName += dwLen - 1; // go to the end
  87. while (*pszPathName != '\\' && dwLen--)
  88. {
  89. pszPathName--;
  90. }
  91. return pszPathName + 1;
  92. }
  93. //+----------------------------------------------------------------------------
  94. // Function: CheckDebugOutputLevel
  95. //
  96. // Synopsis: Performs debugging library initialization
  97. // including reading the registry for the desired infolevel
  98. //
  99. //-----------------------------------------------------------------------------
  100. void CheckDebugOutputLevel ()
  101. {
  102. if ( g_fDebugOutputLevelInit )
  103. return;
  104. g_fDebugOutputLevelInit = true;
  105. HKEY hKey = 0;
  106. DWORD dwDisposition = 0;
  107. LONG lResult = ::RegCreateKeyEx (HKEY_LOCAL_MACHINE, // handle of an open key
  108. DEBUGKEY, // address of subkey name
  109. 0, // reserved
  110. L"", // address of class string
  111. REG_OPTION_VOLATILE, // special options flag
  112. KEY_ALL_ACCESS, // desired security access
  113. NULL, // address of key security structure
  114. &hKey, // address of buffer for opened handle
  115. &dwDisposition); // address of disposition value buffer
  116. if (lResult == ERROR_SUCCESS)
  117. {
  118. DWORD dwSize = sizeof(unsigned long);
  119. lResult = RegQueryValueExW (hKey, DEBUGLEVEL, NULL, NULL,
  120. (LPBYTE)&g_ulDebugOutput, &dwSize);
  121. if (lResult != ERROR_SUCCESS)
  122. {
  123. g_ulDebugOutput = DEBUG_OUTPUT_NONE;
  124. if ( ERROR_FILE_NOT_FOUND == lResult )
  125. {
  126. RegSetValueExW (hKey, DEBUGLEVEL, 0, REG_DWORD,
  127. (LPBYTE)&g_ulDebugOutput, sizeof (g_ulDebugOutput));
  128. }
  129. }
  130. RegCloseKey(hKey);
  131. }
  132. }
  133. #endif // if DBG