Skip to content
Permalink
Browse files

Merge pull request #10987 from unknownbrackets/debugger-core

Improve debugger threadsafety and consistency
  • Loading branch information...
hrydgard committed Jun 6, 2018
2 parents bc6f211 + 6fbd0e2 commit f9cfb05895447fcd3de7502ba835c79e4f998004
@@ -28,22 +28,21 @@
#include "thread/threadutil.h"
#include "profiler/profiler.h"

#include "Common/GraphicsContext.h"
#include "Core/Core.h"
#include "Core/Config.h"
#include "Core/Host.h"
#include "Core/MemMap.h"
#include "Core/SaveState.h"
#include "Core/System.h"
#include "Core/Debugger/Breakpoints.h"
#include "Core/MIPS/MIPS.h"
#include "Common/GraphicsContext.h"

#ifdef _WIN32
#include "Common/CommonWindows.h"
#include "Windows/InputDevice.h"
#endif

#include "Host.h"

#include "Core/Debugger/Breakpoints.h"

// Time until we stop considering the core active without user input.
// Should this be configurable? 2 hours currently.
@@ -54,7 +53,8 @@ static std::mutex m_hStepMutex;
static std::condition_variable m_InactiveCond;
static std::mutex m_hInactiveMutex;
static bool singleStepPending = false;
static std::set<Core_ShutdownFunc> shutdownFuncs;
static int steppingCounter = 0;
static std::set<CoreLifecycleFunc> shutdownFuncs;
static bool windowHidden = false;
static double lastActivity = 0.0;
static double lastKeepAwake = 0.0;
@@ -75,30 +75,19 @@ void Core_NotifyActivity() {
lastActivity = time_now_d();
}

void Core_ListenShutdown(Core_ShutdownFunc func) {
void Core_ListenLifecycle(CoreLifecycleFunc func) {
shutdownFuncs.insert(func);
}

void Core_NotifyShutdown() {
void Core_NotifyLifecycle(CoreLifecycle stage) {
for (auto it = shutdownFuncs.begin(); it != shutdownFuncs.end(); ++it) {
(*it)();
(*it)(stage);
}
}

void Core_ErrorPause() {
Core_UpdateState(CORE_ERROR);
}

void Core_Halt(const char *msg) {
Core_EnableStepping(true);
ERROR_LOG(CPU, "CPU HALTED : %s",msg);
_dbg_update_();
}

void Core_Stop() {
Core_UpdateState(CORE_POWERDOWN);
Core_NotifyShutdown();
m_StepCond.notify_one();
m_StepCond.notify_all();
}

bool Core_IsStepping() {
@@ -239,11 +228,11 @@ void Core_RunLoop(GraphicsContext *ctx) {

void Core_DoSingleStep() {
singleStepPending = true;
m_StepCond.notify_one();
m_StepCond.notify_all();
}

void Core_UpdateSingleStep() {
m_StepCond.notify_one();
m_StepCond.notify_all();
}

void Core_SingleStep() {
@@ -253,7 +242,7 @@ void Core_SingleStep() {
static inline void CoreStateProcessed() {
if (coreStatePending) {
coreStatePending = false;
m_InactiveCond.notify_one();
m_InactiveCond.notify_all();
}
}

@@ -334,10 +323,15 @@ void Core_EnableStepping(bool step) {
sleep_ms(1);
host->SetDebugMode(true);
Core_UpdateState(CORE_STEPPING);
steppingCounter++;
} else {
host->SetDebugMode(false);
coreState = CORE_RUNNING;
coreStatePending = false;
m_StepCond.notify_one();
m_StepCond.notify_all();
}
}

int Core_GetSteppingCounter() {
return steppingCounter;
}
@@ -27,21 +27,28 @@ void UpdateRunLoop();

void Core_Run(GraphicsContext *ctx);
void Core_Stop();
void Core_ErrorPause();
// For platforms that don't call Core_Run
void Core_SetGraphicsContext(GraphicsContext *ctx);

void Core_RunRenderThreadFrame();

// called from gui
void Core_EnableStepping(bool step);
void Core_DoSingleStep();
void Core_UpdateSingleStep();

typedef void (* Core_ShutdownFunc)();
void Core_ListenShutdown(Core_ShutdownFunc func);
void Core_NotifyShutdown();
void Core_Halt(const char *msg);
// Changes every time we enter stepping.
int Core_GetSteppingCounter();

enum class CoreLifecycle {
STARTING,
// Note: includes failure cases. Guaranteed call after STARTING.
START_COMPLETE,
STOPPING,
// Guaranteed call after STOPPING.
STOPPED,
};

typedef void (* CoreLifecycleFunc)(CoreLifecycle stage);
void Core_ListenLifecycle(CoreLifecycleFunc func);
void Core_NotifyLifecycle(CoreLifecycle stage);

bool Core_IsStepping();

@@ -182,7 +182,7 @@ int RegisterEvent(const char *name, TimedCallback callback)
void AntiCrashCallback(u64 userdata, int cyclesLate)
{
ERROR_LOG(SAVESTATE, "Savestate broken: an unregistered event was called.");
Core_Halt("invalid timing events");
Core_EnableStepping(true);
}

void RestoreRegisterEvent(int event_type, const char *name, TimedCallback callback)
Oops, something went wrong.

0 comments on commit f9cfb05

Please sign in to comment.
You can’t perform that action at this time.