Debugger: Added "mark selection as" shortcuts in debugger & memory tools

This commit is contained in:
Sour 2020-02-08 22:30:54 -05:00
parent 44eb8c5eb9
commit b68aaefd7e
21 changed files with 369 additions and 143 deletions

View file

@ -46,16 +46,19 @@ bool CodeDataLogger::LoadCdlFile(string cdlFilepath)
void CodeDataLogger::CalculateStats()
{
_codeSize = 0;
_dataSize = 0;
uint32_t codeSize = 0;
uint32_t dataSize = 0;
for(int i = 0, len = _prgSize; i < len; i++) {
if(IsCode(i)) {
_codeSize++;
codeSize++;
} else if(IsData(i)) {
_dataSize++;
dataSize++;
}
}
_codeSize = codeSize;
_dataSize = dataSize;
}
bool CodeDataLogger::SaveCdlFile(string cdlFilepath)
@ -126,7 +129,6 @@ void CodeDataLogger::SetCdlData(uint8_t *cdlData, uint32_t length)
{
if(length <= _prgSize) {
memcpy(_cdlData, cdlData, length);
CalculateStats();
}
}
@ -140,4 +142,11 @@ void CodeDataLogger::GetCdlData(uint32_t offset, uint32_t length, SnesMemoryType
cdlData[i] = (info.Type == SnesMemoryType::PrgRom && info.Address >= 0) ? _cdlData[info.Address] : 0;
}
}
}
}
void CodeDataLogger::MarkBytesAs(uint32_t start, uint32_t end, uint8_t flags)
{
for(uint32_t i = start; i <= end; i++) {
_cdlData[i] = (_cdlData[i] & 0xFC) | (int)flags;
}
}

View file

@ -36,4 +36,6 @@ public:
void SetCdlData(uint8_t *cdlData, uint32_t length);
void GetCdlData(uint32_t offset, uint32_t length, SnesMemoryType memoryType, uint8_t *cdlData);
void MarkBytesAs(uint32_t start, uint32_t end, uint8_t flags);
};

View file

@ -153,7 +153,8 @@ namespace LineFlags
SubStart = 0x80,
Label = 0x100,
Comment = 0x200,
ShowAsData = 0x400
ShowAsData = 0x400,
UnexecutedCode = 0x800
};
}

View file

@ -483,6 +483,13 @@ void Debugger::SetCdlData(uint8_t *cdlData, uint32_t length)
RefreshCodeCache();
}
void Debugger::MarkBytesAs(uint32_t start, uint32_t end, uint8_t flags)
{
DebugBreakHelper helper(this);
_codeDataLogger->MarkBytesAs(start, end, flags);
RefreshCodeCache();
}
void Debugger::RefreshCodeCache()
{
_disassembler->ResetPrgCache();

View file

@ -119,6 +119,7 @@ public:
AddressInfo GetRelativeAddress(AddressInfo absAddress);
void SetCdlData(uint8_t * cdlData, uint32_t length);
void MarkBytesAs(uint32_t start, uint32_t end, uint8_t flags);
void RefreshCodeCache();
void SetBreakpoints(Breakpoint breakpoints[], uint32_t length);

View file

@ -467,7 +467,7 @@ bool Disassembler::GetLineData(CpuType type, uint32_t lineIndex, CodeLineData &d
if(!disInfo.IsInitialized()) {
disInfo = DisassemblyInfo(src.Data + result.Address.Address, state.PS, CpuType::Cpu);
} else {
data.Flags |= LineFlags::VerifiedCode;
data.Flags |= _cdl->IsCode(data.AbsoluteAddress) ? LineFlags::VerifiedCode : LineFlags::UnexecutedCode;
}
data.OpSize = disInfo.GetOpSize();

View file

@ -82,7 +82,8 @@ extern "C"
DllExport void __stdcall GetMemoryAccessCounts(uint32_t offset, uint32_t length, SnesMemoryType memoryType, MemoryOperationType operationType, uint32_t* counts) { GetDebugger()->GetMemoryAccessCounter()->GetAccessCounts(offset, length, memoryType, operationType, counts); }
DllExport void __stdcall GetCdlData(uint32_t offset, uint32_t length, SnesMemoryType memoryType, uint8_t* cdlData) { GetDebugger()->GetCodeDataLogger()->GetCdlData(offset, length, memoryType, cdlData); }
DllExport void __stdcall SetCdlData(uint8_t *cdlData, uint32_t length) { GetDebugger()->SetCdlData(cdlData, length); }
DllExport void __stdcall SetCdlData(uint8_t* cdlData, uint32_t length) { GetDebugger()->SetCdlData(cdlData, length); }
DllExport void __stdcall MarkBytesAs(uint32_t start, uint32_t end, uint8_t flags) { GetDebugger()->MarkBytesAs(start, end, flags); }
DllExport void __stdcall GetTilemap(GetTilemapOptions options, PpuState state, uint8_t *vram, uint8_t *cgram, uint32_t *buffer) { GetDebugger()->GetPpuTools()->GetTilemap(options, state, vram, cgram, buffer); }
DllExport void __stdcall GetTileView(GetTileViewOptions options, uint8_t *source, uint32_t srcSize, uint8_t *cgram, uint32_t *buffer) { GetDebugger()->GetPpuTools()->GetTileView(options, source, srcSize, cgram, buffer); }

View file

@ -41,11 +41,6 @@ namespace Mesen.GUI.Debugger.Code
ConfigureActiveStatement(props);
}
//TODO
/* else if(_code._code.UnexecutedAddresses.Contains(lineNumber)) {
props.LineBgColor = info.CodeUnexecutedCodeColor;
}*/
if(lineData.Flags.HasFlag(LineFlags.PrgRom)) {
props.AddressColor = Color.Gray;
} else if(lineData.Flags.HasFlag(LineFlags.WorkRam)) {
@ -56,6 +51,8 @@ namespace Mesen.GUI.Debugger.Code
if(lineData.Flags.HasFlag(LineFlags.VerifiedData)) {
props.LineBgColor = cfg.CodeVerifiedDataColor;
} else if(lineData.Flags.HasFlag(LineFlags.UnexecutedCode)) {
props.LineBgColor = cfg.CodeUnexecutedCodeColor;
} else if(!lineData.Flags.HasFlag(LineFlags.VerifiedCode)) {
props.LineBgColor = cfg.CodeUnidentifiedDataColor;
}

View file

@ -146,6 +146,7 @@ namespace Mesen.GUI.Debugger
SubStart = 0x80,
Label = 0x100,
Comment = 0x200,
ShowAsData = 0x400
ShowAsData = 0x400,
UnexecutedCode = 0x800
}
}

View file

@ -312,26 +312,21 @@ namespace Mesen.GUI.Config
}
Keys keys = (XmlKeys)typeof(DebuggerShortcutsConfig).GetField(fieldName).GetValue(ConfigManager.Config.Debug.Shortcuts);
if((keys != Keys.None && !ToolStripManager.IsValidShortcut(keys)) || Program.IsMono) {
//Support normally invalid shortcut keys as a shortcut
item.ShortcutKeys = Keys.None;
item.ShortcutKeyDisplayString = GetShortcutDisplay(keys);
Form parentForm = parent.FindForm();
if(parentForm is BaseForm) {
ProcessCmdKeyHandler onProcessCmdKeyHandler = (Keys keyData, ref bool processed) => {
if(!processed && item.Enabled && parent.ContainsFocus && keyData == keys) {
item.PerformClick();
processed = true;
}
};
item.ShortcutKeys = Keys.None;
item.ShortcutKeyDisplayString = GetShortcutDisplay(keys);
((ShortcutInfo)item.Tag).KeyHandler = onProcessCmdKeyHandler;
(parentForm as BaseForm).OnProcessCmdKey += onProcessCmdKeyHandler;
}
} else {
item.ShortcutKeys = keys;
item.ShortcutKeyDisplayString = GetShortcutDisplay(keys);
Form parentForm = parent.FindForm();
if(parentForm is BaseForm) {
ProcessCmdKeyHandler onProcessCmdKeyHandler = (Keys keyData, ref bool processed) => {
if(!processed && item.Enabled && parent.ContainsFocus && keyData == keys) {
item.PerformClick();
processed = true;
}
};
((ShortcutInfo)item.Tag).KeyHandler = onProcessCmdKeyHandler;
(parentForm as BaseForm).OnProcessCmdKey += onProcessCmdKeyHandler;
}
}
}

View file

@ -30,8 +30,12 @@
this.components = new System.ComponentModel.Container();
this.ctrlCode = new Mesen.GUI.Debugger.Controls.ctrlScrollableTextbox();
this.ctxMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.mnuMarkSelectionAs = new System.Windows.Forms.ToolStripMenuItem();
this.mnuMarkAsCode = new System.Windows.Forms.ToolStripMenuItem();
this.mnuMarkAsData = new System.Windows.Forms.ToolStripMenuItem();
this.mnuMarkAsUnidentifiedData = new System.Windows.Forms.ToolStripMenuItem();
this.sepMarkSelectionAs = new System.Windows.Forms.ToolStripSeparator();
this.mnuToggleBreakpoint = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
this.mnuAddToWatch = new System.Windows.Forms.ToolStripMenuItem();
this.mnuEditLabel = new System.Windows.Forms.ToolStripMenuItem();
this.mnuEditInMemoryTools = new System.Windows.Forms.ToolStripMenuItem();
@ -76,8 +80,9 @@
// ctxMenu
//
this.ctxMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuMarkSelectionAs,
this.sepMarkSelectionAs,
this.mnuToggleBreakpoint,
this.toolStripMenuItem1,
this.mnuAddToWatch,
this.mnuEditLabel,
this.mnuEditInMemoryTools,
@ -87,28 +92,58 @@
this.sepSwitchView,
this.mnuSwitchView});
this.ctxMenu.Name = "ctxMenu";
this.ctxMenu.Size = new System.Drawing.Size(227, 198);
this.ctxMenu.Size = new System.Drawing.Size(227, 220);
this.ctxMenu.Closing += new System.Windows.Forms.ToolStripDropDownClosingEventHandler(this.ctxMenu_Closing);
this.ctxMenu.Opening += new System.ComponentModel.CancelEventHandler(this.ctxMenu_Opening);
//
// mnuMarkSelectionAs
//
this.mnuMarkSelectionAs.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuMarkAsCode,
this.mnuMarkAsData,
this.mnuMarkAsUnidentifiedData});
this.mnuMarkSelectionAs.Name = "mnuMarkSelectionAs";
this.mnuMarkSelectionAs.Size = new System.Drawing.Size(226, 22);
this.mnuMarkSelectionAs.Text = "Mark selection as...";
//
// mnuMarkAsCode
//
this.mnuMarkAsCode.Image = global::Mesen.GUI.Properties.Resources.Accept;
this.mnuMarkAsCode.Name = "mnuMarkAsCode";
this.mnuMarkAsCode.Size = new System.Drawing.Size(199, 22);
this.mnuMarkAsCode.Text = "Verified Code";
//
// mnuMarkAsData
//
this.mnuMarkAsData.Image = global::Mesen.GUI.Properties.Resources.CheatCode;
this.mnuMarkAsData.Name = "mnuMarkAsData";
this.mnuMarkAsData.Size = new System.Drawing.Size(199, 22);
this.mnuMarkAsData.Text = "Verified Data";
//
// mnuMarkAsUnidentifiedData
//
this.mnuMarkAsUnidentifiedData.Image = global::Mesen.GUI.Properties.Resources.Help;
this.mnuMarkAsUnidentifiedData.Name = "mnuMarkAsUnidentifiedData";
this.mnuMarkAsUnidentifiedData.Size = new System.Drawing.Size(199, 22);
this.mnuMarkAsUnidentifiedData.Text = "Unidentified Code/Data";
//
// sepMarkSelectionAs
//
this.sepMarkSelectionAs.Name = "sepMarkSelectionAs";
this.sepMarkSelectionAs.Size = new System.Drawing.Size(223, 6);
//
// mnuToggleBreakpoint
//
this.mnuToggleBreakpoint.Image = global::Mesen.GUI.Properties.Resources.Breakpoint;
this.mnuToggleBreakpoint.Name = "mnuToggleBreakpoint";
this.mnuToggleBreakpoint.Size = new System.Drawing.Size(206, 22);
this.mnuToggleBreakpoint.Size = new System.Drawing.Size(226, 22);
this.mnuToggleBreakpoint.Text = "Toggle Breakpoint";
this.mnuToggleBreakpoint.Click += new System.EventHandler(this.mnuToggleBreakpoint_Click);
//
// toolStripMenuItem1
//
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(203, 6);
//
// mnuAddToWatch
//
this.mnuAddToWatch.Image = global::Mesen.GUI.Properties.Resources.Add;
this.mnuAddToWatch.Name = "mnuAddToWatch";
this.mnuAddToWatch.Size = new System.Drawing.Size(206, 22);
this.mnuAddToWatch.Size = new System.Drawing.Size(226, 22);
this.mnuAddToWatch.Text = "Add to Watch";
this.mnuAddToWatch.Click += new System.EventHandler(this.mnuAddToWatch_Click);
//
@ -116,22 +151,20 @@
//
this.mnuEditLabel.Image = global::Mesen.GUI.Properties.Resources.EditLabel;
this.mnuEditLabel.Name = "mnuEditLabel";
this.mnuEditLabel.Size = new System.Drawing.Size(206, 22);
this.mnuEditLabel.Size = new System.Drawing.Size(226, 22);
this.mnuEditLabel.Text = "Edit Label";
this.mnuEditLabel.Click += new System.EventHandler(this.mnuEditLabel_Click);
//
// mnuEditInMemoryTools
//
this.mnuEditInMemoryTools.Image = global::Mesen.GUI.Properties.Resources.CheatCode;
this.mnuEditInMemoryTools.Name = "mnuEditInMemoryTools";
this.mnuEditInMemoryTools.Size = new System.Drawing.Size(206, 22);
this.mnuEditInMemoryTools.Size = new System.Drawing.Size(226, 22);
this.mnuEditInMemoryTools.Text = "Edit in Memory Tools";
this.mnuEditInMemoryTools.Click += new System.EventHandler(this.mnuEditInMemoryTools_Click);
//
// toolStripMenuItem2
//
this.toolStripMenuItem2.Name = "toolStripMenuItem2";
this.toolStripMenuItem2.Size = new System.Drawing.Size(203, 6);
this.toolStripMenuItem2.Size = new System.Drawing.Size(223, 6);
//
// mnuGoToLocation
//
@ -146,20 +179,20 @@
this.mnuFindOccurrences.Enabled = false;
this.mnuFindOccurrences.Image = global::Mesen.GUI.Properties.Resources.Find;
this.mnuFindOccurrences.Name = "mnuFindOccurrences";
this.mnuFindOccurrences.Size = new System.Drawing.Size(206, 22);
this.mnuFindOccurrences.Size = new System.Drawing.Size(226, 22);
this.mnuFindOccurrences.Text = "Find Occurrences";
this.mnuFindOccurrences.Visible = false;
//
// sepSwitchView
//
this.sepSwitchView.Name = "sepSwitchView";
this.sepSwitchView.Size = new System.Drawing.Size(203, 6);
this.sepSwitchView.Size = new System.Drawing.Size(223, 6);
//
// mnuSwitchView
//
this.mnuSwitchView.Image = global::Mesen.GUI.Properties.Resources.SwitchView;
this.mnuSwitchView.Name = "mnuSwitchView";
this.mnuSwitchView.Size = new System.Drawing.Size(206, 22);
this.mnuSwitchView.Size = new System.Drawing.Size(226, 22);
this.mnuSwitchView.Text = "Switch to Source View";
//
// cboSourceFile
@ -222,7 +255,7 @@
private System.Windows.Forms.ToolStripMenuItem mnuAddToWatch;
private System.Windows.Forms.ToolStripMenuItem mnuToggleBreakpoint;
private System.Windows.Forms.ToolStripMenuItem mnuEditLabel;
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1;
private System.Windows.Forms.ToolStripSeparator sepMarkSelectionAs;
private System.Windows.Forms.ToolStripMenuItem mnuEditInMemoryTools;
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
private System.Windows.Forms.ToolStripMenuItem mnuGoToLocation;
@ -232,5 +265,9 @@
private System.Windows.Forms.ToolStripMenuItem mnuSwitchView;
private System.Windows.Forms.TableLayoutPanel tlpMain;
private System.Windows.Forms.Label lblSourceFile;
}
private System.Windows.Forms.ToolStripMenuItem mnuMarkSelectionAs;
private System.Windows.Forms.ToolStripMenuItem mnuMarkAsCode;
private System.Windows.Forms.ToolStripMenuItem mnuMarkAsData;
private System.Windows.Forms.ToolStripMenuItem mnuMarkAsUnidentifiedData;
}
}

View file

@ -31,13 +31,17 @@ namespace Mesen.GUI.Debugger.Controls
return;
}
InitShortcuts();
DebugWorkspaceManager.SymbolProviderChanged += DebugWorkspaceManager_SymbolProviderChanged;
BreakpointManager.BreakpointsChanged += BreakpointManager_BreakpointsChanged;
LabelManager.OnLabelUpdated += OnLabelUpdated;
}
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
InitShortcuts();
}
protected override void OnHandleDestroyed(EventArgs e)
{
base.OnHandleDestroyed(e);
@ -46,6 +50,12 @@ namespace Mesen.GUI.Debugger.Controls
BreakpointManager.BreakpointsChanged -= BreakpointManager_BreakpointsChanged;
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
UpdateContextMenu();
return base.ProcessCmdKey(ref msg, keyData);
}
private void DebugWorkspaceManager_SymbolProviderChanged(ISymbolProvider symbolProvider)
{
_symbolProvider = symbolProvider;
@ -126,16 +136,70 @@ namespace Mesen.GUI.Debugger.Controls
private void InitShortcuts()
{
mnuToggleBreakpoint.InitShortcut(this, nameof(DebuggerShortcutsConfig.CodeWindow_ToggleBreakpoint));
mnuToggleBreakpoint.Click += (s, e) => ToggleBreakpoint();
mnuEditLabel.InitShortcut(this, nameof(DebuggerShortcutsConfig.CodeWindow_EditLabel));
mnuEditLabel.Click += (s, e) => EditLabel(GetActionTarget());
mnuEditInMemoryTools.InitShortcut(this, nameof(DebuggerShortcutsConfig.CodeWindow_EditInMemoryViewer));
mnuEditInMemoryTools.Click += (s, e) => EditInMemoryTools(GetActionTarget());
mnuAddToWatch.InitShortcut(this, nameof(DebuggerShortcutsConfig.LabelList_AddToWatch));
mnuMarkAsCode.InitShortcut(this, nameof(DebuggerShortcutsConfig.MarkAsCode));
mnuMarkAsCode.Click += (s, e) => MarkSelectionAs(CdlFlags.Code);
mnuMarkAsData.InitShortcut(this, nameof(DebuggerShortcutsConfig.MarkAsData));
mnuMarkAsData.Click += (s, e) => MarkSelectionAs(CdlFlags.Data);
mnuMarkAsUnidentifiedData.InitShortcut(this, nameof(DebuggerShortcutsConfig.MarkAsUnidentified));
mnuMarkAsUnidentifiedData.Click += (s, e) => MarkSelectionAs(CdlFlags.None);
mnuSwitchView.InitShortcut(this, nameof(DebuggerShortcutsConfig.CodeWindow_SwitchView));
mnuSwitchView.Click += (s, e) => { ToggleView(); };
}
private void MarkSelectionAs(CdlFlags type)
{
SelectedAddressRange range = GetSelectedAddressRange();
if(!_inSourceView && range != null && range.Start.Type == SnesMemoryType.PrgRom && range.End.Type == SnesMemoryType.PrgRom) {
DebugApi.MarkBytesAs((UInt32)range.Start.Address, (UInt32)range.End.Address, type);
DebugWindowManager.OpenDebugger(CpuType.Cpu)?.RefreshDisassembly();
}
}
class SelectedAddressRange
{
public AddressInfo Start;
public AddressInfo End;
public string Display;
}
private SelectedAddressRange GetSelectedAddressRange()
{
int firstLineOfSelection = ctrlCode.SelectionStart;
while(_manager.Provider.GetLineAddress(firstLineOfSelection) < 0) {
firstLineOfSelection++;
}
int firstLineAfterSelection = ctrlCode.SelectionStart + ctrlCode.SelectionLength + 1;
while(_manager.Provider.GetLineAddress(firstLineAfterSelection) < 0) {
firstLineAfterSelection++;
}
int start = _manager.Provider.GetLineAddress(firstLineOfSelection);
int end = _manager.Provider.GetLineAddress(firstLineAfterSelection) - 1;
if(start >= 0 && end >= 0) {
return new SelectedAddressRange() {
Start = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = start, Type = _manager.RelativeMemoryType }),
End = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = end, Type = _manager.RelativeMemoryType }),
Display = $"${start.ToString("X4")} - ${end.ToString("X4")}"
};
}
return null;
}
public void ToggleView()
{
_inSourceView = !_inSourceView;
@ -200,7 +264,7 @@ namespace Mesen.GUI.Debugger.Controls
ctrlCode.ScrollToAddress((int)address);
}
public void UpdateCode()
public void UpdateCode(bool refreshDisassembly = false)
{
int centerLineIndex = ctrlCode.GetLineIndexAtPosition(0) + ctrlCode.GetNumberVisibleLines() / 2;
int centerLineAddress;
@ -212,6 +276,12 @@ namespace Mesen.GUI.Debugger.Controls
scrollOffset++;
} while(centerLineAddress < 0 && centerLineIndex > 0);
if(refreshDisassembly) {
DebugApi.RefreshDisassembly(CpuType.Cpu);
DebugApi.RefreshDisassembly(CpuType.Spc);
DebugApi.RefreshDisassembly(CpuType.Sa1);
}
_manager.RefreshCode(_inSourceView ? _symbolProvider : null, _inSourceView ? cboSourceFile.SelectedItem as SourceFileInfo : null);
ctrlCode.DataProvider = _manager.Provider;
@ -354,21 +424,6 @@ namespace Mesen.GUI.Debugger.Controls
return _manager.GetLocationInfo(word, lineIndex);
}
private void mnuToggleBreakpoint_Click(object sender, EventArgs e)
{
ToggleBreakpoint();
}
private void mnuEditLabel_Click(object sender, EventArgs e)
{
EditLabel(GetActionTarget());
}
private void mnuEditInMemoryTools_Click(object sender, EventArgs e)
{
EditInMemoryTools(GetActionTarget());
}
private void mnuGoToLocation_Click(object sender, EventArgs e)
{
GoToLocation(GetActionTarget());
@ -450,17 +505,17 @@ namespace Mesen.GUI.Debugger.Controls
ctrlCode.SetMessage(msg);
}
private void ctxMenu_Opening(object sender, CancelEventArgs e)
private void UpdateContextMenu()
{
LocationInfo location = GetActionTarget();
bool active = location.Address >= 0 || location.Label != null || location.Symbol != null;
string suffix = location.Symbol?.Name ?? location.Label?.Label;
if(string.IsNullOrWhiteSpace(suffix)) {
suffix = (location.Address >= 0 ? ("$" + location.Address.ToString("X6")) : "");
}
string labelName = "";
string labelName = "";
if(suffix.Length > 0) {
labelName = " (" + suffix + ")";
if(location.ArrayIndex.HasValue) {
@ -471,7 +526,7 @@ namespace Mesen.GUI.Debugger.Controls
suffix = "";
labelName = "";
}
bool enableGoToLocation = (location.Address != _manager.Provider.GetLineAddress(ctrlCode.SelectedLine));
mnuAddToWatch.Text = "Add to Watch" + suffix;
@ -479,12 +534,28 @@ namespace Mesen.GUI.Debugger.Controls
mnuEditLabel.Text = "Edit Label" + labelName;
mnuGoToLocation.Text = "Go to Location" + (enableGoToLocation ? suffix : "");
SelectedAddressRange range = GetSelectedAddressRange();
if(range != null && range.Start.Type == SnesMemoryType.PrgRom && range.End.Type == SnesMemoryType.PrgRom) {
mnuMarkSelectionAs.Enabled = true;
mnuMarkSelectionAs.Text = "Mark selection as... (" + range.Display + ")";
} else {
mnuMarkSelectionAs.Enabled = false;
mnuMarkSelectionAs.Text = "Mark selection as...";
}
mnuMarkSelectionAs.Visible = !_inSourceView;
sepMarkSelectionAs.Visible = !_inSourceView;
mnuAddToWatch.Enabled = active;
mnuEditInMemoryTools.Enabled = active;
mnuEditLabel.Enabled = active && location.Symbol == null;
mnuGoToLocation.Enabled = active && enableGoToLocation;
}
private void ctxMenu_Opening(object sender, CancelEventArgs e)
{
UpdateContextMenu();
}
private void ctxMenu_Closing(object sender, ToolStripDropDownClosingEventArgs e)
{
mnuAddToWatch.Enabled = true;

View file

@ -90,6 +90,17 @@ namespace Mesen.GUI.Debugger
throw new Exception("Invalid CPU type");
}
public static frmDebugger GetDebugger(CpuType type)
{
switch(type) {
case CpuType.Cpu: return (frmDebugger)GetExistingSingleInstanceWindow(DebugWindow.Debugger);
case CpuType.Spc: return (frmDebugger)GetExistingSingleInstanceWindow(DebugWindow.SpcDebugger);
case CpuType.Sa1: return (frmDebugger)GetExistingSingleInstanceWindow(DebugWindow.Sa1Debugger);
case CpuType.Gsu: return (frmDebugger)GetExistingSingleInstanceWindow(DebugWindow.GsuDebugger);
}
throw new Exception("Invalid CPU type");
}
public static frmMemoryTools GetMemoryViewer()
{
return _openedWindows.ToList().Find((form) => form.GetType() == typeof(frmMemoryTools)) as frmMemoryTools;

View file

@ -46,14 +46,19 @@
this.statusStrip = new System.Windows.Forms.StatusStrip();
this.lblLocation = new System.Windows.Forms.ToolStripStatusLabel();
this.ctxMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
this.mnuAddToWatch = new System.Windows.Forms.ToolStripMenuItem();
this.mnuEditBreakpoint = new System.Windows.Forms.ToolStripMenuItem();
this.mnuEditLabel = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
this.mnuCopy = new System.Windows.Forms.ToolStripMenuItem();
this.mnuPaste = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem5 = new System.Windows.Forms.ToolStripSeparator();
this.mnuSelectAll = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
this.mnuAddToWatch = new System.Windows.Forms.ToolStripMenuItem();
this.mnuEditBreakpoint = new System.Windows.Forms.ToolStripMenuItem();
this.mnuEditLabel = new System.Windows.Forms.ToolStripMenuItem();
this.mnuMarkSelectionAs = new System.Windows.Forms.ToolStripMenuItem();
this.mnuMarkAsCode = new System.Windows.Forms.ToolStripMenuItem();
this.mnuMarkAsData = new System.Windows.Forms.ToolStripMenuItem();
this.mnuMarkAsUnidentifiedData = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
this.tlpMain.SuspendLayout();
this.flowLayoutPanel1.SuspendLayout();
this.panelSearch.SuspendLayout();
@ -300,6 +305,8 @@
// ctxMenuStrip
//
this.ctxMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuMarkSelectionAs,
this.toolStripMenuItem2,
this.mnuAddToWatch,
this.mnuEditBreakpoint,
this.mnuEditLabel,
@ -309,48 +316,14 @@
this.toolStripMenuItem5,
this.mnuSelectAll});
this.ctxMenuStrip.Name = "ctxMenuStrip";
this.ctxMenuStrip.Size = new System.Drawing.Size(155, 170);
this.ctxMenuStrip.Size = new System.Drawing.Size(181, 198);
this.ctxMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(this.ctxMenuStrip_Opening);
//
// mnuCopy
//
this.mnuCopy.Image = global::Mesen.GUI.Properties.Resources.Copy;
this.mnuCopy.Name = "mnuCopy";
this.mnuCopy.Size = new System.Drawing.Size(154, 22);
this.mnuCopy.Text = "Copy";
this.mnuCopy.Click += new System.EventHandler(this.mnuCopy_Click);
//
// mnuPaste
//
this.mnuPaste.Image = global::Mesen.GUI.Properties.Resources.Paste;
this.mnuPaste.Name = "mnuPaste";
this.mnuPaste.Size = new System.Drawing.Size(154, 22);
this.mnuPaste.Text = "Paste";
this.mnuPaste.Click += new System.EventHandler(this.mnuPaste_Click);
//
// toolStripMenuItem5
//
this.toolStripMenuItem5.Name = "toolStripMenuItem5";
this.toolStripMenuItem5.Size = new System.Drawing.Size(151, 6);
//
// mnuSelectAll
//
this.mnuSelectAll.Image = global::Mesen.GUI.Properties.Resources.SelectAll;
this.mnuSelectAll.Name = "mnuSelectAll";
this.mnuSelectAll.Size = new System.Drawing.Size(154, 22);
this.mnuSelectAll.Text = "Select All";
this.mnuSelectAll.Click += new System.EventHandler(this.mnuSelectAll_Click);
//
// toolStripMenuItem1
//
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(151, 6);
//
// mnuAddToWatch
//
this.mnuAddToWatch.Image = global::Mesen.GUI.Properties.Resources.Add;
this.mnuAddToWatch.Name = "mnuAddToWatch";
this.mnuAddToWatch.Size = new System.Drawing.Size(154, 22);
this.mnuAddToWatch.Size = new System.Drawing.Size(180, 22);
this.mnuAddToWatch.Text = "Add to Watch";
this.mnuAddToWatch.Click += new System.EventHandler(this.mnuAddToWatch_Click);
//
@ -358,7 +331,7 @@
//
this.mnuEditBreakpoint.Image = global::Mesen.GUI.Properties.Resources.BreakpointEnableDisable;
this.mnuEditBreakpoint.Name = "mnuEditBreakpoint";
this.mnuEditBreakpoint.Size = new System.Drawing.Size(154, 22);
this.mnuEditBreakpoint.Size = new System.Drawing.Size(180, 22);
this.mnuEditBreakpoint.Text = "Edit Breakpoint";
this.mnuEditBreakpoint.Click += new System.EventHandler(this.mnuEditBreakpoint_Click);
//
@ -366,10 +339,80 @@
//
this.mnuEditLabel.Image = global::Mesen.GUI.Properties.Resources.EditLabel;
this.mnuEditLabel.Name = "mnuEditLabel";
this.mnuEditLabel.Size = new System.Drawing.Size(154, 22);
this.mnuEditLabel.Size = new System.Drawing.Size(180, 22);
this.mnuEditLabel.Text = "Edit Label";
this.mnuEditLabel.Click += new System.EventHandler(this.mnuEditLabel_Click);
//
// toolStripMenuItem1
//
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(177, 6);
//
// mnuCopy
//
this.mnuCopy.Image = global::Mesen.GUI.Properties.Resources.Copy;
this.mnuCopy.Name = "mnuCopy";
this.mnuCopy.Size = new System.Drawing.Size(180, 22);
this.mnuCopy.Text = "Copy";
this.mnuCopy.Click += new System.EventHandler(this.mnuCopy_Click);
//
// mnuPaste
//
this.mnuPaste.Image = global::Mesen.GUI.Properties.Resources.Paste;
this.mnuPaste.Name = "mnuPaste";
this.mnuPaste.Size = new System.Drawing.Size(180, 22);
this.mnuPaste.Text = "Paste";
this.mnuPaste.Click += new System.EventHandler(this.mnuPaste_Click);
//
// toolStripMenuItem5
//
this.toolStripMenuItem5.Name = "toolStripMenuItem5";
this.toolStripMenuItem5.Size = new System.Drawing.Size(177, 6);
//
// mnuSelectAll
//
this.mnuSelectAll.Image = global::Mesen.GUI.Properties.Resources.SelectAll;
this.mnuSelectAll.Name = "mnuSelectAll";
this.mnuSelectAll.Size = new System.Drawing.Size(180, 22);
this.mnuSelectAll.Text = "Select All";
this.mnuSelectAll.Click += new System.EventHandler(this.mnuSelectAll_Click);
//
// mnuMarkSelectionAs
//
this.mnuMarkSelectionAs.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuMarkAsCode,
this.mnuMarkAsData,
this.mnuMarkAsUnidentifiedData});
this.mnuMarkSelectionAs.Name = "mnuMarkSelectionAs";
this.mnuMarkSelectionAs.Size = new System.Drawing.Size(180, 22);
this.mnuMarkSelectionAs.Text = "Mark selection as...";
//
// mnuMarkAsCode
//
this.mnuMarkAsCode.Image = global::Mesen.GUI.Properties.Resources.Accept;
this.mnuMarkAsCode.Name = "mnuMarkAsCode";
this.mnuMarkAsCode.Size = new System.Drawing.Size(199, 22);
this.mnuMarkAsCode.Text = "Verified Code";
//
// mnuMarkAsData
//
this.mnuMarkAsData.Image = global::Mesen.GUI.Properties.Resources.CheatCode;
this.mnuMarkAsData.Name = "mnuMarkAsData";
this.mnuMarkAsData.Size = new System.Drawing.Size(199, 22);
this.mnuMarkAsData.Text = "Verified Data";
//
// mnuMarkAsUnidentifiedData
//
this.mnuMarkAsUnidentifiedData.Image = global::Mesen.GUI.Properties.Resources.Help;
this.mnuMarkAsUnidentifiedData.Name = "mnuMarkAsUnidentifiedData";
this.mnuMarkAsUnidentifiedData.Size = new System.Drawing.Size(199, 22);
this.mnuMarkAsUnidentifiedData.Text = "Unidentified Code/Data";
//
// toolStripMenuItem2
//
this.toolStripMenuItem2.Name = "toolStripMenuItem2";
this.toolStripMenuItem2.Size = new System.Drawing.Size(177, 6);
//
// ctrlHexViewer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -427,5 +470,10 @@
private System.Windows.Forms.ToolStripMenuItem mnuEditBreakpoint;
private System.Windows.Forms.ToolStripMenuItem mnuEditLabel;
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1;
}
private System.Windows.Forms.ToolStripMenuItem mnuMarkSelectionAs;
private System.Windows.Forms.ToolStripMenuItem mnuMarkAsCode;
private System.Windows.Forms.ToolStripMenuItem mnuMarkAsData;
private System.Windows.Forms.ToolStripMenuItem mnuMarkAsUnidentifiedData;
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
}
}

View file

@ -54,6 +54,13 @@ namespace Mesen.GUI.Debugger.Controls
mnuAddToWatch.InitShortcut(this, nameof(DebuggerShortcutsConfig.MemoryViewer_AddToWatch));
mnuEditBreakpoint.InitShortcut(this, nameof(DebuggerShortcutsConfig.MemoryViewer_EditBreakpoint));
mnuEditLabel.InitShortcut(this, nameof(DebuggerShortcutsConfig.MemoryViewer_EditLabel));
mnuMarkAsCode.InitShortcut(this, nameof(DebuggerShortcutsConfig.MarkAsCode));
mnuMarkAsCode.Click += (s, e) => MarkSelectionAs(CdlFlags.Code);
mnuMarkAsData.InitShortcut(this, nameof(DebuggerShortcutsConfig.MarkAsData));
mnuMarkAsData.Click += (s, e) => MarkSelectionAs(CdlFlags.Data);
mnuMarkAsUnidentifiedData.InitShortcut(this, nameof(DebuggerShortcutsConfig.MarkAsUnidentified));
mnuMarkAsUnidentifiedData.Click += (s, e) => MarkSelectionAs(CdlFlags.None);
}
public new void Focus()
@ -504,9 +511,50 @@ namespace Mesen.GUI.Debugger.Controls
mnuAddToWatch.Enabled = false;
}
if(_memoryType == SnesMemoryType.CpuMemory) {
AddressInfo start = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = (int)startAddress, Type = _memoryType });
AddressInfo end = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = (int)endAddress, Type = _memoryType });
if(start.Address >= 0 && end.Address >= 0 && start.Address <= end.Address && start.Type == SnesMemoryType.PrgRom && end.Type == SnesMemoryType.PrgRom) {
mnuMarkSelectionAs.Text = "Mark selection as... (" + addressRange + ")";
mnuMarkSelectionAs.Enabled = true;
} else {
mnuMarkSelectionAs.Text = "Mark selection as...";
mnuMarkSelectionAs.Enabled = false;
}
} else if(_memoryType == SnesMemoryType.PrgRom) {
mnuMarkSelectionAs.Text = "Mark selection as... (" + addressRange + ")";
mnuMarkSelectionAs.Enabled = true;
} else {
mnuMarkSelectionAs.Text = "Mark selection as...";
mnuMarkSelectionAs.Enabled = false;
}
mnuEditBreakpoint.Enabled = true;
}
private void MarkSelectionAs(CdlFlags type)
{
if(_memoryType != SnesMemoryType.CpuMemory && _memoryType != SnesMemoryType.PrgRom) {
return;
}
int start = SelectionStartAddress;
int end = SelectionEndAddress;
if(_memoryType == SnesMemoryType.CpuMemory) {
start = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = start, Type = _memoryType }).Address;
end = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = end, Type = _memoryType }).Address;
}
if(start >= 0 && end >= 0 && start <= end) {
DebugApi.MarkBytesAs((UInt32)start, (UInt32)end, type);
DebugWindowManager.GetDebugger(_memoryType.ToCpuType())?.RefreshDisassembly();
}
RefreshData(_memoryType);
}
private void mnuAddToWatch_Click(object sender, EventArgs e)
{
if(_memoryType.SupportsWatch()) {

View file

@ -19,7 +19,6 @@ namespace Mesen.GUI.Debugger
private WindowRefreshManager _refreshManager;
private NotificationListener _notifListener;
private TabPage _selectedTab;
private int _frameCount = 0;
public ctrlScanlineCycleSelect ScanlineCycleSelect => null;

View file

@ -36,9 +36,9 @@ namespace Mesen.GUI.Debugger
GetMember(nameof(DebuggerShortcutsConfig.Paste)),
GetMember(nameof(DebuggerShortcutsConfig.SelectAll)),
GetMember(nameof(DebuggerShortcutsConfig.Refresh)),
//GetMember(nameof(DebuggerShortcutsConfig.MarkAsCode)),
//GetMember(nameof(DebuggerShortcutsConfig.MarkAsData)),
//GetMember(nameof(DebuggerShortcutsConfig.MarkAsUnidentified)),
GetMember(nameof(DebuggerShortcutsConfig.MarkAsCode)),
GetMember(nameof(DebuggerShortcutsConfig.MarkAsData)),
GetMember(nameof(DebuggerShortcutsConfig.MarkAsUnidentified)),
//GetMember(nameof(DebuggerShortcutsConfig.GoToAll)),
GetMember(nameof(DebuggerShortcutsConfig.CodeWindow_EditInMemoryViewer)),
GetMember(nameof(DebuggerShortcutsConfig.MemoryViewer_ViewInDisassembly)),

View file

@ -536,26 +536,26 @@
this.mnuShowUnident});
this.mnuUnidentifiedData.Image = global::Mesen.GUI.Properties.Resources.UnidentifiedData;
this.mnuUnidentifiedData.Name = "mnuUnidentifiedData";
this.mnuUnidentifiedData.Size = new System.Drawing.Size(227, 22);
this.mnuUnidentifiedData.Size = new System.Drawing.Size(217, 22);
this.mnuUnidentifiedData.Text = "Unidentified Code/Data";
this.mnuUnidentifiedData.DropDownOpening += new System.EventHandler(this.mnuUnidentifiedData_DropDownOpening);
//
// mnuHideUnident
//
this.mnuHideUnident.Name = "mnuHideUnident";
this.mnuHideUnident.Size = new System.Drawing.Size(170, 22);
this.mnuHideUnident.Size = new System.Drawing.Size(180, 22);
this.mnuHideUnident.Text = "Hide";
//
// mnuDisassembleUnident
//
this.mnuDisassembleUnident.Name = "mnuDisassembleUnident";
this.mnuDisassembleUnident.Size = new System.Drawing.Size(170, 22);
this.mnuDisassembleUnident.Size = new System.Drawing.Size(180, 22);
this.mnuDisassembleUnident.Text = "Show disassembly";
//
// mnuShowUnident
//
this.mnuShowUnident.Name = "mnuShowUnident";
this.mnuShowUnident.Size = new System.Drawing.Size(170, 22);
this.mnuShowUnident.Size = new System.Drawing.Size(180, 22);
this.mnuShowUnident.Text = "Show as data";
//
// mnuVerifiedData
@ -566,52 +566,52 @@
this.mnuShowData});
this.mnuVerifiedData.Image = global::Mesen.GUI.Properties.Resources.VerifiedData;
this.mnuVerifiedData.Name = "mnuVerifiedData";
this.mnuVerifiedData.Size = new System.Drawing.Size(227, 22);
this.mnuVerifiedData.Size = new System.Drawing.Size(217, 22);
this.mnuVerifiedData.Text = "Verified Data";
this.mnuVerifiedData.DropDownOpening += new System.EventHandler(this.mnuVerifiedData_DropDownOpening);
//
// mnuHideData
//
this.mnuHideData.Name = "mnuHideData";
this.mnuHideData.Size = new System.Drawing.Size(170, 22);
this.mnuHideData.Size = new System.Drawing.Size(180, 22);
this.mnuHideData.Text = "Hide";
//
// mnuDisassembleData
//
this.mnuDisassembleData.Name = "mnuDisassembleData";
this.mnuDisassembleData.Size = new System.Drawing.Size(170, 22);
this.mnuDisassembleData.Size = new System.Drawing.Size(180, 22);
this.mnuDisassembleData.Text = "Show disassembly";
//
// mnuShowData
//
this.mnuShowData.Name = "mnuShowData";
this.mnuShowData.Size = new System.Drawing.Size(170, 22);
this.mnuShowData.Size = new System.Drawing.Size(180, 22);
this.mnuShowData.Text = "Show as data";
//
// toolStripMenuItem6
//
this.toolStripMenuItem6.Name = "toolStripMenuItem6";
this.toolStripMenuItem6.Size = new System.Drawing.Size(224, 6);
this.toolStripMenuItem6.Size = new System.Drawing.Size(214, 6);
//
// mnuShowByteCode
//
this.mnuShowByteCode.CheckOnClick = true;
this.mnuShowByteCode.Name = "mnuShowByteCode";
this.mnuShowByteCode.Size = new System.Drawing.Size(227, 22);
this.mnuShowByteCode.Size = new System.Drawing.Size(217, 22);
this.mnuShowByteCode.Text = "Show byte code";
//
// mnuUseLowerCaseDisassembly
//
this.mnuUseLowerCaseDisassembly.CheckOnClick = true;
this.mnuUseLowerCaseDisassembly.Name = "mnuUseLowerCaseDisassembly";
this.mnuUseLowerCaseDisassembly.Size = new System.Drawing.Size(227, 22);
this.mnuUseLowerCaseDisassembly.Size = new System.Drawing.Size(217, 22);
this.mnuUseLowerCaseDisassembly.Text = "Show in lower case";
//
// mnuUseAltSpcOpNames
//
this.mnuUseAltSpcOpNames.CheckOnClick = true;
this.mnuUseAltSpcOpNames.Name = "mnuUseAltSpcOpNames";
this.mnuUseAltSpcOpNames.Size = new System.Drawing.Size(227, 22);
this.mnuUseAltSpcOpNames.Size = new System.Drawing.Size(217, 22);
this.mnuUseAltSpcOpNames.Text = "Use alternative mnemonics";
//
// mnuBreakOptions

View file

@ -248,12 +248,9 @@ namespace Mesen.GUI.Debugger
ConfigManager.Config.Debug.Debugger.ApplyConfig();
}
private void RefreshDisassembly()
public void RefreshDisassembly()
{
DebugApi.RefreshDisassembly(CpuType.Cpu);
DebugApi.RefreshDisassembly(CpuType.Spc);
DebugApi.RefreshDisassembly(CpuType.Sa1);
ctrlDisassemblyView.UpdateCode();
ctrlDisassemblyView.UpdateCode(true);
}
private void mnuBreakOptions_DropDownOpening(object sender, EventArgs e)

View file

@ -245,10 +245,10 @@ namespace Mesen.GUI.Forms
private void BindShortcuts()
{
Func<bool> notClient = () => { return true; }; //TODO
Func<bool> notClient = () => { return !NetplayApi.IsConnected(); };
Func<bool> running = () => { return EmuRunner.IsRunning(); };
Func<bool> runningNotClient = () => { return EmuRunner.IsRunning(); }; //TODO
Func<bool> runningNotClientNotMovie = () => { return EmuRunner.IsRunning(); }; //TODO
Func<bool> runningNotClient = () => { return EmuRunner.IsRunning() && !NetplayApi.IsConnected(); };
Func<bool> runningNotClientNotMovie = () => { return EmuRunner.IsRunning() && !NetplayApi.IsConnected() && !RecordApi.MoviePlaying(); };
_shortcuts.BindShortcut(mnuOpen, EmulatorShortcut.OpenFile);
_shortcuts.BindShortcut(mnuExit, EmulatorShortcut.Exit);

View file

@ -168,6 +168,7 @@ namespace Mesen.GUI
}
[DllImport(DllPath)] public static extern void SetCdlData([In]byte[] cdlData, Int32 length);
[DllImport(DllPath)] public static extern void MarkBytesAs(UInt32 start, UInt32 end, CdlFlags type);
}
public enum SnesMemoryType