2016-12-08 19:30:41 -05:00
|
|
|
#pragma once
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "Debugger.h"
|
2017-10-07 13:01:42 -04:00
|
|
|
#include "Console.h"
|
2016-12-08 19:30:41 -05:00
|
|
|
|
|
|
|
class DebugBreakHelper
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
Debugger* _debugger;
|
|
|
|
bool _needResume = false;
|
2017-10-07 13:01:42 -04:00
|
|
|
bool _isEmulationThread = false;
|
2016-12-08 19:30:41 -05:00
|
|
|
|
|
|
|
public:
|
|
|
|
DebugBreakHelper(Debugger* debugger)
|
|
|
|
{
|
|
|
|
_debugger = debugger;
|
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
_isEmulationThread = debugger->GetConsole()->GetEmulationThreadId() == std::this_thread::get_id();
|
2017-10-07 13:01:42 -04:00
|
|
|
|
|
|
|
if(!_isEmulationThread) {
|
|
|
|
//Only attempt to break if this is done in a thread other than the main emulation thread
|
|
|
|
debugger->PreventResume();
|
|
|
|
if(!debugger->IsExecutionStopped()) {
|
2018-01-01 23:13:24 -05:00
|
|
|
debugger->Break();
|
2017-10-07 13:01:42 -04:00
|
|
|
while(!debugger->IsExecutionStopped()) {}
|
|
|
|
_needResume = true;
|
|
|
|
}
|
2016-12-08 19:30:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~DebugBreakHelper()
|
|
|
|
{
|
2017-10-07 13:01:42 -04:00
|
|
|
if(!_isEmulationThread) {
|
|
|
|
if(_needResume) {
|
2018-01-01 23:13:24 -05:00
|
|
|
_debugger->ResumeFromBreak();
|
2017-10-07 13:01:42 -04:00
|
|
|
}
|
|
|
|
_debugger->AllowResume();
|
2016-12-08 19:30:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|