Debugger: Event Viewer - Added option to display the previous frame's events

This commit is contained in:
Sour 2018-07-26 21:29:56 -04:00
parent 9120ac35a9
commit 96bec3b2ad
9 changed files with 80 additions and 28 deletions

View file

@ -1346,6 +1346,7 @@ void Debugger::ProcessEvent(EventType type)
if(CheckFlag(DebuggerFlags::PpuPartialDraw)) {
_ppu->DebugUpdateFrameBuffer(CheckFlag(DebuggerFlags::PpuShowPreviousFrame));
}
_prevDebugEvents = _debugEvents;
_debugEvents.clear();
} else if(type == EventType::Nmi) {
AddDebugEvent(DebugEventType::Nmi);
@ -1372,7 +1373,7 @@ void Debugger::AddDebugEvent(DebugEventType type, uint16_t address, uint8_t valu
});
}
void Debugger::GetDebugEvents(uint32_t* pictureBuffer, DebugEventInfo *infoArray, uint32_t &maxEventCount)
void Debugger::GetDebugEvents(uint32_t* pictureBuffer, DebugEventInfo *infoArray, uint32_t &maxEventCount, bool returnPreviousFrameData)
{
DebugBreakHelper helper(this);
@ -1383,14 +1384,16 @@ void Debugger::GetDebugEvents(uint32_t* pictureBuffer, DebugEventInfo *infoArray
for(int i = 0; i < PPU::PixelCount; i++) {
pictureBuffer[i] = palette[buffer[i] & 0x3F];
}
uint32_t eventCount = std::min(maxEventCount, (uint32_t)_debugEvents.size());
memcpy(infoArray, _debugEvents.data(), eventCount * sizeof(DebugEventInfo));
vector<DebugEventInfo> &events = returnPreviousFrameData ? _prevDebugEvents : _debugEvents;
uint32_t eventCount = std::min(maxEventCount, (uint32_t)events.size());
memcpy(infoArray, events.data(), eventCount * sizeof(DebugEventInfo));
maxEventCount = eventCount;
}
uint32_t Debugger::GetDebugEventCount()
uint32_t Debugger::GetDebugEventCount(bool returnPreviousFrameData)
{
return (uint32_t)_debugEvents.size();
return (uint32_t)(returnPreviousFrameData ? _prevDebugEvents.size() : _debugEvents.size());
}
uint32_t Debugger::GetScreenPixel(uint8_t x, uint8_t y)

View file

@ -124,6 +124,7 @@ private:
uint32_t _inputOverride[4];
vector<DebugEventInfo> _prevDebugEvents;
vector<DebugEventInfo> _debugEvents;
vector<vector<int>> _debugEventMarkerRpn;
@ -256,8 +257,8 @@ public:
void ProcessPpuOperation(uint16_t addr, uint8_t &value, MemoryOperationType type);
void ProcessEvent(EventType type);
void GetDebugEvents(uint32_t* pictureBuffer, DebugEventInfo *infoArray, uint32_t &maxEventCount);
uint32_t GetDebugEventCount();
void GetDebugEvents(uint32_t* pictureBuffer, DebugEventInfo *infoArray, uint32_t &maxEventCount, bool returnPreviousFrameData);
uint32_t GetDebugEventCount(bool returnPreviousFrameData);
uint32_t GetScreenPixel(uint8_t x, uint8_t y);
};

View file

@ -154,6 +154,7 @@ namespace Mesen.GUI.Config
public bool EventViewerShowIrq = true;
public bool EventViewerShowSpriteZeroHit = true;
public bool EventViewerShowMarkedBreakpoints = true;
public bool EventViewerShowPreviousFrameEvents = true;
public XmlColor EventViewerMapperRegisterWriteColor = ColorTranslator.FromHtml("#007597");
public XmlColor EventViewerMapperRegisterReadColor = ColorTranslator.FromHtml("#C92929");

View file

@ -40,7 +40,7 @@ namespace Mesen.GUI.Debugger.Controls
DebugEventInfo[] eventInfoArray;
byte[] pictureData;
_breakpoints = BreakpointManager.Breakpoints;
InteropEmu.DebugGetDebugEvents(out pictureData, out eventInfoArray);
InteropEmu.DebugGetDebugEvents(false, out pictureData, out eventInfoArray);
this.BeginInvoke((Action)(() => {
lstEvents.BeginUpdate();

View file

@ -20,7 +20,7 @@ namespace Mesen.GUI.Debugger.Controls
private DebugState _state = new DebugState();
private byte[] _pictureData = null;
private Dictionary<int, List<DebugEventInfo>> _debugEventsByCycle = new Dictionary<int, List<DebugEventInfo>>();
private DebugEventInfo[] _debugEvents = new DebugEventInfo[0];
private List<DebugEventInfo> _debugEvents = new List<DebugEventInfo>();
public ctrlEventViewerPpuView()
{
@ -33,18 +33,43 @@ namespace Mesen.GUI.Debugger.Controls
InteropEmu.DebugGetState(ref state);
DebugEventInfo[] eventInfoArray;
InteropEmu.DebugGetDebugEvents(out _pictureData, out eventInfoArray);
DebugEventInfo[] prevEventInfoArray = new DebugEventInfo[0];
InteropEmu.DebugGetDebugEvents(false, out _pictureData, out eventInfoArray);
if(ConfigManager.Config.DebugInfo.EventViewerShowPreviousFrameEvents && (state.PPU.Scanline != -1 || state.PPU.Cycle != 0)) {
//Get the previous frame's data, too
InteropEmu.DebugGetDebugEvents(true, out _pictureData, out prevEventInfoArray);
}
int currentCycle = (int)((state.PPU.Scanline + 1) * 341 + state.PPU.Cycle);
var debugEvents = new Dictionary<int, List<DebugEventInfo>>();
for(int i = 0; i < eventInfoArray.Length; i++) {
int frameCycle = (eventInfoArray[i].Scanline + 1) * 341 + eventInfoArray[i].Cycle;
List<DebugEventInfo> eventList = new List<DebugEventInfo>(eventInfoArray.Length+prevEventInfoArray.Length);
Action<DebugEventInfo> addEvent = (DebugEventInfo eventInfo) => {
int frameCycle = (eventInfo.Scanline + 1) * 341 + eventInfo.Cycle;
List<DebugEventInfo> infoList;
if(!debugEvents.TryGetValue(frameCycle, out infoList)) {
infoList = new List<DebugEventInfo>();
debugEvents[frameCycle] = infoList;
}
infoList.Add(eventInfoArray[i]);
infoList.Add(eventInfo);
eventList.Add(eventInfo);
};
for(int i = 0; i < eventInfoArray.Length; i++) {
addEvent(eventInfoArray[i]);
}
_debugEvents = eventInfoArray;
//Show events from the previous frame, too
for(int i = 0; i < prevEventInfoArray.Length; i++) {
int frameCycle = (prevEventInfoArray[i].Scanline + 1) * 341 + prevEventInfoArray[i].Cycle;
if(frameCycle > currentCycle) {
addEvent(prevEventInfoArray[i]);
}
}
_debugEvents = eventList;
_debugEventsByCycle = debugEvents;
_state = state;
}

View file

@ -55,6 +55,7 @@
this.mnuConfigureColors = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
this.mnuRefreshOnBreak = new System.Windows.Forms.ToolStripMenuItem();
this.chkShowPreviousFrameEvents = new System.Windows.Forms.CheckBox();
this.tabMain.SuspendLayout();
this.tpgPpuView.SuspendLayout();
this.tableLayoutPanel1.SuspendLayout();
@ -149,11 +150,13 @@
this.tableLayoutPanel2.Controls.Add(this.chkShowPpuRegisterWrites, 0, 0);
this.tableLayoutPanel2.Controls.Add(this.chkShowMapperRegisterWrites, 0, 2);
this.tableLayoutPanel2.Controls.Add(this.chkShowSpriteZero, 0, 6);
this.tableLayoutPanel2.Controls.Add(this.chkShowPreviousFrameEvents, 0, 8);
this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel2.Location = new System.Drawing.Point(3, 16);
this.tableLayoutPanel2.Margin = new System.Windows.Forms.Padding(0);
this.tableLayoutPanel2.Name = "tableLayoutPanel2";
this.tableLayoutPanel2.RowCount = 8;
this.tableLayoutPanel2.RowCount = 9;
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle());
@ -163,11 +166,6 @@
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel2.Size = new System.Drawing.Size(198, 507);
this.tableLayoutPanel2.TabIndex = 2;
//
@ -309,7 +307,7 @@
//
this.mnuClose.Image = global::Mesen.GUI.Properties.Resources.Exit;
this.mnuClose.Name = "mnuClose";
this.mnuClose.Size = new System.Drawing.Size(103, 22);
this.mnuClose.Size = new System.Drawing.Size(152, 22);
this.mnuClose.Text = "Close";
this.mnuClose.Click += new System.EventHandler(this.mnuClose_Click);
//
@ -344,6 +342,18 @@
this.mnuRefreshOnBreak.Text = "Refresh on pause/break";
this.mnuRefreshOnBreak.Click += new System.EventHandler(this.mnuRefreshOnBreak_Click);
//
// chkShowPreviousFrameEvents
//
this.chkShowPreviousFrameEvents.AutoSize = true;
this.tableLayoutPanel2.SetColumnSpan(this.chkShowPreviousFrameEvents, 2);
this.chkShowPreviousFrameEvents.Location = new System.Drawing.Point(3, 187);
this.chkShowPreviousFrameEvents.Name = "chkShowPreviousFrameEvents";
this.chkShowPreviousFrameEvents.Size = new System.Drawing.Size(167, 17);
this.chkShowPreviousFrameEvents.TabIndex = 8;
this.chkShowPreviousFrameEvents.Text = "Show previous frame\'s events";
this.chkShowPreviousFrameEvents.UseVisualStyleBackColor = true;
this.chkShowPreviousFrameEvents.Click += new System.EventHandler(this.chkShowPreviousFrameEvents_Click);
//
// frmEventViewer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -395,5 +405,6 @@
private System.Windows.Forms.ToolStripMenuItem mnuRefreshOnBreak;
private System.Windows.Forms.TabPage tpgListView;
private Controls.ctrlEventViewerListView ctrlEventViewerListView;
private System.Windows.Forms.CheckBox chkShowPreviousFrameEvents;
}
}

View file

@ -32,6 +32,7 @@ namespace Mesen.GUI.Debugger
this.chkShowMapperRegisterWrites.Checked = ConfigManager.Config.DebugInfo.EventViewerShowMapperRegisterWrites;
this.chkShowMapperRegisterReads.Checked = ConfigManager.Config.DebugInfo.EventViewerShowMapperRegisterReads;
this.chkBreakpoints.Checked = ConfigManager.Config.DebugInfo.EventViewerShowMarkedBreakpoints;
this.chkShowPreviousFrameEvents.Checked = ConfigManager.Config.DebugInfo.EventViewerShowPreviousFrameEvents;
}
protected override void OnLoad(EventArgs e)
@ -174,6 +175,16 @@ namespace Mesen.GUI.Debugger
this.RefreshViewer();
}
private void chkShowPreviousFrameEvents_Click(object sender, EventArgs e)
{
ConfigManager.Config.DebugInfo.EventViewerShowPreviousFrameEvents = chkShowPreviousFrameEvents.Checked;
ConfigManager.ApplyChanges();
if(InteropEmu.DebugIsExecutionStopped()) {
this.GetData();
this.RefreshViewer();
}
}
private void mnuConfigureColors_Click(object sender, EventArgs e)
{
if(frmEventViewerColors.Instance != null) {

View file

@ -472,18 +472,18 @@ namespace Mesen.GUI
return frameData;
}
[DllImport(DLLPath)] private static extern UInt32 DebugGetDebugEventCount();
[DllImport(DLLPath, EntryPoint = "DebugGetDebugEvents")] private static extern void DebugGetDebugEventsWrapper(IntPtr frameBuffer, IntPtr infoArray, ref UInt32 maxEventCount);
public static void DebugGetDebugEvents(out byte[] pictureData, out DebugEventInfo[] debugEvents)
[DllImport(DLLPath)] private static extern UInt32 DebugGetDebugEventCount([MarshalAs(UnmanagedType.I1)]bool returnPreviousFrameData);
[DllImport(DLLPath, EntryPoint = "DebugGetDebugEvents")] private static extern void DebugGetDebugEventsWrapper(IntPtr frameBuffer, IntPtr infoArray, ref UInt32 maxEventCount, [MarshalAs(UnmanagedType.I1)]bool returnPreviousFrameData);
public static void DebugGetDebugEvents(bool returnPreviousFrameData, out byte[] pictureData, out DebugEventInfo[] debugEvents)
{
pictureData = new byte[256 * 240 * 4];
UInt32 maxEventCount = DebugGetDebugEventCount();
UInt32 maxEventCount = DebugGetDebugEventCount(returnPreviousFrameData);
debugEvents = new DebugEventInfo[maxEventCount];
GCHandle hPictureData = GCHandle.Alloc(pictureData, GCHandleType.Pinned);
GCHandle hDebugEvents = GCHandle.Alloc(debugEvents, GCHandleType.Pinned);
try {
InteropEmu.DebugGetDebugEventsWrapper(hPictureData.AddrOfPinnedObject(), hDebugEvents.AddrOfPinnedObject(), ref maxEventCount);
InteropEmu.DebugGetDebugEventsWrapper(hPictureData.AddrOfPinnedObject(), hDebugEvents.AddrOfPinnedObject(), ref maxEventCount, returnPreviousFrameData);
} finally {
hPictureData.Free();
hDebugEvents.Free();

View file

@ -139,6 +139,6 @@ extern "C"
DllExport void __stdcall DebugRemoveScript(int32_t scriptId) { GetDebugger()->RemoveScript(scriptId); }
DllExport const char* __stdcall DebugGetScriptLog(int32_t scriptId) { return GetDebugger()->GetScriptLog(scriptId); }
DllExport void __stdcall DebugGetDebugEvents(uint32_t* pictureBuffer, DebugEventInfo *infoArray, uint32_t &maxEventCount) { GetDebugger()->GetDebugEvents(pictureBuffer, infoArray, maxEventCount); }
DllExport uint32_t __stdcall DebugGetDebugEventCount() { return GetDebugger()->GetDebugEventCount(); }
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); }
};