2015-07-02 03:17:14 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include <atomic>
|
2015-08-09 18:47:27 +00:00
|
|
|
#include <deque>
|
2016-11-20 18:15:37 +00:00
|
|
|
#include <unordered_set>
|
2016-11-22 03:34:47 +00:00
|
|
|
#include <unordered_map>
|
2015-07-02 03:17:14 +00:00
|
|
|
using std::atomic;
|
2015-08-09 18:47:27 +00:00
|
|
|
using std::deque;
|
2016-11-20 18:15:37 +00:00
|
|
|
using std::unordered_set;
|
2016-11-22 03:34:47 +00:00
|
|
|
using std::unordered_map;
|
2015-07-02 03:17:14 +00:00
|
|
|
|
2016-01-11 00:56:40 +00:00
|
|
|
#include "DebugState.h"
|
2015-07-02 03:17:14 +00:00
|
|
|
#include "Breakpoint.h"
|
2016-01-11 00:56:40 +00:00
|
|
|
#include "TraceLogger.h"
|
2015-07-02 03:17:14 +00:00
|
|
|
#include "../Utilities/SimpleLock.h"
|
2015-08-17 23:32:10 +00:00
|
|
|
#include "CodeDataLogger.h"
|
2016-11-19 04:50:05 +00:00
|
|
|
#include "MemoryDumper.h"
|
2015-07-02 03:17:14 +00:00
|
|
|
|
2016-06-18 00:53:05 +00:00
|
|
|
class CPU;
|
|
|
|
class PPU;
|
2015-07-02 03:17:14 +00:00
|
|
|
class MemoryManager;
|
|
|
|
class Console;
|
|
|
|
class Disassembler;
|
|
|
|
|
2016-06-05 14:26:05 +00:00
|
|
|
enum class DebuggerFlags
|
|
|
|
{
|
2016-11-20 00:21:28 +00:00
|
|
|
PpuPartialDraw = 1,
|
|
|
|
ShowEffectiveAddresses = 2,
|
2016-11-22 03:34:47 +00:00
|
|
|
ShowOnlyDisassembledCode = 4
|
2016-06-05 14:26:05 +00:00
|
|
|
};
|
|
|
|
|
2015-07-02 03:17:14 +00:00
|
|
|
class Debugger
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
static Debugger* Instance;
|
|
|
|
|
2016-11-19 02:32:07 +00:00
|
|
|
const static int BreakpointTypeCount = 6;
|
|
|
|
|
2015-07-02 03:17:14 +00:00
|
|
|
unique_ptr<Disassembler> _disassembler;
|
2016-11-19 04:50:05 +00:00
|
|
|
shared_ptr<MemoryDumper> _memoryDumper;
|
|
|
|
shared_ptr<CodeDataLogger> _codeDataLogger;
|
|
|
|
|
2015-07-02 03:17:14 +00:00
|
|
|
shared_ptr<Console> _console;
|
|
|
|
shared_ptr<CPU> _cpu;
|
|
|
|
shared_ptr<PPU> _ppu;
|
|
|
|
shared_ptr<MemoryManager> _memoryManager;
|
|
|
|
shared_ptr<BaseMapper> _mapper;
|
2016-01-09 18:15:43 +00:00
|
|
|
|
2016-11-19 02:32:07 +00:00
|
|
|
bool _bpUpdateNeeded;
|
|
|
|
SimpleLock _bpUpdateLock;
|
|
|
|
|
2016-06-04 12:55:52 +00:00
|
|
|
atomic<bool> _stopFlag;
|
2016-01-26 21:47:21 +00:00
|
|
|
atomic<bool> _executionStopped;
|
2016-06-04 12:55:52 +00:00
|
|
|
atomic<int32_t> _suspendCount;
|
2016-01-26 21:47:21 +00:00
|
|
|
vector<Breakpoint> _newBreakpoints;
|
2016-11-19 02:32:07 +00:00
|
|
|
vector<Breakpoint> _breakpoints[BreakpointTypeCount];
|
|
|
|
bool _hasBreakpoint[BreakpointTypeCount];
|
2016-01-09 18:15:43 +00:00
|
|
|
|
2016-11-22 03:34:47 +00:00
|
|
|
unordered_map<uint32_t, string> _codeLabels;
|
2016-11-22 23:28:59 +00:00
|
|
|
unordered_map<string, uint32_t> _codeLabelReverseLookup;
|
2016-11-22 03:34:47 +00:00
|
|
|
unordered_map<uint32_t, string> _codeComments;
|
|
|
|
|
2015-08-09 18:47:27 +00:00
|
|
|
deque<uint32_t> _callstackAbsolute;
|
|
|
|
deque<uint32_t> _callstackRelative;
|
2015-07-02 03:17:14 +00:00
|
|
|
|
2016-11-20 18:15:37 +00:00
|
|
|
unordered_set<uint32_t> _functionEntryPoints;
|
|
|
|
|
2016-01-26 21:47:21 +00:00
|
|
|
DebugState _debugState;
|
|
|
|
|
2015-07-02 03:17:14 +00:00
|
|
|
SimpleLock _breakLock;
|
|
|
|
|
2016-07-31 18:31:44 +00:00
|
|
|
shared_ptr<TraceLogger> _traceLogger;
|
2016-01-11 00:56:40 +00:00
|
|
|
|
2016-10-23 14:16:08 +00:00
|
|
|
//Used to alter the executing address via "Set Next Statement"
|
|
|
|
uint16_t *_currentReadAddr;
|
|
|
|
uint8_t *_currentReadValue;
|
2015-08-18 01:59:22 +00:00
|
|
|
|
2016-06-05 14:26:05 +00:00
|
|
|
uint32_t _flags;
|
|
|
|
|
2016-06-18 00:53:05 +00:00
|
|
|
string _romName;
|
2015-07-02 03:17:14 +00:00
|
|
|
string _outputCache;
|
2015-08-10 00:45:45 +00:00
|
|
|
atomic<int32_t> _stepCount;
|
2016-06-04 19:38:48 +00:00
|
|
|
atomic<int32_t> _ppuStepCount;
|
2015-07-02 03:17:14 +00:00
|
|
|
atomic<int32_t> _stepCycleCount;
|
|
|
|
atomic<uint8_t> _lastInstruction;
|
|
|
|
atomic<bool> _stepOut;
|
|
|
|
atomic<int32_t> _stepOverAddr;
|
|
|
|
|
|
|
|
private:
|
2016-01-26 21:47:21 +00:00
|
|
|
void UpdateBreakpoints();
|
|
|
|
|
2016-01-09 18:15:43 +00:00
|
|
|
void PrivateProcessPpuCycle();
|
2016-10-23 14:16:08 +00:00
|
|
|
void PrivateProcessRamOperation(MemoryOperationType type, uint16_t &addr, uint8_t &value);
|
2016-01-09 18:15:43 +00:00
|
|
|
void PrivateProcessVramOperation(MemoryOperationType type, uint16_t addr, uint8_t value);
|
|
|
|
bool HasMatchingBreakpoint(BreakpointType type, uint32_t addr, int16_t value);
|
2016-11-22 05:14:49 +00:00
|
|
|
|
2015-08-17 23:32:10 +00:00
|
|
|
void UpdateCallstack(uint32_t addr);
|
2016-11-22 05:14:49 +00:00
|
|
|
void PrivateProcessInterrupt(uint16_t cpuAddr, uint16_t destCpuAddr, bool forNmi);
|
|
|
|
|
2015-08-17 23:32:10 +00:00
|
|
|
void ProcessStepConditions(uint32_t addr);
|
2015-07-02 03:17:14 +00:00
|
|
|
bool SleepUntilResume();
|
|
|
|
|
|
|
|
public:
|
|
|
|
Debugger(shared_ptr<Console> console, shared_ptr<CPU> cpu, shared_ptr<PPU> ppu, shared_ptr<MemoryManager> memoryManager, shared_ptr<BaseMapper> mapper);
|
|
|
|
~Debugger();
|
|
|
|
|
2016-06-05 14:26:05 +00:00
|
|
|
void SetFlags(uint32_t flags);
|
|
|
|
bool CheckFlag(DebuggerFlags flag);
|
|
|
|
|
2016-01-09 18:15:43 +00:00
|
|
|
void SetBreakpoints(Breakpoint breakpoints[], uint32_t length);
|
2016-11-22 03:34:47 +00:00
|
|
|
void SetLabel(uint32_t address, string label, string comment);
|
2015-07-02 03:17:14 +00:00
|
|
|
|
2016-11-22 23:28:59 +00:00
|
|
|
int32_t GetCodeLabelAddress(string label);
|
|
|
|
|
2016-11-20 18:15:37 +00:00
|
|
|
void GetFunctionEntryPoints(int32_t* entryPoints);
|
2015-08-09 18:47:27 +00:00
|
|
|
void GetCallstack(int32_t* callstackAbsolute, int32_t* callstackRelative);
|
2015-07-02 03:17:14 +00:00
|
|
|
void GetState(DebugState *state);
|
|
|
|
|
2016-06-04 12:55:52 +00:00
|
|
|
void Suspend();
|
|
|
|
void Resume();
|
|
|
|
|
2016-06-04 19:38:48 +00:00
|
|
|
void PpuStep(uint32_t count = 1);
|
2015-07-02 03:17:14 +00:00
|
|
|
void Step(uint32_t count = 1);
|
|
|
|
void StepCycles(uint32_t cycleCount = 1);
|
|
|
|
void StepOver();
|
|
|
|
void StepOut();
|
|
|
|
void Run();
|
|
|
|
|
2015-08-17 23:32:10 +00:00
|
|
|
bool LoadCdlFile(string cdlFilepath);
|
|
|
|
bool SaveCdlFile(string cdlFilepath);
|
|
|
|
CdlRatios GetCdlRatios();
|
|
|
|
void ResetCdlLog();
|
|
|
|
|
2015-08-18 01:59:22 +00:00
|
|
|
void SetNextStatement(uint16_t addr);
|
|
|
|
|
2015-07-02 03:17:14 +00:00
|
|
|
bool IsCodeChanged();
|
|
|
|
string GenerateOutput();
|
|
|
|
string* GetCode();
|
2016-01-10 18:23:19 +00:00
|
|
|
|
2015-07-02 03:17:14 +00:00
|
|
|
uint8_t GetMemoryValue(uint32_t addr);
|
2016-11-20 18:15:37 +00:00
|
|
|
int32_t GetRelativeAddress(uint32_t addr);
|
|
|
|
int32_t GetAbsoluteAddress(uint32_t addr);
|
2016-01-10 18:23:19 +00:00
|
|
|
|
2016-01-11 00:56:40 +00:00
|
|
|
void StartTraceLogger(TraceLoggerOptions options);
|
|
|
|
void StopTraceLogger();
|
|
|
|
|
2016-11-19 04:50:05 +00:00
|
|
|
shared_ptr<MemoryDumper> GetMemoryDumper();
|
|
|
|
|
2016-01-10 18:23:19 +00:00
|
|
|
int32_t EvaluateExpression(string expression, EvalResultType &resultType);
|
2015-07-02 03:17:14 +00:00
|
|
|
|
2016-10-23 14:16:08 +00:00
|
|
|
static void ProcessRamOperation(MemoryOperationType type, uint16_t &addr, uint8_t &value);
|
2016-01-09 18:15:43 +00:00
|
|
|
static void ProcessVramOperation(MemoryOperationType type, uint16_t addr, uint8_t value);
|
|
|
|
static void ProcessPpuCycle();
|
2015-12-30 01:54:55 +00:00
|
|
|
|
2016-11-22 05:14:49 +00:00
|
|
|
static void ProcessInterrupt(uint16_t cpuAddr, uint16_t destCpuAddr, bool forNmi);
|
|
|
|
|
2016-06-05 14:26:05 +00:00
|
|
|
static bool IsEnabled();
|
2015-12-30 01:54:55 +00:00
|
|
|
static void BreakIfDebugging();
|
2015-07-02 03:17:14 +00:00
|
|
|
};
|