From e55229db40c2e523f2e363908656a14a30961dad Mon Sep 17 00:00:00 2001 From: Kingcom Date: Mon, 24 Feb 2014 14:56:09 +0100 Subject: [PATCH] A hackish attempt at step into --- pcsx2/DebugTools/MIPSAnalyst.cpp | 4 ++ pcsx2/DebugTools/MIPSAnalyst.h | 1 + pcsx2/gui/Debugger/CtrlDisassemblyView.cpp | 5 +- pcsx2/gui/Debugger/DebugEvents.cpp | 1 + pcsx2/gui/Debugger/DebugEvents.h | 1 + pcsx2/gui/Debugger/DisassemblyDialog.cpp | 54 ++++++++++++++++++++++ pcsx2/gui/Debugger/DisassemblyDialog.h | 2 + 7 files changed, 67 insertions(+), 1 deletion(-) diff --git a/pcsx2/DebugTools/MIPSAnalyst.cpp b/pcsx2/DebugTools/MIPSAnalyst.cpp index 5c104d205f..dd70f345d9 100644 --- a/pcsx2/DebugTools/MIPSAnalyst.cpp +++ b/pcsx2/DebugTools/MIPSAnalyst.cpp @@ -356,6 +356,10 @@ namespace MIPSAnalyst switch (MIPS_GET_OP(op)) { case 0: // special switch (MIPS_GET_FUNC(op)) { + case 0x0C: // syscall + info.isSyscall = true; + info.branchTarget = 0x80000000+0x180; + break; case 0x20: // add case 0x21: // addu info.hasRelevantAddress = true; diff --git a/pcsx2/DebugTools/MIPSAnalyst.h b/pcsx2/DebugTools/MIPSAnalyst.h index ba636a1b18..5baf4307d5 100644 --- a/pcsx2/DebugTools/MIPSAnalyst.h +++ b/pcsx2/DebugTools/MIPSAnalyst.h @@ -37,6 +37,7 @@ namespace MIPSAnalyst // branches u32 branchTarget; + bool isSyscall; bool isBranch; bool isLinkedBranch; bool isLikelyBranch; diff --git a/pcsx2/gui/Debugger/CtrlDisassemblyView.cpp b/pcsx2/gui/Debugger/CtrlDisassemblyView.cpp index 87964b1b9a..49e06a582c 100644 --- a/pcsx2/gui/Debugger/CtrlDisassemblyView.cpp +++ b/pcsx2/gui/Debugger/CtrlDisassemblyView.cpp @@ -689,7 +689,10 @@ void CtrlDisassemblyView::keydownEvent(wxKeyEvent& evt) break; case WXK_F10: postEvent(debEVT_STEPOVER,0); - break; + return; + case WXK_F11: + postEvent(debEVT_STEPINTO,0); + return; default: evt.Skip(); break; diff --git a/pcsx2/gui/Debugger/DebugEvents.cpp b/pcsx2/gui/Debugger/DebugEvents.cpp index ee03620d8c..e2c3edf020 100644 --- a/pcsx2/gui/Debugger/DebugEvents.cpp +++ b/pcsx2/gui/Debugger/DebugEvents.cpp @@ -8,6 +8,7 @@ DEFINE_LOCAL_EVENT_TYPE( debEVT_GOTOINDISASM ) DEFINE_LOCAL_EVENT_TYPE( debEVT_RUNTOPOS ) DEFINE_LOCAL_EVENT_TYPE( debEVT_MAPLOADED ) DEFINE_LOCAL_EVENT_TYPE( debEVT_STEPOVER ) +DEFINE_LOCAL_EVENT_TYPE( debEVT_STEPINTO ) DEFINE_LOCAL_EVENT_TYPE( debEVT_UPDATE ) bool parseExpression(const char* exp, DebugInterface* cpu, u64& dest) diff --git a/pcsx2/gui/Debugger/DebugEvents.h b/pcsx2/gui/Debugger/DebugEvents.h index b5e2dae30c..111fcf3631 100644 --- a/pcsx2/gui/Debugger/DebugEvents.h +++ b/pcsx2/gui/Debugger/DebugEvents.h @@ -9,6 +9,7 @@ DECLARE_LOCAL_EVENT_TYPE( debEVT_GOTOINDISASM, wxNewEventType() ) DECLARE_LOCAL_EVENT_TYPE( debEVT_RUNTOPOS, wxNewEventType() ) DECLARE_LOCAL_EVENT_TYPE( debEVT_MAPLOADED, wxNewEventType() ) DECLARE_LOCAL_EVENT_TYPE( debEVT_STEPOVER, wxNewEventType() ) +DECLARE_LOCAL_EVENT_TYPE( debEVT_STEPINTO, wxNewEventType() ) DECLARE_LOCAL_EVENT_TYPE( debEVT_UPDATE, wxNewEventType() ) bool executeExpressionWindow(wxWindow* parent, DebugInterface* cpu, u64& dest); diff --git a/pcsx2/gui/Debugger/DisassemblyDialog.cpp b/pcsx2/gui/Debugger/DisassemblyDialog.cpp index 795a578500..ca54702209 100644 --- a/pcsx2/gui/Debugger/DisassemblyDialog.cpp +++ b/pcsx2/gui/Debugger/DisassemblyDialog.cpp @@ -18,6 +18,7 @@ BEGIN_EVENT_TABLE(DisassemblyDialog, wxFrame) EVT_COMMAND( wxID_ANY, debEVT_RUNTOPOS, DisassemblyDialog::onDebuggerEvent ) EVT_COMMAND( wxID_ANY, debEVT_GOTOINDISASM, DisassemblyDialog::onDebuggerEvent ) EVT_COMMAND( wxID_ANY, debEVT_STEPOVER, DisassemblyDialog::onDebuggerEvent ) + EVT_COMMAND( wxID_ANY, debEVT_STEPINTO, DisassemblyDialog::onDebuggerEvent ) EVT_COMMAND( wxID_ANY, debEVT_UPDATE, DisassemblyDialog::onDebuggerEvent ) EVT_CLOSE( DisassemblyDialog::onClose ) END_EVENT_TABLE() @@ -97,6 +98,7 @@ DisassemblyDialog::DisassemblyDialog(wxWindow* parent): stepIntoButton = new wxButton( panel, wxID_ANY, L"Step Into" ); stepIntoButton->Enable(false); + Connect( stepIntoButton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DisassemblyDialog::onStepIntoClicked ) ); topRowSizer->Add(stepIntoButton,0,wxBOTTOM,2); stepOverButton = new wxButton( panel, wxID_ANY, L"Step Over" ); @@ -181,6 +183,11 @@ void DisassemblyDialog::onStepOverClicked(wxCommandEvent& evt) stepOver(); } +void DisassemblyDialog::onStepIntoClicked(wxCommandEvent& evt) +{ + stepInto(); +} + void DisassemblyDialog::onPageChanging(wxCommandEvent& evt) { wxNotebook* notebook = (wxNotebook*)wxWindow::FindWindowById(evt.GetId()); @@ -247,6 +254,48 @@ void DisassemblyDialog::stepOver() r5900Debug.resumeCpu(); } + +void DisassemblyDialog::stepInto() +{ + if (!r5900Debug.isAlive() || !r5900Debug.isCpuPaused() || currentCpu == NULL) + return; + + // todo: breakpoints for iop + if (currentCpu != eeTab) + return; + + CtrlDisassemblyView* disassembly = currentCpu->getDisassembly(); + + // If the current PC is on a breakpoint, the user doesn't want to do nothing. + CBreakPoints::SetSkipFirst(r5900Debug.getPC()); + u32 currentPc = r5900Debug.getPC(); + + MIPSAnalyst::MipsOpcodeInfo info = MIPSAnalyst::GetOpcodeInfo(&r5900Debug,r5900Debug.getPC()); + u32 breakpointAddress = currentPc+disassembly->getInstructionSizeAt(currentPc); + if (info.isBranch) + { + if (info.isConditional == false) + { + breakpointAddress = info.branchTarget; + } else { + if (info.conditionMet) + { + breakpointAddress = info.branchTarget; + } else { + breakpointAddress = currentPc+2*4; + disassembly->scrollStepping(breakpointAddress); + } + } + } + + if (info.isSyscall) + breakpointAddress = info.branchTarget; + + CBreakPoints::AddBreakPoint(breakpointAddress,true); + r5900Debug.resumeCpu(); +} + + void DisassemblyDialog::onBreakpointClick(wxCommandEvent& evt) { if (currentCpu == NULL) @@ -295,6 +344,10 @@ void DisassemblyDialog::onDebuggerEvent(wxCommandEvent& evt) { if (currentCpu != NULL) stepOver(); + } else if (type == debEVT_STEPINTO) + { + if (currentCpu != NULL) + stepInto(); } else if (type == debEVT_UPDATE) { update(); @@ -340,6 +393,7 @@ void DisassemblyDialog::setDebugMode(bool debugMode) breakRunButton->SetLabel(L"Run"); stepOverButton->Enable(true); + stepIntoButton->Enable(true); eeTab->getDisassembly()->gotoPc(); iopTab->getDisassembly()->gotoPc(); diff --git a/pcsx2/gui/Debugger/DisassemblyDialog.h b/pcsx2/gui/Debugger/DisassemblyDialog.h index 511a54b6cb..383f3d0a30 100644 --- a/pcsx2/gui/Debugger/DisassemblyDialog.h +++ b/pcsx2/gui/Debugger/DisassemblyDialog.h @@ -52,11 +52,13 @@ public: protected: void onBreakRunClicked(wxCommandEvent& evt); void onStepOverClicked(wxCommandEvent& evt); + void onStepIntoClicked(wxCommandEvent& evt); void onDebuggerEvent(wxCommandEvent& evt); void onPageChanging(wxCommandEvent& evt); void onBreakpointClick(wxCommandEvent& evt); void onClose(wxCloseEvent& evt); void stepOver(); + void stepInto(); private: CpuTabPage* eeTab; CpuTabPage* iopTab;