2017-08-18 05:08:22 +00:00
|
|
|
#include "stdafx.h"
|
2022-09-21 05:16:07 +00:00
|
|
|
|
2017-08-18 05:08:22 +00:00
|
|
|
#include "DebuggerUI.h"
|
|
|
|
|
|
|
|
#include "Assembler.h"
|
2022-09-21 05:16:07 +00:00
|
|
|
#include "Breakpoints.h"
|
2017-08-18 05:08:22 +00:00
|
|
|
#include "OpInfo.h"
|
2022-09-21 05:16:07 +00:00
|
|
|
#include "Symbols.h"
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2022-07-18 08:31:00 +00:00
|
|
|
#include <Project64-core/N64System/Mips/R4300iInstruction.h>
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-11-03 06:34:43 +00:00
|
|
|
void CCommandList::Attach(HWND hWndNew)
|
|
|
|
{
|
2019-04-19 23:48:53 +00:00
|
|
|
CListViewCtrl::Attach(hWndNew);
|
2017-11-03 06:34:43 +00:00
|
|
|
|
|
|
|
ModifyStyle(LVS_OWNERDRAWFIXED, 0, 0);
|
|
|
|
SetExtendedListViewStyle(LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | LVS_EX_LABELTIP);
|
|
|
|
|
2020-05-12 12:19:05 +00:00
|
|
|
AddColumn(L"", COL_ARROWS);
|
2017-11-03 06:34:43 +00:00
|
|
|
SetColumnWidth(COL_ARROWS, 30);
|
|
|
|
|
2020-05-12 12:19:05 +00:00
|
|
|
AddColumn(L"Address", COL_ADDRESS);
|
2019-04-18 23:29:07 +00:00
|
|
|
SetColumnWidth(COL_ADDRESS, 70);
|
2017-11-03 06:34:43 +00:00
|
|
|
|
2020-05-12 12:19:05 +00:00
|
|
|
AddColumn(L"Command", COL_COMMAND);
|
2019-04-18 23:29:07 +00:00
|
|
|
SetColumnWidth(COL_COMMAND, 65);
|
2017-11-03 06:34:43 +00:00
|
|
|
|
2020-05-12 12:19:05 +00:00
|
|
|
AddColumn(L"Parameters", COL_PARAMETERS);
|
2019-04-18 23:29:07 +00:00
|
|
|
SetColumnWidth(COL_PARAMETERS, 130);
|
2017-11-03 06:34:43 +00:00
|
|
|
|
2020-05-12 12:19:05 +00:00
|
|
|
AddColumn(L"Symbol", COL_SYMBOL);
|
2019-04-18 23:29:07 +00:00
|
|
|
SetColumnWidth(COL_SYMBOL, 180);
|
2017-11-03 06:34:43 +00:00
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
CDebugCommandsView * CDebugCommandsView::_this = nullptr;
|
2021-04-12 11:35:39 +00:00
|
|
|
HHOOK CDebugCommandsView::hWinMessageHook = nullptr;
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
CDebugCommandsView::CDebugCommandsView(CDebuggerUI * debugger, SyncEvent & StepEvent) :
|
2017-11-03 06:34:43 +00:00
|
|
|
CDebugDialog<CDebugCommandsView>(debugger),
|
2018-01-16 21:26:54 +00:00
|
|
|
CToolTipDialog<CDebugCommandsView>(),
|
2018-07-30 13:45:23 +00:00
|
|
|
m_StepEvent(StepEvent),
|
|
|
|
m_Attached(false)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
m_HistoryIndex = -1;
|
|
|
|
m_bIgnoreAddrChange = false;
|
|
|
|
m_StartAddress = 0x80000000;
|
|
|
|
m_Breakpoints = m_Debugger->Breakpoints();
|
|
|
|
m_bEditing = false;
|
2017-10-20 08:57:21 +00:00
|
|
|
m_CommandListRows = 39;
|
|
|
|
m_RowHeight = 13;
|
2020-02-18 20:04:18 +00:00
|
|
|
|
|
|
|
g_Settings->RegisterChangeCB(GameRunning_CPU_Running, this, (CSettings::SettingChangedFunc)GameCpuRunningChanged);
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 06:34:43 +00:00
|
|
|
CDebugCommandsView::~CDebugCommandsView()
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2020-02-18 20:04:18 +00:00
|
|
|
g_Settings->UnregisterChangeCB(GameRunning_CPU_Running, this, (CSettings::SettingChangedFunc)GameCpuRunningChanged);
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2022-01-26 23:33:22 +00:00
|
|
|
m_StartAddress = g_Reg ? g_Reg->m_PROGRAM_COUNTER : 0x80000000;
|
|
|
|
|
2018-01-16 21:26:54 +00:00
|
|
|
g_Settings->RegisterChangeCB(Debugger_WaitingForStep, this, (CSettings::SettingChangedFunc)StaticWaitingForStepChanged);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_SteppingOps, this, (CSettings::SettingChangedFunc)StaticSteppingOpsChanged);
|
|
|
|
|
2017-09-13 10:52:18 +00:00
|
|
|
m_CommandList.Attach(GetDlgItem(IDC_CMD_LIST));
|
|
|
|
m_BreakpointList.Attach(GetDlgItem(IDC_BP_LIST));
|
|
|
|
m_AddressEdit.Attach(GetDlgItem(IDC_ADDR_EDIT));
|
|
|
|
m_PCEdit.Attach(GetDlgItem(IDC_PC_EDIT));
|
|
|
|
m_ViewPCButton.Attach(GetDlgItem(IDC_VIEWPC_BTN));
|
|
|
|
m_StepButton.Attach(GetDlgItem(IDC_STEP_BTN));
|
2018-01-25 06:07:51 +00:00
|
|
|
m_StepOverButton.Attach(GetDlgItem(IDC_STEPOVER_BTN));
|
2017-09-13 10:52:18 +00:00
|
|
|
m_SkipButton.Attach(GetDlgItem(IDC_SKIP_BTN));
|
|
|
|
m_GoButton.Attach(GetDlgItem(IDC_GO_BTN));
|
2019-06-15 11:04:37 +00:00
|
|
|
m_RegisterTabs.Attach(GetDlgItem(IDC_REG_TABS), m_Debugger);
|
2017-09-13 10:52:18 +00:00
|
|
|
m_Scrollbar.Attach(GetDlgItem(IDC_SCRL_BAR));
|
|
|
|
m_BackButton.Attach(GetDlgItem(IDC_BACK_BTN));
|
|
|
|
m_ForwardButton.Attach(GetDlgItem(IDC_FORWARD_BTN));
|
|
|
|
m_OpEdit.Attach(GetDlgItem(IDC_OP_EDIT));
|
|
|
|
|
|
|
|
DlgResize_Init(false, true);
|
2019-01-14 07:06:01 +00:00
|
|
|
DlgSavePos_Init(DebuggerUI_CommandsPos);
|
2017-09-13 10:52:18 +00:00
|
|
|
DlgToolTip_Init();
|
|
|
|
|
|
|
|
// Setup address input
|
2017-11-21 20:37:45 +00:00
|
|
|
m_AddressEdit.SetDisplayType(CEditNumber32::DisplayHex);
|
2017-09-13 10:52:18 +00:00
|
|
|
m_AddressEdit.SetLimitText(8);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 10:52:18 +00:00
|
|
|
// Setup PC register input
|
2017-11-21 20:37:45 +00:00
|
|
|
m_PCEdit.SetDisplayType(CEditNumber32::DisplayHex);
|
2017-09-13 10:52:18 +00:00
|
|
|
m_PCEdit.SetLimitText(8);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 10:52:18 +00:00
|
|
|
m_bIgnorePCChange = true;
|
2022-01-26 23:33:22 +00:00
|
|
|
m_PCEdit.SetValue(m_StartAddress, DisplayMode::ZeroExtend);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2021-03-18 03:45:29 +00:00
|
|
|
// Setup view PC button
|
2017-09-13 10:52:18 +00:00
|
|
|
m_ViewPCButton.EnableWindow(FALSE);
|
|
|
|
m_StepButton.EnableWindow(FALSE);
|
2018-01-25 06:07:51 +00:00
|
|
|
m_StepOverButton.EnableWindow(FALSE);
|
2017-09-13 10:52:18 +00:00
|
|
|
m_SkipButton.EnableWindow(FALSE);
|
|
|
|
m_GoButton.EnableWindow(FALSE);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 10:52:18 +00:00
|
|
|
// Setup breakpoint list
|
|
|
|
m_BreakpointList.ModifyStyle(NULL, LBS_NOTIFY);
|
|
|
|
RefreshBreakpointList();
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 10:52:18 +00:00
|
|
|
// Setup list scrollbar
|
|
|
|
m_Scrollbar.SetScrollRange(0, 100, FALSE);
|
|
|
|
m_Scrollbar.SetScrollPos(50, TRUE);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 10:52:18 +00:00
|
|
|
// Setup history buttons
|
|
|
|
ToggleHistoryButtons();
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 10:52:18 +00:00
|
|
|
// Op editor
|
2017-11-03 06:34:43 +00:00
|
|
|
m_OpEdit.SetCommandsWindow(this);
|
|
|
|
|
|
|
|
m_bIgnoreAddrChange = true;
|
2022-01-26 23:33:22 +00:00
|
|
|
m_AddressEdit.SetValue(m_StartAddress, DisplayMode::ZeroExtend);
|
|
|
|
ShowAddress(m_StartAddress, TRUE);
|
2018-12-27 22:08:14 +00:00
|
|
|
m_bIgnoreAddrChange = false;
|
2017-11-03 06:34:43 +00:00
|
|
|
|
2018-01-15 21:14:15 +00:00
|
|
|
if (isStepping())
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
|
|
|
m_ViewPCButton.EnableWindow(TRUE);
|
|
|
|
m_StepButton.EnableWindow(TRUE);
|
2018-01-25 06:07:51 +00:00
|
|
|
m_StepOverButton.EnableWindow(TRUE);
|
2017-11-03 06:34:43 +00:00
|
|
|
m_SkipButton.EnableWindow(TRUE);
|
|
|
|
m_GoButton.EnableWindow(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
_this = this;
|
|
|
|
|
|
|
|
DWORD dwThreadID = ::GetCurrentThreadId();
|
2021-04-12 11:35:39 +00:00
|
|
|
hWinMessageHook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)HookProc, nullptr, dwThreadID);
|
2017-11-03 06:34:43 +00:00
|
|
|
|
2019-01-14 07:06:01 +00:00
|
|
|
LoadWindowPos();
|
|
|
|
RedrawCommandsAndRegisters();
|
2019-12-25 00:41:20 +00:00
|
|
|
WindowCreated();
|
2018-07-30 13:45:23 +00:00
|
|
|
m_Attached = true;
|
2020-02-18 20:04:18 +00:00
|
|
|
|
|
|
|
RecompilerCheck();
|
|
|
|
|
2017-11-03 06:34:43 +00:00
|
|
|
return TRUE;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2021-01-19 05:58:59 +00:00
|
|
|
void CDebugCommandsView::GameCpuRunningChanged(CDebugCommandsView * DebugCommandsView)
|
2020-02-18 20:04:18 +00:00
|
|
|
{
|
2021-01-19 05:58:59 +00:00
|
|
|
DebugCommandsView->RecompilerCheck();
|
2020-02-18 20:04:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugCommandsView::RecompilerCheck(void)
|
|
|
|
{
|
|
|
|
if (!g_Settings->LoadBool(GameRunning_CPU_Running))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_this->IsWindow())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-26 02:31:54 +00:00
|
|
|
if (g_Settings->LoadBool(Debugger_Enabled) && !g_Settings->LoadBool(Setting_ForceInterpreterCPU) && (CPU_TYPE)g_Settings->LoadDword(Game_CpuType) != CPU_Interpreter)
|
2020-02-18 20:04:18 +00:00
|
|
|
{
|
2022-09-21 05:16:07 +00:00
|
|
|
// TODO: Remove this or fix?
|
2020-05-12 12:19:05 +00:00
|
|
|
MessageBox(L"Debugger support for the recompiler core is experimental.\n\n"
|
2022-09-21 05:16:07 +00:00
|
|
|
L"For optimal experience, enable \"Always use interpreter core\" "
|
|
|
|
L"in advanced settings and restart the emulator.",
|
|
|
|
L"Warning", MB_ICONWARNING | MB_OK);
|
2020-02-18 20:04:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-14 04:03:02 +00:00
|
|
|
void CDebugCommandsView::OnExitSizeMove(void)
|
|
|
|
{
|
2019-12-25 00:41:20 +00:00
|
|
|
SaveWindowPos(true);
|
2019-01-14 04:03:02 +00:00
|
|
|
}
|
|
|
|
|
2017-08-18 05:08:22 +00:00
|
|
|
LRESULT CDebugCommandsView::OnDestroy(void)
|
|
|
|
{
|
2018-07-30 13:45:23 +00:00
|
|
|
m_Attached = false;
|
2018-01-16 21:26:54 +00:00
|
|
|
g_Settings->UnregisterChangeCB(Debugger_SteppingOps, this, (CSettings::SettingChangedFunc)StaticSteppingOpsChanged);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_WaitingForStep, this, (CSettings::SettingChangedFunc)StaticWaitingForStepChanged);
|
|
|
|
|
2017-11-03 06:34:43 +00:00
|
|
|
UnhookWindowsHookEx(hWinMessageHook);
|
2017-09-13 10:52:18 +00:00
|
|
|
m_OpEdit.Detach();
|
|
|
|
m_ForwardButton.Detach();
|
|
|
|
m_BackButton.Detach();
|
|
|
|
m_Scrollbar.Detach();
|
|
|
|
m_RegisterTabs.Detach();
|
|
|
|
m_GoButton.Detach();
|
|
|
|
m_SkipButton.Detach();
|
|
|
|
m_StepButton.Detach();
|
2018-01-25 06:07:51 +00:00
|
|
|
m_StepOverButton.Detach();
|
2017-09-13 10:52:18 +00:00
|
|
|
m_ViewPCButton.Detach();
|
|
|
|
m_PCEdit.Detach();
|
|
|
|
m_AddressEdit.Detach();
|
|
|
|
m_BreakpointList.Detach();
|
|
|
|
m_CommandList.Detach();
|
|
|
|
return 0;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 10:52:18 +00:00
|
|
|
void CDebugCommandsView::InterceptKeyDown(WPARAM wParam, LPARAM /*lParam*/)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-09-13 10:52:18 +00:00
|
|
|
switch (wParam)
|
|
|
|
{
|
|
|
|
case VK_F1: CPUSkip(); break;
|
2022-09-21 05:16:07 +00:00
|
|
|
case VK_F2:
|
2018-01-16 21:26:54 +00:00
|
|
|
if (WaitingForStep())
|
|
|
|
{
|
|
|
|
m_StepEvent.Trigger();
|
|
|
|
}
|
|
|
|
break;
|
2018-01-25 06:07:51 +00:00
|
|
|
case VK_F3: CPUStepOver(); break;
|
2017-09-13 10:52:18 +00:00
|
|
|
case VK_F4: CPUResume(); break;
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 10:52:18 +00:00
|
|
|
void CDebugCommandsView::InterceptMouseWheel(WPARAM wParam, LPARAM /*lParam*/)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-09-13 10:52:18 +00:00
|
|
|
uint32_t newAddress = m_StartAddress - ((short)HIWORD(wParam) / WHEEL_DELTA) * 4;
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 10:52:18 +00:00
|
|
|
m_StartAddress = newAddress;
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2020-04-08 11:44:49 +00:00
|
|
|
m_AddressEdit.SetValue(m_StartAddress, DisplayMode::ZeroExtend);
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CALLBACK CDebugCommandsView::HookProc(int nCode, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2022-09-21 05:16:07 +00:00
|
|
|
MSG * pMsg = (MSG *)lParam;
|
2017-09-13 10:52:18 +00:00
|
|
|
|
|
|
|
if (pMsg->message == WM_KEYDOWN)
|
|
|
|
{
|
|
|
|
_this->InterceptKeyDown(pMsg->wParam, pMsg->lParam);
|
|
|
|
}
|
|
|
|
else if (pMsg->message == WM_MOUSEWHEEL)
|
|
|
|
{
|
|
|
|
_this->InterceptMouseWheel(pMsg->wParam, pMsg->lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nCode < 0)
|
|
|
|
{
|
|
|
|
return CallNextHookEx(hWinMessageHook, nCode, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugCommandsView::ClearBranchArrows()
|
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
m_BranchArrows.clear();
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugCommandsView::AddBranchArrow(int startPos, int endPos)
|
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
int startMargin = 0;
|
|
|
|
int endMargin = 0;
|
|
|
|
int margin = 0;
|
|
|
|
|
2017-11-23 21:15:06 +00:00
|
|
|
for (size_t j = 0; j < m_BranchArrows.size(); j++)
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
|
|
|
BRANCHARROW arrow = m_BranchArrows[j];
|
|
|
|
|
2021-03-18 03:45:29 +00:00
|
|
|
// Arrow's start or end position within another arrow's stride
|
2022-09-26 02:31:54 +00:00
|
|
|
if ((startPos >= arrow.startPos && startPos <= arrow.endPos) || (endPos >= arrow.startPos && endPos <= arrow.endPos) || (arrow.startPos <= startPos && arrow.startPos >= endPos))
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
|
|
|
if (margin <= arrow.margin)
|
|
|
|
{
|
|
|
|
margin = arrow.margin + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (startPos == arrow.startPos)
|
|
|
|
{
|
|
|
|
startMargin = arrow.startMargin + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (startPos == arrow.endPos)
|
|
|
|
{
|
|
|
|
startMargin = arrow.endMargin + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (endPos == arrow.startPos)
|
|
|
|
{
|
|
|
|
endMargin = arrow.startMargin + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (endPos == arrow.endPos)
|
|
|
|
{
|
|
|
|
endMargin = arrow.endMargin + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
m_BranchArrows.push_back({startPos, endPos, startMargin, endMargin, margin});
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugCommandsView::HistoryPushState()
|
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
m_History.push_back(m_StartAddress);
|
|
|
|
m_HistoryIndex = m_History.size() - 1;
|
|
|
|
ToggleHistoryButtons();
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
const char * CDebugCommandsView::GetDataAddressNotes(uint32_t vAddr)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
switch (vAddr)
|
|
|
|
{
|
|
|
|
case 0xA3F00000: return "RDRAM_CONFIG_REG/RDRAM_DEVICE_TYPE_REG";
|
|
|
|
case 0xA3F00004: return "RDRAM_DEVICE_ID_REG";
|
|
|
|
case 0xA3F00008: return "RDRAM_DELAY_REG";
|
|
|
|
case 0xA3F0000C: return "RDRAM_MODE_REG";
|
|
|
|
case 0xA3F00010: return "RDRAM_REF_INTERVAL_REG";
|
|
|
|
case 0xA3F00014: return "RDRAM_REF_ROW_REG";
|
|
|
|
case 0xA3F00018: return "RDRAM_RAS_INTERVAL_REG";
|
|
|
|
case 0xA3F0001C: return "RDRAM_MIN_INTERVAL_REG";
|
|
|
|
case 0xA3F00020: return "RDRAM_ADDR_SELECT_REG";
|
|
|
|
case 0xA3F00024: return "RDRAM_DEVICE_MANUF_REG";
|
|
|
|
|
|
|
|
case 0xA4040000: return "SP_MEM_ADDR_REG";
|
|
|
|
case 0xA4040004: return "SP_DRAM_ADDR_REG";
|
|
|
|
case 0xA4040008: return "SP_RD_LEN_REG";
|
|
|
|
case 0xA404000C: return "SP_WR_LEN_REG";
|
|
|
|
case 0xA4040010: return "SP_STATUS_REG";
|
|
|
|
case 0xA4040014: return "SP_DMA_FULL_REG";
|
|
|
|
case 0xA4040018: return "SP_DMA_BUSY_REG";
|
|
|
|
case 0xA404001C: return "SP_SEMAPHORE_REG";
|
|
|
|
|
|
|
|
case 0xA4080000: return "SP_PC";
|
|
|
|
|
|
|
|
case 0xA4100000: return "DPC_START_REG";
|
|
|
|
case 0xA4100004: return "DPC_END_REG";
|
|
|
|
case 0xA4100008: return "DPC_CURRENT_REG";
|
|
|
|
case 0xA410000C: return "DPC_STATUS_REG";
|
|
|
|
case 0xA4100010: return "DPC_CLOCK_REG";
|
|
|
|
case 0xA4100014: return "DPC_BUFBUSY_REG";
|
|
|
|
case 0xA4100018: return "DPC_PIPEBUSY_REG";
|
|
|
|
case 0xA410001C: return "DPC_TMEM_REG";
|
|
|
|
|
|
|
|
case 0xA4300000: return "MI_INIT_MODE_REG/MI_MODE_REG";
|
|
|
|
case 0xA4300004: return "MI_VERSION_REG/MI_NOOP_REG";
|
|
|
|
case 0xA4300008: return "MI_INTR_REG";
|
|
|
|
case 0xA430000C: return "MI_INTR_MASK_REG";
|
|
|
|
|
|
|
|
case 0xA4400000: return "VI_STATUS_REG/VI_CONTROL_REG";
|
|
|
|
case 0xA4400004: return "VI_ORIGIN_REG/VI_DRAM_ADDR_REG";
|
|
|
|
case 0xA4400008: return "VI_WIDTH_REG/VI_H_WIDTH_REG";
|
|
|
|
case 0xA440000C: return "VI_INTR_REG/VI_V_INTR_REG";
|
|
|
|
case 0xA4400010: return "VI_CURRENT_REG/VI_V_CURRENT_LINE_REG";
|
|
|
|
case 0xA4400014: return "VI_BURST_REG/VI_TIMING_REG";
|
|
|
|
case 0xA4400018: return "VI_V_SYNC_REG";
|
|
|
|
case 0xA440001C: return "VI_H_SYNC_REG";
|
|
|
|
case 0xA4400020: return "VI_LEAP_REG/VI_H_SYNC_LEAP_REG";
|
|
|
|
case 0xA4400024: return "VI_H_START_REG/VI_H_VIDEO_REG";
|
|
|
|
case 0xA4400028: return "VI_V_START_REG/VI_V_VIDEO_REG";
|
|
|
|
case 0xA440002C: return "VI_V_BURST_REG";
|
|
|
|
case 0xA4400030: return "VI_X_SCALE_REG";
|
|
|
|
case 0xA4400034: return "VI_Y_SCALE_REG";
|
|
|
|
|
|
|
|
case 0xA4500000: return "AI_DRAM_ADDR_REG";
|
|
|
|
case 0xA4500004: return "AI_LEN_REG";
|
|
|
|
case 0xA4500008: return "AI_CONTROL_REG";
|
|
|
|
case 0xA450000C: return "AI_STATUS_REG";
|
|
|
|
case 0xA4500010: return "AI_DACRATE_REG";
|
|
|
|
case 0xA4500014: return "AI_BITRATE_REG";
|
|
|
|
|
|
|
|
case 0xA4600000: return "PI_DRAM_ADDR_REG";
|
|
|
|
case 0xA4600004: return "PI_CART_ADDR_REG";
|
|
|
|
case 0xA4600008: return "PI_RD_LEN_REG";
|
|
|
|
case 0xA460000C: return "PI_WR_LEN_REG";
|
|
|
|
case 0xA4600010: return "PI_STATUS_REG";
|
|
|
|
case 0xA4600014: return "PI_BSD_DOM1_LAT_REG";
|
|
|
|
case 0xA4600018: return "PI_BSD_DOM1_PWD_REG";
|
|
|
|
case 0xA460001C: return "PI_BSD_DOM1_PGS_REG";
|
|
|
|
case 0xA4600020: return "PI_BSD_DOM1_RLS_REG";
|
|
|
|
case 0xA4600024: return "PI_BSD_DOM2_LAT_REG";
|
|
|
|
case 0xA4600028: return "PI_BSD_DOM2_PWD_REG";
|
|
|
|
case 0xA460002C: return "PI_BSD_DOM2_PGS_REG";
|
|
|
|
case 0xA4600030: return "PI_BSD_DOM2_RLS_REG";
|
|
|
|
|
|
|
|
case 0xA4700000: return "RI_MODE_REG";
|
|
|
|
case 0xA4700004: return "RI_CONFIG_REG";
|
|
|
|
case 0xA4700008: return "RI_CURRENT_LOAD_REG";
|
|
|
|
case 0xA470000C: return "RI_SELECT_REG";
|
|
|
|
case 0xA4700010: return "RI_REFRESH_REG/RI_COUNT_REG";
|
|
|
|
case 0xA4700014: return "RI_LATENCY_REG";
|
|
|
|
case 0xA4700018: return "RI_RERROR_REG";
|
|
|
|
case 0xA470001C: return "RI_WERROR_REG";
|
|
|
|
|
|
|
|
case 0xA4800000: return "SI_DRAM_ADDR_REG";
|
|
|
|
case 0xA4800004: return "SI_PIF_ADDR_RD64B_REG";
|
|
|
|
case 0xA4800010: return "SI_PIF_ADDR_WR64B_REG";
|
|
|
|
case 0xA4800018: return "SI_STATUS_REG";
|
|
|
|
|
|
|
|
case 0xA5000500: return "ASIC_DATA";
|
|
|
|
case 0xA5000504: return "ASIC_MISC_REG";
|
|
|
|
case 0xA5000508: return "ASIC_STATUS";
|
|
|
|
case 0xA500050C: return "ASIC_CUR_TK";
|
|
|
|
case 0xA5000510: return "ASIC_BM_STATUS";
|
|
|
|
case 0xA5000514: return "ASIC_ERR_SECTOR";
|
|
|
|
case 0xA5000518: return "ASIC_SEQ_STATUS";
|
|
|
|
case 0xA500051C: return "ASIC_CUR_SECTOR";
|
|
|
|
case 0xA5000520: return "ASIC_HARD_RESET";
|
|
|
|
case 0xA5000524: return "ASIC_C1_S0";
|
|
|
|
case 0xA5000528: return "ASIC_HOST_SECBYTE";
|
|
|
|
case 0xA500052C: return "ASIC_C1_S2";
|
|
|
|
case 0xA5000530: return "ASIC_SEC_BYTE";
|
|
|
|
case 0xA5000534: return "ASIC_C1_S4";
|
|
|
|
case 0xA5000538: return "ASIC_C1_S6";
|
|
|
|
case 0xA500053C: return "ASIC_CUR_ADDR";
|
|
|
|
case 0xA5000540: return "ASIC_ID_REG";
|
|
|
|
case 0xA5000544: return "ASIC_TEST_REG";
|
|
|
|
case 0xA5000548: return "ASIC_TEST_PIN_SEL";
|
|
|
|
|
|
|
|
case 0xB0000004: return "Header: Clock rate";
|
|
|
|
case 0xB0000008: return "Header: Game entry point";
|
|
|
|
case 0xB000000C: return "Header: Release";
|
|
|
|
case 0xB0000010: return "Header: CRC1";
|
|
|
|
case 0xB0000014: return "Header: CRC2";
|
|
|
|
}
|
|
|
|
|
2021-04-12 11:35:39 +00:00
|
|
|
return nullptr;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
const char * CDebugCommandsView::GetCodeAddressNotes(uint32_t vAddr)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
switch (vAddr)
|
|
|
|
{
|
|
|
|
case 0x80000000: return "Exception: TLB Refill";
|
|
|
|
case 0x80000080: return "Exception: XTLB Refill";
|
|
|
|
case 0x80000100: return "Exception: Cache error (See A0000100)";
|
|
|
|
case 0x80000180: return "Exception: General";
|
|
|
|
|
|
|
|
case 0xA0000100: return "Exception: Cache error";
|
|
|
|
|
|
|
|
case 0xBFC00000: return "Exception: Reset/NMI";
|
|
|
|
case 0xBFC00200: return "Exception: TLB Refill (boot)";
|
|
|
|
case 0xBFC00280: return "Exception: XTLB Refill (boot)";
|
|
|
|
case 0xBFC00300: return "Exception: Cache error (boot)";
|
|
|
|
case 0xBFC00380: return "Exception: General (boot)";
|
|
|
|
}
|
|
|
|
|
2021-04-12 11:35:39 +00:00
|
|
|
if (g_MMU == nullptr)
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
return nullptr;
|
2017-11-03 06:34:43 +00:00
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
uint8_t * rom = g_Rom->GetRomAddress();
|
|
|
|
uint32_t gameEntryPoint = *(uint32_t *)&rom[0x08];
|
2017-11-03 06:34:43 +00:00
|
|
|
|
|
|
|
if (vAddr == gameEntryPoint)
|
|
|
|
{
|
|
|
|
return "Game entry point";
|
|
|
|
}
|
|
|
|
|
2021-04-12 11:35:39 +00:00
|
|
|
return nullptr;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 20:06:33 +00:00
|
|
|
void CDebugCommandsView::ShowAddress(uint32_t address, bool top, bool bUserInput)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
if (top == TRUE)
|
|
|
|
{
|
2019-01-16 20:06:33 +00:00
|
|
|
m_StartAddress = address - address % 4;
|
|
|
|
|
|
|
|
if (!bUserInput)
|
|
|
|
{
|
|
|
|
m_bIgnoreAddrChange = true;
|
2020-04-08 11:44:49 +00:00
|
|
|
m_AddressEdit.SetValue(address, DisplayMode::ZeroExtend);
|
2019-01-16 20:06:33 +00:00
|
|
|
}
|
2017-11-03 06:34:43 +00:00
|
|
|
|
2018-01-15 21:14:15 +00:00
|
|
|
if (!isStepping())
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
|
|
|
// Disable buttons
|
|
|
|
m_ViewPCButton.EnableWindow(FALSE);
|
|
|
|
m_StepButton.EnableWindow(FALSE);
|
2018-01-25 06:07:51 +00:00
|
|
|
m_StepOverButton.EnableWindow(FALSE);
|
2017-11-03 06:34:43 +00:00
|
|
|
m_SkipButton.EnableWindow(FALSE);
|
|
|
|
m_GoButton.EnableWindow(FALSE);
|
|
|
|
|
|
|
|
m_RegisterTabs.SetColorsEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-26 02:31:54 +00:00
|
|
|
bool bOutOfView = address < m_StartAddress || address > m_StartAddress + (m_CommandListRows - 1) * 4;
|
2017-11-03 06:34:43 +00:00
|
|
|
|
|
|
|
if (bOutOfView)
|
|
|
|
{
|
2019-01-16 20:06:33 +00:00
|
|
|
m_StartAddress = address - address % 4;
|
2017-11-03 06:34:43 +00:00
|
|
|
m_bIgnoreAddrChange = true;
|
2020-04-08 11:44:49 +00:00
|
|
|
m_AddressEdit.SetValue(address, DisplayMode::ZeroExtend);
|
2017-11-03 06:34:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_History.size() == 0 || m_History[m_HistoryIndex] != m_StartAddress)
|
|
|
|
{
|
|
|
|
HistoryPushState();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_bIgnorePCChange = true;
|
2020-04-08 11:44:49 +00:00
|
|
|
m_PCEdit.SetValue(g_Reg->m_PROGRAM_COUNTER, DisplayMode::ZeroExtend);
|
2017-11-03 06:34:43 +00:00
|
|
|
|
|
|
|
// Enable buttons
|
|
|
|
m_ViewPCButton.EnableWindow(TRUE);
|
|
|
|
m_StepButton.EnableWindow(TRUE);
|
2018-01-25 06:07:51 +00:00
|
|
|
m_StepOverButton.EnableWindow(TRUE);
|
2017-11-03 06:34:43 +00:00
|
|
|
m_SkipButton.EnableWindow(TRUE);
|
|
|
|
m_GoButton.EnableWindow(TRUE);
|
|
|
|
|
|
|
|
m_RegisterTabs.SetColorsEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_CommandList.SetRedraw(FALSE);
|
|
|
|
m_CommandList.DeleteAllItems();
|
|
|
|
|
|
|
|
ClearBranchArrows();
|
|
|
|
|
|
|
|
m_bvAnnotatedLines.clear();
|
|
|
|
|
|
|
|
for (int i = 0; i < m_CommandListRows; i++)
|
|
|
|
{
|
|
|
|
uint32_t opAddr = m_StartAddress + i * 4;
|
|
|
|
|
2020-05-12 12:19:05 +00:00
|
|
|
m_CommandList.AddItem(i, CCommandList::COL_ARROWS, L" ");
|
2017-11-03 06:34:43 +00:00
|
|
|
|
|
|
|
char addrStr[9];
|
|
|
|
sprintf(addrStr, "%08X", opAddr);
|
|
|
|
|
2020-05-12 12:19:05 +00:00
|
|
|
m_CommandList.AddItem(i, CCommandList::COL_ADDRESS, stdstr(addrStr).ToUTF16().c_str());
|
2017-11-03 06:34:43 +00:00
|
|
|
|
|
|
|
COpInfo OpInfo;
|
2022-09-21 05:16:07 +00:00
|
|
|
R4300iOpcode & OpCode = OpInfo.m_OpCode;
|
2017-11-03 06:34:43 +00:00
|
|
|
|
2022-07-18 08:31:00 +00:00
|
|
|
if (!m_Debugger->DebugLoad_VAddr(opAddr, OpCode.Value))
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
2020-05-12 12:19:05 +00:00
|
|
|
m_CommandList.AddItem(i, CCommandList::COL_COMMAND, L"***");
|
2017-11-03 06:34:43 +00:00
|
|
|
m_bvAnnotatedLines.push_back(false);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-07-18 08:31:00 +00:00
|
|
|
R4300iInstruction Instruction(opAddr, OpCode.Value);
|
|
|
|
std::string cmdArgs = Instruction.Param();
|
2017-11-03 06:34:43 +00:00
|
|
|
|
2020-02-23 17:28:25 +00:00
|
|
|
CSymbol jalSymbol;
|
|
|
|
|
2017-11-03 06:34:43 +00:00
|
|
|
// Show subroutine symbol name for JAL target
|
|
|
|
if (OpCode.op == R4300i_JAL)
|
|
|
|
{
|
2020-02-23 17:28:25 +00:00
|
|
|
uint32_t targetAddr = (m_StartAddress & 0xF0000000) | (OpCode.target << 2);
|
2017-11-03 06:34:43 +00:00
|
|
|
|
2020-02-23 17:28:25 +00:00
|
|
|
if (m_Debugger->SymbolTable()->GetSymbolByAddress(targetAddr, &jalSymbol))
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
2022-07-18 08:31:00 +00:00
|
|
|
cmdArgs = jalSymbol.m_Name;
|
2017-11-03 06:34:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-18 03:45:29 +00:00
|
|
|
// Detect reads and writes to mapped registers, cart header data, etc.
|
2022-09-21 05:16:07 +00:00
|
|
|
const char * annotation = nullptr;
|
2017-11-03 06:34:43 +00:00
|
|
|
bool bLoadStoreAnnotation = false;
|
|
|
|
|
2020-02-23 17:28:25 +00:00
|
|
|
CSymbol memSymbol;
|
|
|
|
|
2018-03-18 01:14:52 +00:00
|
|
|
if (OpInfo.IsLoadStoreCommand())
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
2017-11-23 21:15:06 +00:00
|
|
|
for (int offset = -4; offset > -24; offset -= 4)
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
2022-07-18 08:31:00 +00:00
|
|
|
R4300iOpcode OpCodeTest;
|
2017-11-03 06:34:43 +00:00
|
|
|
|
2022-07-18 08:31:00 +00:00
|
|
|
if (!m_Debugger->DebugLoad_VAddr(opAddr + offset, OpCodeTest.Value))
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OpCodeTest.op != R4300i_LUI)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OpCodeTest.rt != OpCode.rs)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t memAddr = (OpCodeTest.immediate << 16) + (short)OpCode.offset;
|
|
|
|
|
2020-02-23 17:28:25 +00:00
|
|
|
if (m_Debugger->SymbolTable()->GetSymbolByAddress(memAddr, &memSymbol))
|
2019-12-25 00:41:20 +00:00
|
|
|
{
|
2020-02-23 17:28:25 +00:00
|
|
|
annotation = memSymbol.m_Name;
|
2019-12-25 00:41:20 +00:00
|
|
|
}
|
|
|
|
else
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
|
|
|
annotation = GetDataAddressNotes(memAddr);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-12 11:35:39 +00:00
|
|
|
if (annotation == nullptr)
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
|
|
|
annotation = GetCodeAddressNotes(opAddr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bLoadStoreAnnotation = true;
|
|
|
|
}
|
|
|
|
|
2022-07-18 08:31:00 +00:00
|
|
|
m_CommandList.AddItem(i, CCommandList::COL_COMMAND, stdstr(Instruction.Name()).ToUTF16().c_str());
|
2020-05-12 12:19:05 +00:00
|
|
|
m_CommandList.AddItem(i, CCommandList::COL_PARAMETERS, stdstr(cmdArgs).ToUTF16().c_str());
|
2017-11-03 06:34:43 +00:00
|
|
|
|
|
|
|
// Show routine symbol name for this address
|
2020-02-23 17:28:25 +00:00
|
|
|
CSymbol pcSymbol;
|
|
|
|
if (m_Debugger->SymbolTable()->GetSymbolByAddress(opAddr, &pcSymbol))
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
2020-05-12 12:19:05 +00:00
|
|
|
m_CommandList.AddItem(i, CCommandList::COL_SYMBOL, stdstr(pcSymbol.m_Name).ToUTF16().c_str());
|
2017-11-03 06:34:43 +00:00
|
|
|
m_bvAnnotatedLines.push_back(false);
|
|
|
|
}
|
2021-04-12 11:35:39 +00:00
|
|
|
else if (annotation != nullptr)
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
2022-09-21 05:16:07 +00:00
|
|
|
const char * annotationFormat = bLoadStoreAnnotation ? "// (%s)" : "// %s";
|
2020-05-12 12:19:05 +00:00
|
|
|
m_CommandList.AddItem(i, CCommandList::COL_SYMBOL, stdstr_f(annotationFormat, annotation).ToUTF16().c_str());
|
2017-11-03 06:34:43 +00:00
|
|
|
m_bvAnnotatedLines.push_back(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_bvAnnotatedLines.push_back(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add arrow for branch instruction
|
|
|
|
if (OpInfo.IsBranch())
|
|
|
|
{
|
|
|
|
int startPos = i;
|
|
|
|
int endPos = startPos + (int16_t)OpCode.offset + 1;
|
|
|
|
|
|
|
|
AddBranchArrow(startPos, endPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Branch arrow for close J
|
|
|
|
if (OpCode.op == R4300i_J)
|
|
|
|
{
|
|
|
|
uint32_t target = (OpCode.target << 2);
|
|
|
|
int dist = target - (opAddr & 0x3FFFFFF);
|
|
|
|
if (abs(dist) < 0x10000)
|
|
|
|
{
|
|
|
|
int startPos = i;
|
|
|
|
int endPos = startPos + (dist / 4);
|
|
|
|
AddBranchArrow(startPos, endPos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-18 03:45:29 +00:00
|
|
|
if (!top) // Update registers when called via breakpoint/stepping
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
|
|
|
m_RegisterTabs.RefreshEdits();
|
|
|
|
}
|
|
|
|
|
|
|
|
RefreshBreakpointList();
|
|
|
|
|
|
|
|
m_CommandList.SetRedraw(TRUE);
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
// Highlight command list items and draw branch arrows
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnCustomDrawList(NMHDR * pNMHDR)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2022-09-21 05:16:07 +00:00
|
|
|
NMLVCUSTOMDRAW * pLVCD = reinterpret_cast<NMLVCUSTOMDRAW *>(pNMHDR);
|
2017-11-03 06:34:43 +00:00
|
|
|
DWORD drawStage = pLVCD->nmcd.dwDrawStage;
|
|
|
|
|
|
|
|
switch (drawStage)
|
|
|
|
{
|
2018-01-18 06:53:07 +00:00
|
|
|
case CDDS_PREPAINT: return (CDRF_NOTIFYITEMDRAW | CDRF_NOTIFYPOSTPAINT);
|
|
|
|
case CDDS_ITEMPREPAINT: return CDRF_NOTIFYSUBITEMDRAW;
|
|
|
|
case (CDDS_ITEMPREPAINT | CDDS_SUBITEM): break;
|
2017-11-03 06:34:43 +00:00
|
|
|
case CDDS_POSTPAINT:
|
2018-01-18 06:53:07 +00:00
|
|
|
DrawBranchArrows(pLVCD->nmcd.hdc);
|
2017-11-03 06:34:43 +00:00
|
|
|
return CDRF_DODEFAULT;
|
|
|
|
default:
|
|
|
|
return CDRF_DODEFAULT;
|
|
|
|
}
|
|
|
|
|
2018-01-18 06:53:07 +00:00
|
|
|
uint32_t nItem = (uint32_t)pLVCD->nmcd.dwItemSpec;
|
|
|
|
uint32_t nSubItem = pLVCD->iSubItem;
|
2017-11-03 06:34:43 +00:00
|
|
|
|
|
|
|
uint32_t address = m_StartAddress + (nItem * 4);
|
2021-04-12 11:35:39 +00:00
|
|
|
uint32_t pc = (g_Reg != nullptr) ? g_Reg->m_PROGRAM_COUNTER : 0;
|
2017-11-03 06:34:43 +00:00
|
|
|
|
2022-07-18 08:31:00 +00:00
|
|
|
R4300iOpcode pcOpcode;
|
|
|
|
if (!m_Debugger->DebugLoad_VAddr(pc, pcOpcode.Value))
|
2017-12-12 10:14:49 +00:00
|
|
|
{
|
2022-07-18 08:31:00 +00:00
|
|
|
pcOpcode.Value = 0;
|
2017-12-12 10:14:49 +00:00
|
|
|
}
|
2017-11-03 06:34:43 +00:00
|
|
|
|
|
|
|
if (nSubItem == CCommandList::COL_ARROWS)
|
|
|
|
{
|
|
|
|
return CDRF_DODEFAULT;
|
|
|
|
}
|
|
|
|
|
2021-03-18 03:45:29 +00:00
|
|
|
if (nSubItem == CCommandList::COL_ADDRESS) // ADDR
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
2017-11-23 21:15:06 +00:00
|
|
|
CBreakpoints::BPSTATE bpState = m_Breakpoints->ExecutionBPExists(address);
|
2017-11-03 06:34:43 +00:00
|
|
|
|
|
|
|
if (bpState == CBreakpoints::BP_SET)
|
|
|
|
{
|
2021-03-18 03:45:29 +00:00
|
|
|
// Breakpoint
|
2017-11-03 06:34:43 +00:00
|
|
|
pLVCD->clrTextBk = RGB(0x44, 0x00, 0x00);
|
2022-09-26 02:31:54 +00:00
|
|
|
pLVCD->clrText = (address == pc && isDebugging()) ? RGB(0xFF, 0xFF, 0x00) : RGB(0xFF, 0xCC, 0xCC);
|
2017-11-03 06:34:43 +00:00
|
|
|
}
|
|
|
|
else if (bpState == CBreakpoints::BP_SET_TEMP)
|
|
|
|
{
|
2021-03-18 03:45:29 +00:00
|
|
|
// Breakpoint
|
2017-11-03 06:34:43 +00:00
|
|
|
pLVCD->clrTextBk = RGB(0x66, 0x44, 0x00);
|
2022-09-26 02:31:54 +00:00
|
|
|
pLVCD->clrText = (address == pc && isDebugging()) ? RGB(0xFF, 0xFF, 0x00) : RGB(0xFF, 0xEE, 0xCC);
|
2017-11-03 06:34:43 +00:00
|
|
|
}
|
2018-01-15 21:14:15 +00:00
|
|
|
else if (address == pc && isStepping())
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
2021-03-18 03:45:29 +00:00
|
|
|
// PC
|
2017-11-03 06:34:43 +00:00
|
|
|
pLVCD->clrTextBk = RGB(0x88, 0x88, 0x88);
|
|
|
|
pLVCD->clrText = RGB(0xFF, 0xFF, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-18 03:45:29 +00:00
|
|
|
// Default
|
2017-11-03 06:34:43 +00:00
|
|
|
pLVCD->clrTextBk = RGB(0xEE, 0xEE, 0xEE);
|
|
|
|
pLVCD->clrText = RGB(0x44, 0x44, 0x44);
|
|
|
|
}
|
|
|
|
return CDRF_DODEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
// (nSubItem == 1 || nSubItem == 2)
|
|
|
|
|
2021-03-18 03:45:29 +00:00
|
|
|
// Command and arguments
|
2017-11-03 06:34:43 +00:00
|
|
|
COpInfo OpInfo;
|
2022-09-21 05:16:07 +00:00
|
|
|
R4300iOpcode & OpCode = OpInfo.m_OpCode;
|
2022-07-18 08:31:00 +00:00
|
|
|
bool bAddrOkay = m_Debugger->DebugLoad_VAddr(address, OpCode.Value);
|
2017-11-03 06:34:43 +00:00
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
struct
|
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
COLORREF bg;
|
|
|
|
COLORREF fg;
|
|
|
|
} colors;
|
|
|
|
|
|
|
|
if (!bAddrOkay)
|
|
|
|
{
|
2022-09-21 05:16:07 +00:00
|
|
|
colors = {0xFFFFFF, 0xFF0000};
|
2017-11-03 06:34:43 +00:00
|
|
|
}
|
2018-01-15 21:14:15 +00:00
|
|
|
else if (address == pc && isStepping())
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
2022-09-21 05:16:07 +00:00
|
|
|
colors = {0xFFFFAA, 0x222200};
|
2017-11-03 06:34:43 +00:00
|
|
|
}
|
|
|
|
else if (IsOpEdited(address))
|
|
|
|
{
|
2022-09-21 05:16:07 +00:00
|
|
|
colors = {0xFFEEFF, 0xFF00FF};
|
2017-11-03 06:34:43 +00:00
|
|
|
}
|
|
|
|
else if (OpInfo.IsStackAlloc())
|
|
|
|
{
|
2022-09-21 05:16:07 +00:00
|
|
|
colors = {0xCCDDFF, 0x001144};
|
2017-11-03 06:34:43 +00:00
|
|
|
}
|
|
|
|
else if (OpInfo.IsStackFree())
|
|
|
|
{
|
2022-09-21 05:16:07 +00:00
|
|
|
colors = {0xFFDDDD, 0x440000};
|
2017-11-03 06:34:43 +00:00
|
|
|
}
|
|
|
|
else if (OpInfo.IsNOP())
|
|
|
|
{
|
2022-09-21 05:16:07 +00:00
|
|
|
colors = {0xFFFFFF, 0x888888};
|
2017-11-03 06:34:43 +00:00
|
|
|
}
|
|
|
|
else if (OpInfo.IsJump())
|
|
|
|
{
|
2022-09-21 05:16:07 +00:00
|
|
|
colors = {0xEEFFEE, 0x006600};
|
2017-11-03 06:34:43 +00:00
|
|
|
}
|
|
|
|
else if (OpInfo.IsBranch())
|
|
|
|
{
|
2022-09-21 05:16:07 +00:00
|
|
|
colors = {0xFFFFFF, 0x337700};
|
2017-11-03 06:34:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-21 05:16:07 +00:00
|
|
|
colors = {0xFFFFFF, 0x0000000};
|
2017-11-03 06:34:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Gray annotations
|
|
|
|
if (nSubItem == CCommandList::COL_SYMBOL)
|
|
|
|
{
|
|
|
|
if (m_bvAnnotatedLines[nItem])
|
|
|
|
{
|
|
|
|
colors.fg = 0x666666;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pLVCD->clrTextBk = _byteswap_ulong(colors.bg) >> 8;
|
|
|
|
pLVCD->clrText = _byteswap_ulong(colors.fg) >> 8;
|
|
|
|
|
2018-01-15 21:14:15 +00:00
|
|
|
if (!isStepping())
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
|
|
|
return CDRF_DODEFAULT;
|
|
|
|
}
|
|
|
|
|
2021-03-18 03:45:29 +00:00
|
|
|
// Color register usage
|
2021-05-18 11:51:36 +00:00
|
|
|
// TODO: localize to temporary register context (don't look before/after jumps and frame shifts)
|
2022-09-21 05:16:07 +00:00
|
|
|
COLORREF clrUsedRegister = RGB(0xF5, 0xF0, 0xFF); // Light purple
|
2021-03-18 03:45:29 +00:00
|
|
|
COLORREF clrAffectedRegister = RGB(0xFF, 0xF0, 0xFF); // Light pink
|
2017-11-03 06:34:43 +00:00
|
|
|
|
|
|
|
int pcUsedRegA = 0, pcUsedRegB = 0, pcChangedReg = 0;
|
|
|
|
int curUsedRegA = 0, curUsedRegB = 0, curChangedReg = 0;
|
|
|
|
|
|
|
|
if (pcOpcode.op == R4300i_SPECIAL)
|
|
|
|
{
|
|
|
|
pcUsedRegA = pcOpcode.rs;
|
|
|
|
pcUsedRegB = pcOpcode.rt;
|
|
|
|
pcChangedReg = pcOpcode.rd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pcUsedRegA = pcOpcode.rs;
|
|
|
|
pcChangedReg = pcOpcode.rt;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OpCode.op == R4300i_SPECIAL)
|
|
|
|
{
|
|
|
|
curUsedRegA = OpCode.rs;
|
|
|
|
curUsedRegB = OpCode.rt;
|
|
|
|
curChangedReg = OpCode.rd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
curUsedRegA = OpCode.rs;
|
|
|
|
curChangedReg = OpCode.rt;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (address < pc)
|
|
|
|
{
|
|
|
|
if (curChangedReg != 0 && (pcUsedRegA == curChangedReg || pcUsedRegB == curChangedReg))
|
|
|
|
{
|
|
|
|
pLVCD->clrTextBk = clrUsedRegister;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (address > pc)
|
|
|
|
{
|
|
|
|
if (pcChangedReg != 0 && (curUsedRegA == pcChangedReg || curUsedRegB == pcChangedReg))
|
|
|
|
{
|
|
|
|
pLVCD->clrTextBk = clrAffectedRegister;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CDRF_DODEFAULT;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnMeasureItem(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL & /*bHandled*/)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
if (wParam == IDC_CMD_LIST)
|
|
|
|
{
|
2017-11-21 21:13:11 +00:00
|
|
|
CClientDC dc(m_hWnd);
|
|
|
|
dc.SelectFont(GetFont());
|
|
|
|
TEXTMETRIC tm;
|
|
|
|
dc.GetTextMetrics(&tm);
|
|
|
|
|
|
|
|
m_RowHeight = tm.tmHeight + tm.tmExternalLeading;
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
MEASUREITEMSTRUCT * lpMeasureItem = (MEASUREITEMSTRUCT *)lParam;
|
2017-10-20 08:57:21 +00:00
|
|
|
lpMeasureItem->itemHeight = m_RowHeight;
|
2017-11-03 06:34:43 +00:00
|
|
|
}
|
|
|
|
return FALSE;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draw branch arrows
|
|
|
|
void CDebugCommandsView::DrawBranchArrows(HDC listDC)
|
|
|
|
{
|
2022-09-26 02:31:54 +00:00
|
|
|
COLORREF colors[] = {
|
|
|
|
RGB(240, 240, 240), // White
|
|
|
|
RGB(30, 135, 255), // Blue
|
|
|
|
RGB(255, 0, 200), // Pink
|
|
|
|
RGB(215, 155, 0), // Yellow
|
|
|
|
RGB(100, 180, 0), // Green
|
|
|
|
RGB(200, 100, 255), // Purple
|
|
|
|
RGB(120, 120, 120), // Gray
|
|
|
|
RGB(0, 220, 160), // Cyan
|
|
|
|
RGB(255, 100, 0), // Orange
|
|
|
|
RGB(255, 255, 0), // Yellow
|
|
|
|
};
|
2017-11-03 06:34:43 +00:00
|
|
|
|
|
|
|
int nColors = sizeof(colors) / sizeof(COLORREF);
|
|
|
|
|
|
|
|
CRect listRect;
|
|
|
|
m_CommandList.GetWindowRect(&listRect);
|
|
|
|
ScreenToClient(&listRect);
|
|
|
|
|
|
|
|
CRect headRect;
|
|
|
|
m_CommandList.GetHeader().GetWindowRect(&headRect);
|
|
|
|
ScreenToClient(&headRect);
|
|
|
|
|
|
|
|
int colWidth = m_CommandList.GetColumnWidth(CCommandList::COL_ARROWS);
|
|
|
|
|
|
|
|
int baseX = colWidth - 4;
|
|
|
|
int baseY = headRect.bottom + 7;
|
|
|
|
|
|
|
|
CRect paneRect;
|
|
|
|
paneRect.top = headRect.bottom;
|
|
|
|
paneRect.left = 0;
|
|
|
|
paneRect.right = colWidth;
|
|
|
|
paneRect.bottom = listRect.bottom;
|
|
|
|
|
|
|
|
COLORREF bgColor = RGB(30, 30, 30);
|
2017-11-21 21:13:11 +00:00
|
|
|
CBrush hBrushBg(CreateSolidBrush(bgColor));
|
2017-11-03 06:34:43 +00:00
|
|
|
FillRect(listDC, &paneRect, hBrushBg);
|
|
|
|
|
2017-11-23 21:15:06 +00:00
|
|
|
for (size_t i = 0; i < m_BranchArrows.size(); i++)
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
|
|
|
int colorIdx = i % nColors;
|
|
|
|
COLORREF color = colors[colorIdx];
|
|
|
|
|
|
|
|
BRANCHARROW arrow = m_BranchArrows[i];
|
|
|
|
|
|
|
|
int begX = baseX - arrow.startMargin * 3;
|
|
|
|
int endX = baseX - arrow.endMargin * 3;
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-10-20 08:57:21 +00:00
|
|
|
int begY = baseY + arrow.startPos * m_RowHeight;
|
|
|
|
int endY = baseY + arrow.endPos * m_RowHeight;
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-11-03 06:34:43 +00:00
|
|
|
bool bEndVisible = true;
|
|
|
|
|
|
|
|
if (endY < headRect.bottom)
|
|
|
|
{
|
|
|
|
endY = headRect.bottom + 1;
|
|
|
|
bEndVisible = false;
|
|
|
|
}
|
|
|
|
else if (endY > listRect.bottom)
|
|
|
|
{
|
|
|
|
endY = listRect.bottom - 2;
|
|
|
|
bEndVisible = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int marginX = baseX - (4 + arrow.margin * 3);
|
|
|
|
|
2021-03-18 03:45:29 +00:00
|
|
|
// Draw start pointer
|
2017-11-03 06:34:43 +00:00
|
|
|
SetPixel(listDC, begX + 0, begY - 1, color);
|
|
|
|
SetPixel(listDC, begX + 1, begY - 2, color);
|
|
|
|
SetPixel(listDC, begX + 0, begY + 1, color);
|
|
|
|
SetPixel(listDC, begX + 1, begY + 2, color);
|
|
|
|
|
2021-03-18 03:45:29 +00:00
|
|
|
// Draw outline
|
2017-11-21 21:13:11 +00:00
|
|
|
CPen hPenOutline(CreatePen(PS_SOLID, 3, bgColor));
|
2017-11-03 06:34:43 +00:00
|
|
|
SelectObject(listDC, hPenOutline);
|
2021-04-12 11:35:39 +00:00
|
|
|
MoveToEx(listDC, begX - 1, begY, nullptr);
|
2017-11-03 06:34:43 +00:00
|
|
|
LineTo(listDC, marginX, begY);
|
|
|
|
LineTo(listDC, marginX, endY);
|
|
|
|
if (bEndVisible)
|
|
|
|
{
|
|
|
|
LineTo(listDC, endX + 2, endY);
|
|
|
|
}
|
|
|
|
|
2021-03-18 03:45:29 +00:00
|
|
|
// Draw fill line
|
2017-11-21 21:13:11 +00:00
|
|
|
CPen hPen(CreatePen(PS_SOLID, 1, color));
|
2017-11-03 06:34:43 +00:00
|
|
|
SelectObject(listDC, hPen);
|
2021-04-12 11:35:39 +00:00
|
|
|
MoveToEx(listDC, begX - 1, begY, nullptr);
|
2017-11-03 06:34:43 +00:00
|
|
|
LineTo(listDC, marginX, begY);
|
|
|
|
LineTo(listDC, marginX, endY);
|
|
|
|
if (bEndVisible)
|
|
|
|
{
|
|
|
|
LineTo(listDC, endX + 2, endY);
|
|
|
|
}
|
|
|
|
|
2021-03-18 03:45:29 +00:00
|
|
|
// Draw end pointer
|
2017-11-03 06:34:43 +00:00
|
|
|
if (bEndVisible)
|
|
|
|
{
|
|
|
|
SetPixel(listDC, endX - 0, endY - 1, color);
|
|
|
|
SetPixel(listDC, endX - 1, endY - 2, color);
|
|
|
|
SetPixel(listDC, endX - 1, endY - 1, color);
|
|
|
|
SetPixel(listDC, endX - 0, endY + 1, color);
|
|
|
|
SetPixel(listDC, endX - 1, endY + 2, color);
|
|
|
|
SetPixel(listDC, endX - 1, endY + 1, color);
|
|
|
|
SetPixel(listDC, endX - 1, endY + 3, RGB(30, 30, 30));
|
|
|
|
SetPixel(listDC, endX - 1, endY - 3, RGB(30, 30, 30));
|
|
|
|
}
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugCommandsView::RefreshBreakpointList()
|
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
m_BreakpointList.ResetContent();
|
|
|
|
char rowStr[16];
|
2017-11-23 21:15:06 +00:00
|
|
|
|
|
|
|
CBreakpoints::breakpoints_t ReadBreakPoints = m_Breakpoints->ReadMem();
|
|
|
|
for (CBreakpoints::breakpoints_t::iterator itr = ReadBreakPoints.begin(); itr != ReadBreakPoints.end(); itr++)
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
2017-11-23 21:15:06 +00:00
|
|
|
sprintf(rowStr, "R %s%08X", itr->second ? "T " : "", itr->first);
|
2020-05-12 12:19:05 +00:00
|
|
|
int index = m_BreakpointList.AddString(stdstr(rowStr).ToUTF16().c_str());
|
2017-11-23 21:15:06 +00:00
|
|
|
m_BreakpointList.SetItemData(index, itr->first);
|
2017-11-03 06:34:43 +00:00
|
|
|
}
|
2017-11-23 21:15:06 +00:00
|
|
|
|
|
|
|
CBreakpoints::breakpoints_t WriteBreakPoints = m_Breakpoints->WriteMem();
|
|
|
|
for (CBreakpoints::breakpoints_t::iterator itr = WriteBreakPoints.begin(); itr != WriteBreakPoints.end(); itr++)
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
2017-11-23 21:15:06 +00:00
|
|
|
sprintf(rowStr, "W %s%08X", itr->second ? "T " : "", itr->first);
|
2020-05-12 12:19:05 +00:00
|
|
|
int index = m_BreakpointList.AddString(stdstr(rowStr).ToUTF16().c_str());
|
2017-11-23 21:15:06 +00:00
|
|
|
m_BreakpointList.SetItemData(index, itr->first);
|
2017-11-03 06:34:43 +00:00
|
|
|
}
|
2017-11-23 21:15:06 +00:00
|
|
|
|
|
|
|
CBreakpoints::breakpoints_t ExecutionBreakPoints = m_Breakpoints->Execution();
|
|
|
|
for (CBreakpoints::breakpoints_t::iterator itr = ExecutionBreakPoints.begin(); itr != ExecutionBreakPoints.end(); itr++)
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
2017-11-23 21:15:06 +00:00
|
|
|
sprintf(rowStr, "E %s%08X", itr->second ? "T " : "", itr->first);
|
2020-05-12 12:19:05 +00:00
|
|
|
int index = m_BreakpointList.AddString(stdstr(rowStr).ToUTF16().c_str());
|
2017-11-23 21:15:06 +00:00
|
|
|
m_BreakpointList.SetItemData(index, itr->first);
|
2017-11-03 06:34:43 +00:00
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugCommandsView::RemoveSelectedBreakpoints()
|
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
int nItem = m_BreakpointList.GetCurSel();
|
|
|
|
|
|
|
|
if (nItem == LB_ERR)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-12 12:19:05 +00:00
|
|
|
wchar_t itemText[32];
|
2017-11-03 06:34:43 +00:00
|
|
|
m_BreakpointList.GetText(nItem, itemText);
|
|
|
|
|
|
|
|
uint32_t address = m_BreakpointList.GetItemData(nItem);
|
|
|
|
|
|
|
|
switch (itemText[0])
|
|
|
|
{
|
2020-05-12 12:19:05 +00:00
|
|
|
case L'E':
|
2017-12-04 06:41:27 +00:00
|
|
|
m_Breakpoints->RemoveExecution(address);
|
2017-11-03 06:34:43 +00:00
|
|
|
break;
|
2020-05-12 12:19:05 +00:00
|
|
|
case L'W':
|
2017-11-03 06:34:43 +00:00
|
|
|
m_Breakpoints->WBPRemove(address);
|
|
|
|
break;
|
2020-05-12 12:19:05 +00:00
|
|
|
case L'R':
|
2017-11-03 06:34:43 +00:00
|
|
|
m_Breakpoints->RBPRemove(address);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefreshBreakpointList();
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugCommandsView::CPUSkip()
|
|
|
|
{
|
2018-01-17 11:36:28 +00:00
|
|
|
g_Settings->SaveBool(Debugger_SkipOp, true);
|
|
|
|
if (WaitingForStep())
|
|
|
|
{
|
|
|
|
m_StepEvent.Trigger();
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugCommandsView::CPUResume()
|
|
|
|
{
|
2018-01-15 21:14:15 +00:00
|
|
|
g_Settings->SaveBool(Debugger_SteppingOps, false);
|
2018-01-16 21:26:54 +00:00
|
|
|
if (WaitingForStep())
|
|
|
|
{
|
|
|
|
m_StepEvent.Trigger();
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2018-01-25 06:07:51 +00:00
|
|
|
void CDebugCommandsView::CPUStepOver()
|
|
|
|
{
|
2018-12-09 04:26:11 +00:00
|
|
|
COpInfo opInfo;
|
2022-07-18 08:31:00 +00:00
|
|
|
if (!m_Debugger->DebugLoad_VAddr(g_Reg->m_PROGRAM_COUNTER, opInfo.m_OpCode.Value))
|
2018-01-25 06:07:51 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opInfo.IsJAL())
|
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
// Put temp breakpoints on return address and resume
|
2018-01-25 06:07:51 +00:00
|
|
|
m_Breakpoints->AddExecution(g_Reg->m_PROGRAM_COUNTER + 8, true);
|
|
|
|
CPUResume();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-18 03:45:29 +00:00
|
|
|
// Normal step
|
2018-01-25 06:07:51 +00:00
|
|
|
if (WaitingForStep())
|
|
|
|
{
|
|
|
|
m_StepEvent.Trigger();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnBackButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-12-12 10:14:49 +00:00
|
|
|
if (m_HistoryIndex > 0)
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
2017-12-12 10:14:49 +00:00
|
|
|
m_HistoryIndex--;
|
2020-04-08 11:44:49 +00:00
|
|
|
m_AddressEdit.SetValue(m_History[m_HistoryIndex], DisplayMode::ZeroExtend);
|
2017-12-12 10:14:49 +00:00
|
|
|
ToggleHistoryButtons();
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnForwardButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2017-12-12 10:14:49 +00:00
|
|
|
{
|
|
|
|
if (m_History.size() > 0 && m_HistoryIndex < (int)m_History.size() - 1)
|
|
|
|
{
|
|
|
|
m_HistoryIndex++;
|
2020-04-08 11:44:49 +00:00
|
|
|
m_AddressEdit.SetValue(m_History[m_HistoryIndex], DisplayMode::ZeroExtend);
|
2017-12-12 10:14:49 +00:00
|
|
|
ToggleHistoryButtons();
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnViewPCButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2017-12-12 10:14:49 +00:00
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
if (g_Reg != nullptr && isStepping())
|
2017-12-12 10:14:49 +00:00
|
|
|
{
|
|
|
|
ShowAddress(g_Reg->m_PROGRAM_COUNTER, TRUE);
|
2017-11-03 06:34:43 +00:00
|
|
|
}
|
|
|
|
return FALSE;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnSymbolsButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2017-12-12 10:14:49 +00:00
|
|
|
{
|
2018-01-10 07:05:57 +00:00
|
|
|
m_Debugger->OpenSymbolsWindow();
|
2017-12-12 10:14:49 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnPopupmenuRunTo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2017-12-12 10:14:49 +00:00
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
// Add temp breakpoints and resume
|
2017-12-12 10:14:49 +00:00
|
|
|
m_Breakpoints->AddExecution(m_SelectedAddress, true);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnGoButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2017-12-12 10:14:49 +00:00
|
|
|
{
|
|
|
|
CPUResume();
|
|
|
|
m_AddressEdit.SetFocus();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnStepButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2017-12-12 10:14:49 +00:00
|
|
|
{
|
2018-01-16 21:26:54 +00:00
|
|
|
if (WaitingForStep())
|
|
|
|
{
|
|
|
|
m_StepEvent.Trigger();
|
|
|
|
}
|
2017-12-12 10:14:49 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnStepOverButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2018-01-25 06:07:51 +00:00
|
|
|
{
|
|
|
|
CPUStepOver();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnSkipButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2017-12-12 10:14:49 +00:00
|
|
|
{
|
|
|
|
CPUSkip();
|
|
|
|
m_AddressEdit.SetFocus();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnClearBPButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2017-12-12 10:14:49 +00:00
|
|
|
{
|
|
|
|
m_Breakpoints->BPClear();
|
|
|
|
RefreshBreakpointList();
|
|
|
|
ShowAddress(m_StartAddress, TRUE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnAddBPButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2017-12-12 10:14:49 +00:00
|
|
|
{
|
|
|
|
m_AddBreakpointDlg.DoModal(m_Debugger);
|
|
|
|
RefreshBreakpointList();
|
|
|
|
ShowAddress(m_StartAddress, TRUE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnRemoveBPButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2017-12-12 10:14:49 +00:00
|
|
|
{
|
|
|
|
RemoveSelectedBreakpoints();
|
|
|
|
ShowAddress(m_StartAddress, TRUE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnCopyTabRegistersButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2020-04-09 05:39:31 +00:00
|
|
|
{
|
|
|
|
m_RegisterTabs.CopyTabRegisters();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnCopyAllRegistersButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2020-04-09 05:39:31 +00:00
|
|
|
{
|
|
|
|
m_RegisterTabs.CopyAllRegisters();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnCancel(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2017-12-12 10:14:49 +00:00
|
|
|
{
|
|
|
|
EndDialog(0);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnPopupmenuEdit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2017-12-12 10:14:49 +00:00
|
|
|
{
|
|
|
|
BeginOpEdit(m_SelectedAddress);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnPopupmenuInsertNOP(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2017-12-12 10:14:49 +00:00
|
|
|
{
|
|
|
|
EditOp(m_SelectedAddress, 0x00000000);
|
|
|
|
ShowAddress(m_StartAddress, TRUE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnPopupmenuRestore(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2017-12-12 10:14:49 +00:00
|
|
|
{
|
|
|
|
RestoreOp(m_SelectedAddress);
|
|
|
|
ShowAddress(m_StartAddress, TRUE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnPopupmenuRestoreAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2017-12-12 10:14:49 +00:00
|
|
|
{
|
|
|
|
RestoreAllOps();
|
|
|
|
ShowAddress(m_StartAddress, TRUE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnPopupmenuAddSymbol(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2017-12-12 10:14:49 +00:00
|
|
|
{
|
2019-12-25 00:41:20 +00:00
|
|
|
m_AddSymbolDlg.DoModal(m_Debugger, m_SelectedAddress, SYM_CODE);
|
2017-12-12 10:14:49 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnPopupmenuFollowJump(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2017-12-12 10:14:49 +00:00
|
|
|
{
|
|
|
|
HistoryPushState();
|
|
|
|
ShowAddress(m_FollowAddress, TRUE);
|
|
|
|
HistoryPushState();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnPopupmenuViewMemory(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2017-12-12 10:14:49 +00:00
|
|
|
{
|
|
|
|
m_Debugger->Debug_ShowMemoryLocation(m_FollowAddress, true);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnPopupmenuToggleBP(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2017-12-12 10:14:49 +00:00
|
|
|
{
|
2020-12-17 16:50:09 +00:00
|
|
|
if (m_Breakpoints->ExecutionBPExists(m_SelectedAddress))
|
|
|
|
{
|
|
|
|
m_Breakpoints->RemoveExecution(m_SelectedAddress);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_Breakpoints->AddExecution(m_SelectedAddress);
|
|
|
|
}
|
2017-12-12 10:14:49 +00:00
|
|
|
ShowAddress(m_StartAddress, TRUE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnPopupmenuClearBP(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2017-12-12 10:14:49 +00:00
|
|
|
{
|
|
|
|
m_Breakpoints->EBPClear();
|
|
|
|
ShowAddress(m_StartAddress, TRUE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-08-18 05:08:22 +00:00
|
|
|
void CDebugCommandsView::BeginOpEdit(uint32_t address)
|
|
|
|
{
|
2018-12-09 04:26:11 +00:00
|
|
|
uint32_t opcode;
|
2019-12-25 00:41:20 +00:00
|
|
|
if (!m_Debugger->DebugLoad_VAddr(address, opcode))
|
2018-12-09 04:26:11 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-03 06:34:43 +00:00
|
|
|
CRect listRect;
|
|
|
|
m_CommandList.GetWindowRect(&listRect);
|
|
|
|
ScreenToClient(&listRect);
|
|
|
|
|
|
|
|
m_bEditing = true;
|
|
|
|
//ShowAddress(address, FALSE);
|
|
|
|
int nItem = (address - m_StartAddress) / 4;
|
|
|
|
|
|
|
|
CRect itemRect;
|
|
|
|
m_CommandList.GetSubItemRect(nItem, CCommandList::COL_COMMAND, 0, &itemRect);
|
|
|
|
//itemRect.bottom += 0;
|
|
|
|
itemRect.left += listRect.left + 3;
|
|
|
|
itemRect.right += 100;
|
2022-09-21 05:16:07 +00:00
|
|
|
|
2017-11-03 06:34:43 +00:00
|
|
|
m_OpEdit.ShowWindow(SW_SHOW);
|
|
|
|
m_OpEdit.MoveWindow(&itemRect);
|
|
|
|
m_OpEdit.BringWindowToTop();
|
2022-07-18 08:31:00 +00:00
|
|
|
m_OpEdit.SetWindowText(stdstr(R4300iInstruction(address, opcode).NameAndParam()).ToUTF16().c_str());
|
2017-11-03 06:34:43 +00:00
|
|
|
m_OpEdit.SetFocus();
|
|
|
|
m_OpEdit.SetSelAll();
|
|
|
|
|
|
|
|
m_CommandList.RedrawWindow();
|
|
|
|
m_OpEdit.RedrawWindow();
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugCommandsView::EndOpEdit()
|
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
m_bEditing = false;
|
2020-05-12 12:19:05 +00:00
|
|
|
m_OpEdit.SetWindowText(L"");
|
2017-11-03 06:34:43 +00:00
|
|
|
m_OpEdit.ShowWindow(SW_HIDE);
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnAddrChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2018-07-30 13:45:23 +00:00
|
|
|
if (!m_Attached)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-11-03 06:34:43 +00:00
|
|
|
if (m_bIgnoreAddrChange)
|
|
|
|
{
|
|
|
|
m_bIgnoreAddrChange = false;
|
|
|
|
return 0;
|
|
|
|
}
|
2019-01-16 20:06:33 +00:00
|
|
|
|
|
|
|
uint32_t address = m_AddressEdit.GetValue();
|
|
|
|
ShowAddress(address, TRUE, TRUE);
|
|
|
|
|
2017-11-03 06:34:43 +00:00
|
|
|
return 0;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnPCChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2018-07-30 13:45:23 +00:00
|
|
|
if (!m_Attached)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-11-03 06:34:43 +00:00
|
|
|
if (m_bIgnorePCChange)
|
|
|
|
{
|
|
|
|
m_bIgnorePCChange = false;
|
|
|
|
return 0;
|
|
|
|
}
|
2021-04-12 11:35:39 +00:00
|
|
|
if (g_Reg != nullptr && isStepping())
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
|
|
|
g_Reg->m_PROGRAM_COUNTER = m_PCEdit.GetValue();
|
|
|
|
}
|
|
|
|
return 0;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnCommandListClicked(NMHDR * /*pNMHDR*/)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
EndOpEdit();
|
|
|
|
return 0;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnCommandListDblClicked(NMHDR * pNMHDR)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
// Set PC breakpoint
|
2022-09-21 05:16:07 +00:00
|
|
|
NMITEMACTIVATE * pIA = reinterpret_cast<NMITEMACTIVATE *>(pNMHDR);
|
2017-11-03 06:34:43 +00:00
|
|
|
int nItem = pIA->iItem;
|
|
|
|
|
|
|
|
uint32_t address = m_StartAddress + nItem * 4;
|
2017-11-23 21:15:06 +00:00
|
|
|
if (m_Breakpoints->ExecutionBPExists(address))
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
2017-12-04 06:41:27 +00:00
|
|
|
m_Breakpoints->RemoveExecution(address);
|
2017-11-03 06:34:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-12-04 06:41:27 +00:00
|
|
|
m_Breakpoints->AddExecution(address);
|
2017-11-03 06:34:43 +00:00
|
|
|
}
|
|
|
|
// Cancel blue highlight
|
|
|
|
m_AddressEdit.SetFocus();
|
|
|
|
RefreshBreakpointList();
|
|
|
|
|
|
|
|
return 0;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnCommandListRightClicked(NMHDR * pNMHDR)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
EndOpEdit();
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
NMITEMACTIVATE * pIA = reinterpret_cast<NMITEMACTIVATE *>(pNMHDR);
|
2017-11-03 06:34:43 +00:00
|
|
|
int nItem = pIA->iItem;
|
|
|
|
|
|
|
|
uint32_t address = m_StartAddress + nItem * 4;
|
|
|
|
m_SelectedAddress = address;
|
|
|
|
|
2022-07-18 08:31:00 +00:00
|
|
|
if (!m_Debugger->DebugLoad_VAddr(m_SelectedAddress, m_SelectedOpCode.Value))
|
2018-12-09 04:26:11 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-04-12 11:35:39 +00:00
|
|
|
HMENU hMenu = LoadMenu(GetModuleHandle(nullptr), MAKEINTRESOURCE(IDR_OP_POPUP));
|
2017-11-03 06:34:43 +00:00
|
|
|
HMENU hPopupMenu = GetSubMenu(hMenu, 0);
|
2022-09-21 05:16:07 +00:00
|
|
|
|
2017-11-03 06:34:43 +00:00
|
|
|
if (m_SelectedOpInfo.IsStaticJump())
|
|
|
|
{
|
|
|
|
m_FollowAddress = (m_SelectedAddress & 0xF0000000) | (m_SelectedOpCode.target * 4);
|
|
|
|
}
|
|
|
|
else if (m_SelectedOpInfo.IsBranch())
|
|
|
|
{
|
|
|
|
m_FollowAddress = m_SelectedAddress + ((int16_t)m_SelectedOpCode.offset + 1) * 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EnableMenuItem(hPopupMenu, ID_POPUPMENU_FOLLOWJUMP, MF_DISABLED | MF_GRAYED);
|
|
|
|
}
|
|
|
|
|
2018-03-18 01:14:52 +00:00
|
|
|
if (m_SelectedOpInfo.IsLoadStoreCommand())
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
|
|
|
m_FollowAddress = g_Reg->m_GPR[m_SelectedOpCode.base].UW[0] + (int16_t)m_SelectedOpCode.offset;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EnableMenuItem(hPopupMenu, ID_POPUPMENU_VIEWMEMORY, MF_DISABLED | MF_GRAYED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsOpEdited(m_SelectedAddress))
|
|
|
|
{
|
|
|
|
EnableMenuItem(hPopupMenu, ID_POPUPMENU_RESTORE, MF_DISABLED | MF_GRAYED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_EditedOps.size() == 0)
|
|
|
|
{
|
|
|
|
EnableMenuItem(hPopupMenu, ID_POPUPMENU_RESTOREALL, MF_DISABLED | MF_GRAYED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_SelectedOpInfo.IsNOP())
|
|
|
|
{
|
|
|
|
EnableMenuItem(hPopupMenu, ID_POPUPMENU_INSERTNOP, MF_DISABLED | MF_GRAYED);
|
|
|
|
}
|
|
|
|
|
2017-11-23 21:15:06 +00:00
|
|
|
if (m_Breakpoints->Execution().size() == 0)
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
|
|
|
EnableMenuItem(hPopupMenu, ID_POPUPMENU_CLEARBPS, MF_DISABLED | MF_GRAYED);
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-11-03 06:34:43 +00:00
|
|
|
POINT mouse;
|
|
|
|
GetCursorPos(&mouse);
|
|
|
|
|
2021-04-12 11:35:39 +00:00
|
|
|
TrackPopupMenu(hPopupMenu, TPM_LEFTALIGN, mouse.x, mouse.y, 0, m_hWnd, nullptr);
|
2017-11-03 06:34:43 +00:00
|
|
|
|
|
|
|
DestroyMenu(hMenu);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnListBoxClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
if (wID == IDC_BP_LIST)
|
|
|
|
{
|
|
|
|
int index = m_BreakpointList.GetCaretIndex();
|
|
|
|
uint32_t address = m_BreakpointList.GetItemData(index);
|
|
|
|
int len = m_BreakpointList.GetTextLen(index);
|
2021-04-22 00:00:27 +00:00
|
|
|
std::wstring rowText;
|
|
|
|
rowText.resize(len);
|
|
|
|
|
|
|
|
m_BreakpointList.GetText(index, (wchar_t *)rowText.data());
|
|
|
|
if (rowText[0] == L'E')
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
|
|
|
ShowAddress(address, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_Debugger->Debug_ShowMemoryLocation(address, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnActivate(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/)
|
2018-02-05 20:04:20 +00:00
|
|
|
{
|
2018-07-30 13:45:23 +00:00
|
|
|
if (!m_Attached)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2018-02-19 18:11:34 +00:00
|
|
|
if (LOWORD(wParam) != WA_INACTIVE)
|
2018-02-05 20:04:20 +00:00
|
|
|
{
|
|
|
|
ShowAddress(m_StartAddress, TRUE);
|
|
|
|
RefreshBreakpointList();
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-01-14 07:06:01 +00:00
|
|
|
void CDebugCommandsView::RedrawCommandsAndRegisters()
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
CRect listRect;
|
|
|
|
m_CommandList.GetWindowRect(listRect);
|
|
|
|
|
|
|
|
CRect headRect;
|
|
|
|
CHeaderCtrl listHead = m_CommandList.GetHeader();
|
|
|
|
listHead.GetWindowRect(&headRect);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-11-03 06:34:43 +00:00
|
|
|
int rowsHeight = listRect.Height() - headRect.Height();
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-10-20 08:57:21 +00:00
|
|
|
int nRows = (rowsHeight / m_RowHeight);
|
2017-11-03 06:34:43 +00:00
|
|
|
|
|
|
|
if (m_CommandListRows != nRows)
|
|
|
|
{
|
|
|
|
m_CommandListRows = nRows;
|
|
|
|
ShowAddress(m_StartAddress, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_RegisterTabs.RedrawCurrentTab();
|
|
|
|
|
2021-03-18 03:45:29 +00:00
|
|
|
// Fix command list header
|
2017-11-03 06:34:43 +00:00
|
|
|
listHead.ResizeClient(listRect.Width(), headRect.Height());
|
2019-01-14 07:06:01 +00:00
|
|
|
}
|
2017-11-03 06:34:43 +00:00
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnSizing(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
|
2019-01-14 07:06:01 +00:00
|
|
|
{
|
|
|
|
RedrawCommandsAndRegisters();
|
2017-11-03 06:34:43 +00:00
|
|
|
return FALSE;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnScroll(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
WORD type = LOWORD(wParam);
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case SB_LINEUP:
|
2018-01-16 21:26:54 +00:00
|
|
|
ShowAddress(m_StartAddress - 4, TRUE);
|
2017-11-03 06:34:43 +00:00
|
|
|
break;
|
|
|
|
case SB_LINEDOWN:
|
2018-01-16 21:26:54 +00:00
|
|
|
ShowAddress(m_StartAddress + 4, TRUE);
|
2017-11-03 06:34:43 +00:00
|
|
|
break;
|
|
|
|
case SB_THUMBTRACK:
|
|
|
|
{
|
|
|
|
//int scrollPos = HIWORD(wParam);
|
|
|
|
//ShowAddress(m_StartAddress + (scrollPos - 50) * 4, TRUE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2018-01-16 21:26:54 +00:00
|
|
|
void CDebugCommandsView::WaitingForStepChanged(void)
|
|
|
|
{
|
|
|
|
if (WaitingForStep())
|
|
|
|
{
|
|
|
|
ShowAddress(g_Reg->m_PROGRAM_COUNTER, false);
|
|
|
|
m_Debugger->Debug_RefreshStackWindow();
|
|
|
|
m_Debugger->Debug_RefreshStackTraceWindow();
|
|
|
|
m_StepButton.EnableWindow(true);
|
2018-01-25 06:07:51 +00:00
|
|
|
m_StepOverButton.EnableWindow(true);
|
2018-01-16 21:26:54 +00:00
|
|
|
m_GoButton.EnableWindow(true);
|
|
|
|
m_AddressEdit.SetFocus();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_StepButton.EnableWindow(false);
|
2018-01-25 06:07:51 +00:00
|
|
|
m_StepOverButton.EnableWindow(false);
|
2018-01-16 21:26:54 +00:00
|
|
|
m_GoButton.EnableWindow(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugCommandsView::SteppingOpsChanged(void)
|
|
|
|
{
|
|
|
|
if (!g_Settings->LoadBool(Debugger_SteppingOps))
|
|
|
|
{
|
|
|
|
m_Debugger->Debug_RefreshStackWindow();
|
|
|
|
m_Debugger->Debug_RefreshStackTraceWindow();
|
|
|
|
m_RegisterTabs.SetColorsEnabled(false);
|
|
|
|
m_RegisterTabs.RefreshEdits();
|
|
|
|
ShowAddress(m_StartAddress, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-18 05:08:22 +00:00
|
|
|
void CDebugCommandsView::Reset()
|
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
ClearEditedOps();
|
|
|
|
m_History.clear();
|
|
|
|
ToggleHistoryButtons();
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugCommandsView::ClearEditedOps()
|
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
m_EditedOps.clear();
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL CDebugCommandsView::IsOpEdited(uint32_t address)
|
|
|
|
{
|
2017-11-23 21:15:06 +00:00
|
|
|
for (size_t i = 0; i < m_EditedOps.size(); i++)
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
|
|
|
if (m_EditedOps[i].address == address)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2020-12-17 19:30:28 +00:00
|
|
|
void CDebugCommandsView::EditOp(uint32_t address, uint32_t op, bool bRefresh)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
uint32_t currentOp;
|
2019-12-25 00:41:20 +00:00
|
|
|
if (!m_Debugger->DebugLoad_VAddr(address, currentOp))
|
2018-12-09 04:26:11 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-11-03 06:34:43 +00:00
|
|
|
if (currentOp == op)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2019-12-25 00:41:20 +00:00
|
|
|
m_Debugger->DebugStore_VAddr(address, op);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-11-03 06:34:43 +00:00
|
|
|
if (!IsOpEdited(address))
|
|
|
|
{
|
2022-09-21 05:16:07 +00:00
|
|
|
m_EditedOps.push_back({address, currentOp});
|
2017-11-03 06:34:43 +00:00
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2020-12-17 19:30:28 +00:00
|
|
|
if (bRefresh)
|
|
|
|
{
|
|
|
|
ShowAddress(m_StartAddress, TRUE);
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugCommandsView::RestoreOp(uint32_t address)
|
|
|
|
{
|
2017-11-23 21:15:06 +00:00
|
|
|
for (size_t i = 0; i < m_EditedOps.size(); i++)
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
|
|
|
if (m_EditedOps[i].address == address)
|
|
|
|
{
|
2019-12-25 00:41:20 +00:00
|
|
|
m_Debugger->DebugStore_VAddr(m_EditedOps[i].address, m_EditedOps[i].originalOp);
|
2017-11-03 06:34:43 +00:00
|
|
|
m_EditedOps.erase(m_EditedOps.begin() + i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugCommandsView::RestoreAllOps()
|
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
int lastIndex = m_EditedOps.size() - 1;
|
|
|
|
for (int i = lastIndex; i >= 0; i--)
|
|
|
|
{
|
2019-12-25 00:41:20 +00:00
|
|
|
m_Debugger->DebugStore_VAddr(m_EditedOps[i].address, m_EditedOps[i].originalOp);
|
2017-11-03 06:34:43 +00:00
|
|
|
m_EditedOps.erase(m_EditedOps.begin() + i);
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugCommandsView::ShowPIRegTab()
|
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
m_RegisterTabs.SetCurSel(2);
|
|
|
|
m_RegisterTabs.ShowTab(2);
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnRegisterTabChange(NMHDR * /*pNMHDR*/)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
int nPage = m_RegisterTabs.GetCurSel();
|
|
|
|
m_RegisterTabs.ShowTab(nPage);
|
|
|
|
m_RegisterTabs.RedrawCurrentTab();
|
|
|
|
m_RegisterTabs.RedrawWindow();
|
|
|
|
return FALSE;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebugCommandsView::ToggleHistoryButtons()
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
if (m_BackButton.m_hWnd != nullptr)
|
2017-09-13 10:52:18 +00:00
|
|
|
{
|
|
|
|
m_BackButton.EnableWindow(m_History.size() != 0 && m_HistoryIndex > 0 ? TRUE : FALSE);
|
|
|
|
}
|
|
|
|
|
2021-04-12 11:35:39 +00:00
|
|
|
if (m_ForwardButton.m_hWnd != nullptr)
|
2017-09-13 10:52:18 +00:00
|
|
|
{
|
2017-12-12 10:14:49 +00:00
|
|
|
m_ForwardButton.EnableWindow(m_History.size() != 0 && m_HistoryIndex < (int)m_History.size() - 1 ? TRUE : FALSE);
|
2017-09-13 10:52:18 +00:00
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Opcode editor
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnOpEditKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & bHandled)
|
2020-12-17 19:30:28 +00:00
|
|
|
{
|
|
|
|
if (wParam == VK_UP)
|
|
|
|
{
|
|
|
|
m_SelectedAddress -= 4;
|
|
|
|
BeginOpEdit(m_SelectedAddress);
|
|
|
|
bHandled = TRUE;
|
|
|
|
}
|
|
|
|
else if (wParam == VK_DOWN)
|
|
|
|
{
|
|
|
|
m_SelectedAddress += 4;
|
|
|
|
BeginOpEdit(m_SelectedAddress);
|
|
|
|
bHandled = TRUE;
|
|
|
|
}
|
|
|
|
else if (wParam == VK_RETURN)
|
|
|
|
{
|
|
|
|
uint32_t op;
|
2021-04-20 02:56:16 +00:00
|
|
|
bool bValid = CAssembler::AssembleLine(GetCWindowText(m_OpEdit).c_str(), &op, m_SelectedAddress);
|
2020-12-17 19:30:28 +00:00
|
|
|
if (bValid)
|
|
|
|
{
|
|
|
|
m_OpEdit.SetWindowText(L"");
|
|
|
|
EditOp(m_SelectedAddress, op);
|
|
|
|
m_SelectedAddress += 4;
|
|
|
|
BeginOpEdit(m_SelectedAddress);
|
|
|
|
}
|
|
|
|
bHandled = TRUE;
|
|
|
|
}
|
|
|
|
else if (wParam == VK_ESCAPE)
|
|
|
|
{
|
|
|
|
EndOpEdit();
|
|
|
|
bHandled = TRUE;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CDebugCommandsView::OnOpEditChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
|
2020-12-17 19:30:28 +00:00
|
|
|
{
|
2021-03-18 03:45:29 +00:00
|
|
|
// Handle multiline input
|
2021-04-20 02:56:16 +00:00
|
|
|
std::string text = GetCWindowText(m_OpEdit);
|
|
|
|
if (strchr(text.c_str(), '\n') == nullptr)
|
2020-12-17 19:30:28 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
EndOpEdit();
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
for (size_t i = 0, n = text.size(); i < n; i++)
|
2020-12-17 19:30:28 +00:00
|
|
|
{
|
|
|
|
if (text[i] == '\r')
|
|
|
|
{
|
|
|
|
text[i] = '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 02:56:16 +00:00
|
|
|
char * tokctx;
|
|
|
|
char * line = strtok_s((char *)text.c_str(), "\n", &tokctx);
|
2020-12-17 19:30:28 +00:00
|
|
|
|
2021-04-12 11:35:39 +00:00
|
|
|
while (line != nullptr)
|
2020-12-17 19:30:28 +00:00
|
|
|
{
|
2021-04-20 02:56:16 +00:00
|
|
|
if (strlen(line) != 0)
|
2020-12-17 19:30:28 +00:00
|
|
|
{
|
|
|
|
uint32_t op;
|
2021-04-20 02:56:16 +00:00
|
|
|
bool bValid = CAssembler::AssembleLine(line, &op, m_SelectedAddress);
|
2020-12-17 19:30:28 +00:00
|
|
|
|
|
|
|
if (bValid)
|
|
|
|
{
|
|
|
|
EditOp(m_SelectedAddress, op, false);
|
|
|
|
m_SelectedAddress += 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ShowAddress(m_StartAddress, TRUE);
|
|
|
|
BeginOpEdit(m_SelectedAddress);
|
2021-04-20 02:56:16 +00:00
|
|
|
m_OpEdit.SetWindowText(stdstr(line).ToUTF16().c_str());
|
2020-12-17 19:30:28 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 02:56:16 +00:00
|
|
|
line = strtok_s(nullptr, "\n", &tokctx);
|
2020-12-17 19:30:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ShowAddress(m_StartAddress, TRUE);
|
|
|
|
BeginOpEdit(m_SelectedAddress);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CEditOp::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
if (m_CommandsWindow == nullptr)
|
2017-11-03 06:34:43 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-12-17 19:30:28 +00:00
|
|
|
return m_CommandsWindow->OnOpEditKeyDown(uMsg, wParam, lParam, bHandled);
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
void CEditOp::SetCommandsWindow(CDebugCommandsView * commandsWindow)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
m_CommandsWindow = commandsWindow;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL CEditOp::Attach(HWND hWndNew)
|
|
|
|
{
|
2017-11-03 06:34:43 +00:00
|
|
|
return SubclassWindow(hWndNew);
|
2021-03-18 03:45:29 +00:00
|
|
|
}
|