Line Breakpoints Lab

 Objective

For this lab we will set a common line breakpoint and observe its behavior in a disassembly window as a:

  • hardware breakpoint
  • software breakpoint
  • breakpoint in the simulator.

 Materials

Hardware Tools

Tool About Purchase
Explorer16-50px.png
Explorer 16
Development Board
REALICE-50px.png
MPLAB® REAL ICE™
In-Circuit Emulator
ICD3-50px.png
MPLAB® ICD 3
In-Circuit Debugger

If using hardware, either the REAL ICE™ or MPLAB® ICD 3 can be used with the Explorer 16 Development Board.

Software Tools

Tool About Installers
Installation
Instructions
Windows Linux Mac OSX
MPLAB® X
Integrated Development Environment
MPLAB® XC16
C Compiler

This lab was tested using MPLAB X v3.00.

Exercise Files

File Download
Installation
Instructions
Windows Linux Mac OSX
Project and Source Files

 Procedure

1

Open the project Breakpoints.X

Click on the Open Project button Main_Open_Project.png and open the Breakpoints.X project. If you have not downloaded the files, you can find them in the Exercise Files section of this page.

Each exercise of this lab will make use of the Action Items window and a pre-configured Watches window. Please follow the steps below to open them now.

2

Open the Watches window

Display the Watches tab by selecting it from the menu: Window > Debugging > Watches.

3

Open the saved Watches window

Click on the Gem and Folder button in the window’s sidebar.

SavedWatches.png

In the file dialog that opens, select the ..\Breakpoints.X\Breakpoints.xwatch file and click the Select button.

4

Open the Action Items window

Display the Action Items tab by selecting from the menu: Window > Action Items. When done, you should have at least three tabs open at the bottom right of the Integrated Development Environment (IDE). If for some reason the Output tab isn’t visible, it should open automatically when a project is built.

ActionItems.png

5

Set a line breakpoint

In the Action Items window, double-click on [Exercise 1]. This will take you to a comment immediately above the line of code we are interested in. In the glyph margin (grey bar on left of editor with line numbers), left-click on the line number next to the code LATA = 0;.

6

Debug the project

a

Make sure that the Configuration box on the toolbar (Main_Combo_Box.png) shows REAL_ICE.

Even if the debugger you have connected is the ICD 3, selecting REAL_ICE as the configuration will work.

b

Click on the Debug Project button: Main_Debug_Project.png

This will build the project in debug mode, program the target through the REAL ICE/ICD 3, and run the program. The debugger should pause the program when the breakpoint is hit. You should notice that the program counter (indicated by a green arrow in the glyph margin) points to the next line of code. This is an example of skid. Let’s take a look at what is happening at the machine level.

7

Open the Disassembly window

From the menu, select: Window > Debugging > Disassembly.

Here we can see exactly how far the skid took us. The line we set the breakpoint on consists of two assembly instructions (un-optimized). When working with a hardware debugger, the instruction where the breakpoint is set must complete execution and the one instruction in the pipeline must also be executed completely so that the program can branch into the debug kernel and give you control from the IDE. Therefore, the program counter sits two instructions after the break, ready to execute the line it points to.

SkidEffect.png

8

End the debug session

Click on the Finish Debugger Session button: Debug_Finish_Debugger_Session.png

9

Enable software breakpoints

Go to the Dashboard tab. If it is already open, it may be at the top left along with the Projects tab, or the bottom left by the Navigator tab. If it is not open, select from the menu: Window > Dashboard. On the left side of this window, there is a sidebar with several icons. Click on the third one down to toggle software breakpoints on. After doing so, you should see them enabled under the Debug Resources section of the Dashboard.

ToggleSoftwareBPs.png

10

Debug the project

a

Make sure that the Configuration box on the toolbar (Main_Combo_Box.png) shows REAL_ICE.

b

Click on the Debug Project button: Main_Debug_Project.png

Everything should work as it did in Step 6 until you hit the breakpoint. Before the code halts, you should see the following in the REAL ICE tab:
Setting software breakpoints…….
Setting software breakpoints complete.

Target halted due to Software Breakpoint in user code
You should also notice that the green arrow representing the program counter is sitting right on top of the red square representing the breakpoint. It looks as if there is no skid. To verify this, let’s take a look at the machine view of things.

11

Open the Disassembly window

From the menu, select: Window > Debugging > Disassembly.

Here we can see that there is no skid whatsoever. The program counter is sitting on the very first instruction of the assembly code that implements LATA = 0;.

DisassemblyWindow.png

12

Switch to the simulator

a

Click on the Finish Debugger Session button: Debug_Finish_Debugger_Session.png

b

Change the Configuration box on the toolbar (Main_Combo_Box.png) to show Simulator.

13

Debug the project

a

Click on the Debug Project button: Main_Debug_Project.png

b

From the menu, select: Window > Debugging > Disassembly. The Disassembly window should look exactly as it did with software breakpoints. As was the case with software breakpoints, the simulator never exhibits skid. The program should stop immediately on the instruction where the breakpoint was set.

14

Clean up for the next exercise

a

Click on the Finish Debugger Session button: Debug_Finish_Debugger_Session.png

b

Change the Configuration box on the toolbar (Main_Combo_Box.png) to show REAL_ICE.

c

Disable software breakpoints by clicking on the same button you used to enable them in the Dashboard window (third down on the left).

d

Remove the line breakpoint you set in the main source file by clicking on its icon in the glyph margin. If you can’t find it, double-click on [Exercise 1] in the Action Items tab to take you to the lines immediately above it.

 Conclusions

This lab exercise showed how a line breakpoint behaves differently as a hardware breakpoint, a software breakpoint, and a breakpoint in the simulator.

© 2024 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.