2016-01-10 19:56:40 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
2016-09-03 21:52:59 -04:00
|
|
|
|
using System.IO;
|
2016-01-10 19:56:40 -05:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
2016-09-03 21:52:59 -04:00
|
|
|
|
using Mesen.GUI.Config;
|
2017-03-04 15:18:00 -05:00
|
|
|
|
using Mesen.GUI.Controls;
|
2016-01-10 19:56:40 -05:00
|
|
|
|
using Mesen.GUI.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Debugger
|
|
|
|
|
{
|
|
|
|
|
public partial class frmTraceLogger : BaseForm
|
|
|
|
|
{
|
2017-03-04 15:18:00 -05:00
|
|
|
|
private int _lineCount;
|
2016-09-03 21:52:59 -04:00
|
|
|
|
private bool _loggingEnabled = false;
|
2017-03-04 15:18:00 -05:00
|
|
|
|
private string _lastFilename;
|
2017-03-16 21:34:28 -04:00
|
|
|
|
private EntityBinder _entityBinder = new EntityBinder();
|
2016-09-03 21:52:59 -04:00
|
|
|
|
|
2016-01-10 19:56:40 -05:00
|
|
|
|
public frmTraceLogger()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2017-03-04 15:18:00 -05:00
|
|
|
|
|
|
|
|
|
DebugInfo debugInfo = ConfigManager.Config.DebugInfo;
|
|
|
|
|
mnuAutoRefresh.Checked = debugInfo.TraceAutoRefresh;
|
|
|
|
|
_lineCount = debugInfo.TraceLineCount;
|
2017-03-16 21:34:28 -04:00
|
|
|
|
|
|
|
|
|
_entityBinder.Entity = debugInfo.TraceLoggerOptions;
|
|
|
|
|
_entityBinder.AddBinding("ShowByteCode", chkShowByteCode);
|
|
|
|
|
_entityBinder.AddBinding("ShowCpuCycles", chkShowCpuCycles);
|
|
|
|
|
_entityBinder.AddBinding("ShowEffectiveAddresses", chkShowEffectiveAddresses);
|
|
|
|
|
_entityBinder.AddBinding("ShowExtraInfo", chkShowExtraInfo);
|
|
|
|
|
_entityBinder.AddBinding("ShowPpuFrames", chkShowFrameCount);
|
|
|
|
|
_entityBinder.AddBinding("ShowPpuCycles", chkShowPpuCycles);
|
|
|
|
|
_entityBinder.AddBinding("ShowPpuScanline", chkShowPpuScanline);
|
|
|
|
|
_entityBinder.AddBinding("ShowRegisters", chkShowRegisters);
|
|
|
|
|
_entityBinder.AddBinding("IndentCode", chkIndentCode);
|
|
|
|
|
_entityBinder.AddBinding("UseLabels", chkUseLabels);
|
|
|
|
|
_entityBinder.AddBinding("StatusFormat", cboStatusFlagFormat);
|
|
|
|
|
_entityBinder.UpdateUI();
|
2017-03-04 15:18:00 -05:00
|
|
|
|
|
|
|
|
|
UpdateMenu();
|
|
|
|
|
txtTraceLog.Font = new Font(BaseControl.MonospaceFontFamily, 10);
|
|
|
|
|
tmrUpdateLog.Start();
|
2016-01-10 19:56:40 -05:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-03 21:52:59 -04:00
|
|
|
|
protected override void OnFormClosing(FormClosingEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnFormClosing(e);
|
|
|
|
|
|
2017-03-04 15:18:00 -05:00
|
|
|
|
DebugInfo debugInfo = ConfigManager.Config.DebugInfo;
|
|
|
|
|
debugInfo.TraceAutoRefresh = mnuAutoRefresh.Checked;
|
|
|
|
|
debugInfo.TraceLineCount = _lineCount;
|
|
|
|
|
debugInfo.TraceIndentCode = chkIndentCode.Checked;
|
2017-03-16 21:34:28 -04:00
|
|
|
|
_entityBinder.Entity = debugInfo.TraceLoggerOptions;
|
|
|
|
|
_entityBinder.UpdateObject();
|
|
|
|
|
debugInfo.TraceLoggerOptions = (TraceLoggerOptions)_entityBinder.Entity;
|
|
|
|
|
|
2017-03-04 15:18:00 -05:00
|
|
|
|
ConfigManager.ApplyChanges();
|
|
|
|
|
|
2016-09-03 21:52:59 -04:00
|
|
|
|
if(_loggingEnabled) {
|
|
|
|
|
InteropEmu.DebugStopTraceLogger();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-04 15:18:00 -05:00
|
|
|
|
private void SetOptions()
|
2016-01-10 19:56:40 -05:00
|
|
|
|
{
|
2017-03-16 21:34:28 -04:00
|
|
|
|
_entityBinder.Entity = ConfigManager.Config.DebugInfo.TraceLoggerOptions;
|
|
|
|
|
_entityBinder.UpdateObject();
|
|
|
|
|
InteropEmu.DebugSetTraceOptions((TraceLoggerOptions)_entityBinder.Entity);
|
2017-03-04 15:18:00 -05:00
|
|
|
|
}
|
2016-09-03 21:52:59 -04:00
|
|
|
|
|
2017-03-04 15:18:00 -05:00
|
|
|
|
private void btnStartLogging_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
using(SaveFileDialog sfd = new SaveFileDialog()) {
|
|
|
|
|
sfd.FileName = "Trace logs (*.txt)|*.txt";
|
|
|
|
|
sfd.FileName = "Trace - " + InteropEmu.GetRomInfo().GetRomName() + ".txt";
|
|
|
|
|
sfd.InitialDirectory = ConfigManager.DebuggerFolder;
|
|
|
|
|
if(sfd.ShowDialog() == DialogResult.OK) {
|
|
|
|
|
_lastFilename = sfd.FileName;
|
|
|
|
|
SetOptions();
|
|
|
|
|
InteropEmu.DebugStartTraceLogger(sfd.FileName);
|
|
|
|
|
|
|
|
|
|
btnStartLogging.Enabled = false;
|
|
|
|
|
btnStopLogging.Enabled = true;
|
|
|
|
|
btnOpenTrace.Enabled = false;
|
2016-09-03 21:52:59 -04:00
|
|
|
|
|
2017-03-04 15:18:00 -05:00
|
|
|
|
_loggingEnabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-10 19:56:40 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnStopLogging_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
InteropEmu.DebugStopTraceLogger();
|
2016-09-03 21:52:59 -04:00
|
|
|
|
btnStartLogging.Enabled = true;
|
|
|
|
|
btnStopLogging.Enabled = false;
|
2017-03-04 15:18:00 -05:00
|
|
|
|
btnOpenTrace.Enabled = true;
|
2016-09-03 21:52:59 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnOpenTrace_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try {
|
2017-03-04 15:18:00 -05:00
|
|
|
|
System.Diagnostics.Process.Start(_lastFilename);
|
2016-09-03 21:52:59 -04:00
|
|
|
|
} catch { }
|
2016-01-10 19:56:40 -05:00
|
|
|
|
}
|
2017-03-04 15:18:00 -05:00
|
|
|
|
|
|
|
|
|
private void RefreshLog()
|
|
|
|
|
{
|
|
|
|
|
SetOptions();
|
|
|
|
|
string newTrace = InteropEmu.DebugGetExecutionTrace((UInt32)_lineCount).Replace("\n", Environment.NewLine);
|
|
|
|
|
|
|
|
|
|
if(newTrace != txtTraceLog.Text) {
|
|
|
|
|
txtTraceLog.Text = newTrace;
|
|
|
|
|
txtTraceLog.SelectionStart = txtTraceLog.TextLength;
|
|
|
|
|
txtTraceLog.ScrollToCaret();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateMenu()
|
|
|
|
|
{
|
|
|
|
|
mnu30000Lines.Checked = _lineCount == 30000;
|
|
|
|
|
mnu10000Lines.Checked = _lineCount == 10000;
|
|
|
|
|
mnu1000Lines.Checked = _lineCount == 1000;
|
|
|
|
|
mnu100Lines.Checked = _lineCount == 100;
|
|
|
|
|
|
|
|
|
|
if(_lineCount >= 10000) {
|
|
|
|
|
mnuAutoRefresh.Checked = false;
|
|
|
|
|
} else if(_lineCount == 1000) {
|
|
|
|
|
tmrUpdateLog.Interval = 250;
|
|
|
|
|
} else {
|
|
|
|
|
tmrUpdateLog.Interval = 150;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mnuAutoRefresh.Enabled = _lineCount < 10000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tmrUpdateLog_Tick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(mnuAutoRefresh.Checked) {
|
|
|
|
|
RefreshLog();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void mnu30000Lines_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_lineCount = 30000;
|
|
|
|
|
UpdateMenu();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void mnu10000Lines_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_lineCount = 10000;
|
|
|
|
|
UpdateMenu();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void mnu1000Lines_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_lineCount = 1000;
|
|
|
|
|
UpdateMenu();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void mnu100Lines_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_lineCount = 100;
|
|
|
|
|
UpdateMenu();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void mnuRefresh_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
RefreshLog();
|
|
|
|
|
}
|
2016-01-10 19:56:40 -05:00
|
|
|
|
}
|
|
|
|
|
}
|