Variables

Overview

The Debug Model tutorial gave an overview of the Standard Debug Model interfaces used to populate the Debug view.  This tutorial takes a closer look at the IVariable object and how it is presented in the Variables view.

Active Debug Context

The Variables view uses the Active Debug Context as its input.  The Active Debug Context is a selection driven by the active Debug Context Provider (IDebugContextProvider) in a given window. Typically the only debug context provider is Debug view.  The Variables view is a listener (IDebugContextListener) to changes in the Active Debug Context, and it updates itself whenever this context changes.
Variables Active Context Diagram
Diagram illustrating relationship between Debug view, the Active Debug Context, and Variables view input.

Model Elements

The list of top-level IVariable objects is contained in the IStackFrame object.  The value of the variable is represented by a separate IValue object contained by the variable.  The value object can in turn contain more variable objects, which are shown as children of the containing variable. 
Variables Model Diagram
Class diagram of IVariable object.

The Variables view is "lazy-loading" and it requests data from the model only as needed.  For example, after the initial list of variable objects is retrieved from the stack frame, the value objects are retrieved from the variables only for the variables that are visible in the view.  As user scrolls the view, additional values are retrieved from the model.

Exercise

This tutorial contains an exercise to implement a value object so that it returns the variable's children. From the Welcome Samples Page (Help -> Welcome -> Samples) Import the Push Down Automata (PDA) sample into your project, then follow the steps above to implement the variables children feature.  Hint: to quickly find the locations in the code that need to be completed, search for the text "Exercise 5", or look for it in the Tasks view.

Answers