diff --git a/GUI.NET/Debugger/Controls/CodeViewerActions.cs b/GUI.NET/Debugger/Controls/CodeViewerActions.cs index e03156fb..97216395 100644 --- a/GUI.NET/Debugger/Controls/CodeViewerActions.cs +++ b/GUI.NET/Debugger/Controls/CodeViewerActions.cs @@ -263,9 +263,16 @@ namespace Mesen.GUI.Debugger.Controls public void ToggleBreakpoint(bool toggleEnabledFlag) { - int relativeAddress = Viewer.CodeViewer.CurrentLine; - AddressTypeInfo info = Viewer.GetAddressInfo(Viewer.CodeViewer.SelectedLine); + int lineIndex = Viewer.CodeViewer.SelectedLine; + int relativeAddress = Viewer.CodeViewer.GetLineNumber(lineIndex); + if(relativeAddress < 0 && Viewer.CodeViewer.LineCount > lineIndex + 1) { + //Current line has no address, try using the next line instead. + //(Used when trying to set a breakpoint on a row containing only a label) + lineIndex++; + relativeAddress = Viewer.CodeViewer.GetLineNumber(lineIndex); + } + AddressTypeInfo info = Viewer.GetAddressInfo(lineIndex); BreakpointManager.ToggleBreakpoint(relativeAddress, info, toggleEnabledFlag); } diff --git a/GUI.NET/Debugger/Controls/ctrlDebuggerCode.cs b/GUI.NET/Debugger/Controls/ctrlDebuggerCode.cs index 38a28f34..6e03ae83 100644 --- a/GUI.NET/Debugger/Controls/ctrlDebuggerCode.cs +++ b/GUI.NET/Debugger/Controls/ctrlDebuggerCode.cs @@ -260,8 +260,16 @@ namespace Mesen.GUI.Debugger _tooltipManager.Close(); if(e.Button == MouseButtons.Left && e.Location.X < this.ctrlCodeViewer.CodeMargin / 4) { - int relativeAddress = ctrlCodeViewer.GetLineNumberAtPosition(e.Y); - AddressTypeInfo info = GetAddressInfo(ctrlCodeViewer.GetLineIndexAtPosition(e.Y)); + int lineIndex = ctrlCodeViewer.GetLineIndexAtPosition(e.Y); + int relativeAddress = ctrlCodeViewer.GetLineNumber(lineIndex); + if(relativeAddress < 0 && ctrlCodeViewer.LineCount > lineIndex + 1) { + //Current line has no address, try using the next line instead. + //(Used when trying to set a breakpoint on a row containing only a label) + lineIndex++; + relativeAddress = ctrlCodeViewer.GetLineNumber(lineIndex); + } + + AddressTypeInfo info = GetAddressInfo(lineIndex); BreakpointManager.ToggleBreakpoint(relativeAddress, info, false); } } diff --git a/GUI.NET/Debugger/Controls/ctrlSourceViewer.cs b/GUI.NET/Debugger/Controls/ctrlSourceViewer.cs index 055c4175..636e54bc 100644 --- a/GUI.NET/Debugger/Controls/ctrlSourceViewer.cs +++ b/GUI.NET/Debugger/Controls/ctrlSourceViewer.cs @@ -226,6 +226,13 @@ namespace Mesen.GUI.Debugger.Controls AddressTypeInfo info = GetAddressInfo(ctrlCodeViewer.SelectedLine); if(info.Address >= 0) { BreakpointManager.ToggleBreakpoint(-1, info, false); + } else { + //Current line has no address, try using the next line instead. + //(Used when trying to set a breakpoint on a row containing only a label) + info = GetAddressInfo(ctrlCodeViewer.SelectedLine + 1); + if(info.Address >= 0) { + BreakpointManager.ToggleBreakpoint(-1, info, false); + } } }