Evaluating a Watch Window Expression
Note
This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
Important
In Visual Studio 2015, this way of implementing expression evaluators is deprecated. For information about implementing CLR expression evaluators, please see CLR Expression Evaluators and Managed Expression Evaluator Sample.
When execution pauses, Visual Studio calls the debug engine (DE) to determine the current value of each expression in its watch list. The DE evaluates each expression using an expression evaluator (EE), and Visual Studio displays its value in the Watch window.
Here is an overview of how a watch list expression is evaluated:
Visual Studio calls the DE's GetExpressionContext to get an expression context that can be used to evaluate expressions.
For each expression in the watch list, Visual Studio calls ParseText to convert the expression text into a parsed expression.
IDebugExpressionContext2::ParseText
calls Parse to do the actual work of parsing the text and produce an IDebugParsedExpression object.IDebugExpressionContext2::ParseText
creates an IDebugExpression2 object and puts theIDebugParsedExpression
object into it. This IDebugExpression2
object is then returned to Visual Studio.Visual Studio calls EvaluateSync to evaluate the parsed expression.
IDebugExpression2::EvaluateSync
passes the call to EvaluateSync to do the actual evaluation and produce an IDebugProperty2 object that is returned to Visual Studio.Visual Studio calls GetPropertyInfo to obtain the value of the expression that is then displayed in the watch list.
Parse Then Evaluate
Since parsing a complex expression can take much longer than evaluating it, the process of evaluating an expression is broken up into two steps: 1) parse the expression and 2) evaluate the parsed expression. This way, evaluation can occur many times but the expression needs to be parsed only once. The intermediate parsed expression is returned from the EE in an IDebugParsedExpression object that is in turn encapsulated and returned from the DE as an IDebugExpression2 object. The IDebugExpression
object defers all evaluation to the IDebugParsedExpression
object.
Note
It is not necessary for an EE to adhere to this two-step process even though Visual Studio assumes this; the EE can parse and evaluate in the same step when EvaluateSync is called (this is how the MyCEE sample works, for example). If your language can form complex expressions, you may want to separate the parse step from the evaluation step. This can increase performance in the Visual Studio debugger when many watch expressions are being shown.
In This Section
Sample Implementation of Expression Evaluation
Uses the MyCEE sample to step through the process of expression evaluation.
Evaluating a Watch Expression
Explains what happens after a successful expression parse.
Related Sections
Evaluation Context
Provides the arguments that are passed when the debug engine (DE) calls the expression evaluator (EE).