mirror of
https://github.com/SourMesen/Mesen.git
synced 2025-04-02 10:52:48 -04:00
Debugger: Fixed crash when opening breakpoint edit window
This commit is contained in:
parent
2c2b927e6f
commit
53e7a1a457
3 changed files with 68 additions and 15 deletions
|
@ -20,12 +20,7 @@ namespace Mesen.GUI.Debugger
|
|||
set
|
||||
{
|
||||
_memoryType = value;
|
||||
|
||||
_isCpuBreakpoint = value == DebugMemoryType.CpuMemory ||
|
||||
value == DebugMemoryType.WorkRam ||
|
||||
value == DebugMemoryType.SaveRam ||
|
||||
value == DebugMemoryType.PrgRom;
|
||||
|
||||
_isCpuBreakpoint = IsTypeCpuBreakpoint(value);
|
||||
if(_isCpuBreakpoint) {
|
||||
_equivalentAddressType = value.ToAddressType();
|
||||
}
|
||||
|
@ -77,6 +72,16 @@ namespace Mesen.GUI.Debugger
|
|||
return addr;
|
||||
}
|
||||
|
||||
public static bool IsTypeCpuBreakpoint(DebugMemoryType type)
|
||||
{
|
||||
return (
|
||||
type == DebugMemoryType.CpuMemory ||
|
||||
type == DebugMemoryType.WorkRam ||
|
||||
type == DebugMemoryType.SaveRam ||
|
||||
type == DebugMemoryType.PrgRom
|
||||
);
|
||||
}
|
||||
|
||||
public void SetEnabled(bool enabled)
|
||||
{
|
||||
Enabled = enabled;
|
||||
|
|
|
@ -151,8 +151,7 @@ namespace Mesen.GUI.Debugger
|
|||
}
|
||||
}
|
||||
|
||||
bool isCpuBreakpoint = new Breakpoint() { MemoryType = type }.IsCpuBreakpoint;
|
||||
return chkRead.Checked || chkWrite.Checked || (chkExec.Checked && isCpuBreakpoint) || txtCondition.Text.Length > 0;
|
||||
return chkRead.Checked || chkWrite.Checked || (chkExec.Checked && Breakpoint.IsTypeCpuBreakpoint(type)) || txtCondition.Text.Length > 0;
|
||||
}
|
||||
|
||||
private void txtAddress_Enter(object sender, EventArgs e)
|
||||
|
@ -175,8 +174,7 @@ namespace Mesen.GUI.Debugger
|
|||
{
|
||||
DebugMemoryType type = cboBreakpointType.GetEnumValue<DebugMemoryType>();
|
||||
|
||||
bool isCpuBreakpoint = new Breakpoint() { MemoryType = type }.IsCpuBreakpoint;
|
||||
chkExec.Visible = isCpuBreakpoint;
|
||||
chkExec.Visible = Breakpoint.IsTypeCpuBreakpoint(type);
|
||||
|
||||
string maxValue = (InteropEmu.DebugGetMemorySize(type) - 1).ToString("X2");
|
||||
string minValue = "".PadLeft(maxValue.Length, '0');
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace Mesen.GUI.Forms
|
|||
{
|
||||
private Dictionary<string, Control> _bindings = new Dictionary<string, Control>();
|
||||
private Dictionary<string, eNumberFormat> _fieldFormat = new Dictionary<string, eNumberFormat>();
|
||||
private Dictionary<string, FieldInfo> _fieldInfo = null;
|
||||
private Dictionary<string, FieldInfoWrapper> _fieldInfo = null;
|
||||
|
||||
public object Entity { get; set; }
|
||||
|
||||
|
@ -34,10 +34,15 @@ namespace Mesen.GUI.Forms
|
|||
}
|
||||
|
||||
if(_fieldInfo == null) {
|
||||
_fieldInfo = new Dictionary<string, FieldInfo>();
|
||||
_fieldInfo = new Dictionary<string, FieldInfoWrapper>();
|
||||
PropertyInfo[] properties = BindedType.GetProperties();
|
||||
foreach(PropertyInfo info in properties) {
|
||||
_fieldInfo[info.Name] = new FieldInfoWrapper(info);
|
||||
}
|
||||
|
||||
FieldInfo[] members = BindedType.GetFields();
|
||||
foreach(FieldInfo info in members) {
|
||||
_fieldInfo[info.Name] = info;
|
||||
_fieldInfo[info.Name] = new FieldInfoWrapper(info);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,7 +66,7 @@ namespace Mesen.GUI.Forms
|
|||
if(!_fieldInfo.ContainsKey(kvp.Key)) {
|
||||
throw new Exception("Invalid binding key");
|
||||
} else {
|
||||
FieldInfo field = _fieldInfo[kvp.Key];
|
||||
FieldInfoWrapper field = _fieldInfo[kvp.Key];
|
||||
eNumberFormat format = _fieldFormat[kvp.Key];
|
||||
object value = field.GetValue(this.Entity);
|
||||
if(kvp.Value is TextBox) {
|
||||
|
@ -146,7 +151,7 @@ namespace Mesen.GUI.Forms
|
|||
throw new Exception("Invalid binding key");
|
||||
} else {
|
||||
try {
|
||||
FieldInfo field = _fieldInfo[kvp.Key];
|
||||
FieldInfoWrapper field = _fieldInfo[kvp.Key];
|
||||
eNumberFormat format = _fieldFormat[kvp.Key];
|
||||
if(kvp.Value is TextBox) {
|
||||
object value = kvp.Value.Text;
|
||||
|
@ -231,6 +236,51 @@ namespace Mesen.GUI.Forms
|
|||
}
|
||||
}
|
||||
}
|
||||
private class FieldInfoWrapper
|
||||
{
|
||||
private FieldInfo _fieldInfo;
|
||||
private PropertyInfo _propertyInfo;
|
||||
|
||||
public FieldInfoWrapper(PropertyInfo info)
|
||||
{
|
||||
_propertyInfo = info;
|
||||
}
|
||||
|
||||
public FieldInfoWrapper(FieldInfo info)
|
||||
{
|
||||
_fieldInfo = info;
|
||||
}
|
||||
|
||||
public Type FieldType
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_fieldInfo != null) {
|
||||
return _fieldInfo.FieldType;
|
||||
} else {
|
||||
return _propertyInfo.PropertyType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetValue(object obj, object value)
|
||||
{
|
||||
if(_fieldInfo != null) {
|
||||
_fieldInfo.SetValue(obj, value);
|
||||
} else {
|
||||
_propertyInfo.SetValue(obj, value);
|
||||
}
|
||||
}
|
||||
|
||||
public object GetValue(object obj)
|
||||
{
|
||||
if(_fieldInfo != null) {
|
||||
return _fieldInfo.GetValue(obj);
|
||||
} else {
|
||||
return _propertyInfo.GetValue(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum eNumberFormat
|
||||
|
|
Loading…
Add table
Reference in a new issue