Skip to content

Commit

Permalink
Merge pull request #140 from Kingcom/Debugger
Browse files Browse the repository at this point in the history
Various debugger fixes and enhancements
  • Loading branch information
sudonim1 committed Jul 15, 2014
2 parents 6f0f7ce + 53159a8 commit 80b22ca
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 21 deletions.
73 changes: 62 additions & 11 deletions pcsx2/DebugTools/DebugInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#include "../IopMem.h"
#include "SymbolMap.h"

#ifdef _WIN32
#include <Windows.h>
#endif

extern AppCoreThread CoreThread;

R5900DebugInterface r5900Debug;
Expand Down Expand Up @@ -204,25 +208,48 @@ bool DebugInterface::parseExpression(PostfixExpression& exp, u64& dest)
// R5900DebugInterface
//

u32 R5900DebugInterface::read8(u32 address)
u32 R5900DebugInterface::readMemory(u32 address, u32 size)
{
if (!isValidAddress(address))
return -1;
return memRead8(address);

// TODO: Add linux variant of the following __try/__except
#if defined(_MSC_VER)
__try
{
#endif
switch (size)
{
case 1:
return memRead8(address);
case 2:
return memRead16(address);
case 4:
return memRead32(address);
default:
return -1;
}
#if defined(_MSC_VER)
} __except(GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
{
return -1;
}
#endif
}

u32 R5900DebugInterface::read8(u32 address)
{
return readMemory(address,1);
}

u32 R5900DebugInterface::read16(u32 address)
{
if (!isValidAddress(address))
return -1;
return memRead16(address);
return readMemory(address,2);
}

u32 R5900DebugInterface::read32(u32 address)
{
if (!isValidAddress(address))
return -1;
return memRead32(address);
return readMemory(address,4);
}

u64 R5900DebugInterface::read64(u32 address)
Expand All @@ -231,7 +258,19 @@ u64 R5900DebugInterface::read64(u32 address)
return -1;

u64 result;
memRead64(address,result);

// TODO: Add linux variant of the following __try/__except
#if defined(_MSC_VER)
__try {
#endif
memRead64(address,result);
#if defined(_MSC_VER)
} __except(GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
{
result = -1;
}
#endif

return result;
}

Expand All @@ -240,8 +279,20 @@ u128 R5900DebugInterface::read128(u32 address)
if (!isValidAddress(address))
return u128::From32(-1);

u128 result;
memRead128(address,result);
__aligned16 u128 result;

// TODO: Add linux variant of the following __try/__except
#if defined(_MSC_VER)
__try {
#endif
memRead128(address,result);
#if defined(_MSC_VER)
} __except(GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
{
result.hi = result.lo = -1;
}
#endif

return result;
}

Expand Down
2 changes: 2 additions & 0 deletions pcsx2/DebugTools/DebugInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class R5900DebugInterface: public DebugInterface
virtual std::string disasm(u32 address);
virtual bool isValidAddress(u32 address);
virtual u32 getCycles();
private:
u32 readMemory(u32 address, u32 size);
};


Expand Down
3 changes: 3 additions & 0 deletions pcsx2/DebugTools/MIPSAnalyst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ namespace MIPSAnalyst
case 0x2C: // sdl
size = 8;
off = -7;
case 0x1E: // lq
case 0x1F: // sq
size = 16;
break;
}

Expand Down
4 changes: 2 additions & 2 deletions pcsx2/gui/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,14 +757,14 @@ void Pcsx2App::enterDebugMode()
{
DisassemblyDialog* dlg = GetDisassemblyPtr();
if (dlg)
dlg->setDebugMode(true);
dlg->setDebugMode(true,false);
}

void Pcsx2App::leaveDebugMode()
{
DisassemblyDialog* dlg = GetDisassemblyPtr();
if (dlg)
dlg->setDebugMode(false);
dlg->setDebugMode(false,false);
}

void Pcsx2App::resetDebugger()
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/gui/Debugger/CtrlDisassemblyView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ void CtrlDisassemblyView::updateStatusBarText()
}
case 16:
{
u128 data = cpu->read128(line.info.dataAddress);
__aligned16 u128 data = cpu->read128(line.info.dataAddress);
sprintf(text,"[%08X] = %016llX%016llX",line.info.dataAddress,data._u64[1],data._u64[0]);
break;
}
Expand Down
22 changes: 16 additions & 6 deletions pcsx2/gui/Debugger/DisassemblyDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ DisassemblyDialog::DisassemblyDialog(wxWindow* parent):
SetMinSize(wxSize(1000,600));
panel->GetSizer()->Fit(this);

setDebugMode(true);
setDebugMode(true,true);
}

#ifdef WIN32
Expand Down Expand Up @@ -212,8 +212,10 @@ void DisassemblyDialog::onBreakRunClicked(wxCommandEvent& evt)
// If the current PC is on a breakpoint, the user doesn't want to do nothing.
CBreakPoints::SetSkipFirst(r5900Debug.getPC());
r5900Debug.resumeCpu();
} else
} else {
r5900Debug.pauseCpu();
gotoPc();
}
}

void DisassemblyDialog::onStepOverClicked(wxCommandEvent& evt)
Expand Down Expand Up @@ -352,7 +354,9 @@ void DisassemblyDialog::onDebuggerEvent(wxCommandEvent& evt)
wxEventType type = evt.GetEventType();
if (type == debEVT_SETSTATUSBARTEXT)
{
GetStatusBar()->SetLabel(evt.GetString());
CtrlDisassemblyView* view = reinterpret_cast<CtrlDisassemblyView*>(evt.GetEventObject());
if (view != NULL && view == currentCpu->getDisassembly())
GetStatusBar()->SetLabel(evt.GetString());
} else if (type == debEVT_UPDATELAYOUT)
{
if (currentCpu != NULL)
Expand Down Expand Up @@ -420,7 +424,13 @@ void DisassemblyDialog::reset()
iopTab->getDisassembly()->clearFunctions();
};

void DisassemblyDialog::setDebugMode(bool debugMode)
void DisassemblyDialog::gotoPc()
{
eeTab->getDisassembly()->gotoPc();
iopTab->getDisassembly()->gotoPc();
}

void DisassemblyDialog::setDebugMode(bool debugMode, bool switchPC)
{
bool running = r5900Debug.isAlive();

Expand All @@ -437,8 +447,8 @@ void DisassemblyDialog::setDebugMode(bool debugMode)
stepOverButton->Enable(true);
stepIntoButton->Enable(true);

eeTab->getDisassembly()->gotoPc();
iopTab->getDisassembly()->gotoPc();
if (switchPC || CBreakPoints::GetBreakpointTriggered())
gotoPc();

if (CBreakPoints::GetBreakpointTriggered())
{
Expand Down
3 changes: 2 additions & 1 deletion pcsx2/gui/Debugger/DisassemblyDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class DisassemblyDialog : public wxFrame

void update();
void reset();
void setDebugMode(bool debugMode);
void setDebugMode(bool debugMode, bool switchPC);

#ifdef WIN32
WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
Expand All @@ -79,6 +79,7 @@ class DisassemblyDialog : public wxFrame
void onClose(wxCloseEvent& evt);
void stepOver();
void stepInto();
void gotoPc();
private:
CpuTabPage* eeTab;
CpuTabPage* iopTab;
Expand Down

0 comments on commit 80b22ca

Please sign in to comment.