2017-08-14 23:44:01 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Mesen.GUI.Config;
|
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Debugger
|
|
|
|
|
{
|
|
|
|
|
public class DebugWorkspaceManager
|
|
|
|
|
{
|
|
|
|
|
private static DebugWorkspace _workspace;
|
|
|
|
|
private static string _romName;
|
|
|
|
|
private static object _lock = new object();
|
|
|
|
|
|
|
|
|
|
public static void SaveWorkspace()
|
|
|
|
|
{
|
|
|
|
|
if(_workspace != null) {
|
|
|
|
|
lock(_lock) {
|
|
|
|
|
if(_workspace != null) {
|
|
|
|
|
_workspace.WatchValues = new List<string>(WatchManager.WatchEntries);
|
|
|
|
|
_workspace.Labels = new List<CodeLabel>(LabelManager.GetLabels());
|
|
|
|
|
_workspace.Breakpoints = new List<Breakpoint>(BreakpointManager.Breakpoints);
|
|
|
|
|
_workspace.Save();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Clear()
|
|
|
|
|
{
|
|
|
|
|
lock(_lock) {
|
|
|
|
|
_workspace = null;
|
|
|
|
|
_romName = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ResetWorkspace()
|
|
|
|
|
{
|
|
|
|
|
if(_workspace != null) {
|
|
|
|
|
lock(_lock) {
|
|
|
|
|
if(_workspace != null) {
|
|
|
|
|
_workspace.Breakpoints = new List<Breakpoint>();
|
|
|
|
|
_workspace.Labels = new List<CodeLabel>();
|
|
|
|
|
_workspace.WatchValues = new List<string>();
|
2018-03-03 15:40:11 -05:00
|
|
|
|
LabelManager.ResetLabels();
|
|
|
|
|
WatchManager.WatchEntries = _workspace.WatchValues;
|
|
|
|
|
BreakpointManager.SetBreakpoints(_workspace.Breakpoints);
|
2017-08-14 23:44:01 -04:00
|
|
|
|
_workspace.Save();
|
|
|
|
|
Clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-28 16:44:18 -05:00
|
|
|
|
public static void SetupWorkspace(bool saveCurrentWorkspace = true)
|
2017-12-28 14:15:32 -05:00
|
|
|
|
{
|
2017-12-28 16:44:18 -05:00
|
|
|
|
string romName = InteropEmu.GetRomInfo().GetRomName();
|
2017-12-28 14:15:32 -05:00
|
|
|
|
lock(_lock) {
|
2017-12-28 16:44:18 -05:00
|
|
|
|
if(_workspace != null && _romName == romName) {
|
|
|
|
|
if(saveCurrentWorkspace) {
|
|
|
|
|
SaveWorkspace();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-28 14:15:32 -05:00
|
|
|
|
//Setup labels
|
|
|
|
|
if(_workspace.Labels.Count == 0) {
|
|
|
|
|
LabelManager.ResetLabels();
|
|
|
|
|
if(!ConfigManager.Config.DebugInfo.DisableDefaultLabels) {
|
2018-03-03 15:40:11 -05:00
|
|
|
|
LabelManager.SetDefaultLabels(InteropEmu.GetRomInfo().MapperId);
|
2017-12-28 14:15:32 -05:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
LabelManager.ResetLabels();
|
|
|
|
|
LabelManager.SetLabels(_workspace.Labels, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Load watch entries
|
|
|
|
|
WatchManager.WatchEntries = _workspace.WatchValues;
|
|
|
|
|
|
|
|
|
|
//Load breakpoints
|
|
|
|
|
BreakpointManager.SetBreakpoints(_workspace.Breakpoints);
|
2017-12-28 16:44:18 -05:00
|
|
|
|
} else {
|
|
|
|
|
Clear();
|
2017-12-28 14:15:32 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-28 16:44:18 -05:00
|
|
|
|
public static DebugWorkspace GetWorkspace()
|
2017-08-14 23:44:01 -04:00
|
|
|
|
{
|
|
|
|
|
string romName = InteropEmu.GetRomInfo().GetRomName();
|
2017-12-28 16:44:18 -05:00
|
|
|
|
if(_workspace == null || _romName != romName) {
|
2017-08-14 23:44:01 -04:00
|
|
|
|
lock(_lock) {
|
2017-12-28 16:44:18 -05:00
|
|
|
|
if(_workspace == null || _romName != romName) {
|
2017-08-14 23:44:01 -04:00
|
|
|
|
if(_workspace != null) {
|
|
|
|
|
SaveWorkspace();
|
|
|
|
|
}
|
|
|
|
|
_romName = InteropEmu.GetRomInfo().GetRomName();
|
|
|
|
|
_workspace = DebugWorkspace.GetWorkspace();
|
2017-12-28 16:44:18 -05:00
|
|
|
|
SetupWorkspace(false);
|
2017-08-14 23:44:01 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return _workspace;
|
|
|
|
|
}
|
2018-01-15 22:20:51 -05:00
|
|
|
|
|
|
|
|
|
private static DebuggerFlags _flags = DebuggerFlags.None;
|
|
|
|
|
public static void SetFlags(DebuggerFlags flags)
|
|
|
|
|
{
|
|
|
|
|
_flags |= flags;
|
|
|
|
|
InteropEmu.DebugSetFlags(_flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ClearFlags(DebuggerFlags flags = DebuggerFlags.None)
|
|
|
|
|
{
|
|
|
|
|
if(flags == DebuggerFlags.None) {
|
|
|
|
|
_flags = DebuggerFlags.None;
|
|
|
|
|
} else {
|
|
|
|
|
_flags &= ~flags;
|
|
|
|
|
}
|
|
|
|
|
InteropEmu.DebugSetFlags(_flags);
|
|
|
|
|
}
|
2017-08-14 23:44:01 -04:00
|
|
|
|
}
|
|
|
|
|
}
|