Dump memory dialog

This commit is contained in:
Kingcom 2013-10-01 21:11:41 +02:00
parent 11f8203cc4
commit 1d0ff8809b
7 changed files with 305 additions and 13 deletions

View File

@ -16,6 +16,7 @@
#include "Debugger_Disasm.h"
#include "DebuggerShared.h"
#include "CtrlMemView.h"
#include "DumpMemoryWindow.h"
wchar_t CtrlMemView::szClassName[] = L"CtrlMemView";
extern HMENU g_hPopupMenus;
@ -421,7 +422,6 @@ void CtrlMemView::onMouseUp(WPARAM wParam, LPARAM lParam, int button)
//popup menu?
POINT pt;
GetCursorPos(&pt);
FILE* outputfile;
switch (TrackPopupMenuEx(GetSubMenu(g_hPopupMenus,0),TPM_RIGHTBUTTON|TPM_RETURNCMD,pt.x,pt.y,wnd,0))
{
case ID_MEMVIEW_DUMP:
@ -433,16 +433,8 @@ void CtrlMemView::onMouseUp(WPARAM wParam, LPARAM lParam, int button)
}
else
{
outputfile = fopen("Ram.dump", "wb"); // Could also dump Vram, but not useful for now.
if (outputfile != NULL)
{
fwrite(Memory::GetPointer(0x08800000), 1, 0x01800000, outputfile);
fclose(outputfile);
}
else //file could not be opened as "wb"
{
MessageBox(wnd, L"Ram.dump could not be opened with write privileges", 0, 0);
}
DumpMemoryWindow dump(wnd,debugger);
dump.exec();
break;
}

View File

@ -0,0 +1,230 @@
#include "DumpMemoryWindow.h"
#include "../resource.h"
#include <stdio.h>
#include "Core/MemMap.h"
#include "Windows/W32Util/ShellUtil.h"
DumpMemoryWindow* DumpMemoryWindow::bp;
INT_PTR CALLBACK DumpMemoryWindow::dlgFunc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
switch (iMsg)
{
case WM_INITDIALOG:
bp->changeMode(hwnd,bp->selectedMode);
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_DUMP_USERMEMORY:
switch (HIWORD(wParam))
{
case BN_CLICKED:
bp->changeMode(hwnd,MODE_RAM);
break;
}
break;
case IDC_DUMP_VRAM:
switch (HIWORD(wParam))
{
case BN_CLICKED:
bp->changeMode(hwnd,MODE_VRAM);
break;
}
break;
case IDC_DUMP_SCRATCHPAD:
switch (HIWORD(wParam))
{
case BN_CLICKED:
bp->changeMode(hwnd,MODE_SCRATCHPAD);
break;
}
break;
case IDC_DUMP_CUSTOMRANGE:
switch (HIWORD(wParam))
{
case BN_CLICKED:
bp->changeMode(hwnd,MODE_CUSTOM);
break;
}
break;
case IDC_DUMP_BROWSEFILENAME:
switch (HIWORD(wParam))
{
case BN_CLICKED:
char str[MAX_PATH];
GetWindowTextA(GetDlgItem(hwnd,IDC_DUMP_FILENAME),str,MAX_PATH);
std::string fn = str;
bool result = W32Util::BrowseForFileName(false, hwnd, L"Select filename", NULL,NULL,NULL,fn);
if (result)
{
bp->filenameChosen = true;
SetWindowTextA(GetDlgItem(hwnd,IDC_DUMP_FILENAME),fn.c_str());
}
break;
}
break;
case IDOK:
if (bp->fetchDialogData(hwnd))
{
FILE* output = fopen(bp->fileName,"wb");
if (output == NULL)
{
char errorMessage[256];
sprintf(errorMessage,"Could not open file \"%s\".",bp->fileName);
MessageBoxA(hwnd,errorMessage,"Error",MB_OK);
break;
}
fwrite(Memory::GetPointer(bp->start), 1, bp->size, output);
fclose(output);
MessageBoxA(hwnd,"Done.","Error",MB_OK);
EndDialog(hwnd,true);
}
break;
case IDCANCEL:
EndDialog(hwnd,false);
break;
}
case WM_KEYDOWN:
break;
}
return FALSE;
}
bool isInInterval(u32 start, u32 end, u32 value)
{
return start <= value && value < end;
}
bool DumpMemoryWindow::fetchDialogData(HWND hwnd)
{
char str[256],errorMessage[256];
PostfixExpression exp;
// parse start address
GetWindowTextA(GetDlgItem(hwnd,IDC_DUMP_STARTADDRESS),str,256);
if (cpu->initExpression(str,exp) == false
|| cpu->parseExpression(exp,start) == false)
{
sprintf(errorMessage,"Invalid address expression \"%s\".",str);
MessageBoxA(hwnd,errorMessage,"Error",MB_OK);
return false;
}
// parse size
GetWindowTextA(GetDlgItem(hwnd,IDC_DUMP_SIZE),str,256);
if (cpu->initExpression(str,exp) == false
|| cpu->parseExpression(exp,size) == false)
{
sprintf(errorMessage,"Invalid size expression \"%s\".",str);
MessageBoxA(hwnd,errorMessage,"Error",MB_OK);
return false;
}
if (size == 0)
{
MessageBoxA(hwnd,"Invalid size 0.","Error",MB_OK);
return false;
}
// get filename
GetWindowTextA(GetDlgItem(hwnd,IDC_DUMP_FILENAME),fileName,MAX_PATH);
if (strlen(fileName) == 0) return false;
// now check if data makes sense...
bool invalidSize = false;
bool invalidAddress = false;
if (isInInterval(PSP_GetScratchpadMemoryBase(),PSP_GetScratchpadMemoryEnd(),start))
{
invalidSize = !isInInterval(PSP_GetScratchpadMemoryBase(),PSP_GetScratchpadMemoryEnd(),start+size-1);
} else if (isInInterval(PSP_GetVidMemBase(),PSP_GetVidMemEnd(),start))
{
invalidSize = !isInInterval(PSP_GetVidMemBase(),PSP_GetVidMemEnd(),start+size-1);
} else if (isInInterval(PSP_GetKernelMemoryBase(),PSP_GetUserMemoryEnd(),start))
{
invalidSize = !isInInterval(PSP_GetKernelMemoryBase(),PSP_GetUserMemoryEnd(),start+size-1);
} else
{
invalidAddress = true;
}
if (invalidAddress)
{
sprintf(errorMessage,"Invalid address 0x%08X.",start);
MessageBoxA(hwnd,errorMessage,"Error",MB_OK);
return false;
} else if (invalidSize)
{
sprintf(errorMessage,"Invalid end address 0x%08X.",start+size);
MessageBoxA(hwnd,errorMessage,"Error",MB_OK);
return false;
}
return true;
}
void DumpMemoryWindow::changeMode(HWND hwnd, Mode newMode)
{
char buffer[128];
selectedMode = newMode;
SendMessage(GetDlgItem(hwnd,IDC_DUMP_USERMEMORY),BM_SETCHECK,selectedMode == MODE_RAM ? BST_CHECKED : BST_UNCHECKED,0);
SendMessage(GetDlgItem(hwnd,IDC_DUMP_VRAM),BM_SETCHECK,selectedMode == MODE_VRAM ? BST_CHECKED : BST_UNCHECKED,0);
SendMessage(GetDlgItem(hwnd,IDC_DUMP_SCRATCHPAD),BM_SETCHECK,selectedMode == MODE_SCRATCHPAD ? BST_CHECKED : BST_UNCHECKED,0);
SendMessage(GetDlgItem(hwnd,IDC_DUMP_CUSTOMRANGE),BM_SETCHECK,selectedMode == MODE_CUSTOM ? BST_CHECKED : BST_UNCHECKED,0);
if (selectedMode == MODE_CUSTOM)
{
EnableWindow(GetDlgItem(hwnd,IDC_DUMP_STARTADDRESS),TRUE);
EnableWindow(GetDlgItem(hwnd,IDC_DUMP_SIZE),TRUE);
if (filenameChosen == false)
SetWindowTextA(GetDlgItem(hwnd,IDC_DUMP_FILENAME),"Custom.dump");
} else {
u32 start, size;
const char* defaultFileName;
switch (selectedMode)
{
case MODE_RAM:
start = PSP_GetUserMemoryBase();
size = PSP_GetUserMemoryEnd()-start;
defaultFileName = "RAM.dump";
break;
case MODE_VRAM:
start = PSP_GetVidMemBase();
size = PSP_GetVidMemEnd()-start;
defaultFileName = "VRAM.dump";
break;
case MODE_SCRATCHPAD:
start = PSP_GetScratchpadMemoryBase();
size = PSP_GetScratchpadMemoryEnd()-start;
defaultFileName = "Scratchpad.dump";
break;
}
sprintf(buffer,"0x%08X",start);
SetWindowTextA(GetDlgItem(hwnd,IDC_DUMP_STARTADDRESS),buffer);
EnableWindow(GetDlgItem(hwnd,IDC_DUMP_STARTADDRESS),FALSE);
sprintf(buffer,"0x%08X",size);
SetWindowTextA(GetDlgItem(hwnd,IDC_DUMP_SIZE),buffer);
EnableWindow(GetDlgItem(hwnd,IDC_DUMP_SIZE),FALSE);
if (filenameChosen == false)
SetWindowTextA(GetDlgItem(hwnd,IDC_DUMP_FILENAME),defaultFileName);
}
}
bool DumpMemoryWindow::exec()
{
bp = this;
bool result = DialogBoxParam(GetModuleHandle(0),MAKEINTRESOURCE(IDD_DUMPMEMORY),parentHwnd,dlgFunc,(LPARAM)this) != 0;
return result;
}

View File

@ -0,0 +1,32 @@
#pragma once
#include "Common/CommonWindows.h"
#include "Common/CommonTypes.h"
#include "Core/Debugger/DebugInterface.h"
class DumpMemoryWindow
{
enum Mode { MODE_RAM, MODE_VRAM, MODE_SCRATCHPAD, MODE_CUSTOM };
HWND parentHwnd;
DebugInterface* cpu;
bool filenameChosen;
Mode selectedMode;
u32 start;
u32 size;
char fileName[MAX_PATH];
static DumpMemoryWindow* bp;
void changeMode(HWND hwnd, Mode newMode);
bool fetchDialogData(HWND hwnd);
public:
DumpMemoryWindow(HWND parent, DebugInterface* cpu): cpu(cpu)
{
parentHwnd = parent;
filenameChosen = false;
selectedMode = MODE_RAM;
};
static INT_PTR CALLBACK dlgFunc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
bool exec();
};

View File

@ -279,6 +279,7 @@
<ClCompile Include="Debugger\Debugger_Lists.cpp" />
<ClCompile Include="Debugger\Debugger_MemoryDlg.cpp" />
<ClCompile Include="Debugger\Debugger_VFPUDlg.cpp" />
<ClCompile Include="Debugger\DumpMemoryWindow.cpp" />
<ClCompile Include="GEDebugger\CtrlDisplayListView.cpp" />
<ClCompile Include="GEDebugger\GEDebugger.cpp" />
<ClCompile Include="DinputDevice.cpp" />
@ -326,6 +327,7 @@
<ClInclude Include="Debugger\Debugger_Lists.h" />
<ClInclude Include="Debugger\Debugger_MemoryDlg.h" />
<ClInclude Include="Debugger\Debugger_VFPUDlg.h" />
<ClInclude Include="Debugger\DumpMemoryWindow.h" />
<ClInclude Include="GEDebugger\CtrlDisplayListView.h" />
<ClInclude Include="GEDebugger\GEDebugger.h" />
<ClInclude Include="DinputDevice.h" />

View File

@ -131,6 +131,9 @@
<ClCompile Include="GEDebugger\TabState.cpp">
<Filter>Windows\GE Debugger</Filter>
</ClCompile>
<ClCompile Include="Debugger\DumpMemoryWindow.cpp">
<Filter>Windows\Debugger</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Debugger\CtrlDisAsmView.h">
@ -236,6 +239,9 @@
<ClInclude Include="GEDebugger\TabState.h">
<Filter>Windows\GE Debugger</Filter>
</ClInclude>
<ClInclude Include="Debugger\DumpMemoryWindow.h">
<Filter>Windows\Debugger</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="icon1.ico">

View File

@ -261,6 +261,27 @@ BEGIN
PUSHBUTTON "Cancel",IDC_BREAKPOINT_CANCEL,186,68,42,14
END
IDD_DUMPMEMORY DIALOGEX 0, 0, 230, 85
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dump memory"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
LTEXT "Start",IDC_STATIC,7,8,27,8
EDITTEXT IDC_DUMP_STARTADDRESS,41,7,95,14,ES_AUTOHSCROLL
LTEXT "Size",IDC_STATIC,7,27,14,8
EDITTEXT IDC_DUMP_SIZE,41,25,95,14,ES_AUTOHSCROLL
LTEXT "Filename",IDC_STATIC,7,46,32,8
EDITTEXT IDC_DUMP_FILENAME,41,43,75,14,ES_AUTOHSCROLL
PUSHBUTTON "...",IDC_DUMP_BROWSEFILENAME,119,43,17,14
GROUPBOX "Location",IDC_STATIC,145,1,76,57
CONTROL "RAM",IDC_DUMP_USERMEMORY,"Button",BS_AUTORADIOBUTTON,152,10,31,10
CONTROL "VRAM",IDC_DUMP_VRAM,"Button",BS_AUTORADIOBUTTON,152,22,35,10
CONTROL "Scratchpad",IDC_DUMP_SCRATCHPAD,"Button",BS_AUTORADIOBUTTON,152,34,52,10
CONTROL "Custom range",IDC_DUMP_CUSTOMRANGE,"Button",BS_AUTORADIOBUTTON,152,46,61,10
DEFPUSHBUTTON "OK",IDOK,117,64,50,14
PUSHBUTTON "Cancel",IDCANCEL,173,64,50,14
END
/////////////////////////////////////////////////////////////////////////////
//

View File

@ -79,6 +79,7 @@
#define IDD_GEDEBUGGER 250
#define IDD_TABDISPLAYLISTS 251
#define IDD_GEDBG_TAB_VALUES 252
#define IDD_DUMPMEMORY 253
#define IDC_STOPGO 1001
#define IDC_ADDRESS 1002
@ -146,6 +147,14 @@
#define IDC_DISASMSTATUSBAR 1180
#define IDC_STACKFRAMES 1181
#define IDC_GEDBG_VALUES 1182
#define IDC_DUMP_USERMEMORY 1183
#define IDC_DUMP_VRAM 1184
#define IDC_DUMP_SCRATCHPAD 1185
#define IDC_DUMP_CUSTOMRANGE 1186
#define IDC_DUMP_STARTADDRESS 1187
#define IDC_DUMP_SIZE 1188
#define IDC_DUMP_FILENAME 1189
#define IDC_DUMP_BROWSEFILENAME 1190
// Don't define anything else in the 3000 range.
// It's reserved for languages.
@ -286,9 +295,9 @@
// Next default values for new objects
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 253
#define _APS_NEXT_RESOURCE_VALUE 254
#define _APS_NEXT_COMMAND_VALUE 40130
#define _APS_NEXT_CONTROL_VALUE 1183
#define _APS_NEXT_CONTROL_VALUE 1191
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif