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.

218 lines
3.2 KiB

  1. /*++
  2. Copyright (c) 1994-1998 Microsoft Corporation
  3. Module Name :
  4. debugafx.cpp
  5. Abstract:
  6. Debugging routines using AFX/MFC extensions
  7. Author:
  8. Ronald Meijer (ronaldm)
  9. Project:
  10. Internet Services Manager
  11. Revision History:
  12. --*/
  13. //
  14. // Include Files
  15. //
  16. #include "stdafx.h"
  17. #include "comprop.h"
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char BASED_CODE THIS_FILE[] = __FILE__;
  21. #endif
  22. #define new DEBUG_NEW
  23. #ifdef _DEBUG
  24. LPCSTR
  25. DbgFmtPgm (
  26. IN LPCSTR szFn,
  27. IN int line
  28. )
  29. /*++
  30. Routine Description:
  31. Format debugging string containing file name and line number. Remove
  32. the path portion of the file name if present.
  33. Arguments:
  34. LPCSTR szFn : File name (ANSI)
  35. int line : Line number
  36. Return Value:
  37. Pointer to the internal buffer
  38. --*/
  39. {
  40. LPCSTR pszTail = szFn + ::lstrlenA(szFn);
  41. static CHAR szBuff[MAX_PATH+1];
  42. for ( /**/; pszTail > szFn; --pszTail)
  43. {
  44. if (*pszTail == '\\' || *pszTail == ':')
  45. {
  46. ++pszTail;
  47. break;
  48. }
  49. }
  50. ::wsprintfA(szBuff, "[%s:%d] ", pszTail, line);
  51. return szBuff;
  52. }
  53. CDumpContext & operator << (
  54. IN OUT CDumpContext & out,
  55. IN ENUM_DEBUG_AFX edAfx
  56. )
  57. /*++
  58. Routine Description:
  59. Output debugging control character to the debug context
  60. Arguments:
  61. CDumpContext & out : Output debugging context
  62. edAfx : Control character
  63. Return Value:
  64. Output debugging context reference
  65. --*/
  66. {
  67. static CHAR * szEol = "\r\n";
  68. switch (edAfx)
  69. {
  70. case EDBUG_AFX_EOL:
  71. out << szEol;
  72. break;
  73. default:
  74. break;
  75. }
  76. return out;
  77. }
  78. #ifndef UNICODE
  79. CDumpContext & operator << (
  80. IN OUT CDumpContext & out,
  81. IN LPCWSTR pwchStr
  82. )
  83. /*++
  84. Routine Description:
  85. Insert a wide-character string into the output stream. For non-UNICODE only,
  86. as this functions would be handled by the generic 'T' function otherwise.
  87. Arguments:
  88. CDumpContext & out : Output debugging context
  89. pwchStr : Wide character string
  90. Return Value:
  91. Output debugging context reference
  92. --*/
  93. {
  94. size_t cwch ;
  95. if (pwchStr == NULL)
  96. {
  97. out << "<null>";
  98. }
  99. else if ((cwch = ::wcslen(pwchStr )) > 0)
  100. {
  101. CHAR * pszTemp = (LPSTR)AllocMem(cwch + 2);
  102. if (pszTemp != NULL)
  103. {
  104. for (int i = 0; pwchStr[i]; ++i)
  105. {
  106. pszTemp[i] = (CHAR)pwchStr[i];
  107. }
  108. pszTemp[i] = 0;
  109. out << pszTemp;
  110. FreeMem(pszTemp);
  111. }
  112. else
  113. {
  114. out << "<memerr>";
  115. }
  116. }
  117. else
  118. {
  119. out << "\"\"";
  120. }
  121. return out;
  122. }
  123. #endif // UNICODE
  124. CDumpContext & operator <<(
  125. IN CDumpContext & out,
  126. IN const GUID & guid
  127. )
  128. /*++
  129. Routine Description:
  130. Dump a GUID to the debugger
  131. Arguments:
  132. CDumpContext & out : Output debugging context
  133. GUID & guid : GUID
  134. Return Value:
  135. Output debugging context reference
  136. --*/
  137. {
  138. out << "{ "
  139. << guid.Data1
  140. << ","
  141. << guid.Data2
  142. << ","
  143. << guid.Data3
  144. << ","
  145. << guid.Data4
  146. << "}";
  147. return out;
  148. }
  149. #endif // _DEBUG