Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are breakpoints working on an embedded device? [closed]

This is just a question for personal intrest. I know that my JTAG is able to read the register values of the uController. But I have no clue how the JTAG device knows when to stop the uController. I thought that maybe some code is added calling an interrupt but you are able to add breakpoints during operation therefore this seams to be wrong. So how is it done?

like image 965
Schafwolle Avatar asked Jan 06 '23 01:01

Schafwolle


2 Answers

As mentioned in a comment by @Martin James, the typical way this works is that the target hardware supports breakpoints natively.

The debugger then uses the JTAG interface to set on-chip registers to configure the breakpoints, and the actual "breaking" is then done by the chip itself.

This often means that the number of simultaneous breakpoints you can have is limited to some small number, since there is a limited amount of such hardware present.

This link describes the ARM Cortex-M0's debug hardware for instance, and says that is has (customer-selectable) 1 to at most 4 hardware breakpoints and up to two (2) watchpoints. So, pretty severely limited (but as an actual embedded developer, I see this and think "mmmm hardware breakpoints, such richness").

like image 64
unwind Avatar answered Jan 23 '23 11:01

unwind


@unwind Mentioned the hardware breakpoints already.

Some mcu's also offer a single step interrupt/mechanism.
After each instruction the code will be stopped, but the debugger doesn't need to set breakpoints each time for this single stepping.

And on some older mcu without hardware breakpoints, the breakpoints are realized by replacing instructions by a software interrupt instruction.
When the code resides in flash this is awful, as the flash has to reprogrammed for each breakpoint and this is typically very slow

like image 42
jeb Avatar answered Jan 23 '23 10:01

jeb