Debugger - breakpoints

This commit is contained in:
adelikat 2014-12-06 15:07:01 +00:00
parent 93692b0220
commit 97476a8b69
7 changed files with 494 additions and 7 deletions

View File

@ -636,6 +636,13 @@
<Compile Include="tools\Cheats\Cheats.Designer.cs">
<DependentUpon>Cheats.cs</DependentUpon>
</Compile>
<Compile Include="tools\Debugger\Breakpoint.cs" />
<Compile Include="tools\Debugger\BreakpointControl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="tools\Debugger\BreakpointControl.Designer.cs">
<DependentUpon>BreakpointControl.cs</DependentUpon>
</Compile>
<Compile Include="tools\Debugger\GenericDebugger.cs">
<SubType>Form</SubType>
</Compile>
@ -643,6 +650,7 @@
<DependentUpon>GenericDebugger.cs</DependentUpon>
</Compile>
<Compile Include="tools\Debugger\GenericDebugger.IControlMainform.cs">
<DependentUpon>GenericDebugger.cs</DependentUpon>
<SubType>Form</SubType>
</Compile>
<Compile Include="tools\Debugger\GenericDebugger.IToolForm.cs">
@ -1227,6 +1235,9 @@
<EmbeddedResource Include="tools\Cheats\Cheats.resx">
<DependentUpon>Cheats.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="tools\Debugger\BreakpointControl.resx">
<DependentUpon>BreakpointControl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="tools\Debugger\GenericDebugger.resx">
<DependentUpon>GenericDebugger.cs</DependentUpon>
</EmbeddedResource>

View File

@ -0,0 +1,98 @@
using BizHawk.Emulation.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BizHawk.Client.EmuHawk
{
public class BreakpointList : List<Breakpoint>
{
public Action Callback { get; set; }
public void Add(IDebuggable core, uint address, BreakpointType type)
{
Add(new Breakpoint(core, Callback, address, type));
}
public new void Clear()
{
foreach (var breakpoint in this)
{
breakpoint.Active = false;
}
base.Clear();
}
// TODO: override all ways to remove
}
public class Breakpoint
{
private bool _active;
private readonly IDebuggable _core;
public Breakpoint(IDebuggable core, Action callBack, uint address, BreakpointType type, bool enabled = true)
{
_core = core;
Callback = callBack;
Address = address;
Active = enabled;
if (enabled)
{
AddCallback();
}
}
public Action Callback { get; set; }
public uint Address { get; set; }
public BreakpointType Type { get; set; }
public bool Active
{
get
{
return _active;
}
set
{
if (!value)
{
RemoveCallback();
}
if (!_active && value) // If inactive and changing to active
{
AddCallback();
}
_active = value;
}
}
private void AddCallback()
{
switch (Type)
{
case BreakpointType.Read:
_core.MemoryCallbacks.AddRead(Callback, Address);
break;
case BreakpointType.Write:
_core.MemoryCallbacks.AddWrite(Callback, Address);
break;
case BreakpointType.Execute:
_core.MemoryCallbacks.AddExecute(Callback, Address);
break;
}
}
private void RemoveCallback()
{
_core.MemoryCallbacks.Remove(Callback);
}
}
}

View File

@ -0,0 +1,118 @@
namespace BizHawk.Client.EmuHawk.tools.Debugger
{
partial class BreakpointControl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.BreakpointView = new BizHawk.Client.EmuHawk.VirtualListView();
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.AddBreakpointButton = new System.Windows.Forms.Button();
this.RemoveBreakpointButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// BreakpointView
//
this.BreakpointView.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.BreakpointView.BlazingFast = false;
this.BreakpointView.CheckBoxes = true;
this.BreakpointView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2});
this.BreakpointView.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.BreakpointView.FullRowSelect = true;
this.BreakpointView.GridLines = true;
this.BreakpointView.HideSelection = false;
this.BreakpointView.ItemCount = 0;
this.BreakpointView.Location = new System.Drawing.Point(0, 0);
this.BreakpointView.Name = "BreakpointView";
this.BreakpointView.SelectAllInProgress = false;
this.BreakpointView.selectedItem = -1;
this.BreakpointView.Size = new System.Drawing.Size(193, 384);
this.BreakpointView.TabIndex = 5;
this.BreakpointView.TabStop = false;
this.BreakpointView.UseCompatibleStateImageBehavior = false;
this.BreakpointView.UseCustomBackground = true;
this.BreakpointView.View = System.Windows.Forms.View.Details;
//
// columnHeader1
//
this.columnHeader1.Text = "Address";
this.columnHeader1.Width = 85;
//
// columnHeader2
//
this.columnHeader2.Text = "Type";
this.columnHeader2.Width = 103;
//
// AddBreakpointButton
//
this.AddBreakpointButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.AddBreakpointButton.Location = new System.Drawing.Point(0, 387);
this.AddBreakpointButton.Name = "AddBreakpointButton";
this.AddBreakpointButton.Size = new System.Drawing.Size(60, 23);
this.AddBreakpointButton.TabIndex = 6;
this.AddBreakpointButton.Text = "&Add";
this.AddBreakpointButton.UseVisualStyleBackColor = true;
this.AddBreakpointButton.Click += new System.EventHandler(this.AddBreakpointButton_Click);
//
// RemoveBreakpointButton
//
this.RemoveBreakpointButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.RemoveBreakpointButton.Location = new System.Drawing.Point(130, 387);
this.RemoveBreakpointButton.Name = "RemoveBreakpointButton";
this.RemoveBreakpointButton.Size = new System.Drawing.Size(60, 23);
this.RemoveBreakpointButton.TabIndex = 7;
this.RemoveBreakpointButton.Text = "&Remove";
this.RemoveBreakpointButton.UseVisualStyleBackColor = true;
this.RemoveBreakpointButton.Click += new System.EventHandler(this.RemoveBreakpointButton_Click);
//
// BreakpointControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.RemoveBreakpointButton);
this.Controls.Add(this.AddBreakpointButton);
this.Controls.Add(this.BreakpointView);
this.Name = "BreakpointControl";
this.Size = new System.Drawing.Size(193, 413);
this.Load += new System.EventHandler(this.BreakpointControl_Load);
this.ResumeLayout(false);
}
#endregion
private VirtualListView BreakpointView;
public System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.Button AddBreakpointButton;
private System.Windows.Forms.Button RemoveBreakpointButton;
}
}

View File

@ -0,0 +1,124 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
namespace BizHawk.Client.EmuHawk.tools.Debugger
{
public partial class BreakpointControl : UserControl
{
public IDebuggable Core { get; set; }
public GenericDebugger ParentDebugger { get; set; }
private readonly BreakpointList Breakpoints = new BreakpointList();
public BreakpointControl()
{
InitializeComponent();
BreakpointView.QueryItemText += BreakPointView_QueryItemText;
BreakpointView.VirtualMode = true;
Breakpoints.Callback = BreakpointCallback;
}
private void BreakpointControl_Load(object sender, EventArgs e)
{
}
private void BreakPointView_QueryItemText(int index, int column, out string text)
{
text = string.Empty;
switch (column)
{
case 0:
text = string.Format("{0:X4}", Breakpoints[index].Address);
break;
case 1:
text = Breakpoints[index].Type.ToString();
break;
}
}
private void BreakpointCallback()
{
GlobalWin.MainForm.PauseEmulator();
UpdateValues();
}
public void UpdateValues()
{
if (this.Enabled)
{
}
}
public void GenerateUI()
{
if (Core.MemoryCallbacksAvailable())
{
// TODO: need a way to populate existing breakpoints
}
else
{
this.Enabled = false;
}
}
public void Shutdown()
{
Breakpoints.Clear();
}
private void AddBreakpointButton_Click(object sender, EventArgs e)
{
var b = new AddBreakpointDialog(); // TODO: rename and move this widget
if (b.ShowDialog() == DialogResult.OK)
{
Breakpoints.Add(Core, b.Address, b.BreakType);
}
BreakpointView.ItemCount = Breakpoints.Count;
UpdateBreakpointRemoveButton();
}
private IEnumerable<int> SelectedIndices
{
get { return BreakpointView.SelectedIndices.Cast<int>(); }
}
private IEnumerable<Breakpoint> SelectedItems
{
get { return SelectedIndices.Select(index => Breakpoints[index]); }
}
private void RemoveBreakpointButton_Click(object sender, EventArgs e)
{
if (BreakpointView.SelectedIndices.Count > 0)
{
var items = SelectedItems.ToList();
if (items.Any())
{
foreach (var item in items)
{
Breakpoints.Remove(item);
}
BreakpointView.ItemCount = Breakpoints.Count;
UpdateBreakpointRemoveButton();
}
}
}
private void UpdateBreakpointRemoveButton()
{
RemoveBreakpointButton.Enabled = BreakpointView.SelectedIndices.Count > 0;
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -45,9 +45,11 @@
this.RegistersGroupBox = new System.Windows.Forms.GroupBox();
this.RegisterPanel = new BizHawk.Client.EmuHawk.RegisterBoxControl();
this.BreakpointsGroupBox = new System.Windows.Forms.GroupBox();
this.BreakPointControl1 = new BizHawk.Client.EmuHawk.tools.Debugger.BreakpointControl();
this.menuStrip1.SuspendLayout();
this.TracerBox.SuspendLayout();
this.RegistersGroupBox.SuspendLayout();
this.BreakpointsGroupBox.SuspendLayout();
this.SuspendLayout();
//
// menuStrip1
@ -204,6 +206,7 @@
this.BreakpointsGroupBox.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.BreakpointsGroupBox.Controls.Add(this.BreakPointControl1);
this.BreakpointsGroupBox.Location = new System.Drawing.Point(425, 267);
this.BreakpointsGroupBox.Name = "BreakpointsGroupBox";
this.BreakpointsGroupBox.Size = new System.Drawing.Size(239, 281);
@ -211,6 +214,18 @@
this.BreakpointsGroupBox.TabStop = false;
this.BreakpointsGroupBox.Text = "Breakpoints";
//
// BreakPointControl1
//
this.BreakPointControl1.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.BreakPointControl1.Core = null;
this.BreakPointControl1.Location = new System.Drawing.Point(8, 19);
this.BreakPointControl1.Name = "BreakPointControl1";
this.BreakPointControl1.ParentDebugger = null;
this.BreakPointControl1.Size = new System.Drawing.Size(225, 256);
this.BreakPointControl1.TabIndex = 0;
//
// GenericDebugger
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -230,6 +245,7 @@
this.menuStrip1.PerformLayout();
this.TracerBox.ResumeLayout(false);
this.RegistersGroupBox.ResumeLayout(false);
this.BreakpointsGroupBox.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@ -253,5 +269,6 @@
private System.Windows.Forms.GroupBox RegistersGroupBox;
private RegisterBoxControl RegisterPanel;
private System.Windows.Forms.GroupBox BreakpointsGroupBox;
private tools.Debugger.BreakpointControl BreakPointControl1;
}
}

View File

@ -72,6 +72,10 @@ namespace BizHawk.Client.EmuHawk
RegisterPanel.Core = Core;
RegisterPanel.ParentDebugger = this;
RegisterPanel.GenerateUI();
BreakPointControl1.Core = Core;
BreakPointControl1.ParentDebugger = this;
}
catch (NotImplementedException)
{
@ -82,6 +86,8 @@ namespace BizHawk.Client.EmuHawk
private void DisengageDebugger()
{
SaveConfigSettings();
BreakPointControl1.Shutdown();
}
private void UpdateTraceLog()
@ -103,13 +109,6 @@ namespace BizHawk.Client.EmuHawk
}
}
private void TraceView_QueryItemText(int index, int column, out string text)
{
text = index < _instructions.Count ? _instructions[index] : string.Empty;