Using the Variables Window to Access Local Variables

Last modified by Microchip on 2023/11/10 12:00

What is the Variables Window?

The Variables window is the MPLAB® X IDE utility which allows you to observe and modify local variables (variables that have no permanent address and who exist on the stack). This window is part of the standard MPLAB X IDE debug tools and can be used anytime during an active debug session. The Variables window operates with all MPLAB development ecosystem support debug tools (software simulator, MPLAB ICD 3, MPLAB REAL ICE, and MPLAB PICkit™ 3). Many third-party debug tools and simulators also allow the Variables window to operate

Opening the Variables Window

To open the Variables window:

Make sure you are in a debug session.

Select Windows > Debugging > Variables or (atl + shft + 1).
variables opening

The Variables window will open up in the Output window section (usually the lower right-hand side).
variables opened
On the left-hand side of the Variables window, you will find three display control icons. These icons, along with the current location of the program counter, control which data is displayed in the Variables window.

three icons

Back to top


Accessing All Local Variables

The top-most icon in the group of three controls the range of local variables displayed. Clicking on this icon will toggle the window from displaying all the local variables in a particular function or specifying a range of variables. When the icon displays a set of curly braces { } all the local variables within the scope of the current function will display. The image below shows this icon set to display all the local variables in the function.
variables all local

The debug session must be paused within a function in order to see the local variables with just the Variables window. Please note the green bar is paused within the function foo() in the image above.

Back to top

Accessing Selected Local Variables

Occasionally you may find there are too many local variables displayed for you to easily process when a breakpoint is reached. The Variables window provides the ability to limit the number of variables displayed to only those variables accessed within two source code lines of the active breakpoint.  

To set the Variables window to display only variables near the program counter push the topmost control Icon until it displays a left-to-right green arrow. Below is an example of how to display only the local variables near the program counter.
variables near locals

Back to top

Adding Watches to the Variables Window

In addition to local variables, access to global variables and PIC® Special Function Registers (SFRs) is commonly needed during a debug session. The Variables window has the capability of displaying watches ( i.e. global variables and SFRs) in addition to local variables. Accessing watches in the Variables window is accomplished using the two lower control icons. The center icon allows you to choose whether or not to allow watches in the Variables window. When watches are enabled, the lowest control icon comes into focus and allows the user to enter a new watch into the Variables window.

The accompanying image shows a screenshot of an SFR being displayed in the Variables window.

variables watches and locals

Learn More

Back to top