2014-12-06 15:07:01 +00:00
|
|
|
|
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;
|
|
|
|
|
|
2015-01-21 02:12:59 +00:00
|
|
|
|
using BizHawk.Common.NumberExtensions;
|
2014-12-06 15:07:01 +00:00
|
|
|
|
using BizHawk.Emulation.Common;
|
|
|
|
|
using BizHawk.Emulation.Common.IEmulatorExtensions;
|
2014-12-13 16:59:01 +00:00
|
|
|
|
using BizHawk.Client.Common;
|
2015-01-24 18:23:04 +00:00
|
|
|
|
using BizHawk.Client.EmuHawk.WinFormExtensions;
|
2014-12-06 15:07:01 +00:00
|
|
|
|
|
|
|
|
|
namespace BizHawk.Client.EmuHawk.tools.Debugger
|
|
|
|
|
{
|
|
|
|
|
public partial class BreakpointControl : UserControl
|
|
|
|
|
{
|
|
|
|
|
public IDebuggable Core { get; set; }
|
2014-12-15 22:25:06 +00:00
|
|
|
|
public IMemoryCallbackSystem MCS { get; set; }
|
2014-12-06 15:07:01 +00:00
|
|
|
|
public GenericDebugger ParentDebugger { get; set; }
|
2015-01-14 21:55:48 +00:00
|
|
|
|
public IMemoryDomains MemoryDomains { get; set; }
|
2014-12-06 15:07:01 +00:00
|
|
|
|
private readonly BreakpointList Breakpoints = new BreakpointList();
|
|
|
|
|
|
|
|
|
|
public BreakpointControl()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
BreakpointView.QueryItemText += BreakPointView_QueryItemText;
|
2014-12-10 22:59:28 +00:00
|
|
|
|
BreakpointView.QueryItemBkColor += BreakPointView_QueryItemBkColor;
|
2014-12-06 15:07:01 +00:00
|
|
|
|
BreakpointView.VirtualMode = true;
|
|
|
|
|
Breakpoints.Callback = BreakpointCallback;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BreakpointControl_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-12-13 17:48:11 +00:00
|
|
|
|
UpdateStatsLabel();
|
2014-12-06 15:07:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
2014-12-10 22:47:09 +00:00
|
|
|
|
case 2:
|
|
|
|
|
text = Breakpoints[index].Name;
|
|
|
|
|
break;
|
2014-12-06 15:07:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-10 22:59:28 +00:00
|
|
|
|
private void BreakPointView_QueryItemBkColor(int index, int column, ref Color color)
|
|
|
|
|
{
|
2014-12-10 23:11:04 +00:00
|
|
|
|
color = Breakpoints[index].ReadOnly ? SystemColors.Control
|
|
|
|
|
: Breakpoints[index].Active ? Color.LightCyan
|
|
|
|
|
: Color.White;
|
2014-12-10 22:59:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-06 15:07:01 +00:00
|
|
|
|
private void BreakpointCallback()
|
|
|
|
|
{
|
|
|
|
|
GlobalWin.MainForm.PauseEmulator();
|
|
|
|
|
UpdateValues();
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-21 02:12:59 +00:00
|
|
|
|
private void SeekCallback()
|
2014-12-06 15:07:01 +00:00
|
|
|
|
{
|
2015-01-21 02:12:59 +00:00
|
|
|
|
BreakpointCallback();
|
|
|
|
|
|
|
|
|
|
var seekBreakpoint = Breakpoints.FirstOrDefault(x => x.Name.StartsWith(SeekName));
|
|
|
|
|
|
|
|
|
|
if (seekBreakpoint != null)
|
2014-12-06 15:07:01 +00:00
|
|
|
|
{
|
2015-01-21 02:12:59 +00:00
|
|
|
|
Breakpoints.Remove(seekBreakpoint);
|
|
|
|
|
UpdateValues();
|
|
|
|
|
}
|
2015-01-21 23:04:47 +00:00
|
|
|
|
|
|
|
|
|
ParentDebugger.DisableCancelSeekBtn();
|
2015-01-21 02:12:59 +00:00
|
|
|
|
}
|
2014-12-06 15:07:01 +00:00
|
|
|
|
|
2015-01-21 02:12:59 +00:00
|
|
|
|
public void UpdateValues()
|
|
|
|
|
{
|
|
|
|
|
if (Enabled)
|
|
|
|
|
{
|
2015-01-25 19:50:54 +00:00
|
|
|
|
CheckForNewBreakpoints();
|
|
|
|
|
|
2015-01-21 02:12:59 +00:00
|
|
|
|
BreakpointView.ItemCount = Breakpoints.Count;
|
|
|
|
|
UpdateStatsLabel();
|
2014-12-06 15:07:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-25 19:50:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Did any breakpoints get added from other sources such as lua?
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void CheckForNewBreakpoints()
|
|
|
|
|
{
|
|
|
|
|
if (MCS != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var callback in MCS)
|
|
|
|
|
{
|
|
|
|
|
if (!Breakpoints.Any(b =>
|
|
|
|
|
b.Type == callback.Type &&
|
|
|
|
|
b.Address == callback.Address &&
|
|
|
|
|
b.Name == callback.Name &&
|
|
|
|
|
b.Callback == callback.Callback
|
|
|
|
|
))
|
|
|
|
|
{
|
|
|
|
|
Breakpoints.Add(new Breakpoint(Core, callback));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-06 15:07:01 +00:00
|
|
|
|
public void GenerateUI()
|
|
|
|
|
{
|
2014-12-15 22:25:06 +00:00
|
|
|
|
if (MCS != null)
|
2014-12-06 15:07:01 +00:00
|
|
|
|
{
|
2014-12-15 22:25:06 +00:00
|
|
|
|
foreach (var callback in MCS)
|
2014-12-07 19:38:42 +00:00
|
|
|
|
{
|
2014-12-10 22:47:09 +00:00
|
|
|
|
Breakpoints.Add(new Breakpoint(Core, callback));
|
2014-12-07 19:38:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-10 22:47:09 +00:00
|
|
|
|
BreakpointView.ItemCount = Breakpoints.Count;
|
2014-12-07 19:38:42 +00:00
|
|
|
|
BreakpointView.Refresh();
|
2014-12-10 22:59:28 +00:00
|
|
|
|
UpdateBreakpointRemoveButton();
|
2014-12-13 17:48:11 +00:00
|
|
|
|
UpdateStatsLabel();
|
2014-12-06 15:07:01 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.Enabled = false;
|
2014-12-20 14:45:06 +00:00
|
|
|
|
ParentDebugger.DisableBreakpointBox();
|
2014-12-06 15:07:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Shutdown()
|
|
|
|
|
{
|
|
|
|
|
Breakpoints.Clear();
|
2014-12-13 17:48:11 +00:00
|
|
|
|
UpdateStatsLabel();
|
2014-12-06 15:07:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddBreakpointButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-12-13 16:59:01 +00:00
|
|
|
|
var b = new AddBreakpointDialog
|
|
|
|
|
{
|
|
|
|
|
// TODO: don't use Global.Emulator! Pass in an IMemoryDomains implementation from the parent tool
|
2015-01-24 15:49:02 +00:00
|
|
|
|
MaxAddressSize = Global.Emulator.AsMemoryDomains().SystemBus.Size - 1
|
2014-12-13 16:59:01 +00:00
|
|
|
|
};
|
|
|
|
|
|
2015-01-25 22:14:58 +00:00
|
|
|
|
if (!MCS.ExecuteCallbacksAvailable)
|
|
|
|
|
{
|
|
|
|
|
b.DisableExecuteOption();
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-24 18:23:04 +00:00
|
|
|
|
if (b.ShowHawkDialog() == DialogResult.OK)
|
2014-12-06 15:07:01 +00:00
|
|
|
|
{
|
|
|
|
|
Breakpoints.Add(Core, b.Address, b.BreakType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BreakpointView.ItemCount = Breakpoints.Count;
|
|
|
|
|
UpdateBreakpointRemoveButton();
|
2014-12-13 17:48:11 +00:00
|
|
|
|
UpdateStatsLabel();
|
2014-12-06 15:07:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-21 02:12:59 +00:00
|
|
|
|
private const string SeekName = "Seek to PC ";
|
|
|
|
|
|
|
|
|
|
public void AddSeekBreakpoint(uint pcVal, int pcBitSize)
|
|
|
|
|
{
|
|
|
|
|
Breakpoints.Add(new Breakpoint(true, Core, SeekCallback, pcVal, MemoryCallbackType.Execute)
|
|
|
|
|
{
|
|
|
|
|
Name = SeekName + pcVal.ToHexString(pcBitSize / 4)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-21 23:04:47 +00:00
|
|
|
|
public void RemoveCurrentSeek()
|
|
|
|
|
{
|
|
|
|
|
var seekBreakpoint = Breakpoints.FirstOrDefault(x => x.Name.StartsWith(SeekName));
|
|
|
|
|
|
|
|
|
|
if (seekBreakpoint != null)
|
|
|
|
|
{
|
|
|
|
|
Breakpoints.Remove(seekBreakpoint);
|
|
|
|
|
UpdateValues();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-06 15:07:01 +00:00
|
|
|
|
private IEnumerable<int> SelectedIndices
|
|
|
|
|
{
|
|
|
|
|
get { return BreakpointView.SelectedIndices.Cast<int>(); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<Breakpoint> SelectedItems
|
|
|
|
|
{
|
|
|
|
|
get { return SelectedIndices.Select(index => Breakpoints[index]); }
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-10 23:11:04 +00:00
|
|
|
|
private IEnumerable<Breakpoint> EditableItems
|
|
|
|
|
{
|
|
|
|
|
get { return SelectedItems.Where(item => !item.ReadOnly); }
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-06 15:07:01 +00:00
|
|
|
|
private void RemoveBreakpointButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-12-10 23:11:04 +00:00
|
|
|
|
if (EditableItems.Any())
|
2014-12-06 15:07:01 +00:00
|
|
|
|
{
|
2014-12-10 23:11:04 +00:00
|
|
|
|
var items = EditableItems.ToList();
|
2014-12-06 15:07:01 +00:00
|
|
|
|
if (items.Any())
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in items)
|
|
|
|
|
{
|
|
|
|
|
Breakpoints.Remove(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BreakpointView.ItemCount = Breakpoints.Count;
|
|
|
|
|
UpdateBreakpointRemoveButton();
|
2014-12-13 17:48:11 +00:00
|
|
|
|
UpdateStatsLabel();
|
2014-12-06 15:07:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateBreakpointRemoveButton()
|
|
|
|
|
{
|
2014-12-13 18:25:02 +00:00
|
|
|
|
ToggleButton.Enabled =
|
|
|
|
|
RemoveBreakpointButton.Enabled =
|
|
|
|
|
EditableItems.Any();
|
2014-12-06 15:07:01 +00:00
|
|
|
|
}
|
2014-12-10 22:59:28 +00:00
|
|
|
|
|
|
|
|
|
private void BreakpointView_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
UpdateBreakpointRemoveButton();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BreakpointView_ItemActivate(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-12-10 23:11:04 +00:00
|
|
|
|
if (EditableItems.Any())
|
2014-12-10 22:59:28 +00:00
|
|
|
|
{
|
2014-12-10 23:11:04 +00:00
|
|
|
|
var items = EditableItems.ToList();
|
2014-12-10 22:59:28 +00:00
|
|
|
|
if (items.Any())
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in items)
|
|
|
|
|
{
|
|
|
|
|
item.Active ^= true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BreakpointView.ItemCount = Breakpoints.Count;
|
|
|
|
|
UpdateBreakpointRemoveButton();
|
2014-12-13 17:48:11 +00:00
|
|
|
|
UpdateStatsLabel();
|
2014-12-10 22:59:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BreakpointView_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!e.Control && !e.Alt && !e.Shift && e.KeyCode == Keys.Delete) // Delete
|
|
|
|
|
{
|
|
|
|
|
RemoveBreakpointButton_Click(null, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-12-13 17:48:11 +00:00
|
|
|
|
|
|
|
|
|
private void UpdateStatsLabel()
|
|
|
|
|
{
|
|
|
|
|
BreakpointStatsLabel.Text = string.Format("{0} Total / {1} Active", Breakpoints.Count(), Breakpoints.Count(x => x.Active));
|
|
|
|
|
}
|
2014-12-13 18:25:02 +00:00
|
|
|
|
|
|
|
|
|
private void ToggleButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in SelectedItems)
|
|
|
|
|
{
|
|
|
|
|
item.Active ^= true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BreakpointView.ItemCount = Breakpoints.Count;
|
|
|
|
|
UpdateStatsLabel();
|
|
|
|
|
}
|
2014-12-06 15:07:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|