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.

170 lines
3.6 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. kdlog.c
  5. Abstract:
  6. This app dumps out the KD debugger log, which is produced
  7. by the KD hw ext (e.g. KD1394.DLL, KDCOM.DLL).
  8. Author:
  9. Neil Sandlin (neilsa) 31-Oct-2000
  10. Envirnoment:
  11. Revision History:
  12. --*/
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <kdlog.h>
  18. #include <kdlogctl.h>
  19. VOID
  20. DumpLogData(
  21. PKD_DBG_LOG_CONTEXT LogContext,
  22. PUCHAR pData
  23. );
  24. __cdecl
  25. main(
  26. int argc,
  27. char *argv[],
  28. char *envp[]
  29. )
  30. {
  31. HANDLE DriverHandle;
  32. UNICODE_STRING DriverName;
  33. NTSTATUS status;
  34. OBJECT_ATTRIBUTES ObjA;
  35. IO_STATUS_BLOCK IOSB;
  36. KD_DBG_LOG_CONTEXT LogContext;
  37. PUCHAR pData;
  38. ULONG DataLength;
  39. //
  40. // Open PStat driver
  41. //
  42. RtlInitUnicodeString(&DriverName, L"\\Device\\KDLog");
  43. InitializeObjectAttributes(
  44. &ObjA,
  45. &DriverName,
  46. OBJ_CASE_INSENSITIVE,
  47. 0,
  48. 0 );
  49. status = NtOpenFile (
  50. &DriverHandle, // return handle
  51. SYNCHRONIZE | FILE_READ_DATA, // desired access
  52. &ObjA, // Object
  53. &IOSB, // io status block
  54. FILE_SHARE_READ | FILE_SHARE_WRITE, // share access
  55. FILE_SYNCHRONOUS_IO_ALERT // open options
  56. );
  57. if (!NT_SUCCESS(status)) {
  58. printf("Error: KDLOG.SYS not running\n");
  59. return ;
  60. }
  61. //
  62. // Get the log context
  63. //
  64. status = NtDeviceIoControlFile(
  65. DriverHandle,
  66. (HANDLE) NULL,
  67. (PIO_APC_ROUTINE) NULL,
  68. (PVOID) NULL,
  69. &IOSB,
  70. KDLOG_QUERY_LOG_CONTEXT,
  71. &LogContext,
  72. sizeof (LogContext),
  73. NULL,
  74. 0
  75. );
  76. if (!NT_SUCCESS(status)) {
  77. printf("Error %08x retrieving Log Context\n", status);
  78. NtClose (DriverHandle);
  79. return ;
  80. }
  81. printf("EntryLength %08x, LastIndex %08x\n", LogContext.EntryLength, LogContext.LastIndex);
  82. printf("Count %08x, Index %08x\n\n", LogContext.Count, LogContext.Index);
  83. DataLength = LogContext.EntryLength * (LogContext.LastIndex + 1);
  84. pData = malloc(DataLength);
  85. if (pData == NULL) {
  86. printf("Unable to allocate %08x bytes for data\n", DataLength);
  87. } else {
  88. //
  89. // Get the log data
  90. //
  91. status = NtDeviceIoControlFile(
  92. DriverHandle,
  93. (HANDLE) NULL,
  94. (PIO_APC_ROUTINE) NULL,
  95. (PVOID) NULL,
  96. &IOSB,
  97. KDLOG_GET_LOG_DATA,
  98. pData,
  99. DataLength,
  100. NULL,
  101. 0
  102. );
  103. if (!NT_SUCCESS(status)) {
  104. printf("Error %08x retrieving Log Context\n", status);
  105. } else {
  106. DumpLogData(&LogContext, pData);
  107. }
  108. free(pData);
  109. }
  110. NtClose (DriverHandle);
  111. return;
  112. }
  113. VOID
  114. DumpLogData(
  115. PKD_DBG_LOG_CONTEXT LogContext,
  116. PUCHAR pData
  117. )
  118. {
  119. ULONG Count = LogContext->Count;
  120. ULONG Index = LogContext->Index;
  121. while(Count--) {
  122. if (Index == 0) {
  123. Index = LogContext->LastIndex+1;
  124. }
  125. Index--;
  126. printf("%s", &pData[Index*LogContext->EntryLength]);
  127. }
  128. }