2015-07-01 23:17:14 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Text;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Debugger
|
|
|
|
|
{
|
|
|
|
|
public partial class frmDebugger : Form
|
|
|
|
|
{
|
|
|
|
|
InteropEmu.NotificationListener _notifListener;
|
2015-08-02 19:27:02 -04:00
|
|
|
|
ctrlDebuggerCode _lastCodeWindow;
|
2015-07-01 23:17:14 -04:00
|
|
|
|
|
|
|
|
|
public frmDebugger()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2015-08-02 19:27:02 -04:00
|
|
|
|
|
|
|
|
|
_lastCodeWindow = ctrlDebuggerCode;
|
2015-07-01 23:17:14 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnLoad(e);
|
|
|
|
|
|
2015-07-05 19:03:57 -04:00
|
|
|
|
if(!DesignMode) {
|
|
|
|
|
Icon = Properties.Resources.MesenIcon;
|
|
|
|
|
}
|
2015-07-03 00:12:02 -04:00
|
|
|
|
|
2015-07-01 23:17:14 -04:00
|
|
|
|
_notifListener = new InteropEmu.NotificationListener();
|
|
|
|
|
_notifListener.OnNotification += _notifListener_OnNotification;
|
|
|
|
|
|
|
|
|
|
InteropEmu.DebugInitialize();
|
2015-08-02 22:19:12 -04:00
|
|
|
|
|
|
|
|
|
//Pause a few frames later to give the debugger a chance to disassemble some code
|
|
|
|
|
InteropEmu.DebugStep(100000);
|
2015-07-01 23:17:14 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _notifListener_OnNotification(InteropEmu.NotificationEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(e.NotificationType == InteropEmu.ConsoleNotificationType.CodeBreak) {
|
|
|
|
|
this.BeginInvoke((MethodInvoker)(() => UpdateDebugger()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool UpdateSplitView()
|
|
|
|
|
{
|
|
|
|
|
if(mnuSplitView.Checked) {
|
|
|
|
|
tlpTop.ColumnStyles[1].SizeType = SizeType.Percent;
|
|
|
|
|
tlpTop.ColumnStyles[1].Width = 50f;
|
|
|
|
|
this.MinimumSize = new Size(1250, 650);
|
|
|
|
|
} else {
|
|
|
|
|
tlpTop.ColumnStyles[1].SizeType = SizeType.Absolute;
|
|
|
|
|
tlpTop.ColumnStyles[1].Width = 0f;
|
|
|
|
|
this.MinimumSize = new Size(1000, 650);
|
|
|
|
|
}
|
|
|
|
|
return mnuSplitView.Checked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateDebugger()
|
|
|
|
|
{
|
|
|
|
|
if(InteropEmu.DebugIsCodeChanged()) {
|
|
|
|
|
string code = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(InteropEmu.DebugGetCode());
|
|
|
|
|
ctrlDebuggerCode.Code = code;
|
|
|
|
|
ctrlDebuggerCodeSplit.Code = code;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DebugState state = new DebugState();
|
|
|
|
|
InteropEmu.DebugGetState(ref state);
|
|
|
|
|
|
|
|
|
|
if(UpdateSplitView()) {
|
|
|
|
|
ctrlDebuggerCodeSplit.UpdateCode(true);
|
2015-08-02 19:27:02 -04:00
|
|
|
|
} else {
|
|
|
|
|
_lastCodeWindow = ctrlDebuggerCode;
|
2015-07-01 23:17:14 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-02 19:27:02 -04:00
|
|
|
|
ctrlDebuggerCode.SelectActiveAddress(state.CPU.DebugPC);
|
|
|
|
|
ctrlDebuggerCodeSplit.SetActiveAddress(state.CPU.DebugPC);
|
|
|
|
|
RefreshBreakpoints();
|
|
|
|
|
|
2015-07-01 23:17:14 -04:00
|
|
|
|
ctrlConsoleStatus.UpdateStatus(ref state);
|
|
|
|
|
ctrlWatch.UpdateWatch();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-02 19:27:02 -04:00
|
|
|
|
private void ClearActiveStatement()
|
|
|
|
|
{
|
|
|
|
|
ctrlDebuggerCode.ClearActiveAddress();
|
|
|
|
|
RefreshBreakpoints();
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-01 23:17:14 -04:00
|
|
|
|
private void ToggleBreakpoint()
|
|
|
|
|
{
|
2015-08-02 19:27:02 -04:00
|
|
|
|
ctrlBreakpoints.ToggleBreakpoint(_lastCodeWindow.GetCurrentLine());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RefreshBreakpoints()
|
|
|
|
|
{
|
|
|
|
|
ctrlDebuggerCodeSplit.HighlightBreakpoints(ctrlBreakpoints.GetBreakpoints());
|
|
|
|
|
ctrlDebuggerCode.HighlightBreakpoints(ctrlBreakpoints.GetBreakpoints());
|
2015-07-01 23:17:14 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void mnuContinue_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2015-08-02 19:27:02 -04:00
|
|
|
|
ClearActiveStatement();
|
2015-07-01 23:17:14 -04:00
|
|
|
|
InteropEmu.DebugRun();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void frmDebugger_FormClosed(object sender, FormClosedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
InteropEmu.DebugRelease();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void mnuToggleBreakpoint_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ToggleBreakpoint();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void mnuBreak_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
InteropEmu.DebugStep(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void mnuStepInto_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
InteropEmu.DebugStep(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void mnuStepOut_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
InteropEmu.DebugStepOut();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void mnuStepOver_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
InteropEmu.DebugStepOver();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void mnuRunOneFrame_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
InteropEmu.DebugStepCycles(29780);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ctrlDebuggerCode_OnWatchAdded(WatchAddedEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
this.ctrlWatch.AddWatch(args.Address);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void mnuFind_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void mnuSplitView_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
UpdateDebugger();
|
|
|
|
|
}
|
2015-08-02 19:27:02 -04:00
|
|
|
|
|
|
|
|
|
private void mnuMemoryViewer_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ctrlBreakpoints_BreakpointChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
RefreshBreakpoints();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ctrlDebuggerCode_Enter(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_lastCodeWindow = ctrlDebuggerCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ctrlDebuggerCodeSplit_Enter(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_lastCodeWindow = ctrlDebuggerCodeSplit;
|
|
|
|
|
}
|
2015-08-02 22:19:12 -04:00
|
|
|
|
|
|
|
|
|
private void mnuGoTo_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_lastCodeWindow.GoToAddress();
|
|
|
|
|
}
|
2015-07-01 23:17:14 -04:00
|
|
|
|
}
|
|
|
|
|
}
|