top of page

Knowing your Breakpoints

As developers we have all used breakpoints on a day-to-day basis. But do we know everything about them ? Read on...


What is a Breakpoint.?

A breakpoint makes your program stop whenever a certain point in the program is reached. For each breakpoint, you can add conditions to control in finer detail whether your program stops.


A breakpoint is a means of acquiring knowledge about a program during its execution. During the interruption, the programmer inspects the test environment (general purpose registers, memory, logs, files, etc.) to find out whether the program is functioning as expected.


Classification of Breakpoints

Classification can be done based on the either the condition or the implementation of the breakpoints.

Condition Based Breakpoints


Instruction Breakpoint:

Instruction Breakpoints are used to interrupt a running program immediately before the execution of a programmer-specified instruction.

Data breakpoint:

Data Breakpoints can also be placed based on other conditions such as reading, writing, or modification of a specific location in an area of memory.


There are 2 types of Data Breakpoints and they are usually known as Catchpoints and Watchpoints.

Catchpoint - Stops your program when a certain kind of event occurs.
Watchpoint - Stops your program when the value of an expression/variable changes.
 

Implementation based Breakpoints

The Instruction breakpoint implementation is the most commonly used breakpoint and is discussed below.

Hardware Breakpoint:

A Hardware Breakpoint is implemented by special logic that is integrated into the device.


To support the hardware breaking, the hardware usually contains programmable comparators (comparator – Register + compare logic). The comparators shall be programmed to hold specific addresses in the program where breaking is required.

Operation:

  • When the code is being executed, and the address on the program address bus match the address value written into any of the comparators, the Hardware breakpoint logic generates a signal to the CPU to Halt.

The availability and implementation of the hardware breakpoint are architecture dependent. The number of hardware breakpoints are usually limited (3 typically) as it requires dedicated hardware.

Software Breakpoint:


As the name states, this type of breakpoint is implemented in Software.


There is no dedicated hardware involvement as in the former case. The logic used for the breakpoint is purely handled in software. The hardware architecture usually contains a breakpoint instruction or opcode (typically 1 byte). Whenever a breakpoint is set at a particular instruction, the leading 1 byte of this instruction is replaced with the opcode corresponding to breakpoint instruction. In certain cases a normal HALT instruction may be used instead of a specific breakpoint instruction.

Operation :

  • The original 1 byte of the modified instruction is placed in the breakpoint table (similar to interrupt vector table). During execution whenever a breakpoint is encountered, the CPU halts and debugger replaces the breakpoint opcode with the original 8-bits of the instruction.

  • When the execution is resumed on user input, the debugger flushes the instruction pipeline and re-fetches the next set of instructions, this time with the original opcode instead of the breakpoint opcode. The execution then continues normally as if the instructions were not modified.

When the user tries to check the disassembly of the code where a software breakpoint is places, the breakpoint instruction opcode is not visible. This is usually abstracted from the user to avoid confusion.
 

Hardware Breakpoint vs Software Breakpoint


The hardware breakpoints have less overload due to the dedicated hardware. In case of software breakpoints the overload is high due to the flushing of instruction pipeline and re-fetching of instructions.

The Software breakpoints require modification of the executable binary and hence it shall not be possible in few cases where the binary is loaded into ROM/Flash. Adding SW breakpoints in the binary loaded in RAM is possible. No such memory specific limitation with Hardware breakpoints as the binary is not modified for adding breakpoints.

The advantage with SW breakpoints are that they can be unlimited unlike a very small number of HW breakpoints.

bottom of page