MPLAB® X IDE: Running A Debug Session
After ensuring the desired debug startup option has been set and ensuring the appropriate programmer/debugger has been chosen, a Debug Session can be started by clicking on the Main_Debug_Project.png Debug Project Icon.

Four things will happen when a debug session has been initiated:

  1. The project will build
  2. MPLAB® X IDE will connect to the selected debug tool and download the built image
  3. The Debug Icons will appear on the Toolbar
  4. The application in the PIC® MCU will run according to the debug startup option

An illustration of MPLAB X IDE's user interface immediately after a debug session has been started. This example shows the operation when the Debug Startup option is set to MAIN.

When the program being debugged is not running, the location of the Program Counter is shown on the screen with a green line.

Debug Icons

ToolbarDivider.png Debug_Finish_Debugger_Session.png Debug_Pause.png Debug_Reset.gif Debug_Continue.png Debug_Step_Over.png Debug_Step_Into.png Debug_Run_To_Cursor.png Debug_Set_PC_at_Cursor.gif Debug_Focus_Cursor_at_PC.gif ToolbarDivider.png

Step-by-Step Instructions:
Tour of the debug toolbar Icons

When a debug session has been started, a new toolbar will appear.
The Debug icon toolbar contains 9 buttons which allow for program control and ease of debugging.

Looking at Global Variables and SFRs

Global Variables (variable with fixed addresses and scope) can easily be viewed by the Watches window. When the Watches window is opened, you can add a list of variables to "watch". Each time the debug session pauses the program, the value of the items being watched is updated. PIC® Special Function Registers (SFR) work just like static variables and can be added to any Watches window.

Step-by-Step Instructions:
Setting up the Watches Window

To open the Watches window, select Window>Debugging>Watches from the toolbar. The Watches window will appear as a tab in the lower left-hand corner (where the Output window appears). Right-clicking anywhere in the Watches window will allow you to add or delete Watches.

Observing Local Variables

Local Variables (variables that exist only on the stack) can be viewed by the Variables window. When the Variables window is opened, the variables who are local to the active function are displayed. You have the choice of selecting all local variables or just those near the program counter.

Step-by-Step Instructions:
Setting up the Variables Window

To open the Variables window select Window>Debugging>Variables from the toolbar. Just like the Watches window, the Variables window will appear as a tab in the lower left-hand corner. The three icons on the left-hand side of the Variables window allow you to modify the range of the local variables displayed or to add Watches to the Variables window.

Adding Watches to the Variables window allows one window to display Global variables, SFRs, and Local Variables. Some users find it easier to debug with only one window show data values.

Finishing the Debug Session

When debugging has been completed and you wish to create an image which can run in the PIC MCU without the need of a programmer/debugger, two steps are needed. The first step is to end the debug session. Once the debug session has been ended you will need to create the production-ready image.

To end the debug session click on the 'Finish Debug Session' icon Debug_Finish_Debugger_Session.png.

Running a Debug Session with MPLAB X IDE

The video provided is using an older version of the MPLAB X IDE. However, there have been no significant changes to the interface and you should be able to follow the procedures as shown.

© 2022 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
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.