BizHawk/BizHawk.Client.EmuHawk/tools/Debugger/Breakpoint.cs

184 lines
3.9 KiB
C#
Raw Normal View History

2017-05-24 14:06:31 +00:00
using System;
2014-12-06 15:07:01 +00:00
using System.Collections.Generic;
2017-05-24 14:06:31 +00:00
using BizHawk.Emulation.Common;
2014-12-06 15:07:01 +00:00
namespace BizHawk.Client.EmuHawk
{
public class BreakpointList : List<Breakpoint>
{
2019-06-06 09:04:47 +00:00
public MemoryCallbackDelegate Callback { get; set; }
2014-12-06 15:07:01 +00:00
public void Add(IDebuggable core, string scope, uint address, uint mask, MemoryCallbackType type)
2014-12-06 15:07:01 +00:00
{
Add(new Breakpoint(core, scope, Callback, address, mask, type));
2014-12-06 15:07:01 +00:00
}
public new void Clear()
{
foreach (var breakpoint in this)
{
breakpoint.ReadOnly = false;
2014-12-06 15:07:01 +00:00
breakpoint.Active = false;
}
base.Clear();
}
public new bool Remove(Breakpoint b)
{
var breakpoint = Find(x => x == b);
if (breakpoint != null)
{
breakpoint.ReadOnly = false;
breakpoint.Active = false;
}
2017-05-24 14:06:31 +00:00
return base.Remove(b);
}
public new void RemoveAt(int index)
{
if (index < Count)
{
var breakpoint = this[index];
breakpoint.ReadOnly = false;
breakpoint.Active = false;
base.RemoveAt(index);
}
}
public new int RemoveAll(Predicate<Breakpoint> match)
{
var removeCount = 0;
foreach (var breakpoint in this)
{
if (match(breakpoint))
{
Remove(breakpoint);
2015-06-27 11:03:24 +00:00
removeCount++;
}
}
2017-05-24 14:06:31 +00:00
return removeCount;
}
2014-12-06 15:07:01 +00:00
}
public class Breakpoint
{
private bool _active;
private readonly IDebuggable _core;
2019-06-06 09:04:47 +00:00
public Breakpoint(bool readOnly, IDebuggable core, string scope, MemoryCallbackDelegate callBack, uint address, uint mask, MemoryCallbackType type, bool enabled = true)
{
Scope = scope;
_core = core;
Type = type;
Callback = callBack;
Address = address;
AddressMask = mask;
Name = "Pause";
Active = enabled;
ReadOnly = readOnly;
}
2019-06-06 09:04:47 +00:00
public Breakpoint(IDebuggable core, string scope, MemoryCallbackDelegate callBack, uint address, uint mask, MemoryCallbackType type, bool enabled = true)
2014-12-06 15:07:01 +00:00
{
Scope = scope;
2014-12-06 15:07:01 +00:00
_core = core;
Type = type;
2014-12-06 15:07:01 +00:00
Callback = callBack;
Address = address;
AddressMask = mask;
Name = "Pause";
Active = enabled;
}
2019-06-06 09:04:47 +00:00
public Breakpoint(string name, bool readOnly, IDebuggable core, string scope, MemoryCallbackDelegate callBack, uint address, uint mask, MemoryCallbackType type, bool enabled = true)
{
Scope = scope;
_core = core;
Type = type;
Callback = callBack;
Address = address;
AddressMask = mask;
Name = name;
Active = enabled;
ReadOnly = readOnly;
2014-12-06 15:07:01 +00:00
}
public string Scope { get; }
2019-06-06 09:04:47 +00:00
public MemoryCallbackDelegate Callback { get; }
public uint? Address { get; set; }
public uint? AddressMask { get; set; }
public MemoryCallbackType Type { get; set; }
2017-05-24 14:06:31 +00:00
public string Name { get; }
2015-06-27 11:03:24 +00:00
internal bool ReadOnly { get; set; }
// Adds an existing callback
public Breakpoint(IDebuggable core, IMemoryCallback callback)
{
_core = core;
_active = true;
Callback = callback.Callback;
Address = callback.Address;
AddressMask = callback.AddressMask;
Type = callback.Type;
Name = callback.Name;
// We don't know where this callback came from so don't let the user mess with it
// Most likely it came from lua and doing so could cause some bad things to happen
ReadOnly = true;
}
2014-12-06 15:07:01 +00:00
public bool Active
{
get
{
return _active;
}
set
{
if (!ReadOnly)
2014-12-06 15:07:01 +00:00
{
if (!value)
{
RemoveCallback();
}
2014-12-06 15:07:01 +00:00
if (!_active && value) // If inactive and changing to active
{
AddCallback();
}
2014-12-06 15:07:01 +00:00
_active = value;
}
2014-12-06 15:07:01 +00:00
}
}
private void AddCallback()
{
_core.MemoryCallbacks.Add(new MemoryCallback(Scope, Type, Name, Callback, Address, AddressMask));
2014-12-06 15:07:01 +00:00
}
private void RemoveCallback()
{
_core.MemoryCallbacks.Remove(Callback);
}
public void ResetCallback()
{
if (Active)
{
RemoveCallback();
AddCallback();
}
}
2014-12-06 15:07:01 +00:00
}
}