Permalink
Browse files

GE Debugger: Refactor out stepping callback.

In case we have multiple connected debuggers, we don't want just a
callback.  A counter works fine.
  • Loading branch information...
unknownbrackets committed Sep 1, 2018
1 parent a4c0640 commit f1afc519940ecf4d5c6d8201f8ca39991061845d
View
@@ -50,11 +50,6 @@ class Host {
virtual void SaveSymbolMap() {}
virtual void SetWindowTitle(const char *message) {}
// While debugging is active, it's perfectly fine for these to block.
virtual void GPUNotifyCommand(u32 pc) {}
virtual void GPUNotifyDisplay(u32 framebuf, u32 stride, int format) {}
virtual void GPUNotifyDraw() {}
virtual bool CanCreateShortcut() {return false;}
virtual bool CreateDesktopShortcut(std::string argumentPath, std::string title) {return false;}
View
@@ -15,34 +15,86 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "Core/Host.h"
#include "GPU/GPU.h"
#include "GPU/Debugger/Breakpoints.h"
#include "GPU/Debugger/Debugger.h"
#include "GPU/Debugger/Stepping.h"
namespace GPUDebug {
static bool active = false;
static bool inited = false;
static BreakNext breakNext = BreakNext::NONE;
static void Init() {
if (!inited) {
GPUBreakpoints::Init();
Core_ListenStopRequest(&GPUStepping::ForceUnpause);
inited = true;
}
}
void SetActive(bool flag) {
Init();
active = flag;
if (!active) {
breakNext = BreakNext::NONE;
GPUStepping::ResumeFromStepping();
}
}
bool IsActive() {
return active;
}
void SetBreakNext(BreakNext next) {
SetActive(true);
breakNext = next;
if (next == BreakNext::TEX) {
GPUBreakpoints::AddTextureChangeTempBreakpoint();
} else if (next == BreakNext::PRIM) {
GPUBreakpoints::AddCmdBreakpoint(GE_CMD_PRIM, true);
GPUBreakpoints::AddCmdBreakpoint(GE_CMD_BEZIER, true);
GPUBreakpoints::AddCmdBreakpoint(GE_CMD_SPLINE, true);
}
GPUStepping::ResumeFromStepping();
}
void NotifyCommand(u32 pc) {
host->GPUNotifyCommand(pc);
if (!active)
return;
u32 op = Memory::ReadUnchecked_U32(pc);
if (breakNext == BreakNext::OP || GPUBreakpoints::IsBreakpoint(pc, op)) {
GPUBreakpoints::ClearTempBreakpoints();
auto info = gpuDebug->DissassembleOp(pc);
NOTICE_LOG(G3D, "Waiting at %08x, %s", pc, info.desc.c_str());
GPUStepping::EnterStepping();
}
}
void NotifyDraw() {
host->GPUNotifyDraw();
if (!active)
return;
if (breakNext == BreakNext::DRAW) {
NOTICE_LOG(G3D, "Waiting at a draw");
GPUStepping::EnterStepping();
}
}
void NotifyDisplay(u32 framebuf, u32 stride, int format) {
host->GPUNotifyDisplay(framebuf, stride, format);
if (!active)
return;
if (breakNext == BreakNext::FRAME) {
// This should work fine, start stepping at the first op of the new frame.
breakNext = BreakNext::OP;
}
}
void NotifyTextureAttachment(u32 texaddr) {
if (!active)
return;
}
}
View
@@ -21,9 +21,21 @@
namespace GPUDebug {
enum class BreakNext {
NONE,
OP,
DRAW,
TEX,
NONTEX,
FRAME,
PRIM,
};
void SetActive(bool flag);
bool IsActive();
void SetBreakNext(BreakNext next);
// While debugging is active, these may block.
void NotifyCommand(u32 pc);
void NotifyDraw();
View
@@ -38,6 +38,7 @@ enum PauseAction {
};
static bool isStepping;
static int stepCounter = 0;
static std::mutex pauseLock;
static std::condition_variable pauseWait;
@@ -149,7 +150,7 @@ bool SingleStep() {
return true;
}
bool EnterStepping(std::function<void()> callback) {
bool EnterStepping() {
std::unique_lock<std::mutex> guard(pauseLock);
if (coreState != CORE_RUNNING && coreState != CORE_NEXTFRAME) {
// Shutting down, don't try to step.
@@ -170,8 +171,7 @@ bool EnterStepping(std::function<void()> callback) {
pauseAction = PAUSE_BREAK;
}
isStepping = true;
callback();
stepCounter++;
do {
RunPauseAction();
@@ -187,6 +187,10 @@ bool IsStepping() {
return isStepping;
}
int GetSteppingCounter() {
return stepCounter;
}
static bool GetBuffer(const GPUDebugBuffer *&buffer, PauseAction type, const GPUDebugBuffer &resultBuffer) {
if (!isStepping && coreState != CORE_STEPPING) {
return false;
View
@@ -24,12 +24,12 @@
#include "GPU/Common/GPUDebugInterface.h"
namespace GPUStepping {
// Should be called from the GPU thread.
// Begins stepping and calls callback while inside a lock preparing stepping.
// This would be a good place to deliver a message to code that stepping is ready.
bool EnterStepping(std::function<void()> callback);
// Should be called from the emu thread.
// Begins stepping and increments the stepping counter while inside a lock.
bool EnterStepping();
bool SingleStep();
bool IsStepping();
int GetSteppingCounter();
bool GPU_GetOutputFramebuffer(const GPUDebugBuffer *&buffer);
bool GPU_GetCurrentFramebuffer(const GPUDebugBuffer *&buffer, GPUDebugFramebufferType type);
Oops, something went wrong.

0 comments on commit f1afc51

Please sign in to comment.