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.

210 lines
4.0 KiB

  1. /*++
  2. Copyright (c) 1990-1995 Microsoft Corporation
  3. All rights reserved
  4. Module Name:
  5. debug.c
  6. Abstract:
  7. Simple debug routines to log job references. This will capture
  8. a backtrace of all pIniJob->cRef changes into a memory log.
  9. To enable, do the following:
  10. 1. Define DEBUG_JOB_CREF in sources.
  11. 2. Add this file to sources.
  12. 3. Run with debug version of spoolss.dll (this uses the debug
  13. log routines from spllib that are in spoolss.dll).
  14. When you have a job that won't be deleted, dump it out and
  15. look at the last field (usually it's right before the
  16. 0xdeadbeef trailer in pIniJob). Then use the spllib debug
  17. extensions to dump it (splx.dll, built from spooler\exts).
  18. !splx.ddt -x {pvRef Address}
  19. The -b option is handy to look at backtraces (available on x86
  20. only). Note that ddt list most recent entries first (see
  21. !splx.help for more info.
  22. This code should only be used when debugging specific pIniJob->cRef
  23. problems.
  24. Author:
  25. Environment:
  26. User Mode -Win32
  27. Revision History:
  28. --*/
  29. #include "precomp.h"
  30. #pragma hdrstop
  31. #ifdef DEBUG_JOB_CREF
  32. VOID
  33. DbgJobInit(
  34. PINIJOB pIniJob
  35. )
  36. {
  37. if( gpDbgPointers ){
  38. pIniJob->pvRef = gpDbgPointers->pfnAllocBackTrace();
  39. }
  40. }
  41. VOID
  42. DbgJobFree(
  43. PINIJOB pIniJob
  44. )
  45. {
  46. if( pIniJob->pvRef ){
  47. gpDbgPointers->pfnFreeBackTrace( (HANDLE)pIniJob->pvRef );
  48. }
  49. }
  50. VOID
  51. DbgJobDecRef(
  52. PINIJOB pIniJob
  53. )
  54. {
  55. HANDLE hBackTrace = (HANDLE)pIniJob->pvRef;
  56. SPLASSERT(pIniJob->cRef);
  57. pIniJob->cRef--;
  58. if (!hBackTrace) {
  59. return;
  60. }
  61. gpDbgPointers->pfnCaptureBackTrace( hBackTrace,
  62. pIniJob->cRef+1,
  63. pIniJob->cRef,
  64. 0 );
  65. }
  66. VOID
  67. DbgJobIncRef(
  68. PINIJOB pIniJob
  69. )
  70. {
  71. HANDLE hBackTrace = (HANDLE)pIniJob->pvRef;
  72. pIniJob->cRef++;
  73. if (!hBackTrace) {
  74. return;
  75. }
  76. gpDbgPointers->pfnCaptureBackTrace( hBackTrace,
  77. pIniJob->cRef-1,
  78. pIniJob->cRef,
  79. 0 );
  80. }
  81. #endif // def DEBUG_JOB_CREF
  82. #ifdef DEBUG_PRINTER_CREF
  83. #undef DbgPrinterInit
  84. #undef DbgPrinterFree
  85. #undef DbgPrinterDecRef
  86. #undef DbgPrinterIncRef
  87. VOID
  88. DbgPrinterInit(
  89. PINIPRINTER pIniPrinter
  90. )
  91. {
  92. if( gpDbgPointers ){
  93. pIniPrinter->pvRef = gpDbgPointers->pfnAllocBackTrace();
  94. }
  95. }
  96. VOID
  97. DbgPrinterFree(
  98. PINIPRINTER pIniPrinter
  99. )
  100. {
  101. if( pIniPrinter->pvRef ){
  102. gpDbgPointers->pfnFreeBackTrace( (HANDLE)pIniPrinter->pvRef );
  103. }
  104. }
  105. VOID
  106. DbgPrinterDecRef(
  107. PINIPRINTER pIniPrinter
  108. )
  109. {
  110. HANDLE hBackTrace = (HANDLE)pIniPrinter->pvRef;
  111. SPLASSERT(pIniPrinter->cRef+1);
  112. if (!hBackTrace) {
  113. return;
  114. }
  115. gpDbgPointers->pfnCaptureBackTrace( hBackTrace,
  116. pIniPrinter->cRef+1,
  117. pIniPrinter->cRef,
  118. 0 );
  119. }
  120. VOID
  121. DbgPrinterIncRef(
  122. PINIPRINTER pIniPrinter
  123. )
  124. {
  125. HANDLE hBackTrace = (HANDLE)pIniPrinter->pvRef;
  126. if (!hBackTrace) {
  127. return;
  128. }
  129. gpDbgPointers->pfnCaptureBackTrace( hBackTrace,
  130. pIniPrinter->cRef-1,
  131. pIniPrinter->cRef,
  132. 0 );
  133. }
  134. #endif // def DEBUG_PRINTER_CREF
  135. #ifdef DEBUG_STARTENDDOC
  136. HANDLE ghbtStartEndDoc;
  137. VOID
  138. DbgStartEndDoc(
  139. HANDLE hPort,
  140. PINIJOB pIniJob,
  141. DWORD dwFlags
  142. )
  143. {
  144. if( !ghbtStartEndDoc ){
  145. ghbtStartEndDoc = gpDbgPointers->pfnAllocBackTraceFile();
  146. if( !ghbtStartEndDoc ){
  147. SPLASSERT( FALSE );
  148. return;
  149. }
  150. }
  151. gpDbgPointers->pfnCaptureBackTrace( ghbtStartEndDoc,
  152. (DWORD)hPort,
  153. (DWORD)pIniJob,
  154. dwFlags );
  155. }
  156. #endif