Mesen-SX/UI/Debugger/Workspace/DebugWorkspaceManager.cs

123 lines
3.7 KiB
C#
Raw Normal View History

using Mesen.GUI.Config;
using Mesen.GUI.Debugger.Integration;
using Mesen.GUI.Debugger.Labels;
using Mesen.GUI.Forms;
using System;
2019-03-28 21:20:18 -04:00
using System.Collections.Generic;
using System.IO;
2019-03-28 21:20:18 -04:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mesen.GUI.Debugger.Workspace
{
public class DebugWorkspaceManager
{
2019-05-04 09:33:28 -04:00
public delegate void SymbolProviderChangedHandler(DbgImporter symbolProvider);
public static event SymbolProviderChangedHandler SymbolProviderChanged;
2019-03-28 21:20:18 -04:00
private static DebugWorkspace _workspace;
2019-05-04 09:33:28 -04:00
private static DbgImporter _symbolProvider;
2019-03-28 21:20:18 -04:00
private static string _romName;
private static object _lock = new object();
public static void SaveWorkspace()
{
if(_workspace != null) {
_workspace.WatchValues = new List<string>(WatchManager.GetWatchManager(CpuType.Cpu).WatchEntries);
_workspace.SpcWatchValues = new List<string>(WatchManager.GetWatchManager(CpuType.Spc).WatchEntries);
2019-03-28 21:20:18 -04:00
_workspace.Breakpoints = new List<Breakpoint>(BreakpointManager.Breakpoints);
_workspace.CpuLabels = new List<CodeLabel>(LabelManager.GetLabels(CpuType.Cpu));
_workspace.SpcLabels = new List<CodeLabel>(LabelManager.GetLabels(CpuType.Spc));
2019-03-28 21:20:18 -04:00
_workspace.Save();
}
}
public static void Clear()
{
_workspace = null;
_romName = null;
LabelManager.ResetLabels();
2019-03-28 21:20:18 -04:00
}
public static void ResetWorkspace()
{
if(_workspace != null) {
_workspace.Breakpoints = new List<Breakpoint>();
_workspace.WatchValues = new List<string>();
_workspace.SpcWatchValues = new List<string>();
_workspace.CpuLabels = new List<CodeLabel>();
_workspace.SpcLabels = new List<CodeLabel>();
WatchManager.GetWatchManager(CpuType.Cpu).WatchEntries = _workspace.WatchValues;
WatchManager.GetWatchManager(CpuType.Spc).WatchEntries = _workspace.SpcWatchValues;
2019-03-28 21:20:18 -04:00
BreakpointManager.SetBreakpoints(_workspace.Breakpoints);
LabelManager.SetDefaultLabels();
LabelManager.RefreshLabels();
2019-03-28 21:20:18 -04:00
_workspace.Save();
Clear();
}
}
public static void ResetLabels()
{
if(_workspace != null) {
_workspace.CpuLabels = new List<CodeLabel>();
_workspace.SpcLabels = new List<CodeLabel>();
LabelManager.ResetLabels();
LabelManager.SetDefaultLabels();
LabelManager.RefreshLabels();
}
}
2019-03-28 21:20:18 -04:00
public static DebugWorkspace GetWorkspace()
{
string romName = EmuApi.GetRomInfo().GetRomName();
if(_workspace == null || _romName != romName) {
if(_workspace != null) {
SaveWorkspace();
}
_romName = romName;
_workspace = DebugWorkspace.GetWorkspace();
//Load watch entries
WatchManager.GetWatchManager(CpuType.Cpu).WatchEntries = _workspace.WatchValues;
WatchManager.GetWatchManager(CpuType.Spc).WatchEntries = _workspace.SpcWatchValues;
LabelManager.ResetLabels();
LabelManager.SetLabels(_workspace.CpuLabels);
LabelManager.SetLabels(_workspace.SpcLabels);
LabelManager.SetDefaultLabels();
ImportDbgFile();
LabelManager.RefreshLabels();
2019-03-28 21:20:18 -04:00
//Load breakpoints
BreakpointManager.SetBreakpoints(_workspace.Breakpoints);
}
return _workspace;
}
public static void ImportDbgFile()
{
2019-05-04 09:33:28 -04:00
_symbolProvider = null;
2019-05-04 09:33:28 -04:00
if(ConfigManager.Config.Debug.DbgIntegration.AutoImport) {
RomInfo romInfo = EmuApi.GetRomInfo();
string dbgPath = Path.Combine(((ResourcePath)romInfo.RomPath).Folder, romInfo.GetRomName() + ".dbg");
2019-05-04 09:33:28 -04:00
if(File.Exists(dbgPath)) {
_symbolProvider = new DbgImporter();
_symbolProvider.Import(dbgPath, true);
SymbolProviderChanged?.Invoke(_symbolProvider);
LabelManager.RefreshLabels();
}
}
2019-05-04 09:33:28 -04:00
SymbolProviderChanged?.Invoke(_symbolProvider);
}
public static DbgImporter GetSymbolProvider()
{
return _symbolProvider;
}
2019-03-28 21:20:18 -04:00
}
}