Export (0) Print
Expand All

Evaluating a Watch Window Expression 

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:

  1. Visual Studio calls the DE's IDebugStackFrame2::GetExpressionContext to get an expression context that can be used to evaluate expressions.

  2. For each expression in the watch list, Visual Studio calls IDebugExpressionContext2::ParseText to convert the expression text into a parsed expression.

  3. IDebugExpressionContext2::ParseText calls IDebugExpressionEvaluator::Parse to do the actual work of parsing the text and produce an IDebugParsedExpression object.

  4. IDebugExpressionContext2::ParseText creates an IDebugExpression2 object and puts the IDebugParsedExpression object into it. This IDebugExpression2 object is then returned to Visual Studio.

  5. Visual Studio calls IDebugExpression2::EvaluateSync to evaluate the parsed expression.

  6. IDebugExpression2::EvaluateSync passes the call to IDebugParsedExpression::EvaluateSync to do the actual evaluation and produce an IDebugProperty2 object that is returned to Visual Studio.

  7. Visual Studio calls IDebugProperty2::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.

NoteNote

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 IDebugParsedExpression::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).

See Also

Community Additions

ADD
Show:
© 2014 Microsoft