2016-01-10 19:56:40 -05:00
|
|
|
#pragma once
|
|
|
|
#include "stdafx.h"
|
2017-03-31 22:14:16 -04:00
|
|
|
#include "DebuggerTypes.h"
|
2017-08-05 12:13:53 -04:00
|
|
|
#include "../Utilities/SimpleLock.h"
|
2017-08-05 17:18:09 -04:00
|
|
|
#include "DisassemblyInfo.h"
|
2018-08-02 20:44:48 -04:00
|
|
|
#include "ExpressionEvaluator.h"
|
2016-02-13 22:19:42 -05:00
|
|
|
|
2016-11-19 19:21:28 -05:00
|
|
|
class MemoryManager;
|
2017-03-04 15:18:00 -05:00
|
|
|
class LabelManager;
|
2017-08-05 12:13:53 -04:00
|
|
|
class Debugger;
|
2016-01-10 19:56:40 -05:00
|
|
|
|
2018-05-26 01:14:37 -04:00
|
|
|
enum class RowDataType
|
2017-03-16 21:34:28 -04:00
|
|
|
{
|
2018-05-26 01:14:37 -04:00
|
|
|
Text = 0,
|
|
|
|
ByteCode,
|
|
|
|
Disassembly,
|
|
|
|
EffectiveAddress,
|
|
|
|
MemoryValue,
|
|
|
|
Align,
|
|
|
|
PC,
|
|
|
|
A,
|
|
|
|
X,
|
|
|
|
Y,
|
|
|
|
SP,
|
|
|
|
PS,
|
|
|
|
Cycle,
|
|
|
|
Scanline,
|
|
|
|
FrameCount,
|
|
|
|
CycleCount
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RowPart
|
|
|
|
{
|
|
|
|
RowDataType DataType;
|
|
|
|
string Text;
|
|
|
|
bool DisplayInHex;
|
|
|
|
int MinWidth;
|
2017-03-16 21:34:28 -04:00
|
|
|
};
|
|
|
|
|
2016-01-10 19:56:40 -05:00
|
|
|
struct TraceLoggerOptions
|
|
|
|
{
|
2016-09-03 21:52:59 -04:00
|
|
|
bool ShowExtraInfo;
|
|
|
|
bool IndentCode;
|
2017-03-04 15:18:00 -05:00
|
|
|
bool UseLabels;
|
2018-05-26 01:14:37 -04:00
|
|
|
bool UseWindowsEol;
|
|
|
|
bool ExtendZeroPage;
|
2017-08-05 12:13:53 -04:00
|
|
|
|
|
|
|
char Condition[1000];
|
2018-05-26 01:14:37 -04:00
|
|
|
char Format[1000];
|
2016-01-10 19:56:40 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
class TraceLogger
|
|
|
|
{
|
|
|
|
private:
|
2021-02-08 15:21:03 +08:00
|
|
|
static constexpr int ExecutionLogSize = 20000;
|
2017-09-28 21:27:38 -04:00
|
|
|
|
|
|
|
//Must be static to be thread-safe when switching game
|
|
|
|
static string _executionTrace;
|
|
|
|
|
2016-01-10 19:56:40 -05:00
|
|
|
TraceLoggerOptions _options;
|
|
|
|
string _outputFilepath;
|
2016-11-28 19:51:43 -05:00
|
|
|
string _outputBuffer;
|
2016-01-10 19:56:40 -05:00
|
|
|
ofstream _outputFile;
|
2016-11-19 19:21:28 -05:00
|
|
|
shared_ptr<MemoryManager> _memoryManager;
|
2017-03-04 15:18:00 -05:00
|
|
|
shared_ptr<LabelManager> _labelManager;
|
2017-08-05 12:13:53 -04:00
|
|
|
|
|
|
|
shared_ptr<ExpressionEvaluator> _expEvaluator;
|
2018-08-02 20:44:48 -04:00
|
|
|
ExpressionData _conditionData;
|
2017-08-05 17:18:09 -04:00
|
|
|
|
2018-05-26 01:14:37 -04:00
|
|
|
vector<RowPart> _rowParts;
|
|
|
|
|
2017-08-05 17:18:09 -04:00
|
|
|
bool _pendingLog;
|
2017-08-05 12:13:53 -04:00
|
|
|
DebugState _lastState;
|
2017-08-05 17:18:09 -04:00
|
|
|
DisassemblyInfo _lastDisassemblyInfo;
|
2017-03-04 15:18:00 -05:00
|
|
|
|
|
|
|
bool _logToFile;
|
|
|
|
uint16_t _currentPos;
|
2017-08-05 17:18:09 -04:00
|
|
|
uint32_t _logCount;
|
2017-03-04 15:18:00 -05:00
|
|
|
State _cpuStateCache[ExecutionLogSize] = {};
|
|
|
|
PPUDebugState _ppuStateCache[ExecutionLogSize] = {};
|
2017-08-05 17:18:09 -04:00
|
|
|
DisassemblyInfo _disassemblyCache[ExecutionLogSize];
|
2017-03-04 15:18:00 -05:00
|
|
|
|
2017-08-06 16:23:22 -04:00
|
|
|
State _cpuStateCacheCopy[ExecutionLogSize] = {};
|
|
|
|
PPUDebugState _ppuStateCacheCopy[ExecutionLogSize] = {};
|
|
|
|
DisassemblyInfo _disassemblyCacheCopy[ExecutionLogSize];
|
|
|
|
|
2017-08-05 12:13:53 -04:00
|
|
|
SimpleLock _lock;
|
2017-03-16 21:34:28 -04:00
|
|
|
|
2018-05-26 01:14:37 -04:00
|
|
|
void GetStatusFlag(string &output, uint8_t ps, RowPart& part);
|
2017-08-05 17:18:09 -04:00
|
|
|
void AddRow(DisassemblyInfo &disassemblyInfo, DebugState &state);
|
|
|
|
bool ConditionMatches(DebugState &state, DisassemblyInfo &disassemblyInfo, OperationInfo &operationInfo);
|
|
|
|
|
2018-05-26 01:14:37 -04:00
|
|
|
void GetTraceRow(string &output, State &cpuState, PPUDebugState &ppuState, DisassemblyInfo &disassemblyInfo);
|
|
|
|
|
|
|
|
template<typename T> void WriteValue(string &output, T value, RowPart& rowPart);
|
2016-01-10 19:56:40 -05:00
|
|
|
|
|
|
|
public:
|
2017-08-05 12:13:53 -04:00
|
|
|
TraceLogger(Debugger* debugger, shared_ptr<MemoryManager> memoryManager, shared_ptr<LabelManager> labelManager);
|
2016-01-10 19:56:40 -05:00
|
|
|
~TraceLogger();
|
|
|
|
|
2017-08-05 17:18:09 -04:00
|
|
|
void Log(DebugState &state, DisassemblyInfo &disassemblyInfo, OperationInfo &operationInfo);
|
2019-05-20 17:05:01 -04:00
|
|
|
void Clear();
|
2017-08-05 12:13:53 -04:00
|
|
|
void LogNonExec(OperationInfo& operationInfo);
|
2017-03-04 15:18:00 -05:00
|
|
|
void SetOptions(TraceLoggerOptions options);
|
|
|
|
void StartLogging(string filename);
|
|
|
|
void StopLogging();
|
|
|
|
|
2019-05-12 12:28:01 -04:00
|
|
|
void LogExtraInfo(const char *log, uint64_t cycleCount);
|
2017-03-04 15:18:00 -05:00
|
|
|
|
2018-06-20 20:17:33 -04:00
|
|
|
const char* GetExecutionTrace(uint32_t lineCount);
|
2016-01-10 19:56:40 -05:00
|
|
|
};
|