mirror of
https://github.com/libretro/Mesen.git
synced 2025-03-03 22:07:10 +00:00
Debugger: Fix issues (missing labels, etc.) when power cycling game while debugger is opened
This commit is contained in:
parent
9e09c51e7c
commit
5e32671c4b
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -9,10 +10,17 @@ namespace Mesen.GUI.Debugger
|
||||
{
|
||||
public class BreakpointManager
|
||||
{
|
||||
private static object _lock = new object();
|
||||
private static List<Breakpoint> _breakpoints = new List<Breakpoint>();
|
||||
|
||||
public static event EventHandler BreakpointsChanged;
|
||||
public static List<Breakpoint> Breakpoints { get { return _breakpoints; } }
|
||||
public static ReadOnlyCollection<Breakpoint> Breakpoints {
|
||||
get {
|
||||
lock(_lock) {
|
||||
return _breakpoints.ToList().AsReadOnly();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void RefreshBreakpoints(Breakpoint bp = null)
|
||||
{
|
||||
@ -23,11 +31,23 @@ namespace Mesen.GUI.Debugger
|
||||
SetBreakpoints();
|
||||
}
|
||||
|
||||
public static void SetBreakpoints(List<Breakpoint> breakpoints)
|
||||
{
|
||||
lock(_lock) {
|
||||
_breakpoints = breakpoints.ToList();
|
||||
}
|
||||
|
||||
//Don't refresh breakpoints, doing so will cause them to be enabled even if the debugger window is closed
|
||||
//RefreshBreakpoints();
|
||||
}
|
||||
|
||||
public static void EditBreakpoint(Breakpoint bp)
|
||||
{
|
||||
if(new frmBreakpoint(bp).ShowDialog() == DialogResult.OK) {
|
||||
if(!Breakpoints.Contains(bp)) {
|
||||
Breakpoints.Add(bp);
|
||||
lock(_lock) {
|
||||
if(!_breakpoints.Contains(bp)) {
|
||||
_breakpoints.Add(bp);
|
||||
}
|
||||
}
|
||||
RefreshBreakpoints(bp);
|
||||
}
|
||||
@ -35,13 +55,17 @@ namespace Mesen.GUI.Debugger
|
||||
|
||||
public static void RemoveBreakpoint(Breakpoint bp)
|
||||
{
|
||||
Breakpoints.Remove(bp);
|
||||
lock(_lock) {
|
||||
_breakpoints.Remove(bp);
|
||||
}
|
||||
RefreshBreakpoints(bp);
|
||||
}
|
||||
|
||||
public static void AddBreakpoint(Breakpoint bp)
|
||||
{
|
||||
Breakpoints.Add(bp);
|
||||
lock(_lock) {
|
||||
_breakpoints.Add(bp);
|
||||
}
|
||||
RefreshBreakpoints(bp);
|
||||
}
|
||||
|
||||
@ -53,12 +77,12 @@ namespace Mesen.GUI.Debugger
|
||||
public static Breakpoint GetMatchingBreakpoint(UInt32 startAddress, UInt32 endAddress, bool ppuBreakpoint)
|
||||
{
|
||||
bool isAddressRange = startAddress != endAddress;
|
||||
return BreakpointManager.Breakpoints.Where((bp) =>
|
||||
!bp.IsAbsoluteAddress &&
|
||||
((!isAddressRange && bp.Address == startAddress) || (isAddressRange && bp.StartAddress == startAddress && bp.EndAddress == endAddress)) &&
|
||||
((!ppuBreakpoint && (bp.BreakOnExec || bp.BreakOnRead || bp.BreakOnWrite)) ||
|
||||
(ppuBreakpoint && (bp.BreakOnReadVram || bp.BreakOnWriteVram)))
|
||||
).FirstOrDefault();
|
||||
return Breakpoints.Where((bp) =>
|
||||
!bp.IsAbsoluteAddress &&
|
||||
((!isAddressRange && bp.Address == startAddress) || (isAddressRange && bp.StartAddress == startAddress && bp.EndAddress == endAddress)) &&
|
||||
((!ppuBreakpoint && (bp.BreakOnExec || bp.BreakOnRead || bp.BreakOnWrite)) ||
|
||||
(ppuBreakpoint && (bp.BreakOnReadVram || bp.BreakOnWriteVram)))
|
||||
).FirstOrDefault();
|
||||
}
|
||||
|
||||
public static void ToggleBreakpoint(int address, bool toggleEnabled)
|
||||
@ -86,7 +110,7 @@ namespace Mesen.GUI.Debugger
|
||||
public static void SetBreakpoints()
|
||||
{
|
||||
List<InteropBreakpoint> breakpoints = new List<InteropBreakpoint>();
|
||||
foreach(Breakpoint bp in BreakpointManager.Breakpoints) {
|
||||
foreach(Breakpoint bp in Breakpoints) {
|
||||
if(bp.Enabled) {
|
||||
breakpoints.Add(bp.ToInteropBreakpoint());
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Mesen.GUI.Controls;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Mesen.GUI.Debugger.Controls
|
||||
{
|
||||
@ -26,7 +27,11 @@ namespace Mesen.GUI.Debugger.Controls
|
||||
|
||||
void BreakpointManager_OnBreakpointChanged(object sender, EventArgs e)
|
||||
{
|
||||
RefreshList();
|
||||
if(this.InvokeRequired) {
|
||||
this.BeginInvoke((Action)(() => RefreshList()));
|
||||
} else {
|
||||
RefreshList();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnLoad(EventArgs e)
|
||||
@ -38,8 +43,9 @@ namespace Mesen.GUI.Debugger.Controls
|
||||
public void RefreshListAddresses()
|
||||
{
|
||||
lstBreakpoints.BeginUpdate();
|
||||
for(int i = 0; i < BreakpointManager.Breakpoints.Count; i++) {
|
||||
lstBreakpoints.Items[i].SubItems[2].Text = BreakpointManager.Breakpoints[i].GetAddressString();
|
||||
ReadOnlyCollection<Breakpoint> breakpoints = BreakpointManager.Breakpoints;
|
||||
for(int i = 0; i < breakpoints.Count; i++) {
|
||||
lstBreakpoints.Items[i].SubItems[2].Text = breakpoints[i].GetAddressString();
|
||||
}
|
||||
lstBreakpoints.EndUpdate();
|
||||
}
|
||||
|
@ -31,7 +31,11 @@ namespace Mesen.GUI.Debugger
|
||||
|
||||
private void WatchManager_WatchChanged(object sender, EventArgs e)
|
||||
{
|
||||
this.UpdateWatch();
|
||||
if(this.InvokeRequired) {
|
||||
this.BeginInvoke((Action)(() => this.UpdateWatch()));
|
||||
} else {
|
||||
this.UpdateWatch();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnLoad(EventArgs e)
|
||||
|
@ -50,35 +50,42 @@ namespace Mesen.GUI.Debugger
|
||||
}
|
||||
}
|
||||
|
||||
public static DebugWorkspace GetWorkspace()
|
||||
public static void SetupWorkspace()
|
||||
{
|
||||
lock(_lock) {
|
||||
if(_workspace != null) {
|
||||
//Setup labels
|
||||
if(_workspace.Labels.Count == 0) {
|
||||
LabelManager.ResetLabels();
|
||||
if(!ConfigManager.Config.DebugInfo.DisableDefaultLabels) {
|
||||
LabelManager.SetDefaultLabels(InteropEmu.FdsGetSideCount() > 0);
|
||||
}
|
||||
} else {
|
||||
LabelManager.ResetLabels();
|
||||
LabelManager.SetLabels(_workspace.Labels, false);
|
||||
}
|
||||
|
||||
//Load watch entries
|
||||
WatchManager.WatchEntries = _workspace.WatchValues;
|
||||
|
||||
//Load breakpoints
|
||||
BreakpointManager.SetBreakpoints(_workspace.Breakpoints);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static DebugWorkspace GetWorkspace(bool forceReload = false)
|
||||
{
|
||||
string romName = InteropEmu.GetRomInfo().GetRomName();
|
||||
if(_workspace == null || _romName != romName) {
|
||||
if(_workspace == null || _romName != romName || forceReload) {
|
||||
lock(_lock) {
|
||||
if(_workspace == null || _romName != romName) {
|
||||
if(_workspace == null || _romName != romName || forceReload) {
|
||||
if(_workspace != null) {
|
||||
SaveWorkspace();
|
||||
}
|
||||
_romName = InteropEmu.GetRomInfo().GetRomName();
|
||||
_workspace = DebugWorkspace.GetWorkspace();
|
||||
|
||||
//Setup labels
|
||||
if(_workspace.Labels.Count == 0) {
|
||||
LabelManager.ResetLabels();
|
||||
if(!ConfigManager.Config.DebugInfo.DisableDefaultLabels) {
|
||||
LabelManager.SetDefaultLabels(InteropEmu.FdsGetSideCount() > 0);
|
||||
}
|
||||
} else {
|
||||
LabelManager.ResetLabels();
|
||||
LabelManager.SetLabels(_workspace.Labels, false);
|
||||
}
|
||||
|
||||
//Load watch entries
|
||||
WatchManager.WatchEntries = _workspace.WatchValues;
|
||||
|
||||
//Load breakpoints
|
||||
BreakpointManager.Breakpoints.Clear();
|
||||
BreakpointManager.Breakpoints.AddRange(_workspace.Breakpoints);
|
||||
SetupWorkspace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -513,10 +513,15 @@ namespace Mesen.GUI.Forms
|
||||
UpdateViewerSize();
|
||||
}));
|
||||
|
||||
if(ConfigManager.Config.PreferenceInfo.DeveloperMode) {
|
||||
//Preload workspace in the background to be able to open debugging tools faster
|
||||
Task.Run(() => { DebugWorkspace.GetWorkspace(); });
|
||||
}
|
||||
Task.Run(() => {
|
||||
if(ConfigManager.Config.PreferenceInfo.DeveloperMode) {
|
||||
//Preload workspace in the background to be able to open debugging tools faster
|
||||
DebugWorkspaceManager.GetWorkspace(true);
|
||||
} else {
|
||||
//If a workspace is already loaded, make sure we setup the labels, watch, etc properly
|
||||
DebugWorkspaceManager.SetupWorkspace();
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case InteropEmu.ConsoleNotificationType.PpuFrameDone:
|
||||
|
Loading…
x
Reference in New Issue
Block a user