Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,8 @@ packages/*
!Libretro/hakchi/bin

TestHelper/*
UI/Dependencies.zip
UI/Dependencies.zip

# Visual Studio Code local files
.vscodecsdt/Runners/
.vscode
5 changes: 4 additions & 1 deletion Core/Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<ClInclude Include="NES\Mappers\Unlicensed\Mapper487.h" />
<ClInclude Include="NES\OpnInterface.h" />
<ClInclude Include="Shared\Movies\BizHawkMovie.h" />
<ClInclude Include="Shared\TraceFormat.h" />
<ClInclude Include="Shared\Utilities\S3511ARtc.h" />
<ClInclude Include="Shared\Video\BlendFilter.h" />
<ClInclude Include="Shared\Video\DrawPixelsCommand.h" />
Expand Down Expand Up @@ -451,7 +452,9 @@
<ClInclude Include="Debugger\BaseTraceLogger.h" />
<ClInclude Include="Debugger\DebuggerFeatures.h" />
<ClInclude Include="Debugger\ITraceLogger.h" />
<ClInclude Include="Debugger\TraceLogFileSaver.h" />
<ClInclude Include="Debugger\TraceLogOutput.h" />
<ClInclude Include="Debugger\TraceLogOutputFile.h" />
<ClInclude Include="Debugger\TraceLogOutputNetworkSocket.h" />
<ClInclude Include="Gameboy\Carts\GbsCart.h" />
<ClInclude Include="Gameboy\Debugger\DummyGbCpu.h" />
<ClInclude Include="Gameboy\Debugger\GbTraceLogger.h" />
Expand Down
11 changes: 10 additions & 1 deletion Core/Core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,13 @@
<ClInclude Include="Debugger\ScriptManager.h">
<Filter>Debugger</Filter>
</ClInclude>
<ClInclude Include="Debugger\TraceLogFileSaver.h">
<ClInclude Include="Debugger\TraceLogOutput.h">
<Filter>Debugger</Filter>
</ClInclude>
<ClInclude Include="Debugger\TraceLogOutputFile.h">
<Filter>Debugger</Filter>
</ClInclude>
<ClInclude Include="Debugger\TraceLogOutputNetworkSocket.h">
<Filter>Debugger</Filter>
</ClInclude>
<ClCompile Include="Gameboy\Gameboy.cpp">
Expand Down Expand Up @@ -3021,6 +3027,9 @@
<ClInclude Include="Shared\Video\DrawPixelsCommand.h">
<Filter>Shared\Video</Filter>
</ClInclude>
<ClInclude Include="Shared\TraceFormat.h">
<Filter>Shared</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Shared\Video\RotateFilter.cpp">
Expand Down
155 changes: 139 additions & 16 deletions Core/Debugger/BaseTraceLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#include "Debugger/DebugBreakHelper.h"
#include "Debugger/ITraceLogger.h"
#include "Debugger/ExpressionEvaluator.h"
#include "Debugger/TraceLogFileSaver.h"
#include "Debugger/TraceLogOutputFile.h"
#include "Debugger/TraceLogOutputNetworkSocket.h"
#include "Utilities/HexUtilities.h"
#include "Shared/Emulator.h"
#include "Shared/EmuSettings.h"
Expand Down Expand Up @@ -150,6 +151,7 @@ class BaseTraceLogger : public ITraceLogger
LabelManager* _labelManager;
MemoryDumper* _memoryDumper;
Debugger* _debugger;
bool _rowStateInitialized = false;

CpuType _cpuType = CpuType::Snes;
MemoryType _cpuMemoryType = MemoryType::SnesMemory;
Expand All @@ -170,6 +172,11 @@ class BaseTraceLogger : public ITraceLogger
unique_ptr<ExpressionEvaluator> _expEvaluator;
ExpressionData _conditionData;

bool _anyLoggingActive;
std::queue<DisassemblyInfo> _disassemblyInfoQueuedForLogging;
std::queue<CpuStateType> _cpuStateQueuedForLogging;
std::queue<TraceLogPpuState> _ppuStateQueuedForLogging;

void WriteByteCode(DisassemblyInfo& info, RowPart& rowPart, string& output)
{
string byteCode;
Expand Down Expand Up @@ -297,23 +304,14 @@ class BaseTraceLogger : public ITraceLogger
_rowIds[_currentPos] = ITraceLogger::NextRowId;
ITraceLogger::NextRowId++;

_pendingLog = false;

if(_debugger->GetTraceLogFileSaver()->IsEnabled()) {
string row;
row.reserve(300);

//Display PC
RowPart rowPart = {};
rowPart.DisplayInHex = true;
rowPart.MinWidth = DebugUtilities::GetProgramCounterSize(_cpuType);
WriteIntValue(row, ((TraceLoggerType*)this)->GetProgramCounter(cpuState), rowPart);
row += " ";

((TraceLoggerType*)this)->GetTraceRow(row, cpuState, _ppuState[_currentPos], disassemblyInfo);
_debugger->GetTraceLogFileSaver()->Log(row);
if(_anyLoggingActive) {
_disassemblyInfoQueuedForLogging.push(disassemblyInfo);
_cpuStateQueuedForLogging.push(cpuState);
_ppuStateQueuedForLogging.push(_ppuState[_currentPos]);
}

_pendingLog = false;

_currentPos = (_currentPos + 1) % ExecutionLogSize;
}

Expand Down Expand Up @@ -386,6 +384,27 @@ class BaseTraceLogger : public ITraceLogger

virtual RowDataType GetFormatTagType(string& tag) = 0;

virtual void StartRowStateTracking()
{
}

virtual void StopRowStateTracking()
{
}

virtual bool IsUniqueRow(CpuStateType& cpuState, DisassemblyInfo& disassemblyInfo)
{
return true;
}

virtual void TrackRowState(CpuStateType& cpuState, DisassemblyInfo& disassemblyInfo)
{
}

virtual void GetTraceData(vector<uint8_t>* target, CpuStateType& cpuState, DisassemblyInfo& disassemblyInfo, TraceLogOutput::OutputFormat traceFormat)
{
}

void ProcessSharedTag(RowPart& rowPart, string& output, CpuStateType& cpuState, TraceLogPpuState& ppuState, DisassemblyInfo& disassemblyInfo)
{
switch(rowPart.DataType) {
Expand Down Expand Up @@ -478,6 +497,110 @@ class BaseTraceLogger : public ITraceLogger
}
}

void ProcessEndOfFrame()
{
TraceLoggerType* selfDerived = ((TraceLoggerType*)this);
TraceLogOutput* logOutput = nullptr;

{
TraceLogOutputFile* fileLogger = _debugger->GetTraceLogOutputFile();
TraceLogOutputNetworkSocket* networkLogger = _debugger->GetTraceLogOutputNetworkSocket();

if(fileLogger->IsEnabled()) {
logOutput = fileLogger;
} else if(networkLogger->IsEnabled()) {
logOutput = networkLogger;
}
}

if(logOutput != nullptr) {
_anyLoggingActive = true;

bool needsToTrackRowState = logOutput->GetUniqueRowsOnly();

if(needsToTrackRowState && !_rowStateInitialized) {
StartRowStateTracking();
_rowStateInitialized = true;
}

if(!_cpuStateQueuedForLogging.empty()) {
logOutput->UpdateLastLogTimestamp();
} else {
logOutput->FlushOldBuffers();
return;
}

string rowText;
rowText.reserve(300);

vector<uint8_t> rowData;
rowData.reserve(50);

while(!_cpuStateQueuedForLogging.empty()) {
DisassemblyInfo disassemblyInfo = _disassemblyInfoQueuedForLogging.front();
CpuStateType cpuState = _cpuStateQueuedForLogging.front();
TraceLogPpuState ppuState = _ppuStateQueuedForLogging.front();
_disassemblyInfoQueuedForLogging.pop();
_cpuStateQueuedForLogging.pop();
_ppuStateQueuedForLogging.pop();

bool skipRow = needsToTrackRowState;
if(needsToTrackRowState) {
if(IsUniqueRow(cpuState, disassemblyInfo)) {
TrackRowState(cpuState, disassemblyInfo);
skipRow = false;
}
}

if(!skipRow) {
switch(logOutput->GetOutputFormat()) {
case TraceLogOutput::OutputFormat::Text: {
rowText.clear();

if(logOutput->GetIncludeImplictPC()) {
RowPart rowPart = {};
rowPart.DisplayInHex = true;
rowPart.MinWidth = DebugUtilities::GetProgramCounterSize(_cpuType);
WriteIntValue(rowText, selfDerived->GetProgramCounter(cpuState), rowPart);
rowText += " ";
}

selfDerived->GetTraceRow(rowText, cpuState, ppuState, disassemblyInfo);
rowText += '\n';
logOutput->Log((const uint8_t*)rowText.c_str(), (int)rowText.length());
break;
}

case TraceLogOutput::OutputFormat::Diztinguish:
case TraceLogOutput::OutputFormat::DiztinguishAbridged: {
rowData.clear();
GetTraceData(&rowData, cpuState, disassemblyInfo, logOutput->GetOutputFormat());

if(!rowData.empty()) {
logOutput->Log(&rowData.front(), (int)rowData.size());
}
break;
}
}
}
}
} else {
// These should always have the same size, so just the first check should be good enough.
if(_cpuStateQueuedForLogging.size() > 0 /*|| _ppuStateQueuedForLogging.size() > 0 || _disassemblyInfoQueuedForLogging.size() > 0*/) {
_disassemblyInfoQueuedForLogging = std::queue<DisassemblyInfo>();
_cpuStateQueuedForLogging = std::queue<CpuStateType>();
_ppuStateQueuedForLogging = std::queue<TraceLogPpuState>();
}

if(_rowStateInitialized) {
StopRowStateTracking();
_rowStateInitialized = false;
}

_anyLoggingActive = false;
}
}

void SetOptions(TraceLoggerOptions options) override
{
DebugBreakHelper helper(_debugger);
Expand Down
15 changes: 13 additions & 2 deletions Core/Debugger/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
#include "Debugger/Profiler.h"
#include "Debugger/ExpressionEvaluator.h"
#include "Debugger/BaseEventManager.h"
#include "Debugger/TraceLogFileSaver.h"
#include "Debugger/TraceLogOutputFile.h"
#include "Debugger/TraceLogOutputNetworkSocket.h"
#include "Debugger/CdlManager.h"
#include "Debugger/ITraceLogger.h"
#include "SNES/SnesCpuTypes.h"
Expand Down Expand Up @@ -77,7 +78,8 @@ Debugger::Debugger(Emulator* emu, IConsole* console)
_disassemblySearch.reset(new DisassemblySearch(_disassembler.get(), _labelManager.get()));
_memoryAccessCounter.reset(new MemoryAccessCounter(this));
_scriptManager.reset(new ScriptManager(this));
_traceLogSaver.reset(new TraceLogFileSaver());
_traceLogOutputFile.reset(new TraceLogOutputFile());
_traceLogOutputNetworkSocket.reset(new TraceLogOutputNetworkSocket());
_cdlManager.reset(new CdlManager(this, _disassembler.get()));

//Use cpuTypes for iteration (ordered), not _cpuTypes (order is important for coprocessors, etc.)
Expand Down Expand Up @@ -648,6 +650,15 @@ void Debugger::ProcessEvent(EventType type, std::optional<CpuType> cpuTypeOpt)
}
}

void Debugger::ProcessEndOfFrame()
{
for(int i = 0; i <= (int)DebugUtilities::GetLastCpuType(); i++) {
if(_debuggers[i].Debugger) {
_debuggers[i].Debugger->ProcessEndOfFrame();
}
}
}

template<CpuType type, typename T>
void Debugger::ProcessScripts(uint32_t addr, T& value, MemoryOperationType opType)
{
Expand Down
10 changes: 7 additions & 3 deletions Core/Debugger/Debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class BaseEventManager;
class IAssembler;
class IDebugger;
class ITraceLogger;
class TraceLogFileSaver;
class TraceLogOutputFile;
class TraceLogOutputNetworkSocket;
class FrozenAddressManager;
class ISerializable;

Expand Down Expand Up @@ -74,7 +75,8 @@ class Debugger
unique_ptr<LabelManager> _labelManager;
unique_ptr<CdlManager> _cdlManager;

unique_ptr<TraceLogFileSaver> _traceLogSaver;
unique_ptr<TraceLogOutputFile> _traceLogOutputFile;
unique_ptr<TraceLogOutputNetworkSocket> _traceLogOutputNetworkSocket;

SimpleLock _logLock;
std::list<string> _debuggerLog;
Expand Down Expand Up @@ -125,6 +127,7 @@ class Debugger
void InternalProcessInterrupt(CpuType cpuType, IDebugger& dbg, StepRequest& stepRequest, AddressInfo& src, uint32_t srcAddr, AddressInfo& dest, uint32_t destAddr, AddressInfo& ret, uint32_t retAddr, uint32_t retSp, bool forNmi);

void ProcessEvent(EventType type, std::optional<CpuType> cpuType);
void ProcessEndOfFrame();

void ProcessConfigChange();

Expand Down Expand Up @@ -187,7 +190,8 @@ class Debugger
IDebugger* GetCpuDebugger(CpuType cpuType);
IDebugger* GetMainDebugger();

TraceLogFileSaver* GetTraceLogFileSaver() { return _traceLogSaver.get(); }
TraceLogOutputFile* GetTraceLogOutputFile() { return _traceLogOutputFile.get(); }
TraceLogOutputNetworkSocket* GetTraceLogOutputNetworkSocket() { return _traceLogOutputNetworkSocket.get(); }
MemoryDumper* GetMemoryDumper() { return _memoryDumper.get(); }
MemoryAccessCounter* GetMemoryAccessCounter() { return _memoryAccessCounter.get(); }
Disassembler* GetDisassembler() { return _disassembler.get(); }
Expand Down
2 changes: 2 additions & 0 deletions Core/Debugger/IDebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class IDebugger
virtual void Reset() = 0;
virtual void Run() = 0;

virtual void ProcessEndOfFrame() {}

virtual void Init() {}
virtual void ProcessConfigChange() {}

Expand Down
48 changes: 0 additions & 48 deletions Core/Debugger/TraceLogFileSaver.h

This file was deleted.

Loading