2015-07-01 23:17:14 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
2016-06-04 14:43:13 -04:00
|
|
|
|
using Mesen.GUI.Config;
|
2015-07-01 23:17:14 -04:00
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Debugger
|
|
|
|
|
{
|
|
|
|
|
public partial class ctrlWatch : UserControl
|
|
|
|
|
{
|
|
|
|
|
public ctrlWatch()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2016-06-04 14:43:13 -04:00
|
|
|
|
|
2016-06-04 15:38:48 -04:00
|
|
|
|
bool designMode = (LicenseManager.UsageMode == LicenseUsageMode.Designtime);
|
|
|
|
|
if(!designMode) {
|
|
|
|
|
this.mnuHexDisplay.Checked = ConfigManager.Config.DebugInfo.HexDisplay;
|
2016-06-04 14:43:13 -04:00
|
|
|
|
|
2016-06-04 15:38:48 -04:00
|
|
|
|
foreach(string watchValue in ConfigManager.Config.DebugInfo.WatchValues) {
|
|
|
|
|
lstWatch.Items.Add(watchValue);
|
|
|
|
|
}
|
|
|
|
|
UpdateWatch();
|
2016-06-04 14:43:13 -04:00
|
|
|
|
}
|
2015-07-01 23:17:14 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnLoad(e);
|
|
|
|
|
AdjustColumnWidth();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void lstWatch_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(e.ColumnIndex == 2) {
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
}
|
|
|
|
|
AdjustColumnWidth();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-02 19:27:02 -04:00
|
|
|
|
private void lstWatch_ColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e)
|
2015-07-01 23:17:14 -04:00
|
|
|
|
{
|
|
|
|
|
AdjustColumnWidth();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AdjustColumnWidth()
|
|
|
|
|
{
|
|
|
|
|
lstWatch.ColumnWidthChanging -= lstWatch_ColumnWidthChanging;
|
|
|
|
|
lstWatch.ColumnWidthChanged -= lstWatch_ColumnWidthChanged;
|
|
|
|
|
|
|
|
|
|
//Force watch values to take the full width of the list
|
|
|
|
|
int totalWidth = lstWatch.Columns[0].Width + lstWatch.Columns[1].Width;
|
|
|
|
|
lstWatch.Columns[2].Width = lstWatch.ClientSize.Width - totalWidth;
|
|
|
|
|
|
|
|
|
|
lstWatch.ColumnWidthChanging += lstWatch_ColumnWidthChanging;
|
|
|
|
|
lstWatch.ColumnWidthChanged += lstWatch_ColumnWidthChanged;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-10 13:23:19 -05:00
|
|
|
|
public void UpdateWatch(int currentSelection = -1)
|
2015-07-01 23:17:14 -04:00
|
|
|
|
{
|
|
|
|
|
lstWatch.SelectedIndices.Clear();
|
|
|
|
|
|
|
|
|
|
//Remove empty items
|
|
|
|
|
for(int i = lstWatch.Items.Count - 1; i >= 0; i--) {
|
|
|
|
|
if(string.IsNullOrWhiteSpace(lstWatch.Items[i].Text)) {
|
|
|
|
|
lstWatch.Items.RemoveAt(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lstWatch.Items.Add("");
|
|
|
|
|
|
|
|
|
|
ListViewItem lastItem = lstWatch.Items[lstWatch.Items.Count - 1];
|
|
|
|
|
foreach(ListViewItem item in lstWatch.Items) {
|
|
|
|
|
item.UseItemStyleForSubItems = false;
|
|
|
|
|
if(item != lastItem) {
|
|
|
|
|
string previousValue = null;
|
|
|
|
|
if(item.SubItems.Count > 1) {
|
|
|
|
|
previousValue = item.SubItems[1].Text;
|
|
|
|
|
item.SubItems.RemoveAt(1);
|
|
|
|
|
}
|
2016-01-10 13:23:19 -05:00
|
|
|
|
|
|
|
|
|
string newValue = "";
|
|
|
|
|
EvalResultType resultType;
|
|
|
|
|
Int32 result = InteropEmu.DebugEvaluateExpression(item.Text, out resultType);
|
|
|
|
|
|
|
|
|
|
switch(resultType) {
|
|
|
|
|
case EvalResultType.Numeric:
|
|
|
|
|
if(mnuHexDisplay.Checked) {
|
|
|
|
|
newValue = "$" + result.ToString("X");
|
|
|
|
|
} else {
|
|
|
|
|
newValue = result.ToString();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case EvalResultType.Boolean:
|
|
|
|
|
newValue = result == 0 ? "false" : "true";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EvalResultType.Invalid:
|
|
|
|
|
newValue = "<invalid expression>";
|
|
|
|
|
break;
|
2015-07-01 23:17:14 -04:00
|
|
|
|
}
|
2016-01-10 13:23:19 -05:00
|
|
|
|
|
2015-07-01 23:17:14 -04:00
|
|
|
|
item.SubItems.Add(newValue);
|
|
|
|
|
item.SubItems[1].ForeColor = newValue != previousValue ? Color.Red : Color.Black;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
AdjustColumnWidth();
|
2016-01-10 13:23:19 -05:00
|
|
|
|
|
|
|
|
|
if(currentSelection >= 0 && lstWatch.Items.Count > currentSelection) {
|
|
|
|
|
lstWatch.FocusedItem = lstWatch.Items[currentSelection];
|
|
|
|
|
lstWatch.Items[currentSelection].Selected = true;
|
|
|
|
|
}
|
2016-06-04 14:43:13 -04:00
|
|
|
|
|
|
|
|
|
ConfigManager.Config.DebugInfo.WatchValues.Clear();
|
|
|
|
|
foreach(ListViewItem item in lstWatch.Items) {
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(item.Text)) {
|
|
|
|
|
ConfigManager.Config.DebugInfo.WatchValues.Add(item.Text);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-01 23:17:14 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddWatch(UInt32 address)
|
|
|
|
|
{
|
2016-02-13 23:13:44 -05:00
|
|
|
|
ListViewItem item = lstWatch.Items.Insert(lstWatch.Items.Count - 1, "[$" + address.ToString("X") + "]");
|
2015-07-01 23:17:14 -04:00
|
|
|
|
item.Tag = address;
|
|
|
|
|
UpdateWatch();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-13 23:13:44 -05:00
|
|
|
|
private void lstWatch_BeforeLabelEdit(object sender, LabelEditEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-01 23:17:14 -04:00
|
|
|
|
private void lstWatch_AfterLabelEdit(object sender, LabelEditEventArgs e)
|
|
|
|
|
{
|
2016-01-10 13:23:19 -05:00
|
|
|
|
this.BeginInvoke((MethodInvoker)(() => { this.UpdateWatch(e.Item); }));
|
2015-07-01 23:17:14 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void mnuHexDisplay_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-06-04 14:43:13 -04:00
|
|
|
|
ConfigManager.Config.DebugInfo.HexDisplay = this.mnuHexDisplay.Checked;
|
|
|
|
|
ConfigManager.ApplyChanges();
|
2015-07-01 23:17:14 -04:00
|
|
|
|
UpdateWatch();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void lstWatch_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
mnuRemoveWatch.Enabled = lstWatch.SelectedItems.Count >= 1;
|
|
|
|
|
}
|
2016-01-10 13:23:19 -05:00
|
|
|
|
|
|
|
|
|
private void lstWatch_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(lstWatch.SelectedItems.Count == 1 && string.IsNullOrWhiteSpace(lstWatch.SelectedItems[0].Text)) {
|
|
|
|
|
lstWatch.SelectedItems[0].BeginEdit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void lstWatch_DoubleClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(lstWatch.SelectedItems.Count == 1) {
|
|
|
|
|
lstWatch.SelectedItems[0].BeginEdit();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-13 23:13:44 -05:00
|
|
|
|
|
|
|
|
|
private void mnuRemoveWatch_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(lstWatch.SelectedItems.Count >= 1) {
|
|
|
|
|
var itemsToRemove = new List<ListViewItem>();
|
|
|
|
|
foreach(ListViewItem item in lstWatch.SelectedItems) {
|
|
|
|
|
itemsToRemove.Add(item);
|
|
|
|
|
}
|
|
|
|
|
foreach(ListViewItem item in itemsToRemove) {
|
|
|
|
|
lstWatch.Items.Remove(item);
|
|
|
|
|
}
|
|
|
|
|
UpdateWatch();
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-01 23:17:14 -04:00
|
|
|
|
}
|
|
|
|
|
}
|