From 00523ca5aae491908eddd43fc4bbc6e14c4b380b Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 6 Dec 2014 00:18:51 +0000 Subject: [PATCH] Debugger - implement trace logger --- .../Debugger/GenericDebugger.Designer.cs | 58 +++++++++++++++++- .../Debugger/GenericDebugger.IToolForm.cs | 2 +- .../tools/Debugger/GenericDebugger.cs | 59 ++++++++++++++++++- 3 files changed, 113 insertions(+), 6 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Designer.cs b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Designer.cs index 8f8b741931..7fe4f35ddb 100644 --- a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Designer.cs @@ -39,17 +39,22 @@ this.FloatingWindowMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.RestoreDefaultsMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.TracerBox = new System.Windows.Forms.GroupBox(); + this.TraceView = new BizHawk.Client.EmuHawk.VirtualListView(); + this.Script = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.menuStrip1.SuspendLayout(); + this.TracerBox.SuspendLayout(); this.SuspendLayout(); // // menuStrip1 // + this.menuStrip1.ClickThrough = true; this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.fileToolStripMenuItem, this.OptionsSubMenu}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(638, 24); + this.menuStrip1.Size = new System.Drawing.Size(685, 24); this.menuStrip1.TabIndex = 1; this.menuStrip1.Text = "menuStrip1"; // @@ -65,7 +70,7 @@ // this.ExitMenuItem.Name = "ExitMenuItem"; this.ExitMenuItem.ShortcutKeyDisplayString = "Alt+F4"; - this.ExitMenuItem.Size = new System.Drawing.Size(152, 22); + this.ExitMenuItem.Size = new System.Drawing.Size(145, 22); this.ExitMenuItem.Text = "&Close"; this.ExitMenuItem.Click += new System.EventHandler(this.ExitMenuItem_Click); // @@ -123,11 +128,54 @@ this.RestoreDefaultsMenuItem.Text = "Restore Defaults"; this.RestoreDefaultsMenuItem.Click += new System.EventHandler(this.RestoreDefaultsMenuItem_Click); // + // TracerBox + // + this.TracerBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left))); + this.TracerBox.Controls.Add(this.TraceView); + this.TracerBox.Location = new System.Drawing.Point(12, 27); + this.TracerBox.Name = "TracerBox"; + this.TracerBox.Size = new System.Drawing.Size(407, 521); + this.TracerBox.TabIndex = 7; + this.TracerBox.TabStop = false; + this.TracerBox.Text = "Trace log"; + // + // TraceView + // + this.TraceView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.TraceView.BlazingFast = false; + this.TraceView.CheckBoxes = true; + this.TraceView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.Script}); + this.TraceView.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.TraceView.FullRowSelect = true; + this.TraceView.GridLines = true; + this.TraceView.HideSelection = false; + this.TraceView.ItemCount = 0; + this.TraceView.Location = new System.Drawing.Point(8, 18); + this.TraceView.Name = "TraceView"; + this.TraceView.SelectAllInProgress = false; + this.TraceView.selectedItem = -1; + this.TraceView.Size = new System.Drawing.Size(393, 491); + this.TraceView.TabIndex = 4; + this.TraceView.TabStop = false; + this.TraceView.UseCompatibleStateImageBehavior = false; + this.TraceView.UseCustomBackground = true; + this.TraceView.View = System.Windows.Forms.View.Details; + // + // Script + // + this.Script.Text = "Instructions"; + this.Script.Width = 599; + // // GenericDebugger // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(638, 560); + this.ClientSize = new System.Drawing.Size(685, 560); + this.Controls.Add(this.TracerBox); this.Controls.Add(this.menuStrip1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MainMenuStrip = this.menuStrip1; @@ -137,6 +185,7 @@ this.Load += new System.EventHandler(this.GenericDebugger_Load); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); + this.TracerBox.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); @@ -154,5 +203,8 @@ private System.Windows.Forms.ToolStripMenuItem FloatingWindowMenuItem; private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; private System.Windows.Forms.ToolStripMenuItem RestoreDefaultsMenuItem; + private System.Windows.Forms.GroupBox TracerBox; + private VirtualListView TraceView; + public System.Windows.Forms.ColumnHeader Script; } } \ No newline at end of file diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.IToolForm.cs b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.IToolForm.cs index a79034eee2..e0bb162267 100644 --- a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.IToolForm.cs +++ b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.IToolForm.cs @@ -4,7 +4,7 @@ { public void UpdateValues() { - // TODO + UpdateTraceLog(); } public void FastUpdate() diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs index 2657be065e..274cb9d32f 100644 --- a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs +++ b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs @@ -7,6 +7,8 @@ using System.Linq; using System.Text; using System.Windows.Forms; +using BizHawk.Emulation.Common; +using BizHawk.Emulation.Common.IEmulatorExtensions; using BizHawk.Client.Common; namespace BizHawk.Client.EmuHawk @@ -16,11 +18,17 @@ namespace BizHawk.Client.EmuHawk private int _defaultWidth; private int _defaultHeight; + private IDebuggable Core; + private readonly List _instructions = new List(); + public GenericDebugger() { InitializeComponent(); TopMost = Global.Config.GenericDebuggerSettings.TopMost; - Closing += (o, e) => Shutdown(); + Closing += (o, e) => DisengageDebugger(); + + TraceView.QueryItemText += TraceView_QueryItemText; + TraceView.VirtualMode = true; } private void GenericDebugger_Load(object sender, EventArgs e) @@ -37,13 +45,60 @@ namespace BizHawk.Client.EmuHawk { Size = Global.Config.GenericDebuggerSettings.WindowSize; } + + if (Global.Emulator.CanDebug()) + { + Core = Global.Emulator.AsDebuggable(); + } + else + { + Close(); + } + + EngageDebugger(); } - private void Shutdown() + private void EngageDebugger() + { + try + { + Core.Tracer.Enabled = true; + } + catch (NotImplementedException) + { + TracerBox.Enabled = false; + } + } + + private void DisengageDebugger() { SaveConfigSettings(); } + private void UpdateTraceLog() + { + if (TracerBox.Enabled) + { + var instructions = Core.Tracer.TakeContents().Split('\n'); + if (!string.IsNullOrWhiteSpace(instructions[0])) + { + _instructions.AddRange(instructions.Where(str => !string.IsNullOrEmpty(str))); + } + + if (_instructions.Count >= Global.Config.TraceLoggerMaxLines) + { + _instructions.RemoveRange(0, _instructions.Count - Global.Config.TraceLoggerMaxLines); + } + + TraceView.ItemCount = _instructions.Count; + } + } + + private void TraceView_QueryItemText(int index, int column, out string text) + { + text = index < _instructions.Count ? _instructions[index] : string.Empty; + } + private void SaveConfigSettings() { if (Global.Config.GenericDebuggerSettings.SaveWindowPosition)