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.

179 lines
3.6 KiB

  1. /*
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. kdexts.c
  5. Abstract:
  6. This function contains some example KD debugger extensions
  7. Author:
  8. John Vert (jvert) 6-Aug-1992
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. typedef BOOLEAN
  13. (*PRINT_FUNC) (
  14. IN PROW Row
  15. );
  16. HANDLE FileHandle;
  17. PRINT_FUNC Print;
  18. DWORD
  19. MyOpenFile (
  20. IN PCHAR Name,
  21. IN PWINDBG_OUTPUT_ROUTINE out,
  22. OUT HANDLE *File
  23. )
  24. {
  25. HANDLE hFile;
  26. hFile = CreateFile(Name,
  27. GENERIC_WRITE | GENERIC_READ,
  28. 0,
  29. NULL,
  30. CREATE_ALWAYS ,
  31. FILE_ATTRIBUTE_NORMAL,
  32. NULL);
  33. if (INVALID_HANDLE_VALUE == hFile) {
  34. out ("MyOpenFile: CreateFile Failed.\n");
  35. }
  36. *File = hFile;
  37. return(INVALID_HANDLE_VALUE == hFile ? (!(ERROR_SUCCESS)) : ERROR_SUCCESS);
  38. }
  39. BOOLEAN MyWriteFile(PROW lRow)
  40. {
  41. LONG len;
  42. BOOL bRv;
  43. DWORD dwWritten;
  44. CHAR buffer[1024];
  45. dprintf(".");
  46. wsprintf(buffer, "[%4d] 0x%x:0x%x:0x%x:0x%x: %s\n", lRow->Line, lRow->P1, lRow->P2, lRow->P3, lRow->P4, lRow->Row);
  47. len = strlen(buffer);
  48. bRv = WriteFile( FileHandle, buffer, len, &dwWritten, NULL );
  49. if (!bRv) {
  50. dprintf("WriteFile: Puked\n");
  51. }
  52. return bRv ? TRUE :FALSE;
  53. }
  54. BOOLEAN MyWriteConsole(PROW lRow)
  55. {
  56. dprintf("[%4d] 0x%x:0x%x:0x%x:0x%x: %s\n", lRow->Line, lRow->P1, lRow->P2, lRow->P3, lRow->P4, lRow->Row);
  57. return TRUE;
  58. }
  59. DECLARE_API( tt )
  60. {
  61. UINT i, max, total = 0;
  62. DWORD hostAddress;
  63. LOG LLog;
  64. ULONG status, success;
  65. ULONG bytesread;
  66. CHAR DeviceName[] = "c:\\tmp\\";
  67. CHAR buffer[255];
  68. char LogBase[] = {"&msgpc!Log"};
  69. hostAddress = GetExpression(LogBase);
  70. if ( *args != '\0' ) {
  71. strcpy( buffer, DeviceName );
  72. strcat( buffer, args );
  73. status = MyOpenFile( buffer, dprintf, &FileHandle );
  74. if ( status == ERROR_SUCCESS ) {
  75. Print = MyWriteFile;
  76. max = LOGSIZE;
  77. }
  78. else {
  79. goto cleanup;
  80. }
  81. dprintf( "handle =%x status=%x \n", FileHandle, status);
  82. }
  83. else {
  84. Print = MyWriteConsole;
  85. max = 100;
  86. }
  87. if (!hostAddress){
  88. dprintf("bad string conversion (%s) \n", LogBase);
  89. goto cleanup;
  90. }
  91. success = ReadMemory((ULONG)hostAddress, &LLog, sizeof(LOG), &bytesread );
  92. if (!success){
  93. dprintf("problems reading memory at %x for %x bytes\n", hostAddress, sizeof(LOG));
  94. goto cleanup;
  95. }
  96. dprintf( "TT Log dumping %d entries\n", max);
  97. for(i = LLog.Index; (i < LOGSIZE) && (total < max); i++, total++)
  98. {
  99. PROW pRow;
  100. ROW lRow;
  101. pRow = &LLog.Buffer[i];
  102. success = ReadMemory((ULONG)pRow, &lRow, sizeof(ROW), &bytesread);
  103. if(!success) {
  104. dprintf("problems reading memory at %x for %x bytes\n", pRow, sizeof(LOG));
  105. goto cleanup;
  106. }
  107. (*Print)(&lRow);
  108. }
  109. if (total < max) {
  110. dprintf( "TT Log dumping the rest (%d) from the top....\n", LLog.Index);
  111. }
  112. for(i = 0; (i < LLog.Index) && (total < max); i++, total++)
  113. {
  114. PROW pRow;
  115. ROW lRow;
  116. pRow = &LLog.Buffer[i];
  117. success = ReadMemory((ULONG)pRow, &lRow, sizeof(ROW), &bytesread);
  118. if(!success) {
  119. dprintf("problems reading memory at %x for %x bytes\n", pRow, sizeof(LOG));
  120. goto cleanup;
  121. }
  122. (*Print)(&lRow);
  123. }
  124. cleanup:
  125. if ( *args != '\0' ) {
  126. CloseHandle(FileHandle);
  127. }
  128. return;
  129. }