2016-01-27 09:11:59 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "DebuggerUI.h"
|
2017-08-18 05:08:22 +00:00
|
|
|
#include "ScriptHook.h"
|
|
|
|
|
2019-01-14 09:18:43 +00:00
|
|
|
#include "CPULog.h"
|
2017-08-18 05:08:22 +00:00
|
|
|
#include "DMALog.h"
|
|
|
|
#include "Symbols.h"
|
2016-01-27 09:11:59 +00:00
|
|
|
|
|
|
|
CPj64Module _Module;
|
|
|
|
|
2017-06-18 23:08:35 +00:00
|
|
|
CDebuggerUI::CDebuggerUI() :
|
2016-01-27 09:11:59 +00:00
|
|
|
m_MemoryDump(NULL),
|
|
|
|
m_MemoryView(NULL),
|
|
|
|
m_MemorySearch(NULL),
|
2017-08-18 05:08:22 +00:00
|
|
|
m_DebugTLB(NULL),
|
|
|
|
m_CommandsView(NULL),
|
2017-09-13 12:00:53 +00:00
|
|
|
m_Scripts(NULL),
|
|
|
|
m_Symbols(NULL),
|
|
|
|
m_Breakpoints(NULL),
|
|
|
|
m_ScriptSystem(NULL),
|
|
|
|
m_StackTrace(NULL),
|
|
|
|
m_StackView(NULL),
|
|
|
|
m_DMALogView(NULL),
|
2019-01-14 09:18:43 +00:00
|
|
|
m_CPULogView(NULL),
|
2019-01-17 09:34:24 +00:00
|
|
|
m_ExcBreakpoints(NULL),
|
2018-01-16 21:26:54 +00:00
|
|
|
m_DMALog(NULL),
|
2019-01-14 09:18:43 +00:00
|
|
|
m_CPULog(NULL),
|
2019-12-25 00:41:20 +00:00
|
|
|
m_SymbolTable(NULL),
|
2018-01-16 21:26:54 +00:00
|
|
|
m_StepEvent(false)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
g_Debugger = this;
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
m_Breakpoints = new CBreakpoints();
|
|
|
|
m_ScriptSystem = new CScriptSystem(this);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-09-13 12:00:53 +00:00
|
|
|
m_DMALog = new CDMALog();
|
2019-01-14 09:18:43 +00:00
|
|
|
m_CPULog = new CCPULog();
|
2019-12-25 00:41:20 +00:00
|
|
|
m_SymbolTable = new CSymbolTable(this);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2017-06-18 23:08:35 +00:00
|
|
|
g_Settings->RegisterChangeCB(GameRunning_InReset, this, (CSettings::SettingChangedFunc)GameReset);
|
2018-01-18 12:25:36 +00:00
|
|
|
g_Settings->RegisterChangeCB(Debugger_SteppingOps, this, (CSettings::SettingChangedFunc)SteppingOpsChanged);
|
2019-04-03 18:56:45 +00:00
|
|
|
g_Settings->RegisterChangeCB(GameRunning_CPU_Running, this, (CSettings::SettingChangedFunc)GameCpuRunningChanged);
|
|
|
|
g_Settings->RegisterChangeCB(Game_GameName, this, (CSettings::SettingChangedFunc)GameNameChanged);
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
2017-06-18 23:08:35 +00:00
|
|
|
CDebuggerUI::~CDebuggerUI(void)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
2018-01-18 12:25:36 +00:00
|
|
|
g_Settings->UnregisterChangeCB(Debugger_SteppingOps, this, (CSettings::SettingChangedFunc)SteppingOpsChanged);
|
2017-06-18 23:08:35 +00:00
|
|
|
g_Settings->UnregisterChangeCB(GameRunning_InReset, this, (CSettings::SettingChangedFunc)GameReset);
|
2019-04-03 18:56:45 +00:00
|
|
|
g_Settings->RegisterChangeCB(GameRunning_CPU_Running, this, (CSettings::SettingChangedFunc)GameCpuRunningChanged);
|
|
|
|
g_Settings->UnregisterChangeCB(Game_GameName, this, (CSettings::SettingChangedFunc)GameNameChanged);
|
2016-01-27 09:11:59 +00:00
|
|
|
Debug_Reset();
|
2017-09-13 12:00:53 +00:00
|
|
|
delete m_MemoryView;
|
|
|
|
delete m_CommandsView;
|
|
|
|
delete m_Scripts;
|
|
|
|
delete m_ScriptSystem;
|
|
|
|
delete m_Breakpoints;
|
|
|
|
delete m_Symbols;
|
|
|
|
delete m_MemorySearch;
|
|
|
|
delete m_StackTrace;
|
|
|
|
delete m_DMALogView;
|
2019-01-14 09:18:43 +00:00
|
|
|
delete m_CPULogView;
|
2019-01-17 09:34:24 +00:00
|
|
|
delete m_ExcBreakpoints;
|
2017-09-13 12:00:53 +00:00
|
|
|
delete m_DMALog;
|
2019-01-14 09:18:43 +00:00
|
|
|
delete m_CPULog;
|
2019-12-25 00:41:20 +00:00
|
|
|
delete m_SymbolTable;
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
2018-01-18 12:25:36 +00:00
|
|
|
void CDebuggerUI::SteppingOpsChanged(CDebuggerUI * _this)
|
|
|
|
{
|
|
|
|
if (g_Settings->LoadBool(Debugger_SteppingOps))
|
|
|
|
{
|
|
|
|
_this->OpenCommandWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-03 18:56:45 +00:00
|
|
|
void CDebuggerUI::GameCpuRunningChanged(CDebuggerUI * _this)
|
|
|
|
{
|
|
|
|
if (!g_Settings->LoadBool(GameRunning_CPU_Running))
|
|
|
|
{
|
|
|
|
if (_this->m_MemorySearch)
|
|
|
|
{
|
|
|
|
_this->m_MemorySearch->GameReset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDebuggerUI::GameNameChanged(CDebuggerUI * _this)
|
|
|
|
{
|
|
|
|
if (_this->m_MemorySearch)
|
|
|
|
{
|
|
|
|
_this->m_MemorySearch->GameReset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-18 23:08:35 +00:00
|
|
|
void CDebuggerUI::GameReset(CDebuggerUI * _this)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (!g_Settings->LoadBool(GameRunning_InReset))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_this->m_CommandsView)
|
|
|
|
{
|
|
|
|
_this->m_CommandsView->Reset();
|
|
|
|
}
|
|
|
|
|
2019-04-02 19:16:39 +00:00
|
|
|
if (_this->m_DMALogView)
|
2017-09-13 12:00:53 +00:00
|
|
|
{
|
2019-04-02 19:16:39 +00:00
|
|
|
_this->m_DMALogView->RefreshDMALogWindow(true);
|
2017-09-13 12:00:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_this->m_StackTrace)
|
|
|
|
{
|
|
|
|
_this->m_StackTrace->ClearEntries();
|
|
|
|
}
|
|
|
|
|
2019-12-25 00:41:20 +00:00
|
|
|
if (_this->m_SymbolTable)
|
|
|
|
{
|
|
|
|
_this->m_SymbolTable->Load();
|
|
|
|
}
|
2017-09-13 12:00:53 +00:00
|
|
|
|
|
|
|
if (_this->m_Symbols)
|
|
|
|
{
|
|
|
|
_this->m_Symbols->Refresh();
|
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
2017-06-18 23:08:35 +00:00
|
|
|
void CDebuggerUI::Debug_Reset(void)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
if (m_MemoryDump)
|
|
|
|
{
|
|
|
|
m_MemoryDump->HideWindow();
|
|
|
|
delete m_MemoryDump;
|
|
|
|
m_MemoryDump = NULL;
|
|
|
|
}
|
|
|
|
if (m_MemorySearch)
|
|
|
|
{
|
|
|
|
m_MemorySearch->HideWindow();
|
|
|
|
delete m_MemorySearch;
|
|
|
|
m_MemorySearch = NULL;
|
|
|
|
}
|
|
|
|
if (m_DebugTLB)
|
|
|
|
{
|
|
|
|
m_DebugTLB->HideWindow();
|
|
|
|
delete m_DebugTLB;
|
|
|
|
m_DebugTLB = NULL;
|
|
|
|
}
|
2017-09-13 12:00:53 +00:00
|
|
|
if (m_MemoryView)
|
|
|
|
{
|
|
|
|
m_MemoryView->HideWindow();
|
|
|
|
delete m_MemoryView;
|
|
|
|
m_MemoryView = NULL;
|
|
|
|
}
|
|
|
|
if (m_CommandsView)
|
|
|
|
{
|
|
|
|
m_CommandsView->HideWindow();
|
|
|
|
delete m_CommandsView;
|
|
|
|
m_CommandsView = NULL;
|
|
|
|
}
|
|
|
|
if (m_Scripts)
|
|
|
|
{
|
|
|
|
m_Scripts->HideWindow();
|
|
|
|
delete m_Scripts;
|
|
|
|
m_Scripts = NULL;
|
|
|
|
}
|
|
|
|
if (m_Symbols)
|
|
|
|
{
|
|
|
|
m_Symbols->HideWindow();
|
|
|
|
delete m_Symbols;
|
|
|
|
m_Symbols = NULL;
|
|
|
|
}
|
|
|
|
if (m_DMALogView)
|
|
|
|
{
|
|
|
|
m_DMALogView->HideWindow();
|
|
|
|
delete m_DMALogView;
|
|
|
|
m_DMALogView = NULL;
|
|
|
|
}
|
2019-01-14 09:18:43 +00:00
|
|
|
if (m_CPULogView)
|
|
|
|
{
|
|
|
|
m_CPULogView->HideWindow();
|
|
|
|
delete m_CPULogView;
|
|
|
|
m_CPULogView = NULL;
|
|
|
|
}
|
2017-09-13 12:00:53 +00:00
|
|
|
if (m_StackTrace)
|
|
|
|
{
|
|
|
|
m_StackTrace->HideWindow();
|
|
|
|
delete m_StackTrace;
|
|
|
|
m_StackTrace = NULL;
|
|
|
|
}
|
|
|
|
if (m_StackView)
|
|
|
|
{
|
|
|
|
m_StackView->HideWindow();
|
|
|
|
delete m_StackView;
|
|
|
|
m_StackView = NULL;
|
|
|
|
}
|
2019-01-17 09:34:24 +00:00
|
|
|
if (m_ExcBreakpoints)
|
|
|
|
{
|
|
|
|
m_ExcBreakpoints->HideWindow();
|
|
|
|
delete m_ExcBreakpoints;
|
|
|
|
m_ExcBreakpoints = NULL;
|
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 07:05:57 +00:00
|
|
|
void CDebuggerUI::OpenMemoryDump()
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
if (g_MMU == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_MemoryDump == NULL)
|
|
|
|
{
|
|
|
|
m_MemoryDump = new CDumpMemory(this);
|
|
|
|
}
|
|
|
|
if (m_MemoryDump)
|
|
|
|
{
|
|
|
|
m_MemoryDump->ShowWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-10 07:05:57 +00:00
|
|
|
void CDebuggerUI::OpenMemoryWindow(void)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
if (m_MemoryView == NULL)
|
|
|
|
{
|
|
|
|
m_MemoryView = new CDebugMemoryView(this);
|
|
|
|
}
|
|
|
|
if (m_MemoryView)
|
|
|
|
{
|
|
|
|
m_MemoryView->ShowWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-18 23:08:35 +00:00
|
|
|
void CDebuggerUI::Debug_ShowMemoryLocation(uint32_t Address, bool VAddr)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
2018-01-10 07:05:57 +00:00
|
|
|
OpenMemoryWindow();
|
2016-01-27 09:11:59 +00:00
|
|
|
if (m_MemoryView)
|
|
|
|
{
|
2017-06-18 23:08:35 +00:00
|
|
|
m_MemoryView->ShowAddress(Address, VAddr);
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-10 07:05:57 +00:00
|
|
|
void CDebuggerUI::OpenTLBWindow(void)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
if (g_MMU == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_DebugTLB == NULL)
|
|
|
|
{
|
|
|
|
m_DebugTLB = new CDebugTlb(this);
|
|
|
|
}
|
|
|
|
if (m_DebugTLB)
|
|
|
|
{
|
|
|
|
m_DebugTLB->ShowWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDebuggerUI::Debug_RefreshTLBWindow(void)
|
|
|
|
{
|
|
|
|
if (m_DebugTLB)
|
|
|
|
{
|
|
|
|
m_DebugTLB->RefreshTLBWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-02 18:28:46 +00:00
|
|
|
void CDebuggerUI::Debug_RefreshDMALogWindow(void)
|
|
|
|
{
|
|
|
|
if (m_DMALogView)
|
|
|
|
{
|
|
|
|
m_DMALogView->RefreshDMALogWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-10 07:05:57 +00:00
|
|
|
void CDebuggerUI::OpenMemorySearch()
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
if (m_MemorySearch == NULL)
|
|
|
|
{
|
|
|
|
m_MemorySearch = new CDebugMemorySearch(this);
|
|
|
|
}
|
|
|
|
if (m_MemorySearch)
|
|
|
|
{
|
|
|
|
m_MemorySearch->ShowWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-10 07:05:57 +00:00
|
|
|
void CDebuggerUI::OpenCommandWindow()
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (m_CommandsView == NULL)
|
|
|
|
{
|
2018-01-16 21:26:54 +00:00
|
|
|
m_CommandsView = new CDebugCommandsView(this, m_StepEvent);
|
2017-09-13 12:00:53 +00:00
|
|
|
}
|
|
|
|
m_CommandsView->ShowWindow();
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebuggerUI::Debug_ShowCommandsLocation(uint32_t address, bool top)
|
|
|
|
{
|
2018-01-10 07:05:57 +00:00
|
|
|
OpenCommandWindow();
|
2017-09-13 12:00:53 +00:00
|
|
|
if (m_CommandsView)
|
|
|
|
{
|
|
|
|
m_CommandsView->ShowAddress(address, top);
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 07:05:57 +00:00
|
|
|
void CDebuggerUI::OpenScriptsWindow()
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (m_Scripts == NULL)
|
|
|
|
{
|
|
|
|
m_Scripts = new CDebugScripts(this);
|
|
|
|
}
|
|
|
|
m_Scripts->ShowWindow();
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebuggerUI::Debug_RefreshScriptsWindow()
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (m_Scripts != NULL)
|
|
|
|
{
|
|
|
|
m_Scripts->RefreshList();
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebuggerUI::Debug_LogScriptsWindow(const char* text)
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (m_Scripts != NULL)
|
|
|
|
{
|
|
|
|
m_Scripts->ConsolePrint(text);
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebuggerUI::Debug_ClearScriptsWindow()
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (m_Scripts != NULL)
|
|
|
|
{
|
|
|
|
m_Scripts->ConsoleClear();
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 07:05:57 +00:00
|
|
|
void CDebuggerUI::OpenSymbolsWindow()
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (m_Symbols == NULL)
|
|
|
|
{
|
|
|
|
m_Symbols = new CDebugSymbols(this);
|
|
|
|
}
|
|
|
|
m_Symbols->ShowWindow();
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebuggerUI::Debug_RefreshSymbolsWindow()
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (m_Symbols != NULL)
|
|
|
|
{
|
|
|
|
m_Symbols->Refresh();
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 07:05:57 +00:00
|
|
|
void CDebuggerUI::OpenDMALogWindow(void)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (m_DMALogView == NULL)
|
|
|
|
{
|
|
|
|
m_DMALogView = new CDebugDMALogView(this);
|
|
|
|
}
|
|
|
|
m_DMALogView->ShowWindow();
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2019-01-14 09:18:43 +00:00
|
|
|
void CDebuggerUI::OpenCPULogWindow(void)
|
|
|
|
{
|
|
|
|
if (m_CPULogView == NULL)
|
|
|
|
{
|
|
|
|
m_CPULogView = new CDebugCPULogView(this);
|
|
|
|
}
|
|
|
|
m_CPULogView->ShowWindow();
|
|
|
|
}
|
|
|
|
|
2019-01-17 09:34:24 +00:00
|
|
|
void CDebuggerUI::OpenExcBreakpointsWindow(void)
|
|
|
|
{
|
|
|
|
if (m_ExcBreakpoints == NULL)
|
|
|
|
{
|
|
|
|
m_ExcBreakpoints = new CDebugExcBreakpoints(this);
|
|
|
|
}
|
|
|
|
m_ExcBreakpoints->ShowWindow();
|
|
|
|
}
|
|
|
|
|
2018-01-10 07:05:57 +00:00
|
|
|
void CDebuggerUI::OpenStackTraceWindow(void)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (m_StackTrace == NULL)
|
|
|
|
{
|
|
|
|
m_StackTrace = new CDebugStackTrace(this);
|
|
|
|
}
|
|
|
|
m_StackTrace->ShowWindow();
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 07:05:57 +00:00
|
|
|
void CDebuggerUI::OpenStackViewWindow(void)
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (m_StackView == NULL)
|
|
|
|
{
|
|
|
|
m_StackView = new CDebugStackView(this);
|
|
|
|
}
|
|
|
|
m_StackView->ShowWindow();
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebuggerUI::Debug_RefreshStackWindow(void)
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (m_StackView != NULL)
|
|
|
|
{
|
|
|
|
m_StackView->Refresh();
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2017-08-30 04:54:06 +00:00
|
|
|
void CDebuggerUI::Debug_RefreshStackTraceWindow(void)
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (m_StackTrace != NULL && m_StackTrace->m_hWnd != NULL)
|
|
|
|
{
|
|
|
|
m_StackTrace->Refresh();
|
|
|
|
}
|
2017-08-30 04:54:06 +00:00
|
|
|
}
|
|
|
|
|
2019-01-14 09:18:43 +00:00
|
|
|
void CDebuggerUI::Debug_RefreshCPULogWindow(void)
|
|
|
|
{
|
|
|
|
if (m_CPULogView != NULL)
|
|
|
|
{
|
|
|
|
m_CPULogView->RefreshList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-18 05:08:22 +00:00
|
|
|
CBreakpoints* CDebuggerUI::Breakpoints()
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
return m_Breakpoints;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CScriptSystem* CDebuggerUI::ScriptSystem()
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
return m_ScriptSystem;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CDebugScripts* CDebuggerUI::ScriptConsole()
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
return m_Scripts;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CDMALog* CDebuggerUI::DMALog()
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
return m_DMALog;
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2019-01-14 09:18:43 +00:00
|
|
|
CCPULog* CDebuggerUI::CPULog()
|
|
|
|
{
|
|
|
|
return m_CPULog;
|
|
|
|
}
|
|
|
|
|
2019-12-25 00:41:20 +00:00
|
|
|
CSymbolTable* CDebuggerUI::SymbolTable()
|
|
|
|
{
|
|
|
|
return m_SymbolTable;
|
|
|
|
}
|
|
|
|
|
2017-08-18 05:08:22 +00:00
|
|
|
// CDebugger implementation
|
|
|
|
|
2016-01-27 09:11:59 +00:00
|
|
|
void CDebuggerUI::TLBChanged()
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
Debug_RefreshTLBWindow();
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2019-01-17 09:34:24 +00:00
|
|
|
// Exception handling - break on exception vector if exception bp is set
|
2019-01-14 09:18:43 +00:00
|
|
|
void CDebuggerUI::HandleCPUException(void)
|
|
|
|
{
|
2019-01-17 09:34:24 +00:00
|
|
|
int exc = (g_Reg->CAUSE_REGISTER >> 2) & 0x1F;
|
2019-08-20 22:20:49 +00:00
|
|
|
int intr = (g_Reg->CAUSE_REGISTER >> 8) & 0xFF;
|
|
|
|
int fpExc = (g_Reg->m_FPCR[31] >> 12) & 0x3F;
|
|
|
|
int rcpIntr = g_Reg->MI_INTR_REG & 0x2F;
|
|
|
|
|
|
|
|
if ((ExceptionBreakpoints() & (1 << exc)))
|
2019-01-14 09:18:43 +00:00
|
|
|
{
|
2019-08-20 22:20:49 +00:00
|
|
|
if (exc == 15) // floating-point exception
|
|
|
|
{
|
|
|
|
if (fpExc & FpExceptionBreakpoints())
|
|
|
|
{
|
|
|
|
goto have_bp;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (exc == 0) // interrupt exception
|
|
|
|
{
|
|
|
|
if (intr & IntrBreakpoints())
|
|
|
|
{
|
|
|
|
if (intr & 0x04) // RCP interrupt (IP2)
|
|
|
|
{
|
|
|
|
if (rcpIntr & RcpIntrBreakpoints())
|
|
|
|
{
|
|
|
|
goto have_bp;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else // other interrupts
|
|
|
|
{
|
|
|
|
goto have_bp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else // other exceptions
|
2019-01-14 09:18:43 +00:00
|
|
|
{
|
2019-08-20 22:20:49 +00:00
|
|
|
goto have_bp;
|
2019-01-14 09:18:43 +00:00
|
|
|
}
|
2019-08-20 22:20:49 +00:00
|
|
|
}
|
2019-01-14 09:18:43 +00:00
|
|
|
|
2019-08-20 22:20:49 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
have_bp:
|
|
|
|
if (bCPULoggingEnabled())
|
|
|
|
{
|
|
|
|
g_Debugger->OpenCPULogWindow();
|
2019-01-14 09:18:43 +00:00
|
|
|
}
|
2019-08-20 22:20:49 +00:00
|
|
|
|
|
|
|
g_Settings->SaveBool(Debugger_SteppingOps, true);
|
2019-01-14 09:18:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebuggerUI::HandleCartToRamDMA(void)
|
|
|
|
{
|
|
|
|
COpInfo opInfo(R4300iOp::m_Opcode);
|
|
|
|
|
|
|
|
uint32_t dmaRomAddr = g_Reg->PI_CART_ADDR_REG & 0x0FFFFFFF;
|
|
|
|
uint32_t dmaRamAddr = g_Reg->PI_DRAM_ADDR_REG | 0x80000000;
|
|
|
|
uint32_t dmaLen = opInfo.GetStoreValueUnsigned() + 1;
|
|
|
|
|
|
|
|
m_DMALog->AddEntry(dmaRomAddr, dmaRamAddr, dmaLen);
|
2019-04-02 18:28:46 +00:00
|
|
|
Debug_RefreshDMALogWindow();
|
|
|
|
|
2019-01-14 09:18:43 +00:00
|
|
|
// break if write breakpoint exists anywhere in target buffer
|
|
|
|
if (m_Breakpoints->WriteBPExistsInChunk(dmaRamAddr, dmaLen))
|
|
|
|
{
|
|
|
|
g_Settings->SaveBool(Debugger_SteppingOps, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-18 05:08:22 +00:00
|
|
|
// Called from the interpreter core at the beginning of every CPU step
|
2018-01-17 11:36:28 +00:00
|
|
|
void CDebuggerUI::CPUStepStarted()
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2019-12-01 10:10:36 +00:00
|
|
|
uint32_t pc = g_Reg->m_PROGRAM_COUNTER;
|
|
|
|
COpInfo opInfo(R4300iOp::m_Opcode);
|
|
|
|
bool bStoreOp = opInfo.IsStoreCommand();
|
|
|
|
uint32_t storeAddress = bStoreOp ? opInfo.GetLoadStoreAddress() : 0;
|
|
|
|
|
2019-01-19 20:14:26 +00:00
|
|
|
if (isStepping() && bCPULoggingEnabled())
|
|
|
|
{
|
|
|
|
Debug_RefreshCPULogWindow();
|
|
|
|
}
|
|
|
|
|
2019-12-01 10:10:36 +00:00
|
|
|
if(bStoreOp && m_Breakpoints->NumMemLocks() > 0)
|
2019-01-14 09:18:43 +00:00
|
|
|
{
|
2019-12-01 10:10:36 +00:00
|
|
|
if (m_Breakpoints->MemLockExists(storeAddress, opInfo.NumBytesToStore()))
|
2019-01-14 09:18:43 +00:00
|
|
|
{
|
|
|
|
// Memory is locked, skip op
|
|
|
|
g_Settings->SaveBool(Debugger_SkipOp, true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2019-12-01 10:10:36 +00:00
|
|
|
if (m_ScriptSystem->HaveCallbacks())
|
|
|
|
{
|
|
|
|
m_ScriptSystem->HookCPUExec()->InvokeByAddressInRange(pc);
|
|
|
|
if (SkipOp()) { return; }
|
2019-01-14 09:18:43 +00:00
|
|
|
|
2019-12-01 10:10:36 +00:00
|
|
|
m_ScriptSystem->HookCPUExecOpcode()->InvokeByAddressInRange_MaskedOpcode(pc, R4300iOp::m_Opcode.Hex);
|
|
|
|
if (SkipOp()) { return; }
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2019-12-01 10:10:36 +00:00
|
|
|
m_ScriptSystem->HookCPUGPRValue()->InvokeByAddressInRange_GPRValue(pc);
|
|
|
|
if (SkipOp()) { return; }
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2019-12-01 10:10:36 +00:00
|
|
|
if (bStoreOp)
|
2017-09-13 12:00:53 +00:00
|
|
|
{
|
2019-12-01 10:10:36 +00:00
|
|
|
m_ScriptSystem->HookCPUWrite()->InvokeByAddressInRange(storeAddress);
|
2019-01-14 09:18:43 +00:00
|
|
|
if (SkipOp()) { return; }
|
2017-09-13 12:00:53 +00:00
|
|
|
}
|
2019-12-01 10:10:36 +00:00
|
|
|
|
|
|
|
if (opInfo.IsLoadCommand())
|
2017-09-13 12:00:53 +00:00
|
|
|
{
|
2019-12-01 10:10:36 +00:00
|
|
|
m_ScriptSystem->HookCPURead()->InvokeByAddressInRange(opInfo.GetLoadStoreAddress());
|
2019-01-14 09:18:43 +00:00
|
|
|
if (SkipOp()) { return; }
|
2018-01-15 21:28:54 +00:00
|
|
|
}
|
2017-09-13 12:00:53 +00:00
|
|
|
}
|
|
|
|
|
2019-12-01 10:10:36 +00:00
|
|
|
if (bStoreOp && storeAddress == 0xA460000C) // PI_WR_LEN_REG
|
|
|
|
{
|
|
|
|
HandleCartToRamDMA();
|
|
|
|
}
|
|
|
|
|
2019-01-17 09:34:24 +00:00
|
|
|
if (CDebugSettings::ExceptionBreakpoints() != 0)
|
2017-09-13 12:00:53 +00:00
|
|
|
{
|
2019-01-17 09:34:24 +00:00
|
|
|
if (pc == 0x80000000 || pc == 0x80000080 ||
|
|
|
|
pc == 0xA0000100 || pc == 0x80000180)
|
|
|
|
{
|
2019-08-20 22:20:49 +00:00
|
|
|
if ((g_Reg->STATUS_REGISTER >> 1) & 3) // if exl/erl bits are set
|
|
|
|
{
|
|
|
|
HandleCPUException();
|
|
|
|
}
|
2019-01-17 09:34:24 +00:00
|
|
|
}
|
2017-09-13 12:00:53 +00:00
|
|
|
}
|
2019-01-20 08:52:49 +00:00
|
|
|
|
2019-12-01 10:10:36 +00:00
|
|
|
if (m_Breakpoints->HaveRegBP())
|
2019-01-20 08:52:49 +00:00
|
|
|
{
|
2019-12-01 10:10:36 +00:00
|
|
|
if (m_Breakpoints->HaveAnyGPRWriteBP())
|
2019-01-20 08:52:49 +00:00
|
|
|
{
|
2019-12-01 10:10:36 +00:00
|
|
|
int nReg = 0;
|
|
|
|
opInfo.WritesGPR(&nReg);
|
|
|
|
|
|
|
|
if (nReg != 0 && m_Breakpoints->HaveGPRWriteBP(nReg))
|
|
|
|
{
|
|
|
|
g_Settings->SaveBool(Debugger_SteppingOps, true);
|
|
|
|
}
|
2019-01-20 08:52:49 +00:00
|
|
|
}
|
|
|
|
|
2019-12-01 10:10:36 +00:00
|
|
|
if (m_Breakpoints->HaveAnyGPRReadBP())
|
|
|
|
{
|
|
|
|
int nReg1 = 0, nReg2 = 0;
|
|
|
|
opInfo.ReadsGPR(&nReg1, &nReg2);
|
2019-01-20 08:52:49 +00:00
|
|
|
|
2019-12-01 10:10:36 +00:00
|
|
|
if ((nReg1 != 0 && m_Breakpoints->HaveGPRReadBP(nReg1)) ||
|
|
|
|
(nReg2 != 0 && m_Breakpoints->HaveGPRReadBP(nReg2)))
|
|
|
|
{
|
|
|
|
g_Settings->SaveBool(Debugger_SteppingOps, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_Breakpoints->HaveHIWriteBP() && opInfo.WritesHI() ||
|
|
|
|
m_Breakpoints->HaveLOWriteBP() && opInfo.WritesLO() ||
|
|
|
|
m_Breakpoints->HaveHIReadBP() && opInfo.ReadsHI() ||
|
|
|
|
m_Breakpoints->HaveLOReadBP() && opInfo.ReadsLO())
|
2019-01-20 08:52:49 +00:00
|
|
|
{
|
|
|
|
g_Settings->SaveBool(Debugger_SteppingOps, true);
|
|
|
|
}
|
|
|
|
}
|
2019-01-17 09:34:24 +00:00
|
|
|
}
|
2017-09-13 12:00:53 +00:00
|
|
|
|
2019-01-17 09:34:24 +00:00
|
|
|
// Called before opcode is executed (not called if SkipOp is set)
|
|
|
|
void CDebuggerUI::CPUStep()
|
|
|
|
{
|
2019-01-14 09:18:43 +00:00
|
|
|
if (bCPULoggingEnabled())
|
2017-09-13 12:00:53 +00:00
|
|
|
{
|
2019-01-14 09:18:43 +00:00
|
|
|
m_CPULog->PushState();
|
2017-09-13 12:00:53 +00:00
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
2019-01-17 09:34:24 +00:00
|
|
|
// Called after opcode has been executed
|
|
|
|
void CDebuggerUI::CPUStepEnded()
|
2017-08-18 05:08:22 +00:00
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
if (m_StackTrace == NULL)
|
|
|
|
{
|
2019-12-01 10:10:36 +00:00
|
|
|
return;
|
2017-09-13 12:00:53 +00:00
|
|
|
}
|
2019-12-01 10:10:36 +00:00
|
|
|
|
|
|
|
OPCODE Opcode = R4300iOp::m_Opcode;
|
|
|
|
uint32_t op = Opcode.op;
|
|
|
|
uint32_t funct = Opcode.funct;
|
2017-09-13 12:00:53 +00:00
|
|
|
|
|
|
|
if (op == R4300i_JAL || ((op == R4300i_SPECIAL) && (funct == R4300i_SPECIAL_JALR) && (Opcode.rd == 31))) // JAL or JALR RA, x
|
|
|
|
{
|
|
|
|
m_StackTrace->PushEntry(R4300iOp::m_JumpToLocation, g_Reg->m_PROGRAM_COUNTER);
|
|
|
|
}
|
|
|
|
else if (funct == R4300i_SPECIAL_JR && Opcode.rs == 31) // JR RA
|
|
|
|
{
|
|
|
|
m_StackTrace->PopEntry();
|
|
|
|
}
|
|
|
|
else if (op == R4300i_CP0 && funct == R4300i_COP0_CO_ERET) // TODO may need more work
|
|
|
|
{
|
|
|
|
m_StackTrace->ClearEntries();
|
|
|
|
}
|
2017-08-18 05:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebuggerUI::FrameDrawn()
|
|
|
|
{
|
2017-09-13 12:00:53 +00:00
|
|
|
static HWND hMainWnd = NULL;
|
|
|
|
|
|
|
|
static HFONT monoFont = CreateFont(-11, 0, 0, 0,
|
|
|
|
FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
|
|
|
|
OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
|
2020-05-12 12:19:05 +00:00
|
|
|
PROOF_QUALITY, FF_DONTCARE, L"Consolas"
|
2017-09-13 12:00:53 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if (hMainWnd == NULL)
|
|
|
|
{
|
|
|
|
RenderWindow* mainWindow = g_Plugins->MainWindow();
|
|
|
|
|
|
|
|
if (mainWindow == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hMainWnd = (HWND)mainWindow->GetWindowHandle();
|
|
|
|
}
|
|
|
|
|
|
|
|
HDC hdc = GetDC(hMainWnd);
|
|
|
|
|
|
|
|
CRect rt;
|
|
|
|
|
|
|
|
GetClientRect(hMainWnd, &rt);
|
|
|
|
SetBkColor(hdc, RGB(0, 0, 0));
|
|
|
|
|
|
|
|
SelectObject(hdc, monoFont);
|
|
|
|
SetTextColor(hdc, RGB(255, 255, 255));
|
|
|
|
SetBkColor(hdc, RGB(0, 0, 0));
|
|
|
|
|
|
|
|
m_ScriptSystem->SetScreenDC(hdc);
|
|
|
|
m_ScriptSystem->HookFrameDrawn()->InvokeAll();
|
|
|
|
|
|
|
|
ReleaseDC(hMainWnd, hdc);
|
2018-01-16 21:26:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDebuggerUI::WaitForStep(void)
|
|
|
|
{
|
|
|
|
g_Settings->SaveBool(Debugger_WaitingForStep, true);
|
|
|
|
m_StepEvent.IsTriggered(SyncEvent::INFINITE_TIMEOUT);
|
|
|
|
g_Settings->SaveBool(Debugger_WaitingForStep, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CDebuggerUI::ExecutionBP(uint32_t address)
|
|
|
|
{
|
|
|
|
return m_Breakpoints != NULL && m_Breakpoints->ExecutionBPExists(address, true) != CBreakpoints::BP_NOT_SET;
|
|
|
|
}
|
2018-02-01 17:28:08 +00:00
|
|
|
|
2018-02-05 06:43:46 +00:00
|
|
|
bool CDebuggerUI::ReadBP8(uint32_t address)
|
|
|
|
{
|
|
|
|
return m_Breakpoints != NULL && m_Breakpoints->ReadBPExists8(address) != CBreakpoints::BP_NOT_SET;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CDebuggerUI::ReadBP16(uint32_t address)
|
|
|
|
{
|
|
|
|
return m_Breakpoints != NULL && m_Breakpoints->ReadBPExists16(address) != CBreakpoints::BP_NOT_SET;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CDebuggerUI::ReadBP32(uint32_t address)
|
|
|
|
{
|
|
|
|
return m_Breakpoints != NULL && m_Breakpoints->ReadBPExists32(address) != CBreakpoints::BP_NOT_SET;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CDebuggerUI::ReadBP64(uint32_t address)
|
|
|
|
{
|
|
|
|
return m_Breakpoints != NULL && m_Breakpoints->ReadBPExists64(address) != CBreakpoints::BP_NOT_SET;
|
|
|
|
}
|
|
|
|
|
2018-02-01 17:28:08 +00:00
|
|
|
bool CDebuggerUI::WriteBP8(uint32_t address)
|
|
|
|
{
|
|
|
|
return m_Breakpoints != NULL && m_Breakpoints->WriteBPExists8(address) != CBreakpoints::BP_NOT_SET;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CDebuggerUI::WriteBP16(uint32_t address)
|
|
|
|
{
|
|
|
|
return m_Breakpoints != NULL && m_Breakpoints->WriteBPExists16(address) != CBreakpoints::BP_NOT_SET;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CDebuggerUI::WriteBP32(uint32_t address)
|
|
|
|
{
|
|
|
|
return m_Breakpoints != NULL && m_Breakpoints->WriteBPExists32(address) != CBreakpoints::BP_NOT_SET;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CDebuggerUI::WriteBP64(uint32_t address)
|
|
|
|
{
|
|
|
|
return m_Breakpoints != NULL && m_Breakpoints->WriteBPExists64(address) != CBreakpoints::BP_NOT_SET;
|
|
|
|
}
|