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.

151 lines
3.2 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. dbgprint.c
  5. Abstract:
  6. WinDbg Extension Api
  7. Author:
  8. Wesley Witt (wesw) 15-Aug-1993
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. DECLARE_API( dbgprint )
  16. /*++
  17. Routine Description:
  18. This routine dumps the DbgPrint buffer.
  19. Arguments:
  20. args - not used
  21. Return Value:
  22. None
  23. --*/
  24. {
  25. ULONG64 BufferBase;
  26. ULONG64 BufferEnd;
  27. ULONG64 WritePointer;
  28. PUCHAR LocalBuffer = NULL;
  29. PUCHAR LocalBufferEnd;
  30. PUCHAR p;
  31. PUCHAR Start;
  32. ULONG result;
  33. //
  34. // First check and see if this is an updated kernel
  35. // where the buffer can be changed.
  36. //
  37. if (!(BufferBase = GetNtDebuggerData( KdPrintCircularBufferPtr ))) {
  38. // No, use the old variables.
  39. BufferBase = GetNtDebuggerData( KdPrintCircularBuffer );
  40. BufferEnd = GetNtDebuggerData( KdPrintCircularBufferEnd );
  41. } else {
  42. ULONG64 BufferSize;
  43. // Yes, use the new variables.
  44. BufferBase = GetNtDebuggerDataPtrValue( KdPrintCircularBufferPtr );
  45. BufferSize = GetNtDebuggerDataPtrValue( KdPrintBufferSize ) &
  46. 0xffffffff;
  47. BufferEnd = BufferBase + BufferSize;
  48. }
  49. WritePointer = GetNtDebuggerDataPtrValue( KdPrintWritePointer );
  50. if (!BufferBase || !BufferEnd || !WritePointer) {
  51. dprintf("Can't find DbgPrint buffer\n");
  52. goto exit;
  53. }
  54. if ((WritePointer < BufferBase) || (WritePointer > BufferEnd) )
  55. {
  56. dprintf("Bad nt!KdDebuggerDataBlock.KdPrintWritePointer %p\n", WritePointer);
  57. goto exit;
  58. }
  59. LocalBuffer = LocalAlloc(LPTR, (ULONG) ( BufferEnd - BufferBase)+ 1);
  60. ZeroMemory(LocalBuffer, (ULONG) ( BufferEnd - BufferBase) + 1);
  61. if (!LocalBuffer) {
  62. dprintf("Could not allocate memory for local copy of DbgPrint buffer\n");
  63. goto exit;
  64. }
  65. if ((!ReadMemory(BufferBase,
  66. LocalBuffer,
  67. (ULONG) (BufferEnd - BufferBase),
  68. &result)) || (result < BufferEnd - BufferBase)) {
  69. dprintf("%08p: Could not read DbgPrint buffer\n", BufferBase);
  70. goto exit;
  71. }
  72. LocalBufferEnd = LocalBuffer + BufferEnd - BufferBase;
  73. Start = LocalBuffer + ((ULONG) WritePointer - BufferBase);
  74. p = Start;
  75. do {
  76. //
  77. // consume NULs
  78. //
  79. while (p < LocalBufferEnd && *p == 0) {
  80. p++;
  81. }
  82. if (p < LocalBufferEnd) {
  83. //
  84. // print a string and consume it
  85. //
  86. dprintf("%s", p);
  87. while (p < LocalBufferEnd && *p != 0) {
  88. p++;
  89. }
  90. }
  91. } while (p < LocalBufferEnd);
  92. //
  93. // repeat until we hit the start
  94. //
  95. p = LocalBuffer;
  96. while (p < Start && *p == 0) {
  97. p++;
  98. }
  99. if (p < Start) {
  100. dprintf("%s", p);
  101. while (p < Start && *p != 0) {
  102. p++;
  103. }
  104. }
  105. exit:
  106. if (LocalBuffer) {
  107. LocalFree( LocalBuffer );
  108. }
  109. return S_OK;
  110. }