Variables Window

 Summary

When debugging an MPLAB® X project you may find it useful to view the variables and PIC Special Function Registers ( SFRs). Global Variables and SFRs have permanent and fixed memory devices. All programs can access these data elements at any time. Local variables, those defined within a function, have no fixed addresses. Local veriables exist on the software stack only during the period of time the function is being executed. While transient, the value of local variables may be essential in debugging an application. This page shows how to access local variables. At the end of this page is a link to a tutorial demonstrating how to access local variables

What is the Variables Window

The Variables Window is the MPLAB X utilty which allows the user to observe and modify Local Variables ( variables who have no permanent address and who exist on the stack). This window is the part of the standard MPLABX debug tools and can be used anytime during an active debug session. The variables window operates with all MPLABX support debug tools ( software simulator, ICD3, RealICE, and PICKit3) Many 3rd party debug tools and simulators also allow the Variables window to operate

In order to operate the Variables Window MPLAB X must be in operating with an active debug Main_Debug_Project.png session.

1 How to Open the Variables Window

To open the Variables window:

  1. Make sure you are in a debug session
  2. Select Windows->-Debugging->Variables or ( atl + shft + 1)
opening.png



The variables window will open up in the output window section ( usually the lower right-hand side)

Opened.png



On the Left hand side of the Variables Windows 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

3Icons.png

2 Accessing ALL the 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 variable. When the Icon display 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.

All_local.png

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

Accessing Selected local variables

Occasionally you will find too many variable within the current frame to easily view. The variables window allows you to view the variables "near" the current Program Counter location. By near it is meant you can view any locate variable modify in the line pointed to by the Program Counter and the line immediately before the current program counter. This will allow you to set breakpoints and see just the local variables values as they are accessed by the program.

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

Near_locals.png

Adding Watches to the Variables Window

In addition to local variables access to Global Variables and PIC Special Function Registers (SFRs) are commonly needed during a debug session. The Variables Window has the capability of dislaying Watches ( i.e. Global Variable and SFRs) in addition to local variables. Accessing Watches in the Variable Windows is accomplished using the two lower control Icons. The Center Icon allow whether or not to allow Watches in the Variables Window. When Watches are enabled the lowest control Icon comes into focus and allow the user to enter a new watch into the Variables Window.

the Image below shows a screen shot of an SFR being displayed in the Variables Window

WatchesandLocals.png
When displayed Locals variables will be displayed next to a green side-ways sqaure: Window_Debugging_Variables.png while Watches will be displayed using a Diamond Icon Window_Debugging_Watches.png

Video Example of Using the Variables Window

20th Annual
Microchip MASTERs Conference 2016
Register now - Deadline: July 29

JW Marriott Desert Ridge Resort-Phoenix, AZ

© 2016 Microchip Technology, Inc.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.