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.

128 lines
2.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;
  29. PUCHAR LocalBufferEnd;
  30. PUCHAR p;
  31. PUCHAR Start;
  32. ULONG result;
  33. BufferBase = GetNtDebuggerData( KdPrintCircularBuffer );
  34. BufferEnd = GetNtDebuggerData( KdPrintCircularBufferEnd );
  35. WritePointer = GetNtDebuggerDataPtrValue( KdPrintWritePointer );
  36. if (!BufferBase || !BufferEnd || !WritePointer) {
  37. dprintf("Can't find DbgPrint buffer\n");
  38. goto exit;
  39. }
  40. LocalBuffer = LocalAlloc(LPTR, (ULONG) ( BufferEnd - BufferBase));
  41. if (!LocalBuffer) {
  42. dprintf("Could not allocate memory for local copy of DbgPrint buffer\n");
  43. goto exit;
  44. }
  45. if ((!ReadMemory(BufferBase,
  46. LocalBuffer,
  47. (ULONG) (BufferEnd - BufferBase),
  48. &result)) || (result < BufferEnd - BufferBase)) {
  49. dprintf("%08p: Could not read DbgPrint buffer\n", BufferBase);
  50. goto exit;
  51. }
  52. LocalBufferEnd = LocalBuffer + BufferEnd - BufferBase;
  53. Start = LocalBuffer + ((ULONG) WritePointer - BufferBase);
  54. p = Start;
  55. do {
  56. //
  57. // consume NULs
  58. //
  59. while (p < LocalBufferEnd && *p == 0) {
  60. p++;
  61. }
  62. if (p < LocalBufferEnd) {
  63. //
  64. // print a string and consume it
  65. //
  66. dprintf("%s", p);
  67. while (p < LocalBufferEnd && *p != 0) {
  68. p++;
  69. }
  70. }
  71. } while (p < LocalBufferEnd);
  72. //
  73. // repeat until we hit the start
  74. //
  75. p = LocalBuffer;
  76. while (p < Start && *p == 0) {
  77. p++;
  78. }
  79. if (p < Start) {
  80. dprintf("%s", p);
  81. while (p < Start && *p != 0) {
  82. p++;
  83. }
  84. }
  85. exit:
  86. if (LocalBuffer) {
  87. LocalFree( LocalBuffer );
  88. }
  89. return S_OK;
  90. }