Debugger: Fixed issues with break on uninit reads

-Break did not trigger properly when using the new breakpoint logic
-Fixed issue with step back not working when using the new breakpoint logic
This commit is contained in:
Sour 2019-01-13 14:53:14 -05:00
parent 8027cd0c26
commit cab24bbd70
4 changed files with 21 additions and 13 deletions

View file

@ -411,8 +411,13 @@ bool Debugger::ProcessBreakpoints(BreakpointType type, OperationInfo &operationI
}
}
void Debugger::ProcessAllBreakpoints(OperationInfo &operationInfo, AddressTypeInfo &addressInfo)
void Debugger::ProcessAllBreakpoints(OperationInfo &operationInfo)
{
if(_runToCycle != 0) {
//Disable all breakpoints while stepping backwards
return;
}
if(_hasBreakpoint[BreakpointType::Execute]) {
ProcessBreakpoints(BreakpointType::Execute, operationInfo, true, true);
}
@ -454,7 +459,9 @@ void Debugger::ProcessAllBreakpoints(OperationInfo &operationInfo, AddressTypeIn
} else {
if(!isDummyRead && checkUninitReads) {
//Break on uninit memory read
if(_memoryAccessCounter->IsAddressUninitialized(addressInfo)) {
AddressTypeInfo info;
GetAbsoluteAddressAndType(addr, &info);
if(_memoryAccessCounter->IsAddressUninitialized(info)) {
Step(1);
SleepUntilResume(BreakSource::BreakOnUninitMemoryRead, 0, BreakpointType::ReadRam, addr, value);
return;
@ -731,7 +738,8 @@ bool Debugger::ProcessRamOperation(MemoryOperationType type, uint16_t &addr, uin
int32_t absoluteAddr = addressInfo.Type == AddressType::PrgRom ? addressInfo.Address : -1;
int32_t absoluteRamAddr = addressInfo.Type == AddressType::WorkRam ? addressInfo.Address : -1;
if(addressInfo.Address >= 0 && type != MemoryOperationType::DummyRead && type != MemoryOperationType::DummyWrite) {
if(addressInfo.Address >= 0 && type != MemoryOperationType::DummyRead && type != MemoryOperationType::DummyWrite && _runToCycle == 0) {
//Ignore dummy read/writes and do not change counters while using the step back feature
if(type == MemoryOperationType::Write && CheckFlag(DebuggerFlags::IgnoreRedundantWrites)) {
if(_memoryManager->DebugRead(addr) != value) {
_memoryAccessCounter->ProcessMemoryAccess(addressInfo, type, _cpu->GetCycleCount());
@ -741,7 +749,7 @@ bool Debugger::ProcessRamOperation(MemoryOperationType type, uint16_t &addr, uin
if(!_breakOnFirstCycle && _enableBreakOnUninitRead && CheckFlag(DebuggerFlags::BreakOnUninitMemoryRead)) {
//Break on uninit memory read
Step(1);
breakDone = SleepUntilResume(BreakSource::BreakOnUninitMemoryRead);
breakDone = SleepUntilResume(BreakSource::BreakOnUninitMemoryRead, 0, BreakpointType::Global, operationInfo.Address, operationInfo.Value, operationInfo.OperationType);
}
}
}
@ -843,7 +851,7 @@ bool Debugger::ProcessRamOperation(MemoryOperationType type, uint16_t &addr, uin
if(_breakOnFirstCycle) {
if(type == MemoryOperationType::ExecOpCode && !breakDone) {
ProcessAllBreakpoints(operationInfo, addressInfo);
ProcessAllBreakpoints(operationInfo);
} else if(_hasBreakpoint[breakpointType]) {
//Process marked breakpoints
ProcessBreakpoints(breakpointType, operationInfo, false, true);
@ -1485,7 +1493,11 @@ const char* Debugger::GetScriptLog(int32_t scriptId)
void Debugger::ResetCounters()
{
_memoryAccessCounter->ResetCounts();
//This is called when loading a state (among other things)
//Prevent counter reset when using step back (_runToCycle != 0), because step back will load a state
if(_runToCycle == 0) {
_memoryAccessCounter->ResetCounts();
}
_profiler->Reset();
}

View file

@ -144,7 +144,7 @@ private:
private:
bool ProcessBreakpoints(BreakpointType type, OperationInfo &operationInfo, bool allowBreak = true, bool allowMark = true);
void ProcessAllBreakpoints(OperationInfo &operationInfo, AddressTypeInfo &addressInfo);
void ProcessAllBreakpoints(OperationInfo &operationInfo);
void AddCallstackFrame(uint16_t source, uint16_t target, StackFrameFlags flags);
void UpdateCallstack(uint8_t currentInstruction, uint32_t addr);

View file

@ -25,7 +25,6 @@ MemoryAccessCounter::MemoryAccessCounter(Debugger* debugger)
_writeStamps[i].insert(_writeStamps[i].end(), memorySizes[i], 0);
_execStamps[i].insert(_execStamps[i].end(), memorySizes[i], 0);
_initWrites[i].insert(_initWrites[i].end(), memorySizes[i], 0);
_uninitReads[i].insert(_uninitReads[i].end(), memorySizes[i], 0);
}
}
@ -46,7 +45,7 @@ bool MemoryAccessCounter::IsAddressUninitialized(AddressTypeInfo &addressInfo)
{
if(addressInfo.Type == AddressType::InternalRam || addressInfo.Type == AddressType::WorkRam) {
int index = (int)addressInfo.Type;
return !_initWrites[index][addressInfo.Address];
return _writeCounts[index][addressInfo.Address] == 0;
}
return false;
}
@ -60,9 +59,7 @@ bool MemoryAccessCounter::ProcessMemoryAccess(AddressTypeInfo &addressInfo, Memo
vector<int> &stamps = GetArray(operation, addressInfo.Type, true);
stamps.data()[addressInfo.Address] = cpuCycle;
if(operation == MemoryOperationType::Write) {
_initWrites[index][addressInfo.Address] = true;
} else if((addressInfo.Type == AddressType::InternalRam || addressInfo.Type == AddressType::WorkRam) && !_initWrites[index][addressInfo.Address]) {
if(operation == MemoryOperationType::Read && (addressInfo.Type == AddressType::InternalRam || addressInfo.Type == AddressType::WorkRam) && !_writeCounts[index][addressInfo.Address]) {
//Mark address as read before being written to (if trying to read/execute)
_uninitReads[index][addressInfo.Address] = true;
return true;

View file

@ -17,7 +17,6 @@ private:
vector<int32_t> _writeStamps[4];
vector<int32_t> _execStamps[4];
vector<uint8_t> _initWrites[4];
vector<uint8_t> _uninitReads[4];
vector<int32_t>& GetArray(MemoryOperationType operationType, AddressType addressType, bool stampArray);