简体   繁体   中英

How debugging works in MCU systems programmed in C

As I understand, on linux systems debugging is done via the ptrace sys-call.
I would like to know how would I write a debugger for a micro-controller (no-OS).
Let us for the sake of simplicity assume the case of a software debugger for a board like Arduino Due (ARM based).

  • What would I have to learn to accomplish such a project, assuming I have a fair idea on how debuggers work on Linux and Windows
  • How different would programming a debugger for a MCU system be? (I can't use sys-calls)
  • Is debugging achievable via USB or serial interface?
  • Which languages should I use? (C, C++, Arm assembly)
  • How can the armgcc compiler help me with my project (are there flag options such as -g etc?)

I plan to implement the debugger as a command line Linux utility.

Most modern processors, including the ARM on the Arduino Due have on-chip debug support accesses via a JTAG interface. The Cortex-M3 on-chip debug supports 8 hardware breakpoints and some other features - with code running in flash memory you cannot set software breakpoints.

The JTAG interface itself is rather simple, but you will need special hardware to support it from a PC. Depending of performance and features a JTAG debugger may vary in cost hugely from very low to serious money. Software to interface the JTAG to the debugger software is required. OpenOCD is an open source tool for interfacing JTAG/On-chip debug to GDB allowing GDB-ARM to be hosted on a PC to debug the remote ARM target.

You could in theory write your own software to to access the OCD via JTAG. I have never considered implementating a target hosted debugger on a microcontroller, although I have used VxWorks on ARM9, SrongARM and x86 and it has limited support for target hosted debugging. The utility of target hosted debug is limited by the lack of the source code and symbol table information that is available to a hosted debugger to support source-level debugging.

Even so, I believe that it is possible to access the on-chip debug from the target itself see ARM's documentation for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM