2016-01-27 09:11:59 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* *
|
|
|
|
* Project64 - A Nintendo 64 emulator. *
|
|
|
|
* http://www.pj64-emu.com/ *
|
|
|
|
* Copyright (C) 2012 Project64. All rights reserved. *
|
|
|
|
* *
|
|
|
|
* License: *
|
|
|
|
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
|
|
|
#include "stdafx.h"
|
2018-01-21 01:51:36 +00:00
|
|
|
#include <Project64-core/ExceptionHandler.h>
|
|
|
|
#include <Common/MemoryManagement.h>
|
2016-01-27 09:11:59 +00:00
|
|
|
|
|
|
|
#include "DebuggerUI.h"
|
2017-08-18 05:08:22 +00:00
|
|
|
#include "Symbols.h"
|
|
|
|
#include "DMALog.h"
|
2016-01-27 09:11:59 +00:00
|
|
|
|
2017-08-30 06:15:28 +00:00
|
|
|
CDebugMemoryView* CDebugMemoryView::_this = NULL;
|
|
|
|
HHOOK CDebugMemoryView::hWinMessageHook = NULL;
|
|
|
|
|
2016-01-27 09:11:59 +00:00
|
|
|
CDebugMemoryView::CDebugMemoryView(CDebuggerUI * debugger) :
|
2017-09-13 12:00:53 +00:00
|
|
|
CDebugDialog<CDebugMemoryView>(debugger),
|
|
|
|
m_MemoryList(NULL)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
if (m_MemoryList == NULL)
|
|
|
|
{
|
|
|
|
m_MemoryList = new CListCtrl;
|
|
|
|
m_MemoryList->RegisterClass();
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
m_Breakpoints = m_Debugger->Breakpoints();
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CDebugMemoryView::~CDebugMemoryView()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CDebugMemoryView::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
m_SymbolColorStride = 0;
|
|
|
|
m_SymbolColorPhase = 0;
|
2016-01-27 09:11:59 +00:00
|
|
|
m_DataStartLoc = (DWORD)-1;
|
|
|
|
m_CompareStartLoc = (DWORD)-1;
|
|
|
|
memset(m_CompareData, 0, sizeof(m_CompareData));
|
|
|
|
memset(m_CompareValid, 0, sizeof(m_CompareValid));
|
|
|
|
|
|
|
|
HWND hScrlBar = GetDlgItem(IDC_SCRL_BAR);
|
|
|
|
if (hScrlBar)
|
|
|
|
{
|
|
|
|
SCROLLINFO si;
|
|
|
|
|
|
|
|
si.cbSize = sizeof(si);
|
|
|
|
si.fMask = SIF_RANGE | SIF_POS | SIF_PAGE;
|
|
|
|
si.nMin = 0;
|
|
|
|
si.nMax = 0xFFFF;
|
|
|
|
si.nPos = 0x8000;
|
|
|
|
si.nPage = 100;
|
|
|
|
::SetScrollInfo(hScrlBar, SB_CTL, &si, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_MemAddr.Attach(GetDlgItem(IDC_ADDR_EDIT));
|
2017-11-21 20:37:45 +00:00
|
|
|
m_MemAddr.SetDisplayType(CEditNumber32::DisplayHex);
|
2017-08-18 05:08:22 +00:00
|
|
|
m_MemAddr.SetValue(0x80000000, false, true);
|
2016-01-27 09:11:59 +00:00
|
|
|
|
|
|
|
SendDlgItemMessage(IDC_CHK_VADDR, BM_SETCHECK, BST_CHECKED, 0);
|
|
|
|
|
|
|
|
if (m_MemoryList == NULL)
|
|
|
|
{
|
|
|
|
m_MemoryList = new CListCtrl;
|
|
|
|
m_MemoryList->RegisterClass();
|
|
|
|
}
|
|
|
|
m_MemoryList->SubclassWindow(GetDlgItem(IDC_MEM_DETAILS));
|
|
|
|
m_MemoryList->ShowHeader(false);
|
|
|
|
m_MemoryList->SetSortEnabled(FALSE);
|
|
|
|
m_MemoryList->AddColumn(_T("Address"), 90);
|
|
|
|
m_MemoryList->AddColumn(_T("1"), 20);
|
|
|
|
m_MemoryList->AddColumn(_T("2"), 20);
|
|
|
|
m_MemoryList->AddColumn(_T("3"), 20);
|
|
|
|
m_MemoryList->AddColumn(_T("4"), 20);
|
|
|
|
m_MemoryList->AddColumn(_T("-"), 10);
|
|
|
|
m_MemoryList->AddColumn(_T("5"), 20);
|
|
|
|
m_MemoryList->AddColumn(_T("6"), 20);
|
|
|
|
m_MemoryList->AddColumn(_T("7"), 20);
|
|
|
|
m_MemoryList->AddColumn(_T("8"), 20);
|
|
|
|
m_MemoryList->AddColumn(_T("-"), 10);
|
|
|
|
m_MemoryList->AddColumn(_T("9"), 20);
|
|
|
|
m_MemoryList->AddColumn(_T("10"), 20);
|
|
|
|
m_MemoryList->AddColumn(_T("11"), 20);
|
|
|
|
m_MemoryList->AddColumn(_T("12"), 20);
|
|
|
|
m_MemoryList->AddColumn(_T("-"), 10);
|
|
|
|
m_MemoryList->AddColumn(_T("13"), 20);
|
|
|
|
m_MemoryList->AddColumn(_T("14"), 20);
|
|
|
|
m_MemoryList->AddColumn(_T("15"), 20);
|
|
|
|
m_MemoryList->AddColumn(_T("16"), 35);
|
|
|
|
m_MemoryList->AddColumn(_T("Memory Ascii"), 140);
|
|
|
|
::SetWindowLongPtr(m_MemoryList->m_hWnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE);
|
|
|
|
RefreshMemory(false);
|
|
|
|
int height = m_MemoryList->GetTotalHeight();
|
|
|
|
|
|
|
|
RECT MemoryListRect = { 0 };
|
|
|
|
::GetClientRect(GetDlgItem(IDC_MEM_DETAILS), &MemoryListRect);
|
|
|
|
|
|
|
|
if (height > MemoryListRect.bottom)
|
|
|
|
{
|
|
|
|
RECT MemoryListWindow = { 0 };
|
|
|
|
GetWindowRect(&MemoryListWindow);
|
|
|
|
SetWindowPos(NULL, 0, 0, MemoryListWindow.right - MemoryListWindow.left, (MemoryListWindow.bottom - MemoryListWindow.top) + (height - MemoryListRect.bottom), SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOZORDER);
|
|
|
|
|
|
|
|
RECT DlgItemRect = { 0 };
|
|
|
|
|
|
|
|
::GetWindowRect(GetDlgItem(IDC_MEM_DETAILS), &DlgItemRect);
|
|
|
|
::SetWindowPos(GetDlgItem(IDC_MEM_DETAILS), NULL, 0, 0, DlgItemRect.right - DlgItemRect.left, (DlgItemRect.bottom - DlgItemRect.top) + (height - MemoryListRect.bottom), SWP_NOMOVE);
|
|
|
|
|
|
|
|
::GetWindowRect(GetDlgItem(IDC_SCRL_BAR), &DlgItemRect);
|
|
|
|
::SetWindowPos(GetDlgItem(IDC_SCRL_BAR), NULL, 0, 0, DlgItemRect.right - DlgItemRect.left, (DlgItemRect.bottom - DlgItemRect.top) + (height - MemoryListRect.bottom), SWP_NOMOVE);
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
m_SymInfo.Attach(GetDlgItem(IDC_SYM_INFO));
|
|
|
|
m_DMAInfo.Attach(GetDlgItem(IDC_DMA_INFO));
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
_this = this;
|
2017-08-30 06:15:28 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
DWORD dwThreadID = ::GetCurrentThreadId();
|
|
|
|
hWinMessageHook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)HookProc, NULL, dwThreadID);
|
2017-08-30 06:15:28 +00:00
|
|
|
|
2016-01-27 09:11:59 +00:00
|
|
|
WindowCreated();
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
m_AutoRefreshThread = CreateThread(NULL, 0, AutoRefreshProc, (void*)this, 0, NULL);
|
|
|
|
|
2016-01-27 09:11:59 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
DWORD WINAPI CDebugMemoryView::AutoRefreshProc(void* _self)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
CDebugMemoryView* self = (CDebugMemoryView*)_self;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
self->RefreshMemory(true);
|
|
|
|
Sleep(100);
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
void CDebugMemoryView::InterceptMouseWheel(WPARAM wParam, LPARAM /*lParam*/)
|
2017-08-30 06:15:28 +00:00
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
uint32_t newAddress = m_DataStartLoc - ((short)HIWORD(wParam) / WHEEL_DELTA) * 16;
|
2017-08-30 06:15:28 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
m_DataStartLoc = newAddress;
|
2017-08-30 06:15:28 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
m_MemAddr.SetValue(m_DataStartLoc, false, true);
|
2017-08-30 06:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CALLBACK CDebugMemoryView::HookProc(int nCode, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
MSG *pMsg = (MSG*)lParam;
|
2017-08-30 06:15:28 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
if (pMsg->message == WM_MOUSEWHEEL)
|
|
|
|
{
|
|
|
|
_this->InterceptMouseWheel(pMsg->wParam, pMsg->lParam);
|
|
|
|
}
|
2017-08-30 06:15:28 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
if (nCode < 0)
|
|
|
|
{
|
|
|
|
return CallNextHookEx(hWinMessageHook, nCode, wParam, lParam);
|
|
|
|
}
|
2017-08-30 06:15:28 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
return 0;
|
2017-08-30 06:15:28 +00:00
|
|
|
}
|
|
|
|
|
2016-01-27 09:11:59 +00:00
|
|
|
LRESULT CDebugMemoryView::OnDestroy(void)
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (m_AutoRefreshThread != NULL)
|
|
|
|
{
|
|
|
|
TerminateThread(m_AutoRefreshThread, 0);
|
|
|
|
CloseHandle(m_AutoRefreshThread);
|
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
if (m_MemoryList)
|
|
|
|
{
|
|
|
|
m_MemoryList->UnsubclassWindow();
|
|
|
|
delete m_MemoryList;
|
|
|
|
m_MemoryList = NULL;
|
|
|
|
}
|
2017-09-13 12:00:53 +00:00
|
|
|
UnhookWindowsHookEx(hWinMessageHook);
|
2016-01-27 09:11:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CDebugMemoryView::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL& /*bHandled*/)
|
|
|
|
{
|
|
|
|
switch (wID)
|
|
|
|
{
|
|
|
|
case IDC_REFRSH_MEM:
|
|
|
|
RefreshMemory(true);
|
|
|
|
break;
|
|
|
|
case IDC_CHK_VADDR:
|
|
|
|
RefreshMemory(false);
|
|
|
|
break;
|
|
|
|
case IDC_DUMP_MEM:
|
2018-01-10 07:05:57 +00:00
|
|
|
m_Debugger->OpenMemoryDump();
|
2016-01-27 09:11:59 +00:00
|
|
|
break;
|
|
|
|
case IDC_SEARCH_MEM:
|
2018-01-10 07:05:57 +00:00
|
|
|
m_Debugger->OpenMemorySearch();
|
2016-01-27 09:11:59 +00:00
|
|
|
break;
|
2017-09-13 12:00:53 +00:00
|
|
|
case IDC_SYMBOLS_BTN:
|
2018-01-10 07:05:57 +00:00
|
|
|
m_Debugger->OpenSymbolsWindow();
|
2017-09-13 12:00:53 +00:00
|
|
|
break;
|
2016-01-27 09:11:59 +00:00
|
|
|
case IDCANCEL:
|
|
|
|
EndDialog(0);
|
|
|
|
break;
|
2017-09-13 12:00:53 +00:00
|
|
|
case ID_POPUPMENU_TOGGLERBP:
|
|
|
|
m_Breakpoints->RBPToggle(m_CtxMenuAddr);
|
|
|
|
RefreshMemory(true);
|
|
|
|
break;
|
|
|
|
case ID_POPUPMENU_TOGGLEWBP:
|
|
|
|
m_Breakpoints->WBPToggle(m_CtxMenuAddr);
|
|
|
|
RefreshMemory(true);
|
|
|
|
break;
|
|
|
|
case ID_POPUPMENU_CLEARALLBPS:
|
|
|
|
m_Breakpoints->RBPClear();
|
|
|
|
m_Breakpoints->WBPClear();
|
|
|
|
RefreshMemory(true);
|
|
|
|
break;
|
|
|
|
case ID_POPUPMENU_VIEWDISASM:
|
|
|
|
m_Debugger->Debug_ShowCommandsLocation(m_CtxMenuAddr, true);
|
|
|
|
break;
|
|
|
|
case ID_POPUPMENU_ADDSYMBOL:
|
|
|
|
m_AddSymbolDlg.DoModal(m_Debugger, m_CtxMenuAddr);
|
|
|
|
break;
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-08-18 05:08:22 +00:00
|
|
|
LRESULT CDebugMemoryView::OnMemoryRightClicked(LPNMHDR lpNMHDR)
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
uint32_t address;
|
|
|
|
bool bData = GetItemAddress(lpNMHDR, address);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
if (!bData)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
m_CtxMenuAddr = address;
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
HMENU hMenu = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_MEM_BP_POPUP));
|
|
|
|
HMENU hPopupMenu = GetSubMenu(hMenu, 0);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-11-23 21:15:06 +00:00
|
|
|
if (m_Breakpoints->ReadMem().size() == 0 && m_Breakpoints->WriteMem().size() == 0)
|
2017-09-13 12:00:53 +00:00
|
|
|
{
|
|
|
|
EnableMenuItem(hPopupMenu, ID_POPUPMENU_CLEARALLBPS, MF_DISABLED | MF_GRAYED);
|
|
|
|
}
|
|
|
|
|
|
|
|
POINT mouse;
|
|
|
|
GetCursorPos(&mouse);
|
|
|
|
|
|
|
|
TrackPopupMenu(hPopupMenu, TPM_LEFTALIGN, mouse.x, mouse.y, 0, m_hWnd, NULL);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
DestroyMenu(hMenu);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
return 0;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CDebugMemoryView::OnHotItemChanged(LPNMHDR lpNMHDR)
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
uint32_t address;
|
|
|
|
bool bData = GetItemAddress(lpNMHDR, address);
|
|
|
|
|
|
|
|
if (!bData)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
CSymbols::EnterCriticalSection();
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
CSymbolEntry* lpSymbol = CSymbols::GetEntryByAddress(address);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
stdstr symbolInfo;
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
if (lpSymbol != NULL)
|
|
|
|
{
|
|
|
|
char* desc = lpSymbol->m_Description;
|
|
|
|
desc = desc ? desc : "";
|
|
|
|
symbolInfo = stdstr_f("%08X: %s %s // %s", address, lpSymbol->TypeName(), lpSymbol->m_Name, desc);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
symbolInfo = stdstr_f("%08X", address);
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
CSymbols::LeaveCriticalSection();
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
m_SymInfo.SetWindowTextA(symbolInfo.c_str());
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
uint32_t romAddr, offset;
|
|
|
|
DMALOGENTRY* lpEntry = m_Debugger->DMALog()->GetEntryByRamAddress(address, &romAddr, &offset);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
stdstr dmaInfo;
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
if (lpEntry != NULL)
|
|
|
|
{
|
|
|
|
dmaInfo = stdstr_f("Last DMA: %08X -> %08X [%X] (%08X, +%X) ", lpEntry->romAddr, lpEntry->ramAddr, lpEntry->length, romAddr, offset);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dmaInfo = stdstr_f("Last DMA: ?");
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
m_DMAInfo.SetWindowTextA(dmaInfo.c_str());
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
return 0;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2016-01-27 09:11:59 +00:00
|
|
|
LRESULT CDebugMemoryView::OnMemoryModified(LPNMHDR lpNMHDR)
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
uint32_t Pos = 0;
|
|
|
|
bool bData = GetItemOffset(lpNMHDR, Pos);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
if (!bData)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2016-01-27 09:11:59 +00:00
|
|
|
CListNotify *pListNotify = reinterpret_cast<CListNotify *>(lpNMHDR);
|
|
|
|
int LineNumber = pListNotify->m_nItem;
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2016-01-27 09:11:59 +00:00
|
|
|
LPCSTR strValue = m_MemoryList->GetItemText(pListNotify->m_nItem, pListNotify->m_nSubItem);
|
2017-09-13 12:00:53 +00:00
|
|
|
unsigned long long Value = strtoull(strValue, NULL, 16);
|
|
|
|
|
2016-01-27 09:11:59 +00:00
|
|
|
if (m_CurrentData[Pos] == Value)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2016-01-27 09:11:59 +00:00
|
|
|
if (m_CompareStartLoc != m_DataStartLoc ||
|
|
|
|
m_CompareVAddrr != m_DataVAddrr)
|
|
|
|
{
|
|
|
|
// copy current data for change comparison
|
|
|
|
m_CompareStartLoc = m_DataStartLoc;
|
|
|
|
m_CompareVAddrr = m_DataVAddrr;
|
|
|
|
memcpy(m_CompareData, m_CurrentData, sizeof(m_CurrentData));
|
|
|
|
memcpy(m_CompareValid, m_DataValid, sizeof(m_CompareValid));
|
|
|
|
}
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2016-01-27 09:11:59 +00:00
|
|
|
m_CompareData[Pos] = m_CurrentData[Pos];
|
|
|
|
m_CurrentData[Pos] = (BYTE)Value;
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2016-01-27 09:11:59 +00:00
|
|
|
//sb
|
2018-01-21 01:51:36 +00:00
|
|
|
__except_try()
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
2018-01-21 01:51:36 +00:00
|
|
|
if (m_DataVAddrr)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
2018-01-21 01:51:36 +00:00
|
|
|
if (!g_MMU->SB_VAddr(m_DataStartLoc + Pos, (BYTE)Value))
|
|
|
|
{
|
|
|
|
WriteTrace(TraceUserInterface, TraceError, "failed to store at %X", m_DataStartLoc + Pos);
|
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
2018-01-21 01:51:36 +00:00
|
|
|
else
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
2018-01-21 01:51:36 +00:00
|
|
|
if (!g_MMU->SB_PAddr(m_DataStartLoc + Pos, (BYTE)Value))
|
|
|
|
{
|
|
|
|
WriteTrace(TraceUserInterface, TraceError, "failed to store at %X", m_DataStartLoc + Pos);
|
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
2018-01-21 01:51:36 +00:00
|
|
|
uint32_t PhysicalAddress = m_DataStartLoc + Pos;
|
|
|
|
if (!m_DataVAddrr || g_MMU->TranslateVaddr(PhysicalAddress, PhysicalAddress))
|
|
|
|
{
|
|
|
|
if (PhysicalAddress > 0x10000000 && (PhysicalAddress - 0x10000000) < g_Rom->GetRomSize())
|
|
|
|
{
|
|
|
|
uint8_t * ROM = g_Settings->LoadBool(Game_LoadRomToMemory) ? g_MMU->Rdram() + 0x10000000: g_Rom->GetRomAddress();
|
|
|
|
ProtectMemory(ROM, g_Rom->GetRomSize(), MEM_READWRITE);
|
|
|
|
ROM[(PhysicalAddress - 0x10000000) ^ 3] = (uint8_t)Value;
|
|
|
|
ProtectMemory(ROM, g_Rom->GetRomSize(), MEM_READONLY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__except_catch()
|
|
|
|
{
|
|
|
|
g_Notify->FatalError(GS(MSG_UNKNOWN_MEM_ACTION));
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
Insert_MemoryLineDump(LineNumber);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-18 05:08:22 +00:00
|
|
|
void CDebugMemoryView::OnAddrChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
RefreshMemory(false);
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugMemoryView::OnVScroll(int request, short Pos, HWND ctrl)
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (ctrl != GetDlgItem(IDC_SCRL_BAR))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DWORD Location = m_MemAddr.GetValue();
|
|
|
|
switch (request)
|
|
|
|
{
|
|
|
|
case SB_LINEDOWN:
|
|
|
|
m_MemAddr.SetValue(Location < 0xFFFFFFEF ? Location + 0x10 : 0xFFFFFFFF, false, true);
|
|
|
|
break;
|
|
|
|
case SB_LINEUP:
|
|
|
|
m_MemAddr.SetValue(Location > 0x10 ? Location - 0x10 : 0, false, true);
|
|
|
|
break;
|
|
|
|
case SB_PAGEDOWN:
|
|
|
|
m_MemAddr.SetValue(Location < 0xFFFFFEFF ? Location + 0x100 : 0xFFFFFFFF, false, true);
|
|
|
|
break;
|
|
|
|
case SB_PAGEUP:
|
|
|
|
m_MemAddr.SetValue(Location > 0x100 ? Location - 0x100 : 0, false, true);
|
|
|
|
break;
|
|
|
|
case SB_THUMBPOSITION:
|
|
|
|
m_MemAddr.SetValue((DWORD)Pos << 0x10, false, true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
LRESULT CDebugMemoryView::OnActivate(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
WORD type = LOWORD(wParam);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
if (type == WA_INACTIVE)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
RefreshMemory(false);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
return FALSE;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2016-01-27 09:11:59 +00:00
|
|
|
void CDebugMemoryView::ShowAddress(DWORD Address, bool VAddr)
|
|
|
|
{
|
|
|
|
if (m_hWnd == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SendDlgItemMessage(IDC_CHK_VADDR, BM_SETCHECK, VAddr ? BST_CHECKED : BST_UNCHECKED, 0);
|
2017-08-18 05:08:22 +00:00
|
|
|
m_MemAddr.SetValue(Address, false, true);
|
2016-01-27 09:11:59 +00:00
|
|
|
RefreshMemory(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugMemoryView::Insert_MemoryLineDump(int LineNumber)
|
|
|
|
{
|
|
|
|
if (m_MemoryList == NULL || m_MemoryList->GetColumnCount() == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
char Output[20], Hex[60], Ascii[20], AsciiAddOn[15];
|
|
|
|
sprintf(Output, "0x%08X", m_DataStartLoc + (LineNumber << 4));
|
|
|
|
if (m_MemoryList->GetItemCount() <= LineNumber)
|
|
|
|
{
|
|
|
|
HFONT hFont = (HFONT)GetStockObject(ANSI_FIXED_FONT);
|
|
|
|
m_MemoryList->AddItemAt(LineNumber, Output);
|
|
|
|
for (int i = 0; i < m_MemoryList->GetColumnCount(); i++)
|
|
|
|
{
|
|
|
|
m_MemoryList->SetItemFont(LineNumber, i, hFont);
|
|
|
|
if (i == 5 || i == 10 || i == 15)
|
|
|
|
{
|
|
|
|
m_MemoryList->SetItemText(LineNumber, i, "-");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (strcmp(Output, m_MemoryList->GetItemText(LineNumber, 0)) != 0)
|
|
|
|
{
|
|
|
|
m_MemoryList->SetItemText(LineNumber, 0, Output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Hex[0] = 0;
|
|
|
|
Ascii[0] = 0;
|
|
|
|
int CompareStartPos = m_DataStartLoc - m_CompareStartLoc;
|
|
|
|
|
|
|
|
for (int i = 0, col = 1; i < 0x10; i++, col++)
|
|
|
|
{
|
|
|
|
int Pos = ((LineNumber << 4) + i);
|
|
|
|
if (m_DataValid[Pos])
|
|
|
|
{
|
|
|
|
int ComparePos = CompareStartPos + Pos;
|
|
|
|
bool Changed = false;
|
|
|
|
|
|
|
|
if (ComparePos >= 0 && ComparePos < MemoryToDisplay &&
|
|
|
|
m_DataVAddrr == m_CompareVAddrr &&
|
|
|
|
m_DataValid[ComparePos] &&
|
|
|
|
m_CurrentData[Pos] != m_CompareData[ComparePos])
|
|
|
|
{
|
|
|
|
Changed = true;
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2016-01-27 09:11:59 +00:00
|
|
|
sprintf(Hex, "%02X", m_CurrentData[Pos]);
|
2017-09-13 12:00:53 +00:00
|
|
|
|
|
|
|
m_MemoryList->SetItemText(LineNumber, col, Hex);
|
2016-01-27 09:11:59 +00:00
|
|
|
m_MemoryList->SetItemFormat(LineNumber, col, ITEM_FORMAT_EDIT, ITEM_FLAGS_EDIT_HEX);
|
|
|
|
m_MemoryList->SetItemMaxEditLen(LineNumber, col, 2);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
uint32_t vaddr = 0x80000000 | (m_DataStartLoc + Pos);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
COLORREF bgColor, fgColor, fgHiColor;
|
|
|
|
SelectColors(vaddr, Changed, bgColor, fgColor, fgHiColor);
|
|
|
|
|
|
|
|
m_MemoryList->SetItemColours(LineNumber, col, bgColor, fgColor);
|
2017-08-18 05:08:22 +00:00
|
|
|
m_MemoryList->SetItemHighlightColours(LineNumber, col, fgHiColor);
|
2017-09-13 12:00:53 +00:00
|
|
|
|
|
|
|
if (m_CurrentData[Pos] < 30)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
strcat(Ascii, ".");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprintf(AsciiAddOn, "%c", m_CurrentData[Pos]);
|
|
|
|
strcat(Ascii, AsciiAddOn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_MemoryList->SetItemText(LineNumber, col, "**");
|
|
|
|
m_MemoryList->SetItemFormat(LineNumber, col, ITEM_FORMAT_NONE, ITEM_FLAGS_NONE);
|
|
|
|
m_MemoryList->SetItemColours(LineNumber, col, GetSysColor(COLOR_WINDOW), GetSysColor(COLOR_WINDOWTEXT));
|
|
|
|
strcat(Ascii, "*");
|
|
|
|
}
|
|
|
|
if (i != 0xF)
|
|
|
|
{
|
|
|
|
if ((i & 3) == 3)
|
|
|
|
{
|
|
|
|
col += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(Ascii, m_MemoryList->GetItemText(LineNumber, 20)) != 0)
|
|
|
|
{
|
|
|
|
m_MemoryList->SetItemText(LineNumber, 20, Ascii);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-18 05:08:22 +00:00
|
|
|
void CDebugMemoryView::RefreshMemory(bool ResetCompare)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
m_SymbolColorPhase = 0;
|
2016-01-27 09:11:59 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
if (g_MMU == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
|
|
|
|
if (m_MemoryList && m_MemoryList->GetHasEditItem())
|
|
|
|
{
|
|
|
|
m_MemoryList->SetFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD NewAddress = m_MemAddr.GetValue();
|
|
|
|
if (NewAddress != m_DataStartLoc)
|
|
|
|
{
|
|
|
|
HWND hScrlBar = GetDlgItem(IDC_SCRL_BAR);
|
|
|
|
if (hScrlBar)
|
|
|
|
{
|
|
|
|
SCROLLINFO si;
|
|
|
|
|
|
|
|
si.cbSize = sizeof(si);
|
|
|
|
si.fMask = SIF_POS;
|
|
|
|
si.nPos = NewAddress >> 0x10;
|
|
|
|
::SetScrollInfo(hScrlBar, SB_CTL, &si, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ResetCompare)
|
|
|
|
{
|
|
|
|
// copy current data for change comparison
|
|
|
|
m_CompareStartLoc = m_DataStartLoc;
|
|
|
|
m_CompareVAddrr = m_DataVAddrr;
|
|
|
|
memcpy(m_CompareData, m_CurrentData, sizeof(m_CurrentData));
|
|
|
|
memcpy(m_CompareValid, m_DataValid, sizeof(m_CompareValid));
|
|
|
|
}
|
|
|
|
|
|
|
|
m_DataStartLoc = m_MemAddr.GetValue();
|
|
|
|
if (m_DataStartLoc > 0xFFFFFF00) { m_DataStartLoc = 0xFFFFFF00; }
|
|
|
|
int WritePos = 0;
|
|
|
|
|
|
|
|
m_DataVAddrr = (SendDlgItemMessage(IDC_CHK_VADDR, BM_GETCHECK, 0, 0) & BST_CHECKED) != 0;
|
|
|
|
|
|
|
|
if ((m_DataStartLoc & 3) != 0)
|
|
|
|
{
|
|
|
|
MIPS_WORD word;
|
|
|
|
bool ValidData = true;
|
|
|
|
|
|
|
|
if (m_DataVAddrr)
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (!AddressSafe(m_DataStartLoc & ~3))
|
|
|
|
{
|
|
|
|
ValidData = false;
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
else if (!g_MMU->LW_VAddr(m_DataStartLoc & ~3, word.UW))
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
ValidData = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if ((m_DataStartLoc & ~3) >= g_MMU->RdramSize())
|
|
|
|
{
|
|
|
|
ValidData = false;
|
|
|
|
}
|
|
|
|
else if (!g_MMU->LW_PAddr(m_DataStartLoc & ~3, word.UW))
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
ValidData = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int Offset = (m_DataStartLoc & 3);
|
|
|
|
for (int i = 0; i < (4 - Offset); i++)
|
|
|
|
{
|
|
|
|
if (WritePos >= MemoryToDisplay)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
m_DataValid[WritePos + i] = ValidData;
|
|
|
|
if (ValidData)
|
|
|
|
{
|
|
|
|
m_CurrentData[WritePos + i] = word.UB[3 - (i + Offset)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WritePos = 4 - Offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (DWORD Pos = ((m_DataStartLoc + 3) & ~3); Pos < (m_DataStartLoc + MemoryToDisplay); WritePos += 4, Pos += 4)
|
|
|
|
{
|
|
|
|
MIPS_WORD word;
|
|
|
|
bool ValidData = true;
|
|
|
|
|
|
|
|
if (m_DataVAddrr)
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (!AddressSafe(Pos))
|
|
|
|
{
|
|
|
|
ValidData = false;
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
else if (!g_MMU->LW_VAddr(Pos, word.UW))
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
ValidData = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (Pos >= g_MMU->RdramSize())
|
|
|
|
{
|
|
|
|
ValidData = false;
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
else if (!g_MMU->LW_PAddr(Pos, word.UW))
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
ValidData = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
if ((WritePos + i) >= MemoryToDisplay)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
m_DataValid[WritePos + i] = ValidData;
|
|
|
|
if (ValidData)
|
|
|
|
{
|
|
|
|
m_CurrentData[WritePos + i] = word.UB[3 - i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int count = 0; count < 16; count++)
|
|
|
|
{
|
|
|
|
Insert_MemoryLineDump(count);
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CDebugMemoryView::GetItemOffset(LPNMHDR lpNMHDR, uint32_t &offset)
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
CListNotify *pListNotify = reinterpret_cast<CListNotify *>(lpNMHDR);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
int nRow = pListNotify->m_nItem;
|
|
|
|
int nCol = pListNotify->m_nSubItem - 1;
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
if (nCol < 0 || (nCol % 5) == 4)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
offset = (nRow * 0x10) + (nCol / 5) * 4 + (nCol % 5);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
return true;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CDebugMemoryView::GetItemAddress(LPNMHDR lpNMHDR, uint32_t &address)
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
uint32_t offset;
|
|
|
|
bool bData = GetItemOffset(lpNMHDR, offset);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
if (!bData)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
address = 0x80000000 | (m_DataStartLoc + offset);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
return true;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugMemoryView::SelectColors(uint32_t vaddr, bool changed, COLORREF& bgColor, COLORREF& fgColor, COLORREF& fgHiColor)
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
CSymbols::EnterCriticalSection();
|
|
|
|
CSymbolEntry* lpSymbol = CSymbols::GetEntryByAddress(vaddr);
|
|
|
|
|
|
|
|
if (lpSymbol != NULL)
|
|
|
|
{
|
|
|
|
m_SymbolColorStride = lpSymbol->TypeSize();
|
|
|
|
m_SymbolColorPhase = m_SymbolColorPhase ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSymbols::LeaveCriticalSection();
|
|
|
|
|
2017-11-23 21:15:06 +00:00
|
|
|
bool bHaveReadBP = m_Breakpoints->ReadBPExists(vaddr) == CBreakpoints::BP_SET;
|
|
|
|
bool bHaveWriteBP = m_Breakpoints->WriteBPExists(vaddr) == CBreakpoints::BP_SET;
|
2017-09-13 12:00:53 +00:00
|
|
|
|
|
|
|
fgHiColor = RGB(0x00, 0x00, 0x00);
|
|
|
|
|
|
|
|
if (bHaveReadBP && bHaveWriteBP)
|
|
|
|
{
|
|
|
|
bgColor = RGB(0xAA, 0xDD, 0xDD);
|
|
|
|
}
|
|
|
|
else if (bHaveReadBP)
|
|
|
|
{
|
|
|
|
bgColor = RGB(0xDD, 0xDD, 0xAA);
|
|
|
|
}
|
|
|
|
else if (bHaveWriteBP)
|
|
|
|
{
|
|
|
|
bgColor = RGB(0xAA, 0xAA, 0xDD);
|
|
|
|
}
|
|
|
|
else if (m_SymbolColorStride > 0)
|
|
|
|
{
|
|
|
|
bgColor = m_SymbolColorPhase ? RGB(0xD0, 0xF0, 0xD0) : RGB(0xAA, 0xCC, 0xAA);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bgColor = GetSysColor(COLOR_WINDOW);
|
|
|
|
fgHiColor = (changed ? RGB(255, 0, 0) : GetSysColor(COLOR_HIGHLIGHTTEXT));
|
|
|
|
fgColor = (changed ? RGB(255, 0, 0) : GetSysColor(COLOR_WINDOWTEXT));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_SymbolColorStride > 0)
|
|
|
|
{
|
|
|
|
m_SymbolColorStride--;
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if KSEG0 addr is out of bounds
|
|
|
|
bool CDebugMemoryView::AddressSafe(uint32_t vaddr)
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (g_MMU == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vaddr >= 0x80000000 && vaddr <= 0x9FFFFFFF)
|
|
|
|
{
|
|
|
|
if ((vaddr & 0x1FFFFFFF) >= g_MMU->RdramSize())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2015-12-14 10:51:33 +00:00
|
|
|
}
|