ARM®v8‑M processors provide hardware features that enable debug tools to collect information about core activity and program execution, halt the core, and step through code execution.
You can set software or hardware breakpoints on specific instructions, causing the debugger to take control when the core reaches that instruction.
Software breakpoints work by replacing the instruction with the opcode of the
BKPT instruction. Software breakpoints can only be used on code
that is stored in RAM, but have the advantage that they can be used in large numbers.
The debug software tracks where it has placed software breakpoints and what opcodes
originally at those addresses so that it can replace the correct code when executing
Hardware breakpoints use comparators that are built into the core and stop execution when execution reaches the specified address. Hardware breakpoints can be used anywhere in memory as they do not require changes to code, but the hardware provides limited numbers of hardware breakpoint units.
Debug tools can support more complex breakpoints. For example, stopping on any instruction in a range of addresses, or only when a specific sequence of events occurs or hardware is in a specific state.
Data watchpoints, or breakpoints, give debugger control when a particular data address or address range is read or written. On hitting a breakpoint, or when single-stepping, you can inspect and change the contents of ARM registers and memory. A special case of changing memory is code download. Debug tools typically enable you to change your code, recompile, and then download the new image to the system.