Debugger: Properly support division by 0 in expressions

This commit is contained in:
Sour 2017-12-29 22:08:50 -05:00
parent 423ac65a7e
commit 3fdc000a3d
4 changed files with 18 additions and 4 deletions

View file

@ -335,8 +335,19 @@ int32_t ExpressionEvaluator::Evaluate(vector<int> &rpnList, DebugState &state, E
resultType = EvalResultType::Numeric;
switch(token) {
case EvalOperators::Multiplication: token = left * right; break;
case EvalOperators::Division: token = left / right; break;
case EvalOperators::Modulo: token = left % right; break;
case EvalOperators::Division:
if(right == 0) {
resultType = EvalResultType::DivideBy0;
return 0;
}
token = left / right; break;
case EvalOperators::Modulo:
if(right == 0) {
resultType = EvalResultType::DivideBy0;
return 0;
}
token = left % right;
break;
case EvalOperators::Addition: token = left + right; break;
case EvalOperators::Substration: token = left - right; break;
case EvalOperators::ShiftLeft: token = left << right; break;

View file

@ -69,7 +69,8 @@ enum EvalResultType
{
Numeric = 0,
Boolean = 1,
Invalid = 2
Invalid = 2,
DivideBy0 = 3
};
class StringHasher

View file

@ -35,6 +35,7 @@ namespace Mesen.GUI.Debugger
case EvalResultType.Numeric: newValue = useHex ? ("$" + result.ToString("X2")) : result.ToString(); break;
case EvalResultType.Boolean: newValue = result == 0 ? "false" : "true"; break;
case EvalResultType.Invalid: newValue = "<invalid expression>"; forceHasChanged = true; break;
case EvalResultType.DivideBy0: newValue = "<division by zero>"; forceHasChanged = true; break;
}
list.Add(new WatchValueInfo() { Expression = expression, Value = newValue, HasChanged = forceHasChanged || (i < _previousValues.Count ? (_previousValues[i].Value != newValue) : false) });

View file

@ -1800,7 +1800,8 @@ namespace Mesen.GUI
{
Numeric = 0,
Boolean = 1,
Invalid = 2
Invalid = 2,
DivideBy0 = 3
}
public enum NesModel