2015-07-01 23:17:14 -04:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "../Core/Console.h"
|
|
|
|
#include "../Core/Debugger.h"
|
2015-08-17 19:32:10 -04:00
|
|
|
#include "../Core/CodeDataLogger.h"
|
2016-11-22 22:38:14 -05:00
|
|
|
#include "../Core/LabelManager.h"
|
2016-12-01 19:38:48 -05:00
|
|
|
#include "../Core/MemoryDumper.h"
|
|
|
|
#include "../Core/MemoryAccessCounter.h"
|
2016-12-08 19:30:41 -05:00
|
|
|
#include "../Core/Profiler.h"
|
2017-03-07 17:51:14 -05:00
|
|
|
#include "../Core/Assembler.h"
|
2018-07-01 15:21:05 -04:00
|
|
|
#include "../Core/TraceLogger.h"
|
2019-01-24 00:50:42 -05:00
|
|
|
#include "../Core/PerformanceTracker.h"
|
2018-09-02 15:37:13 -04:00
|
|
|
#include "../Core/LuaScriptingContext.h"
|
2018-07-01 15:21:05 -04:00
|
|
|
|
2018-07-13 22:19:26 -04:00
|
|
|
enum class ConsoleId;
|
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
extern shared_ptr<Console> _console;
|
2018-07-13 22:19:26 -04:00
|
|
|
extern shared_ptr<Console> GetConsoleById(ConsoleId consoleId);
|
|
|
|
|
|
|
|
static ConsoleId _debugConsoleId = ConsoleId::Master;
|
2015-07-01 23:17:14 -04:00
|
|
|
|
2015-08-21 22:42:44 -04:00
|
|
|
shared_ptr<Debugger> GetDebugger()
|
|
|
|
{
|
2018-07-06 00:10:10 -04:00
|
|
|
return GetConsoleById(_debugConsoleId)->GetDebugger();
|
2015-08-21 22:42:44 -04:00
|
|
|
}
|
2015-07-01 23:17:14 -04:00
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
//Debugger wrapper
|
|
|
|
DllExport void __stdcall DebugInitialize()
|
|
|
|
{
|
2018-07-02 21:32:59 -04:00
|
|
|
GetDebugger();
|
2015-07-01 23:17:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
DllExport void __stdcall DebugRelease()
|
|
|
|
{
|
2018-07-06 00:10:10 -04:00
|
|
|
GetConsoleById(_debugConsoleId)->StopDebugger();
|
2015-07-01 23:17:14 -04:00
|
|
|
}
|
|
|
|
|
2016-08-25 19:02:33 -04:00
|
|
|
DllExport bool __stdcall DebugIsDebuggerRunning()
|
|
|
|
{
|
2018-07-06 00:10:10 -04:00
|
|
|
return GetConsoleById(_debugConsoleId)->GetDebugger(false).get() != nullptr;
|
|
|
|
}
|
|
|
|
|
2018-07-13 22:19:26 -04:00
|
|
|
DllExport void __stdcall DebugSetDebuggerConsole(ConsoleId consoleId)
|
2018-07-06 00:10:10 -04:00
|
|
|
{
|
|
|
|
_debugConsoleId = consoleId;
|
2016-08-25 19:02:33 -04:00
|
|
|
}
|
|
|
|
|
2016-06-05 10:26:05 -04:00
|
|
|
DllExport void __stdcall DebugSetFlags(uint32_t flags) { GetDebugger()->SetFlags(flags); }
|
|
|
|
|
2015-08-21 22:42:44 -04:00
|
|
|
DllExport void __stdcall DebugGetState(DebugState *state) { GetDebugger()->GetState(state); }
|
2016-11-26 17:48:11 -05:00
|
|
|
DllExport void __stdcall DebugSetState(DebugState state) { GetDebugger()->SetState(state); }
|
2018-01-01 23:23:18 -05:00
|
|
|
DllExport void __stdcall DebugGetApuState(ApuState *state) { GetDebugger()->GetApuState(state); }
|
2018-12-23 11:56:28 -05:00
|
|
|
DllExport void __stdcall DebugGetInstructionProgress(InstructionProgress *state) { GetDebugger()->GetInstructionProgress(*state); }
|
2015-07-01 23:17:14 -04:00
|
|
|
|
2016-01-09 13:15:43 -05:00
|
|
|
DllExport void __stdcall DebugSetBreakpoints(Breakpoint breakpoints[], uint32_t length) { GetDebugger()->SetBreakpoints(breakpoints, length); }
|
2016-11-22 22:38:14 -05:00
|
|
|
DllExport void __stdcall DebugSetLabel(uint32_t address, AddressType addressType, char* label, char* comment) { GetDebugger()->GetLabelManager()->SetLabel(address, addressType, label, comment); }
|
2018-06-09 21:25:49 -04:00
|
|
|
DllExport void __stdcall DebugDeleteLabels() { GetDebugger()->GetLabelManager()->DeleteLabels(); }
|
2016-11-26 17:48:11 -05:00
|
|
|
|
|
|
|
DllExport bool __stdcall DebugIsExecutionStopped() { return GetDebugger()->IsExecutionStopped(); }
|
2015-08-21 22:42:44 -04:00
|
|
|
DllExport void __stdcall DebugRun() { GetDebugger()->Run(); }
|
2018-12-23 00:10:00 -05:00
|
|
|
DllExport void __stdcall DebugStep(uint32_t count, BreakSource breakSource) { GetDebugger()->Step(count, breakSource); }
|
2015-08-21 22:42:44 -04:00
|
|
|
DllExport void __stdcall DebugStepCycles(uint32_t count) { GetDebugger()->StepCycles(count); }
|
|
|
|
DllExport void __stdcall DebugStepOver() { GetDebugger()->StepOver(); }
|
|
|
|
DllExport void __stdcall DebugStepOut() { GetDebugger()->StepOut(); }
|
2017-08-01 22:49:50 -04:00
|
|
|
DllExport void __stdcall DebugStepBack() { GetDebugger()->StepBack(); }
|
2016-06-04 15:38:48 -04:00
|
|
|
DllExport void __stdcall DebugPpuStep(uint32_t count) { GetDebugger()->PpuStep(count); }
|
2018-02-24 11:07:27 -05:00
|
|
|
DllExport void __stdcall DebugBreakOnScanline(int32_t scanline) { GetDebugger()->BreakOnScanline(scanline); }
|
2017-03-09 23:50:20 -05:00
|
|
|
DllExport const char* __stdcall DebugGetCode(uint32_t &length) { return GetDebugger()->GetCode(length); }
|
2018-09-08 13:16:17 -04:00
|
|
|
|
2018-04-10 17:05:54 -04:00
|
|
|
DllExport void __stdcall DebugSetPpuViewerScanlineCycle(int32_t ppuViewerId, int32_t scanline, int32_t cycle) { return GetDebugger()->SetPpuViewerScanlineCycle(ppuViewerId, scanline, cycle); }
|
|
|
|
DllExport void __stdcall DebugClearPpuViewerSettings(int32_t ppuViewerId) { return GetDebugger()->ClearPpuViewerSettings(ppuViewerId); }
|
2016-11-26 20:44:23 -05:00
|
|
|
|
2015-08-21 22:42:44 -04:00
|
|
|
DllExport void __stdcall DebugSetNextStatement(uint16_t addr) { GetDebugger()->SetNextStatement(addr); }
|
2019-01-13 19:15:37 -05:00
|
|
|
DllExport void __stdcall DebugSetMemoryState(DebugMemoryType type, uint8_t *buffer, int32_t length) { GetDebugger()->GetMemoryDumper()->SetMemoryState(type, buffer, length); }
|
2015-08-21 22:42:44 -04:00
|
|
|
|
2017-05-02 21:23:28 -04:00
|
|
|
DllExport uint32_t __stdcall DebugGetMemorySize(DebugMemoryType type) { return GetDebugger()->GetMemoryDumper()->GetMemorySize(type); }
|
|
|
|
DllExport uint32_t __stdcall DebugGetMemoryState(DebugMemoryType type, uint8_t *buffer) { return GetDebugger()->GetMemoryDumper()->GetMemoryState(type, buffer); }
|
2019-01-19 14:50:47 -05:00
|
|
|
DllExport void __stdcall DebugGetNametable(uint32_t nametableIndex, NametableDisplayMode mode, uint32_t *frameBuffer, uint8_t *tileData, uint8_t *attributeData) { GetDebugger()->GetMemoryDumper()->GetNametable(nametableIndex, mode, frameBuffer, tileData, attributeData); }
|
2018-07-28 15:32:38 -04:00
|
|
|
DllExport void __stdcall DebugGetChrBank(uint32_t bankIndex, uint32_t *frameBuffer, uint8_t palette, bool largeSprites, CdlHighlightType highlightType, bool useAutoPalette, bool showSingleColorTilesInGrayscale, uint32_t *paletteBuffer) { GetDebugger()->GetMemoryDumper()->GetChrBank(bankIndex, frameBuffer, palette, largeSprites, highlightType, useAutoPalette, showSingleColorTilesInGrayscale, paletteBuffer); }
|
2016-11-18 23:50:05 -05:00
|
|
|
DllExport void __stdcall DebugGetSprites(uint32_t *frameBuffer) { GetDebugger()->GetMemoryDumper()->GetSprites(frameBuffer); }
|
|
|
|
DllExport void __stdcall DebugGetPalette(uint32_t *frameBuffer) { GetDebugger()->GetMemoryDumper()->GetPalette(frameBuffer); }
|
2015-08-05 20:40:10 -04:00
|
|
|
|
2018-03-05 21:18:29 -05:00
|
|
|
DllExport void __stdcall DebugGetCallstack(StackFrameInfo *callstackArray, uint32_t &callstackSize) { GetDebugger()->GetCallstack(callstackArray, callstackSize); }
|
2017-03-09 23:50:20 -05:00
|
|
|
DllExport int32_t __stdcall DebugGetFunctionEntryPointCount() { return GetDebugger()->GetFunctionEntryPointCount(); }
|
|
|
|
DllExport void __stdcall DebugGetFunctionEntryPoints(int32_t *entryPoints, int32_t maxCount) { GetDebugger()->GetFunctionEntryPoints(entryPoints, maxCount); }
|
2015-08-09 14:47:27 -04:00
|
|
|
|
2016-11-22 22:38:14 -05:00
|
|
|
DllExport int32_t __stdcall DebugGetRelativeAddress(uint32_t addr, AddressType type) { return GetDebugger()->GetRelativeAddress(addr, type); }
|
2019-01-14 19:01:13 -05:00
|
|
|
DllExport int32_t __stdcall DebugGetRelativePpuAddress(uint32_t addr, PpuAddressType type) { return GetDebugger()->GetRelativePpuAddress(addr, type); }
|
2016-11-21 22:34:47 -05:00
|
|
|
DllExport int32_t __stdcall DebugGetAbsoluteAddress(uint32_t addr) { return GetDebugger()->GetAbsoluteAddress(addr); }
|
2017-08-13 20:45:36 -04:00
|
|
|
DllExport int32_t __stdcall DebugGetAbsoluteChrAddress(uint32_t addr) { return GetDebugger()->GetAbsoluteChrAddress(addr); }
|
2016-11-22 22:38:14 -05:00
|
|
|
DllExport void __stdcall DebugGetAbsoluteAddressAndType(uint32_t relativeAddr, AddressTypeInfo* info) { return GetDebugger()->GetAbsoluteAddressAndType(relativeAddr, info); }
|
2019-01-14 19:01:13 -05:00
|
|
|
DllExport void __stdcall DebugGetPpuAbsoluteAddressAndType(uint32_t relativeAddr, PpuAddressTypeInfo* info) { return GetDebugger()->GetPpuAbsoluteAddressAndType(relativeAddr, info); }
|
2015-08-17 19:32:10 -04:00
|
|
|
|
2015-08-21 22:42:44 -04:00
|
|
|
DllExport bool __stdcall DebugLoadCdlFile(char* cdlFilepath) { return GetDebugger()->LoadCdlFile(cdlFilepath); }
|
2016-12-05 23:35:07 -05:00
|
|
|
DllExport bool __stdcall DebugSaveCdlFile(char* cdlFilepath) { return GetDebugger()->GetCodeDataLogger()->SaveCdlFile(cdlFilepath); }
|
|
|
|
DllExport void __stdcall DebugGetCdlRatios(CdlRatios* cdlRatios) { *cdlRatios = GetDebugger()->GetCodeDataLogger()->GetRatios(); }
|
2017-08-19 22:00:12 -04:00
|
|
|
DllExport void __stdcall DebugResetCdlLog() { GetDebugger()->ResetCdl(); }
|
2018-02-23 08:28:29 -05:00
|
|
|
DllExport void __stdcall DebugSetCdlData(uint8_t* cdlData, uint32_t length) { GetDebugger()->SetCdlData(cdlData, length); }
|
2017-12-26 17:33:46 -05:00
|
|
|
DllExport void __stdcall DebugGetCdlData(uint32_t offset, uint32_t length, DebugMemoryType memoryType, uint8_t* cdlData) { GetDebugger()->GetCodeDataLogger()->GetCdlData(offset, length, memoryType, cdlData); }
|
2018-01-03 18:48:16 -05:00
|
|
|
DllExport void __stdcall DebugMarkPrgBytesAs(uint32_t start, uint32_t end, CdlPrgFlags type) { GetDebugger()->GetCodeDataLogger()->MarkPrgBytesAs(start, end, type); }
|
|
|
|
|
2018-08-02 20:44:48 -04:00
|
|
|
DllExport int32_t __stdcall DebugEvaluateExpression(char* expression, EvalResultType *resultType, bool useCache) { return GetDebugger()->EvaluateExpression(expression, *resultType, useCache); }
|
2016-01-10 19:56:40 -05:00
|
|
|
|
2017-03-04 15:18:00 -05:00
|
|
|
DllExport void __stdcall DebugSetTraceOptions(TraceLoggerOptions options) { GetDebugger()->GetTraceLogger()->SetOptions(options); }
|
|
|
|
DllExport void __stdcall DebugStartTraceLogger(char* filename) { GetDebugger()->GetTraceLogger()->StartLogging(filename); }
|
|
|
|
DllExport void __stdcall DebugStopTraceLogger() { GetDebugger()->GetTraceLogger()->StopLogging(); }
|
|
|
|
DllExport const char* DebugGetExecutionTrace(uint32_t lineCount) { return GetDebugger()->GetTraceLogger()->GetExecutionTrace(lineCount); }
|
2016-12-01 19:38:48 -05:00
|
|
|
|
2017-03-04 21:50:19 -05:00
|
|
|
DllExport uint8_t __stdcall DebugGetMemoryValue(DebugMemoryType type, uint32_t address) { return GetDebugger()->GetMemoryDumper()->GetMemoryValue(type, address); }
|
2017-02-26 20:47:39 -05:00
|
|
|
DllExport void __stdcall DebugSetMemoryValue(DebugMemoryType type, uint32_t address, uint8_t value) { return GetDebugger()->GetMemoryDumper()->SetMemoryValue(type, address, value); }
|
2017-03-11 15:01:33 -05:00
|
|
|
DllExport void __stdcall DebugSetMemoryValues(DebugMemoryType type, uint32_t address, uint8_t* data, int32_t length) { return GetDebugger()->GetMemoryDumper()->SetMemoryValues(type, address, data, length); }
|
|
|
|
|
2016-12-01 19:38:48 -05:00
|
|
|
DllExport void __stdcall DebugResetMemoryAccessCounts() { GetDebugger()->GetMemoryAccessCounter()->ResetCounts(); }
|
2017-03-01 20:52:15 -05:00
|
|
|
DllExport void __stdcall DebugGetMemoryAccessStamps(uint32_t offset, uint32_t length, DebugMemoryType memoryType, MemoryOperationType operationType, uint32_t* stamps) { GetDebugger()->GetMemoryAccessCounter()->GetAccessStamps(offset, length, memoryType, operationType, stamps); }
|
2019-01-13 18:32:27 -05:00
|
|
|
DllExport void __stdcall DebugGetMemoryAccessCounts(uint32_t offset, uint32_t length, DebugMemoryType memoryType, MemoryOperationType operationType, int32_t* counts) { GetDebugger()->GetMemoryAccessCounter()->GetAccessCounts(offset, length, memoryType, operationType, counts); }
|
|
|
|
DllExport void __stdcall DebugGetUninitMemoryReads(DebugMemoryType memoryType, int32_t* counts) { GetDebugger()->GetMemoryAccessCounter()->GetUninitMemoryReads(memoryType, counts); }
|
|
|
|
DllExport void __stdcall DebugGetNametableChangedData(bool* ntChangedData) { GetDebugger()->GetMemoryAccessCounter()->GetNametableChangedData(ntChangedData); }
|
2016-12-02 18:10:37 -05:00
|
|
|
|
2016-12-08 19:30:41 -05:00
|
|
|
DllExport void __stdcall DebugGetProfilerData(int64_t* profilerData, ProfilerDataType dataType) { GetDebugger()->GetProfiler()->GetProfilerData(profilerData, dataType); }
|
|
|
|
DllExport void __stdcall DebugResetProfiler() { GetDebugger()->GetProfiler()->Reset(); }
|
2017-03-02 20:33:25 -05:00
|
|
|
|
|
|
|
DllExport void __stdcall DebugSetFreezeState(uint16_t address, bool frozen) { GetDebugger()->SetFreezeState(address, frozen); }
|
|
|
|
DllExport void __stdcall DebugGetFreezeState(uint16_t startAddress, uint16_t length, bool* freezeState) { GetDebugger()->GetFreezeState(startAddress, length, freezeState); }
|
2016-12-08 19:30:41 -05:00
|
|
|
|
2016-12-02 18:10:37 -05:00
|
|
|
DllExport uint32_t __stdcall DebugGetPpuScroll() { return GetDebugger()->GetPpuScroll(); }
|
2017-03-04 22:24:41 -05:00
|
|
|
|
2017-03-07 17:51:14 -05:00
|
|
|
DllExport uint32_t __stdcall DebugAssembleCode(char* code, uint16_t startAddress, int16_t* assembledOutput) { return GetDebugger()->GetAssembler()->AssembleCode(code, startAddress, assembledOutput); }
|
2017-03-11 21:03:45 -05:00
|
|
|
DllExport void __stdcall DebugStartCodeRunner(uint8_t* byteCode, uint32_t codeLength) { return GetDebugger()->StartCodeRunner(byteCode, codeLength); }
|
2017-08-12 16:52:45 -04:00
|
|
|
|
|
|
|
DllExport void __stdcall DebugGetNesHeader(uint8_t* header) { GetDebugger()->GetNesHeader(header); }
|
2018-01-01 12:09:33 -05:00
|
|
|
DllExport void __stdcall DebugSaveRomToDisk(char* filename, bool saveIpsFile, uint8_t* header, CdlStripFlag cdlStripFlag) { GetDebugger()->SaveRomToDisk(filename, saveIpsFile, header, cdlStripFlag); }
|
2017-08-21 23:11:14 -04:00
|
|
|
DllExport bool __stdcall DebugHasPrgChrChanges() { return GetDebugger()->HasPrgChrChanges(); }
|
|
|
|
DllExport void __stdcall DebugRevertPrgChrChanges() { GetDebugger()->RevertPrgChrChanges(); }
|
2017-03-09 20:42:53 -05:00
|
|
|
|
2018-02-24 14:23:54 -05:00
|
|
|
DllExport bool __stdcall DebugHasUndoHistory() { return GetDebugger()->GetMemoryDumper()->HasUndoHistory(); }
|
|
|
|
DllExport void __stdcall DebugPerformUndo() { GetDebugger()->GetMemoryDumper()->PerformUndo(); }
|
|
|
|
|
2017-03-09 20:42:53 -05:00
|
|
|
DllExport int32_t __stdcall DebugFindSubEntryPoint(uint16_t relativeAddress) { return GetDebugger()->FindSubEntryPoint(relativeAddress); }
|
2017-08-05 23:26:21 -04:00
|
|
|
|
2019-01-24 00:50:42 -05:00
|
|
|
DllExport PerfTrackerMode __stdcall DebugGetPerformanceTrackerMode() { return GetDebugger()->GetPerformanceTracker()->GetMode(); }
|
|
|
|
DllExport void __stdcall DebugSetPerformanceTracker(uint32_t address, AddressType type, PerfTrackerMode mode) { GetDebugger()->GetPerformanceTracker()->Initialize(address, type, mode); }
|
|
|
|
|
2017-08-05 23:26:21 -04:00
|
|
|
DllExport void __stdcall DebugSetInputOverride(uint32_t port, uint32_t state) { GetDebugger()->SetInputOverride(port, state); }
|
2017-08-30 18:31:27 -04:00
|
|
|
|
2017-10-07 15:16:14 -04:00
|
|
|
DllExport int32_t __stdcall DebugLoadScript(char* name, char* content, int32_t scriptId) { return GetDebugger()->LoadScript(name, content, scriptId); }
|
2017-08-30 18:31:27 -04:00
|
|
|
DllExport void __stdcall DebugRemoveScript(int32_t scriptId) { GetDebugger()->RemoveScript(scriptId); }
|
|
|
|
DllExport const char* __stdcall DebugGetScriptLog(int32_t scriptId) { return GetDebugger()->GetScriptLog(scriptId); }
|
2018-09-02 15:37:13 -04:00
|
|
|
DllExport void __stdcall DebugSetScriptTimeout(uint32_t timeout) { LuaScriptingContext::SetScriptTimeout(timeout); }
|
2018-02-16 17:36:37 -05:00
|
|
|
|
2018-07-26 21:29:56 -04:00
|
|
|
DllExport void __stdcall DebugGetDebugEvents(uint32_t* pictureBuffer, DebugEventInfo *infoArray, uint32_t &maxEventCount, bool returnPreviousFrameData) { GetDebugger()->GetDebugEvents(pictureBuffer, infoArray, maxEventCount, returnPreviousFrameData); }
|
|
|
|
DllExport uint32_t __stdcall DebugGetDebugEventCount(bool returnPreviousFrameData) { return GetDebugger()->GetDebugEventCount(returnPreviousFrameData); }
|
2015-07-01 23:17:14 -04:00
|
|
|
};
|