Debugger: Fixed expression evaluation when using multi-byte labels
+ Added "label out of scope" message for watch expressions using labels that can't be evaluated right now (but are valid labels)
This commit is contained in:
parent
8aa4d4a6ec
commit
a67003b347
5 changed files with 24 additions and 5 deletions
|
@ -105,6 +105,12 @@ bool ExpressionEvaluator::CheckSpecialTokens(string expression, size_t &pos, str
|
|||
} else {
|
||||
string originalExpression = expression.substr(initialPos, pos - initialPos);
|
||||
bool validLabel = _debugger->GetLabelManager()->ContainsLabel(originalExpression);
|
||||
if(!validLabel) {
|
||||
//Check if a multi-byte label exists for this name
|
||||
string label = originalExpression + "+0";
|
||||
validLabel = _debugger->GetLabelManager()->ContainsLabel(label);
|
||||
}
|
||||
|
||||
if(validLabel) {
|
||||
data.Labels.push_back(originalExpression);
|
||||
output += std::to_string(EvalValues::FirstLabelIndex + data.Labels.size() - 1);
|
||||
|
@ -292,12 +298,17 @@ int32_t ExpressionEvaluator::Evaluate(ExpressionData &data, DebugState &state, E
|
|||
int64_t labelIndex = token - EvalValues::FirstLabelIndex;
|
||||
if((size_t)labelIndex < data.Labels.size()) {
|
||||
token = _debugger->GetLabelManager()->GetLabelRelativeAddress(data.Labels[(uint32_t)labelIndex]);
|
||||
if(token < -1) {
|
||||
//Label doesn't exist, try to find a matching multi-byte label
|
||||
string label = data.Labels[(uint32_t)labelIndex] + "+0";
|
||||
token = _debugger->GetLabelManager()->GetLabelRelativeAddress(label);
|
||||
}
|
||||
} else {
|
||||
token = -1;
|
||||
token = -2;
|
||||
}
|
||||
if(token < 0) {
|
||||
//Label is no longer valid
|
||||
resultType = EvalResultType::Invalid;
|
||||
resultType = token == -1 ? EvalResultType::OutOfScope : EvalResultType::Invalid;
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
|
@ -502,5 +513,8 @@ void ExpressionEvaluator::RunTests()
|
|||
test("1+3*3+10/(3+4)", EvalResultType::Numeric, 11);
|
||||
test("(1+3*3+10)/(3+4)", EvalResultType::Numeric, 2);
|
||||
test("(1+3*3+10)/3+4", EvalResultType::Numeric, 10);
|
||||
|
||||
test("{$4500}", EvalResultType::Numeric, 0x4545);
|
||||
test("[$4500]", EvalResultType::Numeric, 0x45);
|
||||
}
|
||||
#endif
|
|
@ -73,7 +73,8 @@ enum EvalResultType : int32_t
|
|||
Numeric = 0,
|
||||
Boolean = 1,
|
||||
Invalid = 2,
|
||||
DivideBy0 = 3
|
||||
DivideBy0 = 3,
|
||||
OutOfScope = 4
|
||||
};
|
||||
|
||||
class StringHasher
|
||||
|
|
|
@ -159,11 +159,13 @@ int32_t LabelManager::GetLabelRelativeAddress(string &label)
|
|||
} else if((address & 0x30000000) == 0x30000000) {
|
||||
type = AddressType::Register;
|
||||
} else {
|
||||
//Label is out of scope
|
||||
return -1;
|
||||
}
|
||||
return _mapper->FromAbsoluteAddress(address & 0x0FFFFFFF, type);
|
||||
}
|
||||
return -1;
|
||||
//Label doesn't exist
|
||||
return -2;
|
||||
}
|
||||
|
||||
bool LabelManager::HasLabelOrComment(uint16_t relativeAddr)
|
||||
|
|
|
@ -49,6 +49,7 @@ namespace Mesen.GUI.Debugger
|
|||
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;
|
||||
case EvalResultType.OutOfScope: newValue = "<label out of scope>"; forceHasChanged = true; break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2164,7 +2164,8 @@ namespace Mesen.GUI
|
|||
Numeric = 0,
|
||||
Boolean = 1,
|
||||
Invalid = 2,
|
||||
DivideBy0 = 3
|
||||
DivideBy0 = 3,
|
||||
OutOfScope = 4
|
||||
}
|
||||
|
||||
public enum NesModel
|
||||
|
|
Loading…
Add table
Reference in a new issue