Step 4: Debug Mode
Debug Mode
To set a breakpoint, select the desired line in the code editor. The red mark indicates where to click, and the blue mark highlights the breakpoint line. This action pauses program execution at the specified line during debugging, enabling inspection of variables and program flow.
The Program Counter (PC) holds the address of the next instruction to be executed; when a breakpoint is encountered, execution halts and the PC retains the address of that instruction until the user resumes the program.
A breakpoint is a debugging tool that pauses the execution of the program at a specific line, enabling the examination of the program's behavior and identification of any issues.

Connect the PIC32CM LS00 Curiosity Nano Evaluation Kit to the PC via USB. Open the project properties, under the Connected Hardware Tool section, select the PIC32CM LS00 Curiosity Nano + Touch Evaluation Kit as shown.

To explore Debug mode, click on the Debug Main Project icon as shown. The evaluation kit must be connected to a PC in order to explore Debug mode.

The following are the debug options available in the debug toolbar. These controls are standard in MPLAB® X IDE and are used to manage the debug session for a project:
- Finish Debugger Session
( shortcut: Shift + F5)- Ends the current debug session and closes the connection to the debug tool
- For multiple sessions, a specific session can be ended via the Sessions window
- Pause
(shortcut: Ctrl + Alt + 8)- Pauses the debugging operation without finishing the session
- Debug windows (memory, watches, etc.) update to reflect the current state of the device
- Reset

- Performs a processor reset
- Additional resets (POR/BOR, MCLR, System) are available depending on the device
- Continue (Resume)
(shortcut: F5)- Resumes debugging until the next breakpoint or the end of the program is reached
- Step Over
(shortcut: F8)- Executes one source line of the program
- If the line is a function call, the entire function executes, then stops
- Step Into
(shortcut: F7)- Executes one source line of the program
- If the line is a function call, the program up to the function's first statement executes and stops
- Step Out
(shortcut: Ctrl + F7)- Executes one source line of a program
- If the line is a function call, it executes the functions and returns control to the caller
- Run to Cursor
(shortcut: F4)- Runs the current project to the cursor's location in the file and stops program execution
- Set PC at Cursor

- Sets the program counter (PC) value to the line address of the cursor
- Focus Cursor at PC

- Moves the cursor to the current PC address and centers this address in the window
Once debugging begins, whether the breakpoint is triggered depends on its location in the code. The following image demonstrates a scenario where the breakpoint is successfully hit.

The following image illustrates a situation where the breakpoint is broken. Under normal operation, this line is never executed because the code runs within an infinite while loop.
