Mesen-SX/Core/BreakpointManager.cpp

101 lines
2.8 KiB
C++
Raw Normal View History

2019-03-01 20:27:49 -05:00
#include "stdafx.h"
#include "BreakpointManager.h"
#include "DebugTypes.h"
#include "Debugger.h"
#include "Breakpoint.h"
2019-07-30 22:34:52 -04:00
#include "DebugUtilities.h"
2019-03-01 20:27:49 -05:00
#include "ExpressionEvaluator.h"
#include "EventManager.h"
2019-03-01 20:27:49 -05:00
BreakpointManager::BreakpointManager(Debugger *debugger, CpuType cpuType, IEventManager* eventManager)
2019-03-01 20:27:49 -05:00
{
_debugger = debugger;
_cpuType = cpuType;
_hasBreakpoint = false;
_eventManager = eventManager ? eventManager : debugger->GetEventManager(cpuType).get();
2019-03-01 20:27:49 -05:00
}
void BreakpointManager::SetBreakpoints(Breakpoint breakpoints[], uint32_t count)
{
_hasBreakpoint = false;
for(int i = 0; i < BreakpointManager::BreakpointTypeCount; i++) {
_breakpoints[i].clear();
_rpnList[i].clear();
_hasBreakpointType[i] = false;
2019-03-01 20:27:49 -05:00
}
_bpExpEval.reset(new ExpressionEvaluator(_debugger, _cpuType));
2019-03-01 20:27:49 -05:00
for(uint32_t j = 0; j < count; j++) {
Breakpoint &bp = breakpoints[j];
for(int i = 0; i < BreakpointManager::BreakpointTypeCount; i++) {
BreakpointType bpType = (BreakpointType)i;
2019-05-04 16:54:53 -04:00
if((bp.IsMarked() || bp.IsEnabled()) && bp.HasBreakpointType(bpType)) {
CpuType cpuType = bp.GetCpuType();
if(_cpuType != cpuType) {
continue;
}
_breakpoints[i].push_back(bp);
2019-03-01 20:27:49 -05:00
if(bp.HasCondition()) {
bool success = true;
ExpressionData data = _bpExpEval->GetRpnList(bp.GetCondition(), success);
_rpnList[i].push_back(success ? data : ExpressionData());
2019-03-01 20:27:49 -05:00
} else {
_rpnList[i].push_back(ExpressionData());
2019-03-01 20:27:49 -05:00
}
_hasBreakpoint = true;
_hasBreakpointType[i] = true;
2019-03-01 20:27:49 -05:00
}
}
}
}
BreakpointType BreakpointManager::GetBreakpointType(MemoryOperationType type)
{
switch(type) {
default:
case MemoryOperationType::ExecOperand:
case MemoryOperationType::ExecOpCode:
return BreakpointType::Execute;
case MemoryOperationType::DmaRead:
case MemoryOperationType::Read:
return BreakpointType::Read;
2019-03-01 20:27:49 -05:00
case MemoryOperationType::DmaWrite:
case MemoryOperationType::Write:
return BreakpointType::Write;
2019-03-01 20:27:49 -05:00
}
}
int BreakpointManager::InternalCheckBreakpoint(MemoryOperationInfo operationInfo, AddressInfo &address)
2019-03-01 20:27:49 -05:00
{
BreakpointType type = GetBreakpointType(operationInfo.Type);
if(!_hasBreakpointType[(int)type]) {
return -1;
2019-03-01 20:27:49 -05:00
}
DebugState state;
_debugger->GetState(state, false);
2019-03-01 20:27:49 -05:00
EvalResultType resultType;
vector<Breakpoint> &breakpoints = _breakpoints[(int)type];
2019-03-01 20:27:49 -05:00
for(size_t i = 0; i < breakpoints.size(); i++) {
if(breakpoints[i].Matches(operationInfo.Address, address)) {
if(!breakpoints[i].HasCondition() || _bpExpEval->Evaluate(_rpnList[(int)type][i], state, resultType, operationInfo)) {
if(breakpoints[i].IsMarked()) {
_eventManager->AddEvent(DebugEventType::Breakpoint, operationInfo, breakpoints[i].GetId());
}
if(breakpoints[i].IsEnabled()) {
return breakpoints[i].GetId();
}
2019-03-01 20:27:49 -05:00
}
}
}
return -1;
2019-03-01 20:27:49 -05:00
}