2016-11-20 13:15:37 -05: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;
|
|
|
|
|
using System.Collections;
|
2016-12-11 14:25:29 -05:00
|
|
|
|
using Mesen.GUI.Controls;
|
2016-11-20 13:15:37 -05:00
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Debugger.Controls
|
|
|
|
|
{
|
2016-12-11 14:25:29 -05:00
|
|
|
|
public partial class ctrlFunctionList : BaseControl
|
2016-11-20 13:15:37 -05:00
|
|
|
|
{
|
2016-11-27 10:56:37 -05:00
|
|
|
|
public event EventHandler OnFindOccurrence;
|
2016-11-20 13:15:37 -05:00
|
|
|
|
public event EventHandler OnFunctionSelected;
|
2016-11-27 10:56:37 -05:00
|
|
|
|
|
2016-11-20 13:15:37 -05:00
|
|
|
|
public ctrlFunctionList()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class FunctionComparer : IComparer
|
|
|
|
|
{
|
|
|
|
|
int IComparer.Compare(object x, object y)
|
|
|
|
|
{
|
|
|
|
|
ListViewItem a = x as ListViewItem;
|
|
|
|
|
ListViewItem b = y as ListViewItem;
|
|
|
|
|
|
|
|
|
|
string aText = string.IsNullOrWhiteSpace(a.Text) ? "ZZZZZZZZZZZZZZZZZZZZZZZ" : a.Text;
|
|
|
|
|
string bText = string.IsNullOrWhiteSpace(b.Text) ? "ZZZZZZZZZZZZZZZZZZZZZZZ" : b.Text;
|
2016-11-27 10:56:37 -05:00
|
|
|
|
Int32 aRelative = (Int32)a.SubItems[1].Tag == -1 ? Int32.MaxValue : (Int32)a.SubItems[1].Tag;
|
|
|
|
|
Int32 bRelative = (Int32)b.SubItems[1].Tag == -1 ? Int32.MaxValue : (Int32)b.SubItems[1].Tag;
|
2016-11-26 14:15:50 -05:00
|
|
|
|
Int32 aAbsolute = (Int32)a.SubItems[2].Tag;
|
|
|
|
|
Int32 bAbsolute = (Int32)b.SubItems[2].Tag;
|
2016-11-20 13:15:37 -05:00
|
|
|
|
|
|
|
|
|
if(a.Text == b.Text) {
|
|
|
|
|
if(a.Tag == b.Tag) {
|
|
|
|
|
return aAbsolute > bAbsolute ? 1 : -1;
|
|
|
|
|
} else {
|
|
|
|
|
return aRelative > bRelative ? 1 : -1;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return string.Compare(aText, bText);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-26 14:15:50 -05:00
|
|
|
|
private Dictionary<Int32, ListViewItem> _functions = new Dictionary<int, ListViewItem>();
|
|
|
|
|
public void UpdateFunctionList(bool reset)
|
2016-11-20 13:15:37 -05:00
|
|
|
|
{
|
2016-11-26 14:15:50 -05:00
|
|
|
|
if(reset) {
|
|
|
|
|
lstFunctions.Items.Clear();
|
|
|
|
|
_functions.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-20 13:15:37 -05:00
|
|
|
|
Int32[] entryPoints = InteropEmu.DebugGetFunctionEntryPoints();
|
2016-11-26 14:15:50 -05:00
|
|
|
|
bool updating = false;
|
2016-11-20 13:15:37 -05:00
|
|
|
|
|
2017-04-30 20:27:02 -04:00
|
|
|
|
for(int i = 0; i < entryPoints.Length && entryPoints[i] >= 0; i++) {
|
2016-11-26 14:15:50 -05:00
|
|
|
|
Int32 entryPoint = entryPoints[i];
|
|
|
|
|
ListViewItem item;
|
|
|
|
|
if(!_functions.TryGetValue(entryPoint, out item)) {
|
|
|
|
|
if(!updating) {
|
|
|
|
|
updating = true;
|
|
|
|
|
lstFunctions.BeginUpdate();
|
|
|
|
|
lstFunctions.ListViewItemSorter = null;
|
|
|
|
|
}
|
2016-11-20 13:15:37 -05:00
|
|
|
|
|
2016-11-26 14:15:50 -05:00
|
|
|
|
CodeLabel label = LabelManager.GetLabel((UInt32)entryPoint, AddressType.PrgRom);
|
|
|
|
|
item = lstFunctions.Items.Add(label?.Label);
|
2016-11-27 10:56:37 -05:00
|
|
|
|
item.Tag = label;
|
2016-11-26 18:50:34 -05:00
|
|
|
|
|
|
|
|
|
item.SubItems.Add("[n/a]");
|
2016-11-27 10:56:37 -05:00
|
|
|
|
item.SubItems[1].Tag = -1;
|
2016-11-26 18:50:34 -05:00
|
|
|
|
item.ForeColor = Color.Gray;
|
|
|
|
|
item.Font = new Font(item.Font, FontStyle.Italic);
|
|
|
|
|
|
2016-11-26 14:15:50 -05:00
|
|
|
|
item.SubItems.Add("$" + entryPoint.ToString("X4"));
|
|
|
|
|
item.SubItems[2].Tag = entryPoint;
|
|
|
|
|
|
|
|
|
|
_functions[entryPoint] = item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Int32 relativeAddress = InteropEmu.DebugGetRelativeAddress((UInt32)entryPoint, AddressType.PrgRom);
|
2016-11-27 10:56:37 -05:00
|
|
|
|
if(relativeAddress != (Int32)item.SubItems[1].Tag) {
|
2016-11-26 14:15:50 -05:00
|
|
|
|
if(!updating) {
|
|
|
|
|
updating = true;
|
|
|
|
|
lstFunctions.BeginUpdate();
|
|
|
|
|
lstFunctions.ListViewItemSorter = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(relativeAddress >= 0) {
|
|
|
|
|
item.SubItems[1].Text = "$" + relativeAddress.ToString("X4");
|
|
|
|
|
item.ForeColor = Color.Black;
|
|
|
|
|
item.Font = new Font(item.Font, FontStyle.Regular);
|
|
|
|
|
} else {
|
|
|
|
|
item.SubItems[1].Text = "[n/a]";
|
|
|
|
|
item.ForeColor = Color.Gray;
|
|
|
|
|
item.Font = new Font(item.Font, FontStyle.Italic);
|
|
|
|
|
}
|
2016-11-27 10:56:37 -05:00
|
|
|
|
item.SubItems[1].Tag = relativeAddress;
|
2016-11-20 13:15:37 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-26 14:15:50 -05:00
|
|
|
|
|
|
|
|
|
if(updating) {
|
|
|
|
|
lstFunctions.ListViewItemSorter = new FunctionComparer();
|
|
|
|
|
lstFunctions.Sort();
|
|
|
|
|
lstFunctions.EndUpdate();
|
|
|
|
|
}
|
2016-11-20 13:15:37 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void lstFunctions_DoubleClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(lstFunctions.SelectedItems.Count > 0) {
|
2016-11-27 12:14:32 -05:00
|
|
|
|
Int32 relativeAddress = (Int32)lstFunctions.SelectedItems[0].SubItems[1].Tag;
|
2016-11-20 13:15:37 -05:00
|
|
|
|
|
|
|
|
|
if(relativeAddress >= 0) {
|
|
|
|
|
OnFunctionSelected?.Invoke(relativeAddress, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-27 10:56:37 -05:00
|
|
|
|
|
|
|
|
|
private void mnuEditLabel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-12-03 09:57:58 -05:00
|
|
|
|
if(lstFunctions.SelectedItems.Count > 0) {
|
|
|
|
|
CodeLabel label = lstFunctions.SelectedItems[0].Tag as CodeLabel;
|
|
|
|
|
if(label != null) {
|
|
|
|
|
ctrlLabelList.EditLabel(label.Address, label.AddressType);
|
|
|
|
|
} else {
|
|
|
|
|
ctrlLabelList.EditLabel((UInt32)(Int32)lstFunctions.SelectedItems[0].SubItems[2].Tag, AddressType.PrgRom);
|
|
|
|
|
}
|
2016-11-27 10:56:37 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void mnuFindOccurrences_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-12-21 15:12:37 -05:00
|
|
|
|
if(lstFunctions.SelectedItems.Count > 0) {
|
2017-12-29 13:08:43 -05:00
|
|
|
|
int relativeAddress = (int)lstFunctions.SelectedItems[0].SubItems[1].Tag;
|
|
|
|
|
if(relativeAddress >= 0) {
|
|
|
|
|
CodeLabel label = lstFunctions.SelectedItems[0].Tag as CodeLabel;
|
|
|
|
|
if(label != null) {
|
|
|
|
|
OnFindOccurrence?.Invoke(label.Label, null);
|
|
|
|
|
} else {
|
|
|
|
|
OnFindOccurrence?.Invoke("$" + ((int)lstFunctions.SelectedItems[0].SubItems[1].Tag).ToString("X4"), null);
|
|
|
|
|
}
|
2017-12-21 15:12:37 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-27 10:56:37 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void contextMenuStrip_Opening(object sender, CancelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
mnuEditLabel.Enabled = lstFunctions.SelectedItems.Count == 1;
|
|
|
|
|
mnuFindOccurrences.Enabled = lstFunctions.SelectedItems.Count == 1;
|
2017-12-29 13:08:43 -05:00
|
|
|
|
if(lstFunctions.SelectedItems.Count == 1) {
|
|
|
|
|
int relativeAddress = (int)lstFunctions.SelectedItems[0].SubItems[1].Tag;
|
|
|
|
|
if(relativeAddress < 0) {
|
|
|
|
|
mnuFindOccurrences.Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-27 10:56:37 -05:00
|
|
|
|
}
|
2017-12-21 15:12:37 -05:00
|
|
|
|
|
|
|
|
|
private void mnuAddBreakpoint_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(lstFunctions.SelectedItems.Count > 0) {
|
|
|
|
|
CodeLabel label = lstFunctions.SelectedItems[0].Tag as CodeLabel;
|
|
|
|
|
int absoluteAddress = (int)lstFunctions.SelectedItems[0].SubItems[2].Tag;
|
|
|
|
|
BreakpointManager.AddBreakpoint(new Breakpoint() {
|
2018-02-10 21:23:22 -05:00
|
|
|
|
MemoryType = DebugMemoryType.PrgRom,
|
2017-12-21 15:12:37 -05:00
|
|
|
|
BreakOnExec = true,
|
|
|
|
|
BreakOnRead = false,
|
|
|
|
|
BreakOnWrite = false,
|
|
|
|
|
Address = (UInt32)absoluteAddress,
|
|
|
|
|
StartAddress = (UInt32)absoluteAddress,
|
|
|
|
|
EndAddress = (UInt32)absoluteAddress,
|
2018-02-10 21:23:22 -05:00
|
|
|
|
AddressType = BreakpointAddressType.SingleAddress
|
2017-12-21 15:12:37 -05:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-20 13:15:37 -05:00
|
|
|
|
}
|
|
|
|
|
}
|