Add a memory dump facility.

svn path=/trunk/; revision=63342
This commit is contained in:
Hermès Bélusca-Maïto 2014-05-17 23:49:35 +00:00
parent 7c2c3d6d1f
commit ad69b4a3c0
11 changed files with 110 additions and 10 deletions

View file

@ -337,6 +337,87 @@ static VOID WINAPI PitChan2Out(LPVOID Param, BOOLEAN State)
/* PUBLIC FUNCTIONS ***********************************************************/ /* PUBLIC FUNCTIONS ***********************************************************/
VOID DumpMemory(VOID)
{
static ULONG DumpNumber = 0;
HANDLE hFile;
WCHAR FileName[MAX_PATH];
#define LINE_SIZE 75 + 2
ULONG i;
PBYTE Ptr1, Ptr2;
CHAR LineBuffer[LINE_SIZE];
PCHAR Line;
SIZE_T LineSize;
/* Build a suitable file name */
_snwprintf(FileName, MAX_PATH, L"memdump%lu.txt", DumpNumber);
++DumpNumber;
/* Always create the dump file */
hFile = CreateFileW(FileName,
GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
DPRINT1("Error when creating '%S' for memory dumping, GetLastError() = %u\n",
FileName, GetLastError());
return;
}
/* Dump the VM memory */
SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
Ptr1 = Ptr2 = REAL_TO_PHYS(NULL);
while (MAX_ADDRESS - (ULONG_PTR)PHYS_TO_REAL(Ptr1) > 0)
{
Ptr1 = Ptr2;
Line = LineBuffer;
/* Print the address */
Line += snprintf(Line, LINE_SIZE + LineBuffer - Line, "%08x ", PHYS_TO_REAL(Ptr1));
/* Print up to 16 bytes... */
/* ... in hexadecimal form first... */
i = 0;
while (i++ <= 0x0F && (MAX_ADDRESS - (ULONG_PTR)PHYS_TO_REAL(Ptr1) > 0))
{
Line += snprintf(Line, LINE_SIZE + LineBuffer - Line, " %02x", *Ptr1);
++Ptr1;
}
/* ... align with spaces if needed... */
RtlFillMemory(Line, 0x0F + 4 - i, ' ');
Line += 0x0F + 4 - i;
/* ... then in character form. */
i = 0;
while (i++ <= 0x0F && (MAX_ADDRESS - (ULONG_PTR)PHYS_TO_REAL(Ptr2) > 0))
{
Line += snprintf(Line, LINE_SIZE + LineBuffer - Line, "%c",
(*Ptr2 >= 0x20 && *Ptr2 <= 0x7E) || (*Ptr2 >= 0x80 && *Ptr2 < 0xFF) ? *Ptr2 : '.');
++Ptr2;
}
/* Newline */
*Line++ = '\r';
*Line++ = '\n';
/* Finally write the line to the file */
LineSize = Line - LineBuffer;
WriteFile(hFile, LineBuffer, LineSize, &LineSize, NULL);
}
/* Close the file */
CloseHandle(hFile);
}
DWORD WINAPI PumpConsoleInput(LPVOID Parameter); DWORD WINAPI PumpConsoleInput(LPVOID Parameter);
BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput) BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput)

View file

@ -98,6 +98,8 @@ extern BOOLEAN VdmRunning;
/* FUNCTIONS ******************************************************************/ /* FUNCTIONS ******************************************************************/
VOID DumpMemory(VOID);
VOID WINAPI EmulatorReadMemory VOID WINAPI EmulatorReadMemory
( (
PFAST486_STATE State, PFAST486_STATE State,

View file

@ -15,5 +15,6 @@ END
STRINGTABLE STRINGTABLE
BEGIN BEGIN
IDS_VDM_QUIT, "&Ukončit ReactOS VDM" IDS_VDM_DUMPMEM, "Dump &Memory"
IDS_VDM_QUIT , "&Ukončit ReactOS VDM"
END END

View file

@ -9,5 +9,6 @@ END
STRINGTABLE STRINGTABLE
BEGIN BEGIN
IDS_VDM_QUIT, "ReactOS VDM b&eenden" IDS_VDM_DUMPMEM, "Dump &Memory"
IDS_VDM_QUIT , "ReactOS VDM b&eenden"
END END

View file

@ -9,5 +9,6 @@ END
STRINGTABLE STRINGTABLE
BEGIN BEGIN
IDS_VDM_QUIT, "&Quit the ReactOS VDM" IDS_VDM_DUMPMEM, "Dump &Memory"
IDS_VDM_QUIT , "&Quit the ReactOS VDM"
END END

View file

@ -9,5 +9,6 @@ END
STRINGTABLE STRINGTABLE
BEGIN BEGIN
IDS_VDM_QUIT, "&Salir de ReactOS VDM" IDS_VDM_DUMPMEM, "Dump &Memory"
IDS_VDM_QUIT , "&Salir de ReactOS VDM"
END END

View file

@ -9,5 +9,6 @@ END
STRINGTABLE STRINGTABLE
BEGIN BEGIN
IDS_VDM_QUIT, "&Quitter la ReactOS VDM" IDS_VDM_DUMPMEM, "Vidage &Mémoire"
IDS_VDM_QUIT , "&Quitter la ReactOS VDM"
END END

View file

@ -9,5 +9,6 @@ END
STRINGTABLE STRINGTABLE
BEGIN BEGIN
IDS_VDM_QUIT, "&Esci da ReactOS VDM" IDS_VDM_DUMPMEM, "Dump &Memory"
IDS_VDM_QUIT , "&Esci da ReactOS VDM"
END END

View file

@ -11,5 +11,6 @@ END
STRINGTABLE STRINGTABLE
BEGIN BEGIN
IDS_VDM_QUIT, "&Wyjdź z ReactOS VDM" IDS_VDM_DUMPMEM, "Dump &Memory"
IDS_VDM_QUIT , "&Wyjdź z ReactOS VDM"
END END

View file

@ -51,7 +51,8 @@ typedef struct _VDM_MENUITEM
static const VDM_MENUITEM VdmMenuItems[] = static const VDM_MENUITEM VdmMenuItems[] =
{ {
{ IDS_VDM_QUIT, NULL, ID_VDM_QUIT }, { IDS_VDM_DUMPMEM, NULL, ID_VDM_DUMPMEM },
{ IDS_VDM_QUIT , NULL, ID_VDM_QUIT },
{ 0, NULL, 0 } /* End of list */ { 0, NULL, 0 } /* End of list */
}; };
@ -368,6 +369,10 @@ PumpConsoleInput(LPVOID Parameter)
ShowPointer = !ShowPointer; ShowPointer = !ShowPointer;
break; break;
case ID_VDM_DUMPMEM:
DumpMemory();
break;
case ID_VDM_QUIT: case ID_VDM_QUIT:
/* Stop the VDM */ /* Stop the VDM */
EmulatorTerminate(); EmulatorTerminate();

View file

@ -1,14 +1,19 @@
#pragma once #pragma once
/* Menu IDs */
#define ID_SHOWHIDE_MOUSE 1000 #define ID_SHOWHIDE_MOUSE 1000
#define ID_VDM_QUIT 1001 #define ID_VDM_DUMPMEM 1001
#define ID_VDM_QUIT 1002
/* String IDs */
#define IDS_HIDE_MOUSE 100 #define IDS_HIDE_MOUSE 100
#define IDS_SHOW_MOUSE 101 #define IDS_SHOW_MOUSE 101
#define IDS_VDM_MENU 102 #define IDS_VDM_MENU 102
#define IDS_VDM_QUIT 200 #define IDS_VDM_DUMPMEM 200
#define IDS_VDM_QUIT 201
/* Icon */
#define IDI_APPICON 1 #define IDI_APPICON 1
/* EOF */ /* EOF */