Breakpoints and Watchpoints

The JTAG debugger allows breakpoint and watchpoints to be set using hardware in the ST40 core. In some circumstances, these can be very useful, however, they are limited by the available debug hardware within the ST40.

Hardware breakpoints

A hardware breakpoint is set using the hbreak command. The syntax of the hbreak command is identical to the break command (the command that sets software breakpoints):

hbreak function|line|file:line|*address

A maximum of three hardware breakpoints can be set as the physical hardware does not support more than three at the same time. If used in conjunction with hardware watchpoints, it is only possible to have a combined total of three breakpoints and watchpoints at any one time.

Note: The number of software breakpoints is not limited by the hardware.

Hardware breakpoints can be used to debug applications running from read-only memory, where software breakpoints are not usable.

Hardware watchpoint support

To set a hardware watchpoint, use one of the commands listed in the table below, where location is a location expression (for example, an address or a symbolic object name).

CommandWhen triggered
rwatch location Read accesses only
watch location Write accesses only
awatch location Both read and write accesses only

A maximum of three hardware watchpoints can be set simultaneously as the physical hardware does not support more. If used in conjunction with hardware breakpoints it is only possible for a combined total of three hardware breakpoints and watchpoints to be set at any time.

Additionally, the ST40 hardware watchpoints have the ability to refine a watchpoint to only report matches when the CPU accesses the watched address range using a specific access size and ignoring accesses of other sizes. The CPU access sizes supported by the ST40 hardware watchpoints are 1, 2, 4 and 8 bytes. This feature is controlled using the use-watchpoint-access-size command. The following table lists the access size settings of the use-watchpoint-access-size command:

ModeDescription
off Access size checking is disabled. Any CPU access matching the watch conditions will be reported.
on Access size is enabled and is derived from the watched region size1. This is the default.
1 Enable 8-bit access size checking (for example, MOV.B Rm, @Rn)
2 Enable 16-bit access size checking (for example, MOV.W Rm, @Rn)
4 Enable 32-bit access size checking (for example, MOV.L Rm, @Rn)
8 Enable 64-bit access size checking (for example, FMOV when FPSCR.SZ=1)

1In this mode, access size checking is only performed if the size of the watched region is 1, 2 or 4 bytes; if not then access size checking is disabled for the watched region. Checking for 64-bit access sizes for a watch region of 8 bytes (or any watch region size) is only supported using the use-watchpoint-access-size command to set the access size checking mode to 8.

The access size checking mode set by the use-watchpoint-access-size command is global and is only applied to the hardware watchpoints when a target is restarted. Therefore, the order in which the use-watchpoint-access-size and hardware watchpoint commands are used is unimportant; the access size checking mode for hardware watchpoints only takes effect when the target is restarted.

Note that the ST40 hardware watchpoints have limited capability in the regions they are able to watch. If a watch region greater than 4 bytes is requested then the ST40 hardware is only able to watch a fixed range of memory region sizes and alignments. This is because the address comparator of the ST40 watchpoint hardware only supports the following options:

  • all bits compared
  • upper 22 bits compared (1KiB page)
  • upper 20 bits compared (4KiB page)
  • upper 16 bits compared (64KiB page)
  • upper 12 bits compared (1MiB page)
  • no bits compared (any address matches)

As a result, if the requested watch region does not match one of the above page sizes and alignments the GDB implementation selects the page size and alignment that covers the address range of the watch region. As a consequence, this results in spurious watchpoints being reported for addresses outside the requested watch region (the worst case being for watch regions that do not fit within a 1MiB page causing watchpoints to be reported for every memory access). Note that for watchpoints set using the watch command GDB only reports a watchpoint if the value of the data in watch region has been changed and not just written to.

Watch expressions can be used with literal addresses instead of symbols (which may require more than one hardware watchpoint to implement). For example, the following watches a 4-Kbyte region at the address 0x84001000 without any access size checking (and no page alignment issues):

use-watchpoint-access-size off 
watch *(unsigned char[4096] *) 0x84001000 
continue

GDB supports alternative forms of the watch expression, such as:

watch *(unsigned char *) 0x84001000 @ 4096

and:

watch {unsigned char} 0x84001000 @ 4096

GDB also supports software watchpoints. However, using software watchpoints reduces program performance significantly. For this reason, GDB will always set watchpoints in hardware if possible.