Вы находитесь на странице: 1из 2

BREAKPOINTS

Definition
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
Classification can be done based on the either the condition or the implementation of the breakpoints.

Breakpoint conditions
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.

Breakpoint Implementations
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. 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.

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

Breakpoint Facts

1. When the user tries to check the disassembly of the code where a software breakpoint is
places, it shall be surprising to see that the breakpoint instruction opcode is not visible. Rather the original
instruction opcode is shown. This is because the IDE usually checks the breakpoint table for any content
before it displays the contents. If there is a breakpoint, the IDE always displays the original instruction
opcode.

2. Some IDEs are able to detect the memory map and places Hardware and Software
breakpoints accordingly.

3. There are 2 types of Data breakpoint and are usually termed as Catchpoint and Watchpoint
and not as breakpoints.
Catchpoint - stops your program when a certain kind of event occurs.
Watchpoint - stops your program when the value of an expression/variable changes.

Вам также может понравиться