2019-02-13 14:10:36 -05:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "../Core/Console.h"
|
|
|
|
#include "../Core/Debugger.h"
|
|
|
|
#include "../Core/TraceLogger.h"
|
2019-02-15 21:33:13 -05:00
|
|
|
#include "../Core/MemoryDumper.h"
|
2019-03-28 17:47:43 -04:00
|
|
|
#include "../Core/MemoryAccessCounter.h"
|
2019-02-27 19:49:26 -05:00
|
|
|
#include "../Core/Disassembler.h"
|
2019-02-15 21:33:13 -05:00
|
|
|
#include "../Core/DebugTypes.h"
|
2019-03-01 20:27:49 -05:00
|
|
|
#include "../Core/Breakpoint.h"
|
|
|
|
#include "../Core/BreakpointManager.h"
|
2019-03-03 16:34:23 -05:00
|
|
|
#include "../Core/PpuTools.h"
|
2019-03-28 17:47:43 -04:00
|
|
|
#include "../Core/CodeDataLogger.h"
|
2019-03-07 20:12:32 -05:00
|
|
|
#include "../Core/EventManager.h"
|
2019-03-24 12:05:51 -04:00
|
|
|
#include "../Core/CallstackManager.h"
|
2019-04-28 22:19:52 -04:00
|
|
|
#include "../Core/LabelManager.h"
|
2019-05-12 21:18:05 -04:00
|
|
|
#include "../Core/ScriptManager.h"
|
2020-02-08 17:08:33 -05:00
|
|
|
#include "../Core/Profiler.h"
|
2020-02-11 22:01:06 -05:00
|
|
|
#include "../Core/Assembler.h"
|
2020-05-21 20:57:00 -04:00
|
|
|
#include "../Core/BaseEventManager.h"
|
2019-02-13 14:10:36 -05:00
|
|
|
|
|
|
|
extern shared_ptr<Console> _console;
|
2020-06-23 18:34:03 -04:00
|
|
|
static string _logString;
|
2019-02-13 14:10:36 -05:00
|
|
|
|
|
|
|
shared_ptr<Debugger> GetDebugger()
|
|
|
|
{
|
2019-02-16 00:47:53 -05:00
|
|
|
return _console->GetDebugger();
|
2019-02-13 14:10:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
//Debugger wrapper
|
|
|
|
DllExport void __stdcall InitializeDebugger()
|
|
|
|
{
|
|
|
|
GetDebugger();
|
|
|
|
}
|
|
|
|
|
|
|
|
DllExport void __stdcall ReleaseDebugger()
|
|
|
|
{
|
2019-03-16 12:20:18 -04:00
|
|
|
_console->StopDebugger();
|
2019-02-13 14:10:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
DllExport bool __stdcall IsDebuggerRunning()
|
|
|
|
{
|
|
|
|
return _console->GetDebugger(false).get() != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
DllExport bool __stdcall IsExecutionStopped() { return GetDebugger()->IsExecutionStopped(); }
|
2019-03-01 20:27:49 -05:00
|
|
|
DllExport void __stdcall ResumeExecution() { if(IsDebuggerRunning()) GetDebugger()->Run(); }
|
2019-07-25 22:22:09 -04:00
|
|
|
DllExport void __stdcall Step(CpuType cpuType, uint32_t count, StepType type) { GetDebugger()->Step(cpuType, count, type); }
|
2019-02-27 19:49:26 -05:00
|
|
|
|
2019-04-28 22:19:52 -04:00
|
|
|
DllExport void __stdcall RefreshDisassembly(CpuType type) { GetDebugger()->GetDisassembler()->RefreshDisassembly(type); }
|
2019-04-07 12:25:14 -04:00
|
|
|
DllExport void __stdcall GetDisassemblyLineData(CpuType type, uint32_t lineIndex, CodeLineData &data) { GetDebugger()->GetDisassembler()->GetLineData(type, lineIndex, data); }
|
|
|
|
DllExport uint32_t __stdcall GetDisassemblyLineCount(CpuType type) { return GetDebugger()->GetDisassembler()->GetLineCount(type); }
|
|
|
|
DllExport uint32_t __stdcall GetDisassemblyLineIndex(CpuType type, uint32_t cpuAddress) { return GetDebugger()->GetDisassembler()->GetLineIndex(type, cpuAddress); }
|
|
|
|
DllExport int32_t __stdcall SearchDisassembly(CpuType type, const char* searchString, int32_t startPosition, int32_t endPosition, bool searchBackwards) { return GetDebugger()->GetDisassembler()->SearchDisassembly(type, searchString, startPosition, endPosition, searchBackwards); }
|
2019-02-13 14:10:36 -05:00
|
|
|
|
|
|
|
DllExport void __stdcall SetTraceOptions(TraceLoggerOptions options) { GetDebugger()->GetTraceLogger()->SetOptions(options); }
|
|
|
|
DllExport void __stdcall StartTraceLogger(char* filename) { GetDebugger()->GetTraceLogger()->StartLogging(filename); }
|
|
|
|
DllExport void __stdcall StopTraceLogger() { GetDebugger()->GetTraceLogger()->StopLogging(); }
|
2019-05-20 17:14:50 -04:00
|
|
|
DllExport void __stdcall ClearTraceLog() { GetDebugger()->GetTraceLogger()->Clear(); }
|
2019-02-13 14:10:36 -05:00
|
|
|
DllExport const char* GetExecutionTrace(uint32_t lineCount) { return GetDebugger()->GetTraceLogger()->GetExecutionTrace(lineCount); }
|
|
|
|
|
2019-10-11 16:07:30 -04:00
|
|
|
DllExport void __stdcall SetBreakpoints(Breakpoint breakpoints[], uint32_t length) { GetDebugger()->SetBreakpoints(breakpoints, length); }
|
2020-11-01 16:52:30 +03:00
|
|
|
DllExport void __stdcall GetBreakpoints(CpuType cpuType, Breakpoint* breakpoints, int& execs, int& reads, int& writes) { GetDebugger()->GetBreakpoints(cpuType, breakpoints, execs, reads, writes); }
|
|
|
|
|
2019-04-07 14:38:22 -04:00
|
|
|
DllExport int32_t __stdcall EvaluateExpression(char* expression, CpuType cpuType, EvalResultType *resultType, bool useCache) { return GetDebugger()->EvaluateExpression(expression, cpuType, *resultType, useCache); }
|
2019-04-07 12:25:14 -04:00
|
|
|
DllExport void __stdcall GetCallstack(CpuType cpuType, StackFrameInfo *callstackArray, uint32_t &callstackSize) { GetDebugger()->GetCallstackManager(cpuType)->GetCallstack(callstackArray, callstackSize); }
|
2020-02-08 17:08:33 -05:00
|
|
|
DllExport void __stdcall GetProfilerData(CpuType cpuType, ProfiledFunction* profilerData, uint32_t& functionCount) { GetDebugger()->GetCallstackManager(cpuType)->GetProfiler()->GetProfilerData(profilerData, functionCount); }
|
|
|
|
DllExport void __stdcall ResetProfiler(CpuType cpuType) { GetDebugger()->GetCallstackManager(cpuType)->GetProfiler()->Reset(); }
|
2019-02-27 20:33:56 -05:00
|
|
|
|
2020-06-23 18:34:03 -04:00
|
|
|
DllExport void __stdcall GetState(DebugState& state) { GetDebugger()->GetState(state, false); }
|
2020-11-01 16:52:30 +03:00
|
|
|
DllExport bool __stdcall GetCpuProcFlag(ProcFlags::ProcFlags flag) { return GetDebugger()->GetCpuProcFlag(flag); }
|
2020-10-11 13:57:01 +03:00
|
|
|
|
|
|
|
DllExport void __stdcall SetCpuRegister(CpuRegister reg, uint16_t value) { GetDebugger()->SetCpuRegister(reg, value); }
|
2020-10-12 18:19:46 +03:00
|
|
|
DllExport void __stdcall SetCpuProcFlag(ProcFlags::ProcFlags flag, bool set) { GetDebugger()->SetCpuProcFlag(flag, set); };
|
2020-10-12 16:49:10 +03:00
|
|
|
DllExport void __stdcall SetSpcRegister(SpcRegister reg, uint16_t value) { GetDebugger()->SetSpcRegister(reg, value); }
|
|
|
|
DllExport void __stdcall SetNecDspRegister(NecDspRegister reg, uint16_t value) { GetDebugger()->SetNecDspRegister(reg, value); }
|
|
|
|
DllExport void __stdcall SetSa1Register(CpuRegister reg, uint16_t value) { GetDebugger()->SetSa1Register(reg, value); }
|
|
|
|
DllExport void __stdcall SetGsuRegister(GsuRegister reg, uint16_t value) { GetDebugger()->SetGsuRegister(reg, value); }
|
2020-10-11 13:57:01 +03:00
|
|
|
DllExport void __stdcall SetCx4Register(Cx4Register reg, uint32_t value) { GetDebugger()->SetCx4Register(reg, value); }
|
2020-10-12 16:49:10 +03:00
|
|
|
DllExport void __stdcall SetGameboyRegister(GbRegister reg, uint16_t value) { GetDebugger()->SetGameboyRegister(reg, value); }
|
2020-10-11 13:57:01 +03:00
|
|
|
|
2020-06-23 18:34:03 -04:00
|
|
|
DllExport const char* __stdcall GetDebuggerLog()
|
|
|
|
{
|
|
|
|
_logString = GetDebugger()->GetLog();
|
|
|
|
return _logString.c_str();
|
|
|
|
}
|
2019-02-15 21:33:13 -05:00
|
|
|
|
|
|
|
DllExport void __stdcall SetMemoryState(SnesMemoryType type, uint8_t *buffer, int32_t length) { GetDebugger()->GetMemoryDumper()->SetMemoryState(type, buffer, length); }
|
|
|
|
DllExport uint32_t __stdcall GetMemorySize(SnesMemoryType type) { return GetDebugger()->GetMemoryDumper()->GetMemorySize(type); }
|
|
|
|
DllExport void __stdcall GetMemoryState(SnesMemoryType type, uint8_t *buffer) { GetDebugger()->GetMemoryDumper()->GetMemoryState(type, buffer); }
|
|
|
|
DllExport uint8_t __stdcall GetMemoryValue(SnesMemoryType type, uint32_t address) { return GetDebugger()->GetMemoryDumper()->GetMemoryValue(type, address); }
|
|
|
|
DllExport void __stdcall SetMemoryValue(SnesMemoryType type, uint32_t address, uint8_t value) { return GetDebugger()->GetMemoryDumper()->SetMemoryValue(type, address, value); }
|
|
|
|
DllExport void __stdcall SetMemoryValues(SnesMemoryType type, uint32_t address, uint8_t* data, int32_t length) { return GetDebugger()->GetMemoryDumper()->SetMemoryValues(type, address, data, length); }
|
2019-03-03 16:34:23 -05:00
|
|
|
|
2019-04-27 12:10:31 -04:00
|
|
|
DllExport AddressInfo __stdcall GetAbsoluteAddress(AddressInfo relAddress) { return GetDebugger()->GetAbsoluteAddress(relAddress); }
|
2020-02-23 15:58:14 -05:00
|
|
|
DllExport AddressInfo __stdcall GetRelativeAddress(AddressInfo absAddress, CpuType cpuType) { return GetDebugger()->GetRelativeAddress(absAddress, cpuType); }
|
2019-04-27 12:10:31 -04:00
|
|
|
|
2019-04-28 22:19:52 -04:00
|
|
|
DllExport void __stdcall SetLabel(uint32_t address, SnesMemoryType memType, char* label, char* comment) { GetDebugger()->GetLabelManager()->SetLabel(address, memType, label, comment); }
|
|
|
|
DllExport void __stdcall ClearLabels() { GetDebugger()->GetLabelManager()->ClearLabels(); }
|
|
|
|
|
2020-02-15 10:49:11 -05:00
|
|
|
DllExport void __stdcall ResetMemoryAccessCounts() { GetDebugger()->GetMemoryAccessCounter()->ResetCounts(); }
|
2020-02-12 21:26:50 -05:00
|
|
|
DllExport void __stdcall GetMemoryAccessCounts(uint32_t offset, uint32_t length, SnesMemoryType memoryType, AddressCounters* counts) { GetDebugger()->GetMemoryAccessCounter()->GetAccessCounts(offset, length, memoryType, counts); }
|
2019-04-29 20:40:52 -04:00
|
|
|
|
2020-02-25 23:56:55 -05:00
|
|
|
DllExport void __stdcall GetCdlData(uint32_t offset, uint32_t length, SnesMemoryType memoryType, uint8_t* cdlData) { GetDebugger()->GetCdlData(offset, length, memoryType, cdlData); }
|
2020-06-18 00:58:22 -04:00
|
|
|
DllExport void __stdcall SetCdlData(CpuType cpuType, uint8_t* cdlData, uint32_t length) { GetDebugger()->SetCdlData(cpuType, cdlData, length); }
|
|
|
|
DllExport void __stdcall MarkBytesAs(CpuType cpuType, uint32_t start, uint32_t end, uint8_t flags) { GetDebugger()->MarkBytesAs(cpuType, start, end, flags); }
|
2019-04-29 20:40:52 -04:00
|
|
|
|
2019-07-18 16:21:41 -04:00
|
|
|
DllExport void __stdcall GetTilemap(GetTilemapOptions options, PpuState state, uint8_t *vram, uint8_t *cgram, uint32_t *buffer) { GetDebugger()->GetPpuTools()->GetTilemap(options, state, vram, cgram, buffer); }
|
2019-03-30 12:20:52 -04:00
|
|
|
DllExport void __stdcall GetTileView(GetTileViewOptions options, uint8_t *source, uint32_t srcSize, uint8_t *cgram, uint32_t *buffer) { GetDebugger()->GetPpuTools()->GetTileView(options, source, srcSize, cgram, buffer); }
|
2019-04-25 19:49:15 -04:00
|
|
|
DllExport void __stdcall GetSpritePreview(GetSpritePreviewOptions options, PpuState state, uint8_t* vram, uint8_t *oamRam, uint8_t *cgram, uint32_t *buffer) { GetDebugger()->GetPpuTools()->GetSpritePreview(options, state, vram, oamRam, cgram, buffer); }
|
2020-06-18 00:58:22 -04:00
|
|
|
DllExport void __stdcall SetViewerUpdateTiming(uint32_t viewerId, uint16_t scanline, uint16_t cycle, CpuType cpuType) { GetDebugger()->GetPpuTools()->SetViewerUpdateTiming(viewerId, scanline, cycle, cpuType); }
|
2019-03-07 20:12:32 -05:00
|
|
|
|
2020-06-01 21:42:49 -04:00
|
|
|
DllExport void __stdcall GetGameboyTilemap(uint8_t* vram, GbPpuState state, uint16_t offset, uint32_t* buffer) { GetDebugger()->GetPpuTools()->GetGameboyTilemap(vram, state, offset, buffer); }
|
2020-06-01 23:36:18 -04:00
|
|
|
DllExport void __stdcall GetGameboySpritePreview(GetSpritePreviewOptions options, GbPpuState state, uint8_t* vram, uint8_t* oamRam, uint32_t* buffer) { GetDebugger()->GetPpuTools()->GetGameboySpritePreview(options, state, vram, oamRam, buffer); }
|
2020-05-18 16:10:53 -04:00
|
|
|
|
2020-06-18 00:58:22 -04:00
|
|
|
DllExport void __stdcall GetDebugEvents(CpuType cpuType, DebugEventInfo *infoArray, uint32_t &maxEventCount) { GetDebugger()->GetEventManager(cpuType)->GetEvents(infoArray, maxEventCount); }
|
|
|
|
DllExport uint32_t __stdcall GetDebugEventCount(CpuType cpuType, EventViewerDisplayOptions options) { return GetDebugger()->GetEventManager(cpuType)->GetEventCount(options); }
|
|
|
|
DllExport void __stdcall GetEventViewerOutput(CpuType cpuType, uint32_t *buffer, uint32_t bufferSize, EventViewerDisplayOptions options) { GetDebugger()->GetEventManager(cpuType)->GetDisplayBuffer(buffer, bufferSize, options); }
|
|
|
|
DllExport void __stdcall GetEventViewerEvent(CpuType cpuType, DebugEventInfo *evtInfo, uint16_t scanline, uint16_t cycle, EventViewerDisplayOptions options) { *evtInfo = GetDebugger()->GetEventManager(cpuType)->GetEvent(scanline, cycle, options); }
|
|
|
|
DllExport uint32_t __stdcall TakeEventSnapshot(CpuType cpuType, EventViewerDisplayOptions options) { return GetDebugger()->GetEventManager(cpuType)->TakeEventSnapshot(options); }
|
2019-05-12 21:18:05 -04:00
|
|
|
|
|
|
|
DllExport int32_t __stdcall LoadScript(char* name, char* content, int32_t scriptId) { return GetDebugger()->GetScriptManager()->LoadScript(name, content, scriptId); }
|
|
|
|
DllExport void __stdcall RemoveScript(int32_t scriptId) { GetDebugger()->GetScriptManager()->RemoveScript(scriptId); }
|
|
|
|
DllExport const char* __stdcall GetScriptLog(int32_t scriptId) { return GetDebugger()->GetScriptManager()->GetScriptLog(scriptId); }
|
|
|
|
//DllExport void __stdcall DebugSetScriptTimeout(uint32_t timeout) { LuaScriptingContext::SetScriptTimeout(timeout); }
|
2020-02-11 22:01:06 -05:00
|
|
|
|
2020-06-06 22:27:54 -04:00
|
|
|
DllExport uint32_t __stdcall AssembleCode(CpuType cpuType, char* code, uint32_t startAddress, int16_t* assembledOutput) { return GetDebugger()->GetAssembler(cpuType)->AssembleCode(code, startAddress, assembledOutput); }
|
2020-02-12 19:36:47 -05:00
|
|
|
|
|
|
|
DllExport void __stdcall SaveRomToDisk(char* filename, bool saveIpsFile, CdlStripOption cdlStripOption) { GetDebugger()->SaveRomToDisk(filename, saveIpsFile, cdlStripOption); }
|
2019-02-13 14:10:36 -05:00
|
|
|
};
|